source: josm/trunk/scripts/SyncEditorLayerIndex.groovy@ 13533

Last change on this file since 13533 was 13533, checked in by stoecker, 8 years ago

enable new checks

  • Property svn:eol-style set to native
File size: 41.3 KB
RevLine 
[7726]1// License: GPL. For details, see LICENSE file.
2/**
[11854]3 * Compare and analyse the differences of the editor layer index and the JOSM imagery list.
[7726]4 * The goal is to keep both lists in sync.
5 *
[11854]6 * The editor layer index project (https://github.com/osmlab/editor-layer-index)
[11694]7 * provides also a version in the JOSM format, but the GEOJSON is the original source
[7726]8 * format, so we read that.
9 *
10 * How to run:
11 * -----------
12 *
13 * Main JOSM binary needs to be in classpath, e.g.
14 *
[11854]15 * $ groovy -cp ../dist/josm-custom.jar SyncEditorLayerIndex.groovy
[9667]16 *
[7726]17 * Add option "-h" to show the available command line flags.
18 */
[11967]19import java.text.DecimalFormat
[7726]20import javax.json.Json
21import javax.json.JsonArray
22import javax.json.JsonObject
23import javax.json.JsonReader
24
[9953]25import org.openstreetmap.josm.data.imagery.ImageryInfo
[11410]26import org.openstreetmap.josm.data.imagery.Shape
[13526]27import org.openstreetmap.josm.data.projection.Projections;
[7726]28import org.openstreetmap.josm.io.imagery.ImageryReader
29
[11854]30class SyncEditorLayerIndex {
[7726]31
32 List<ImageryInfo> josmEntries;
[11582]33 JsonArray eliEntries;
[7726]34
[11582]35 def eliUrls = new HashMap<String, JsonObject>()
[7726]36 def josmUrls = new HashMap<String, ImageryInfo>()
[11420]37 def josmMirrors = new HashMap<String, ImageryInfo>()
[13530]38 static def oldproj = new HashMap<String, String>()
39 static def ignoreproj = new LinkedList<String>()
[9667]40
[11965]41 static String eliInputFile = 'imagery_eli.geojson'
42 static String josmInputFile = 'imagery_josm.imagery.xml'
43 static String ignoreInputFile = 'imagery_josm.ignores.txt'
[12066]44 static FileOutputStream outputFile = null
45 static OutputStreamWriter outputStream = null
[11582]46 def skip = [:]
[9505]47
[7726]48 static def options
[9658]49
[7726]50 /**
51 * Main method.
52 */
53 static main(def args) {
[11967]54 Locale.setDefault(Locale.ROOT);
[7726]55 parse_command_line_arguments(args)
[11854]56 def script = new SyncEditorLayerIndex()
[13530]57 script.setupProj()
[9505]58 script.loadSkip()
[9658]59 script.start()
[7726]60 script.loadJosmEntries()
[11964]61 if(options.josmxml) {
[12066]62 def file = new FileOutputStream(options.josmxml)
63 def stream = new OutputStreamWriter(file, "UTF-8")
[11964]64 script.printentries(script.josmEntries, stream)
[12066]65 stream.close();
66 file.close();
[11964]67 }
[11582]68 script.loadELIEntries()
[11964]69 if(options.elixml) {
[12066]70 def file = new FileOutputStream(options.elixml)
71 def stream = new OutputStreamWriter(file, "UTF-8")
[11964]72 script.printentries(script.eliEntries, stream)
[12066]73 stream.close();
74 file.close();
[11964]75 }
[7726]76 script.checkInOneButNotTheOther()
77 script.checkCommonEntries()
[9658]78 script.end()
[9505]79 if(outputStream != null) {
80 outputStream.close();
81 }
82 if(outputFile != null) {
83 outputFile.close();
84 }
[7726]85 }
[9653]86
[7726]87 /**
88 * Parse command line arguments.
89 */
90 static void parse_command_line_arguments(args) {
[9658]91 def cli = new CliBuilder(width: 160)
[9505]92 cli.o(longOpt:'output', args:1, argName: "output", "Output file, - prints to stdout (default: -)")
[11854]93 cli.e(longOpt:'eli_input', args:1, argName:"eli_input", "Input file for the editor layer index (geojson). Default is $eliInputFile (current directory).")
[9505]94 cli.j(longOpt:'josm_input', args:1, argName:"josm_input", "Input file for the JOSM imagery list (xml). Default is $josmInputFile (current directory).")
[11238]95 cli.i(longOpt:'ignore_input', args:1, argName:"ignore_input", "Input file for the ignore list. Default is $ignoreInputFile (current directory).")
[7726]96 cli.s(longOpt:'shorten', "shorten the output, so it is easier to read in a console window")
[9505]97 cli.n(longOpt:'noskip', argName:"noskip", "don't skip known entries")
[9658]98 cli.x(longOpt:'xhtmlbody', argName:"xhtmlbody", "create XHTML body for display in a web page")
99 cli.X(longOpt:'xhtml', argName:"xhtml", "create XHTML for display in a web page")
[11964]100 cli.p(longOpt:'elixml', args:1, argName:"elixml", "ELI entries for use in JOSM as XML file (incomplete)")
101 cli.q(longOpt:'josmxml', args:1, argName:"josmxml", "JOSM entries reoutput as XML file (incomplete)")
[11965]102 cli.m(longOpt:'noeli', argName:"noeli", "don't show output for ELI problems")
[7726]103 cli.h(longOpt:'help', "show this help")
104 options = cli.parse(args)
105
106 if (options.h) {
107 cli.usage()
108 System.exit(0)
109 }
[11582]110 if (options.eli_input) {
111 eliInputFile = options.eli_input
[7726]112 }
113 if (options.josm_input) {
114 josmInputFile = options.josm_input
115 }
[11238]116 if (options.ignore_input) {
117 ignoreInputFile = options.ignore_input
118 }
[9505]119 if (options.output && options.output != "-") {
[12066]120 outputFile = new FileOutputStream(options.output)
121 outputStream = new OutputStreamWriter(outputFile, "UTF-8")
[9505]122 }
[7726]123 }
124
[13530]125 void setupProj() {
126 oldproj.put("EPSG:3359", "EPSG:3404")
127 oldproj.put("EPSG:3785", "EPSG:3857")
128 oldproj.put("EPSG:31297", "EPGS:31287")
[13533]129 oldproj.put("EPSG:31464", "EPSG:31468")
[13530]130 oldproj.put("EPSG:54004", "EPSG:3857")
131 oldproj.put("EPSG:102100", "EPSG:3857")
132 oldproj.put("EPSG:102113", "EPSG:3857")
133 oldproj.put("EPSG:900913", "EPGS:3857")
134 ignoreproj.add("EPSG:4267")
135 ignoreproj.add("EPSG:5221")
136 ignoreproj.add("EPSG:5514")
137 ignoreproj.add("EPSG:32019")
138 ignoreproj.add("EPSG:102066")
139 ignoreproj.add("EPSG:102067")
140 ignoreproj.add("EPSG:102685")
141 ignoreproj.add("EPSG:102711")
142 }
143
[9505]144 void loadSkip() {
[12061]145 def fr = new InputStreamReader(new FileInputStream(ignoreInputFile), "UTF-8")
[11238]146 def line
147
148 while((line = fr.readLine()) != null) {
[11582]149 def res = (line =~ /^\|\| *(ELI|Ignore) *\|\| *\{\{\{(.+)\}\}\} *\|\|/)
[11238]150 if(res.count)
151 {
[11582]152 if(res[0][1].equals("Ignore")) {
153 skip[res[0][2]] = "green"
[11238]154 } else {
[11582]155 skip[res[0][2]] = "darkgoldenrod"
[11238]156 }
157 }
[11234]158 }
[11238]159 }
[9653]160
[9658]161 void myprintlnfinal(String s) {
162 if(outputStream != null) {
[12067]163 outputStream.write(s+System.getProperty("line.separator"))
[9658]164 } else {
[11964]165 println s
[9658]166 }
167 }
168
[9505]169 void myprintln(String s) {
[11582]170 if(skip.containsKey(s)) {
171 String color = skip.get(s)
172 skip.remove(s)
[9658]173 if(options.xhtmlbody || options.xhtml) {
[11582]174 s = "<pre style=\"margin:3px;color:"+color+"\">"+s.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")+"</pre>"
[9658]175 }
[9662]176 if (!options.noskip) {
[11964]177 return
[9662]178 }
[9658]179 } else if(options.xhtmlbody || options.xhtml) {
[13526]180 String color = s.startsWith("***") ? "black" : ((s.startsWith("+ ") || s.startsWith("+++ ELI")) ? "blue" :
181 (s.startsWith("#") ? "indigo" : (s.startsWith("!") ? "orange" : "red")))
[9658]182 s = "<pre style=\"margin:3px;color:"+color+"\">"+s.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")+"</pre>"
[9505]183 }
[12246]184 if ((s.startsWith("+ ") || s.startsWith("+++ ELI") || s.startsWith("#")) && options.noeli) {
[11965]185 return
186 }
[9658]187 myprintlnfinal(s)
188 }
189
190 void start() {
191 if (options.xhtml) {
192 myprintlnfinal "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
[11582]193 myprintlnfinal "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/><title>JOSM - ELI differences</title></head><body>\n"
[9505]194 }
195 }
[9653]196
[9658]197 void end() {
[11582]198 for (def s: skip.keySet()) {
[9658]199 myprintln "+++ Obsolete skip entry: " + s
200 }
201 if (options.xhtml) {
202 myprintlnfinal "</body></html>\n"
203 }
204 }
205
[11582]206 void loadELIEntries() {
207 FileReader fr = new FileReader(eliInputFile)
[7726]208 JsonReader jr = Json.createReader(fr)
[11582]209 eliEntries = jr.readObject().get("features")
[7726]210 jr.close()
[9653]211
[11582]212 for (def e : eliEntries) {
[12242]213 def url = getUrlStripped(e)
[9653]214 if (url.contains("{z}")) {
[11582]215 myprintln "+++ ELI-URL uses {z} instead of {zoom}: "+url
[9653]216 url = url.replace("{z}","{zoom}")
217 }
[11582]218 if (eliUrls.containsKey(url)) {
219 myprintln "+++ ELI-URL is not unique: "+url
[9505]220 } else {
[11582]221 eliUrls.put(url, e)
[9505]222 }
[13530]223 def s = e.get("properties").get("available_projections")
224 if (s) {
225 def old = new LinkedList<String>()
226 for (def p : s) {
227 def proj = p.getString()
228 if(oldproj.containsKey(proj) || ("CRS:84".equals(proj) && !(url =~ /(?i)version=1\.3/))) {
229 old.add(proj)
230 }
231 }
232 if (old) {
233 def str = String.join(", ", old)
234 myprintln "+ ELI Projections ${str} not useful: ${getDescription(e)}"
235 }
236 }
[7726]237 }
[11582]238 myprintln "*** Loaded ${eliEntries.size()} entries (ELI). ***"
[7726]239 }
[11975]240 String cdata(def s, boolean escape = false) {
241 if(escape) {
242 return s.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;")
243 } else if(s =~ /[<>&]/)
[11968]244 return "<![CDATA[$s]]>"
245 return s
246 }
[7726]247
[11967]248 String maininfo(def entry, String offset) {
[11975]249 String t = getType(entry)
250 String res = offset + "<type>$t</type>\n"
[11968]251 res += offset + "<url>${cdata(getUrl(entry))}</url>\n"
[13474]252 if(getMinZoom(entry) != null)
253 res += offset + "<min-zoom>${getMinZoom(entry)}</min-zoom>\n"
254 if(getMaxZoom(entry) != null)
255 res += offset + "<max-zoom>${getMaxZoom(entry)}</max-zoom>\n"
[13476]256 if (t == "wms") {
[11975]257 def p = getProjections(entry)
258 if (p) {
259 res += offset + "<projections>\n"
260 for (def c : p)
261 res += offset + " <code>$c</code>\n"
262 res += offset + "</projections>\n"
263 }
[11967]264 }
265 return res
266 }
[12061]267
[11964]268 void printentries(def entries, def stream) {
[11967]269 DecimalFormat df = new DecimalFormat("#.#######")
270 df.setRoundingMode(java.math.RoundingMode.CEILING)
[11964]271 stream.write "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
272 stream.write "<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n"
273 for (def e : entries) {
274 def best = "eli-best".equals(getQuality(e))
275 stream.write " <entry"+(best ? " eli-best=\"true\"" : "" )+">\n"
[11975]276 stream.write " <name>${cdata(getName(e), true)}</name>\n"
[11964]277 stream.write " <id>${getId(e)}</id>\n"
[11968]278 def t
279 if((t = getDate(e)))
280 stream.write " <date>$t</date>\n"
281 if((t = getCountryCode(e)))
282 stream.write " <country-code>$t</country-code>\n"
[12226]283 if((getDefault(e)))
284 stream.write " <default>true</default>\n"
[11975]285 stream.write maininfo(e, " ")
286 if((t = getAttributionText(e)))
287 stream.write " <attribution-text mandatory=\"true\">${cdata(t, true)}</attribution-text>\n"
288 if((t = getAttributionUrl(e)))
289 stream.write " <attribution-url>${cdata(t)}</attribution-url>\n"
[12261]290 if((t = getLogoImage(e)))
291 stream.write " <logo-image>${cdata(t, true)}</logo-image>\n"
292 if((t = getLogoUrl(e)))
293 stream.write " <logo-url>${cdata(t)}</logo-url>\n"
[11975]294 if((t = getTermsOfUseText(e)))
295 stream.write " <terms-of-use-text>${cdata(t, true)}</terms-of-use-text>\n"
296 if((t = getTermsOfUseUrl(e)))
297 stream.write " <terms-of-use-url>${cdata(t)}</terms-of-use-url>\n"
298 if((t = getPermissionReferenceUrl(e)))
299 stream.write " <permission-ref>${cdata(t)}</permission-ref>\n"
300 if((getValidGeoreference(e)))
301 stream.write " <valid-georeference>true</valid-georeference>\n"
[11968]302 if((t = getIcon(e)))
303 stream.write " <icon>${cdata(t)}</icon>\n"
[11975]304 for (def d : getDescriptions(e)) {
305 stream.write " <description lang=\"${d.getKey()}\">${d.getValue()}</description>\n"
306 }
[11967]307 for (def m : getMirrors(e)) {
308 stream.write " <mirror>\n"+maininfo(m, " ")+" </mirror>\n"
309 }
[11964]310 def minlat = 1000
311 def minlon = 1000
312 def maxlat = -1000
313 def maxlon = -1000
314 def shapes = ""
315 def sep = "\n "
316 for(def s: getShapes(e)) {
317 shapes += " <shape>"
318 def i = 0
319 for(def p: s.getPoints()) {
320 def lat = p.getLat()
321 def lon = p.getLon()
322 if(lat > maxlat) maxlat = lat
323 if(lon > maxlon) maxlon = lon
324 if(lat < minlat) minlat = lat
325 if(lon < minlon) minlon = lon
326 if(!(i++%3)) {
327 shapes += sep + " "
328 }
[11967]329 shapes += "<point lat='${df.format(lat)}' lon='${df.format(lon)}'/>"
[11964]330 }
331 shapes += sep + "</shape>\n"
332 }
333 if(shapes) {
[11967]334 stream.write " <bounds min-lat='${df.format(minlat)}' min-lon='${df.format(minlon)}' max-lat='${df.format(maxlat)}' max-lon='${df.format(maxlon)}'>\n"
[11964]335 stream.write shapes + " </bounds>\n"
336 }
[11967]337 stream.write " </entry>\n"
[11964]338 }
339 stream.write "</imagery>\n"
340 stream.close()
341 }
342
[7726]343 void loadJosmEntries() {
344 def reader = new ImageryReader(josmInputFile)
345 josmEntries = reader.parse()
[9667]346
[7726]347 for (def e : josmEntries) {
[12242]348 def url = getUrlStripped(e)
[9658]349 if (url.contains("{z}")) {
350 myprintln "+++ JOSM-URL uses {z} instead of {zoom}: "+url
351 url = url.replace("{z}","{zoom}")
352 }
[9505]353 if (josmUrls.containsKey(url)) {
354 myprintln "+++ JOSM-URL is not unique: "+url
355 } else {
[11420]356 josmUrls.put(url, e)
[7726]357 }
[9658]358 for (def m : e.getMirrors()) {
[12242]359 url = getUrlStripped(m)
[11574]360 m.origName = m.getOriginalName().replaceAll(" mirror server( \\d+)?","")
[9658]361 if (josmUrls.containsKey(url)) {
362 myprintln "+++ JOSM-Mirror-URL is not unique: "+url
363 } else {
[11420]364 josmUrls.put(url, m)
365 josmMirrors.put(url, m)
[9658]366 }
367 }
[7726]368 }
[9505]369 myprintln "*** Loaded ${josmEntries.size()} entries (JOSM). ***"
[7726]370 }
371
[13517]372 List inOneButNotTheOther(Map m1, Map m2, String code, String https) {
[7726]373 def l = []
[13518]374 def k = new LinkedList<String>(m1.keySet())
375 for (def url : k) {
[7726]376 if (!m2.containsKey(url)) {
[13517]377 String urlhttps = url.replace("http:","https:")
378 if(!https || !m2.containsKey(urlhttps))
379 {
380 def name = getName(m1.get(url))
381 l += code+" "+getDescription(m1.get(url))
382 }
383 else
384 {
385 l += https+" Missing https: "+getDescription(m1.get(url))
[13518]386 m1.put(urlhttps, m1.get(url))
387 m1.remove(url)
[13517]388 }
[7726]389 }
390 }
391 l.sort()
392 }
[9667]393
[7726]394 void checkInOneButNotTheOther() {
[13517]395 def l1 = inOneButNotTheOther(eliUrls, josmUrls, "-", "+")
[11582]396 myprintln "*** URLs found in ELI but not in JOSM (${l1.size()}): ***"
[9658]397 if (!l1.isEmpty()) {
[11412]398 for (def l : l1) {
[13517]399 myprintln l
[11412]400 }
[7726]401 }
402
[13517]403 def l2 = inOneButNotTheOther(josmUrls, eliUrls, "+", "")
[11582]404 myprintln "*** URLs found in JOSM but not in ELI (${l2.size()}): ***"
[9658]405 if (!l2.isEmpty()) {
[11412]406 for (def l : l2) {
[13517]407 myprintln l
[11412]408 }
[7726]409 }
410 }
[9667]411
[7726]412 void checkCommonEntries() {
[9505]413 myprintln "*** Same URL, but different name: ***"
[11582]414 for (def url : eliUrls.keySet()) {
415 def e = eliUrls.get(url)
[7726]416 if (!josmUrls.containsKey(url)) continue
417 def j = josmUrls.get(url)
[12061]418 def ename = getName(e).replace("'","\u2019")
419 def jname = getName(j).replace("'","\u2019")
[11951]420 if (!ename.equals(jname)) {
[12242]421 myprintln "* Name differs ('${getName(e)}' != '${getName(j)}'): ${getUrl(j)}"
[7726]422 }
423 }
[9667]424
[12226]425 myprintln "*** Same URL, but different Id: ***"
[12126]426 for (def url : eliUrls.keySet()) {
427 def e = eliUrls.get(url)
428 if (!josmUrls.containsKey(url)) continue
429 def j = josmUrls.get(url)
430 def ename = getId(e)
431 def jname = getId(j)
432 if (!ename.equals(jname)) {
[12245]433 myprintln "# Id differs ('${getId(e)}' != '${getId(j)}'): ${getUrl(j)}"
[12126]434 }
[12226]435 }
[12126]436
[9505]437 myprintln "*** Same URL, but different type: ***"
[11582]438 for (def url : eliUrls.keySet()) {
439 def e = eliUrls.get(url)
[7726]440 if (!josmUrls.containsKey(url)) continue
441 def j = josmUrls.get(url)
442 if (!getType(e).equals(getType(j))) {
[12242]443 myprintln "* Type differs (${getType(e)} != ${getType(j)}): ${getName(j)} - ${getUrl(j)}"
[7726]444 }
445 }
[9667]446
[9505]447 myprintln "*** Same URL, but different zoom bounds: ***"
[11582]448 for (def url : eliUrls.keySet()) {
449 def e = eliUrls.get(url)
[7726]450 if (!josmUrls.containsKey(url)) continue
451 def j = josmUrls.get(url)
452
453 Integer eMinZoom = getMinZoom(e)
454 Integer jMinZoom = getMinZoom(j)
[9518]455 if (eMinZoom != jMinZoom && !(eMinZoom == 0 && jMinZoom == null)) {
[11582]456 myprintln "* Minzoom differs (${eMinZoom} != ${jMinZoom}): ${getDescription(j)}"
[7726]457 }
458 Integer eMaxZoom = getMaxZoom(e)
459 Integer jMaxZoom = getMaxZoom(j)
460 if (eMaxZoom != jMaxZoom) {
[11582]461 myprintln "* Maxzoom differs (${eMaxZoom} != ${jMaxZoom}): ${getDescription(j)}"
[7726]462 }
463 }
[9667]464
[9505]465 myprintln "*** Same URL, but different country code: ***"
[11582]466 for (def url : eliUrls.keySet()) {
467 def e = eliUrls.get(url)
[7726]468 if (!josmUrls.containsKey(url)) continue
469 def j = josmUrls.get(url)
470 if (!getCountryCode(e).equals(getCountryCode(j))) {
[11582]471 myprintln "* Country code differs (${getCountryCode(e)} != ${getCountryCode(j)}): ${getDescription(j)}"
[7726]472 }
473 }
[11599]474 myprintln "*** Same URL, but different quality: ***"
[11582]475 for (def url : eliUrls.keySet()) {
476 def e = eliUrls.get(url)
[9515]477 if (!josmUrls.containsKey(url)) {
478 def q = getQuality(e)
[11582]479 if("eli-best".equals(q)) {
480 myprintln "- Quality best entry not in JOSM for ${getDescription(e)}"
[9515]481 }
482 continue
483 }
[9505]484 def j = josmUrls.get(url)
485 if (!getQuality(e).equals(getQuality(j))) {
[11582]486 myprintln "* Quality differs (${getQuality(e)} != ${getQuality(j)}): ${getDescription(j)}"
[9505]487 }
[11599]488 }
[11665]489 myprintln "*** Same URL, but different dates: ***"
[11582]490 for (def url : eliUrls.keySet()) {
[11612]491 def ed = getDate(eliUrls.get(url))
[11573]492 if (!josmUrls.containsKey(url)) continue
493 def j = josmUrls.get(url)
[11612]494 def jd = getDate(j)
495 // The forms 2015;- or -;2015 or 2015;2015 are handled equal to 2015
[11964]496 String ef = ed.replaceAll("\\A-;","").replaceAll(";-\\z","").replaceAll("\\A([0-9-]+);\\1\\z","\$1")
[11639]497 // ELI has a strange and inconsistent used end_date definition, so we try again with subtraction by one
[11964]498 String ed2 = ed
[11639]499 def reg = (ed =~ /^(.*;)(\d\d\d\d)(-(\d\d)(-(\d\d))?)?$/)
500 if(reg != null && reg.count == 1) {
[11964]501 Calendar cal = Calendar.getInstance()
[11639]502 cal.set(reg[0][2] as Integer, reg[0][4] == null ? 0 : (reg[0][4] as Integer)-1, reg[0][6] == null ? 1 : reg[0][6] as Integer)
503 cal.add(Calendar.DAY_OF_MONTH, -1)
[11667]504 ed2 = reg[0][1] + cal.get(Calendar.YEAR)
[11639]505 if (reg[0][4] != null)
506 ed2 += "-" + String.format("%02d", cal.get(Calendar.MONTH)+1)
507 if (reg[0][6] != null)
508 ed2 += "-" + String.format("%02d", cal.get(Calendar.DAY_OF_MONTH))
509 }
[11964]510 String ef2 = ed2.replaceAll("\\A-;","").replaceAll(";-\\z","").replaceAll("\\A([0-9-]+);\\1\\z","\$1")
[11639]511 if (!ed.equals(jd) && !ef.equals(jd) && !ed2.equals(jd) && !ef2.equals(jd)) {
[11964]512 String t = "'${ed}'"
[11612]513 if (!ed.equals(ef)) {
[11964]514 t += " or '${ef}'"
[11612]515 }
[11666]516 if (jd.isEmpty()) {
517 myprintln "- Missing JOSM date (${t}): ${getDescription(j)}"
[11668]518 } else if (!ed.isEmpty()) {
[12145]519 myprintln "* Date differs ('${t}' != '${jd}'): ${getDescription(j)}"
[11668]520 } else if (!options.nomissingeli) {
[11666]521 myprintln "+ Missing ELI date ('${jd}'): ${getDescription(j)}"
522 }
[11573]523 }
[11665]524 }
[11981]525 myprintln "*** Same URL, but different information: ***"
526 for (def url : eliUrls.keySet()) {
527 if (!josmUrls.containsKey(url)) continue
528 def e = eliUrls.get(url)
529 def j = josmUrls.get(url)
530
531 def et = getDescriptions(e)
532 def jt = getDescriptions(j)
[12008]533 et = (et.size() > 0) ? et["en"] : ""
534 jt = (jt.size() > 0) ? jt["en"] : ""
[12086]535 if (!et.equals(jt)) {
[11981]536 if (!jt) {
[12179]537 myprintln "- Missing JOSM description (${et}): ${getDescription(j)}"
[11981]538 } else if (et) {
[12145]539 myprintln "* Description differs ('${et}' != '${jt}'): ${getDescription(j)}"
[11981]540 } else if (!options.nomissingeli) {
541 myprintln "+ Missing ELI description ('${jt}'): ${getDescription(j)}"
542 }
543 }
544
545 et = getPermissionReferenceUrl(e)
546 jt = getPermissionReferenceUrl(j)
547 if (!jt) jt = getTermsOfUseUrl(j)
548 if (!et.equals(jt)) {
549 if (!jt) {
[12266]550 myprintln "- Missing JOSM license URL (${et}): ${getDescription(j)}"
[11981]551 } else if (et) {
[12266]552 myprintln "* License URL differs ('${et}' != '${jt}'): ${getDescription(j)}"
[11981]553 } else if (!options.nomissingeli) {
554 myprintln "+ Missing ELI license URL ('${jt}'): ${getDescription(j)}"
555 }
556 }
557
558 et = getAttributionUrl(e)
559 jt = getAttributionUrl(j)
560 if (!et.equals(jt)) {
561 if (!jt) {
[12143]562 myprintln "- Missing JOSM attribution URL (${et}): ${getDescription(j)}"
[11981]563 } else if (et) {
[13518]564 def ethttps = et.replace("http:","https:")
565 if(jt.equals(ethttps)) {
566 myprintln "+ Attribution URL differs ('${et}' != '${jt}'): ${getDescription(j)}"
567 } else {
568 myprintln "* Attribution URL differs ('${et}' != '${jt}'): ${getDescription(j)}"
569 }
[11981]570 } else if (!options.nomissingeli) {
571 myprintln "+ Missing ELI attribution URL ('${jt}'): ${getDescription(j)}"
572 }
573 }
574
575 et = getAttributionText(e)
576 jt = getAttributionText(j)
577 if (!et.equals(jt)) {
578 if (!jt) {
[12143]579 myprintln "- Missing JOSM attribution text (${et}): ${getDescription(j)}"
[11981]580 } else if (et) {
[12266]581 myprintln "* Attribution text differs ('${et}' != '${jt}'): ${getDescription(j)}"
[11981]582 } else if (!options.nomissingeli) {
583 myprintln "+ Missing ELI attribution text ('${jt}'): ${getDescription(j)}"
584 }
585 }
586
587 et = getProjections(e)
588 jt = getProjections(j)
[11983]589 if (et) { et = new LinkedList(et); Collections.sort(et); et = String.join(" ", et) }
590 if (jt) { jt = new LinkedList(jt); Collections.sort(jt); jt = String.join(" ", jt) }
[11981]591 if (!et.equals(jt)) {
592 if (!jt) {
[12143]593 myprintln "- Missing JOSM projections (${et}): ${getDescription(j)}"
[11981]594 } else if (et) {
[12179]595 myprintln "* Projections differ ('${et}' != '${jt}'): ${getDescription(j)}"
[12144]596 } else if (!options.nomissingeli && !getType(e).equals("tms")) {
[11981]597 myprintln "+ Missing ELI projections ('${jt}'): ${getDescription(j)}"
598 }
599 }
[12226]600
601 et = getDefault(e)
602 jt = getDefault(j)
603 if (!et.equals(jt)) {
604 if (!jt) {
[12227]605 myprintln "- Missing JOSM default: ${getDescription(j)}"
[12226]606 } else if (!options.nomissingeli) {
607 myprintln "+ Missing ELI default: ${getDescription(j)}"
608 }
609 }
[11981]610 }
[11410]611 myprintln "*** Mismatching shapes: ***"
612 for (def url : josmUrls.keySet()) {
613 def j = josmUrls.get(url)
614 def num = 1
615 for (def shape : getShapes(j)) {
616 def p = shape.getPoints()
617 if(!p[0].equals(p[p.size()-1])) {
618 myprintln "+++ JOSM shape $num unclosed: ${getDescription(j)}"
619 }
[11964]620 for (def nump = 1; nump < p.size(); ++nump) {
621 if (p[nump-1] == p[nump]) {
622 myprintln "+++ JOSM shape $num double point at ${nump-1}: ${getDescription(j)}"
623 }
624 }
[11410]625 ++num
626 }
627 }
[11582]628 for (def url : eliUrls.keySet()) {
629 def e = eliUrls.get(url)
[11410]630 def num = 1
631 def s = getShapes(e)
632 for (def shape : s) {
633 def p = shape.getPoints()
[11582]634 if(!p[0].equals(p[p.size()-1]) && !options.nomissingeli) {
635 myprintln "+++ ELI shape $num unclosed: ${getDescription(e)}"
[11410]636 }
[11964]637 for (def nump = 1; nump < p.size(); ++nump) {
638 if (p[nump-1] == p[nump]) {
639 myprintln "+++ ELI shape $num double point at ${nump-1}: ${getDescription(e)}"
640 }
641 }
[11410]642 ++num
643 }
644 if (!josmUrls.containsKey(url)) {
645 continue
646 }
647 def j = josmUrls.get(url)
[11411]648 def js = getShapes(j)
[11414]649 if(!s.size() && js.size()) {
[11582]650 if(!options.nomissingeli) {
651 myprintln "+ No ELI shape: ${getDescription(j)}"
[11414]652 }
[11413]653 } else if(!js.size() && s.size()) {
[11415]654 // don't report boundary like 5 point shapes as difference
655 if (s.size() != 1 || s[0].getPoints().size() != 5) {
656 myprintln "- No JOSM shape: ${getDescription(j)}"
657 }
[11414]658 } else if(s.size() != js.size()) {
659 myprintln "* Different number of shapes (${s.size()} != ${js.size()}): ${getDescription(j)}"
[11413]660 } else {
[11414]661 for(def nums = 0; nums < s.size(); ++nums) {
662 def ep = s[nums].getPoints()
663 def jp = js[nums].getPoints()
664 if(ep.size() != jp.size()) {
665 myprintln "* Different number of points for shape ${nums+1} (${ep.size()} ! = ${jp.size()})): ${getDescription(j)}"
666 } else {
667 for(def nump = 0; nump < ep.size(); ++nump) {
668 def ept = ep[nump]
669 def jpt = jp[nump]
670 if(Math.abs(ept.getLat()-jpt.getLat()) > 0.000001 || Math.abs(ept.getLon()-jpt.getLon()) > 0.000001) {
671 myprintln "* Different coordinate for point ${nump+1} of shape ${nums+1}: ${getDescription(j)}"
672 nump = ep.size()
673 num = s.size()
[11413]674 }
675 }
676 }
[11411]677 }
[11410]678 }
679 }
[11420]680 myprintln "*** Mismatching icons: ***"
[11582]681 for (def url : eliUrls.keySet()) {
682 def e = eliUrls.get(url)
[11420]683 if (!josmUrls.containsKey(url)) {
684 continue
685 }
686 def j = josmUrls.get(url)
687 def ij = getIcon(j)
688 def ie = getIcon(e)
689 if(ij != null && ie == null) {
[11582]690 if(!options.nomissingeli) {
691 myprintln "+ No ELI icon: ${getDescription(j)}"
[11420]692 }
693 } else if(ij == null && ie != null) {
694 myprintln "- No JOSM icon: ${getDescription(j)}"
695 } else if(!ij.equals(ie)) {
696 myprintln "* Different icons: ${getDescription(j)}"
697 }
698 }
699 myprintln "*** Miscellaneous checks: ***"
700 def josmIds = new HashMap<String, ImageryInfo>()
[13527]701 def all = Projections.getAllProjectionCodes()
[11420]702 for (def url : josmUrls.keySet()) {
703 def j = josmUrls.get(url)
704 def id = getId(j)
[13526]705 if("wms".equals(getType(j))) {
706 if(!getProjections(j)) {
707 myprintln "* WMS without projections: ${getDescription(j)}"
708 } else {
[13527]709 def unsupported = new LinkedList<String>()
710 def old = new LinkedList<String>()
[13530]711 for (def p : getProjectionsUnstripped(j)) {
[13526]712 if("CRS:84".equals(p)) {
713 if(!(url =~ /(?i)version=1\.3/)) {
[13533]714 myprintln "* CRS:84 without WMS 1.3: ${getDescription(j)}"
[13526]715 }
[13527]716 } else if(oldproj.containsKey(p)) {
717 old.add(p)
[13528]718 } else if(!all.contains(p) && !ignoreproj.contains(p)) {
[13526]719 unsupported.add(p)
720 }
721 }
722 if (unsupported) {
[13527]723 def s = String.join(", ", unsupported)
[13533]724 myprintln "* Projections ${s} not supported by JOSM: ${getDescription(j)}"
[13526]725 }
[13527]726 for (def o : old) {
[13533]727 myprintln "* Projection ${o} is an old unsupported code and has been replaced by ${oldproj.get(o)}: ${getDescription(j)}"
[13527]728 }
[13526]729 }
730 if((url =~ /(?i)version=1\.3/) && !(url =~ /[Cc][Rr][Ss]=\{proj\}/)) {
731 myprintln "* WMS 1.3 with strange CRS specification: ${getDescription(j)}"
732 }
733 if((url =~ /(?i)version=1\.1/) && !(url =~ /[Ss][Rr][Ss]=\{proj\}/)) {
734 myprintln "* WMS 1.1 with strange SRS specification: ${getDescription(j)}"
735 }
[13511]736 }
[13532]737 if(!(url =~ /^https?:\/\//) && !"scanex".equals(getType(j))) {
738 myprintln "* Strange URL: ${getDescription(j)}"
739 }
[11420]740 if(josmMirrors.containsKey(url)) {
[11964]741 continue
[11420]742 }
743 if(id == null) {
744 myprintln "* No JOSM-ID: ${getDescription(j)}"
745 } else if(josmIds.containsKey(id)) {
746 myprintln "* JOSM-ID ${id} not unique: ${getDescription(j)}"
747 } else {
[11964]748 josmIds.put(id, j)
[11420]749 }
[11572]750 def d = getDate(j)
[11573]751 if(!d.isEmpty()) {
[11639]752 def reg = (d =~ /^(-|(\d\d\d\d)(-(\d\d)(-(\d\d))?)?)(;(-|(\d\d\d\d)(-(\d\d)(-(\d\d))?)?))?$/)
[11572]753 if(reg == null || reg.count != 1) {
754 myprintln "* JOSM-Date '${d}' is strange: ${getDescription(j)}"
755 } else {
756 try {
[11964]757 def first = verifyDate(reg[0][2],reg[0][4],reg[0][6])
758 def second = verifyDate(reg[0][9],reg[0][11],reg[0][13])
[11572]759 if(second.compareTo(first) < 0) {
760 myprintln "* JOSM-Date '${d}' is strange (second earlier than first): ${getDescription(j)}"
761 }
762 }
763 catch (Exception e) {
764 myprintln "* JOSM-Date '${d}' is strange (${e.getMessage()}): ${getDescription(j)}"
765 }
766 }
[11603]767 }
[12261]768 if(getAttributionUrl(j) && !getAttributionText(j)) {
769 myprintln "* Attribution link without text: ${getDescription(j)}"
770 }
771 if(getLogoUrl(j) && !getLogoImage(j)) {
772 myprintln "* Logo link without image: ${getDescription(j)}"
773 }
774 if(getTermsOfUseText(j) && !getTermsOfUseUrl(j)) {
775 myprintln "* Terms of Use text without link: ${getDescription(j)}"
776 }
[11422]777 def js = getShapes(j)
778 if(js.size()) {
[11964]779 def minlat = 1000
780 def minlon = 1000
781 def maxlat = -1000
782 def maxlon = -1000
[11422]783 for(def s: js) {
784 for(def p: s.getPoints()) {
[11964]785 def lat = p.getLat()
786 def lon = p.getLon()
787 if(lat > maxlat) maxlat = lat
788 if(lon > maxlon) maxlon = lon
789 if(lat < minlat) minlat = lat
790 if(lon < minlon) minlon = lon
[11422]791 }
792 }
[11964]793 def b = j.getBounds()
[11422]794 if(b.getMinLat() != minlat || b.getMinLon() != minlon || b.getMaxLat() != maxlat || b.getMaxLon() != maxlon) {
[11423]795 myprintln "* Bounds do not match shape (is ${b.getMinLat()},${b.getMinLon()},${b.getMaxLat()},${b.getMaxLon()}, calculated <bounds min-lat='${minlat}' min-lon='${minlon}' max-lat='${maxlat}' max-lon='${maxlon}'>): ${getDescription(j)}"
[11422]796 }
797 }
[11420]798 }
[7726]799 }
[9667]800
[7726]801 /**
802 * Utility functions that allow uniform access for both ImageryInfo and JsonObject.
803 */
804 static String getUrl(Object e) {
805 if (e instanceof ImageryInfo) return e.url
[11412]806 return e.get("properties").getString("url")
[7726]807 }
[12242]808 static String getUrlStripped(Object e) {
809 return getUrl(e).replaceAll("\\?(apikey|access_token)=.*","")
810 }
[11572]811 static String getDate(Object e) {
[11573]812 if (e instanceof ImageryInfo) return e.date ? e.date : ""
813 def p = e.get("properties")
814 def start = p.containsKey("start_date") ? p.getString("start_date") : ""
815 def end = p.containsKey("end_date") ? p.getString("end_date") : ""
816 if(!start.isEmpty() && !end.isEmpty())
[11572]817 return start+";"+end
[11573]818 else if(!start.isEmpty())
[11612]819 return start+";-"
820 else if(!end.isEmpty())
821 return "-;"+end
[11964]822 return ""
[11572]823 }
824 static Date verifyDate(String year, String month, String day) {
825 def date
[11854]826 if(year == null) {
[11572]827 date = "3000-01-01"
[11854]828 } else {
[11572]829 date = year + "-" + (month == null ? "01" : month) + "-" + (day == null ? "01" : day)
[11854]830 }
[11572]831 def df = new java.text.SimpleDateFormat("yyyy-MM-dd")
832 df.setLenient(false)
833 return df.parse(date)
834 }
[11420]835 static String getId(Object e) {
836 if (e instanceof ImageryInfo) return e.getId()
837 return e.get("properties").getString("id")
838 }
[7726]839 static String getName(Object e) {
[10517]840 if (e instanceof ImageryInfo) return e.getOriginalName()
[11412]841 return e.get("properties").getString("name")
[7726]842 }
[11967]843 static List<Object> getMirrors(Object e) {
844 if (e instanceof ImageryInfo) return e.getMirrors()
845 return []
846 }
[11975]847 static List<Object> getProjections(Object e) {
[13530]848 def r = []
849 def u = getProjectionsUnstripped(e)
850 if(u) {
851 for (def p : u) {
852 if(!oldproj.containsKey(p) && !("CRS:84".equals(p) && !(getUrlStripped(e) =~ /(?i)version=1\.3/))) {
853 r += p
854 }
855 }
856 }
857 return r
858 }
859 static List<Object> getProjectionsUnstripped(Object e) {
[11975]860 def r
861 if (e instanceof ImageryInfo) {
862 r = e.getServerProjections()
863 } else {
[11981]864 def s = e.get("properties").get("available_projections")
865 if (s) {
866 r = []
[13530]867 for (def p : s) {
[11981]868 r += p.getString()
[13530]869 }
[11981]870 }
[11975]871 }
872 return r ? r : []
873 }
[11410]874 static List<Shape> getShapes(Object e) {
875 if (e instanceof ImageryInfo) {
[11964]876 def bounds = e.getBounds()
[11411]877 if(bounds != null) {
[11964]878 return bounds.getShapes()
[11411]879 }
880 return []
[11410]881 }
[11412]882 if(!e.isNull("geometry")) {
883 def ex = e.get("geometry")
884 if(ex != null && !ex.isNull("coordinates")) {
885 def poly = ex.get("coordinates")
[11410]886 List<Shape> l = []
887 for(def shapes: poly) {
888 def s = new Shape()
889 for(def point: shapes) {
890 def lon = point[0].toString()
891 def lat = point[1].toString()
892 s.addPoint(lat, lon)
893 }
894 l.add(s)
895 }
896 return l
897 }
898 }
899 return []
900 }
[7726]901 static String getType(Object e) {
902 if (e instanceof ImageryInfo) return e.getImageryType().getTypeString()
[11412]903 return e.get("properties").getString("type")
[7726]904 }
905 static Integer getMinZoom(Object e) {
906 if (e instanceof ImageryInfo) {
[12007]907 if("wms".equals(getType(e)) && e.getName() =~ / mirror/)
908 return null;
[7726]909 int mz = e.getMinZoom()
910 return mz == 0 ? null : mz
911 } else {
[11412]912 def num = e.get("properties").getJsonNumber("min_zoom")
[7726]913 if (num == null) return null
914 return num.intValue()
915 }
916 }
917 static Integer getMaxZoom(Object e) {
918 if (e instanceof ImageryInfo) {
[12007]919 if("wms".equals(getType(e)) && e.getName() =~ / mirror/)
920 return null;
[7726]921 int mz = e.getMaxZoom()
922 return mz == 0 ? null : mz
923 } else {
[11412]924 def num = e.get("properties").getJsonNumber("max_zoom")
[7726]925 if (num == null) return null
926 return num.intValue()
927 }
928 }
929 static String getCountryCode(Object e) {
930 if (e instanceof ImageryInfo) return "".equals(e.getCountryCode()) ? null : e.getCountryCode()
[11412]931 return e.get("properties").getString("country_code", null)
[7726]932 }
[9505]933 static String getQuality(Object e) {
[11575]934 if (e instanceof ImageryInfo) return e.isBestMarked() ? "eli-best" : null
[11603]935 return (e.get("properties").containsKey("best")
936 && e.get("properties").getBoolean("best")) ? "eli-best" : null
[9505]937 }
[11420]938 static String getIcon(Object e) {
939 if (e instanceof ImageryInfo) return e.getIcon()
940 return e.get("properties").getString("icon", null)
941 }
[11975]942 static String getAttributionText(Object e) {
943 if (e instanceof ImageryInfo) return e.getAttributionText(0, null, null)
944 try {return e.get("properties").get("attribution").getString("text", null)} catch (NullPointerException ex) {return null}
945 }
946 static String getAttributionUrl(Object e) {
947 if (e instanceof ImageryInfo) return e.getAttributionLinkURL()
948 try {return e.get("properties").get("attribution").getString("url", null)} catch (NullPointerException ex) {return null}
949 }
950 static String getTermsOfUseText(Object e) {
951 if (e instanceof ImageryInfo) return e.getTermsOfUseText()
952 return null
953 }
954 static String getTermsOfUseUrl(Object e) {
955 if (e instanceof ImageryInfo) return e.getTermsOfUseURL()
956 return null
957 }
[12261]958 static String getLogoImage(Object e) {
959 if (e instanceof ImageryInfo) return e.getAttributionImageRaw()
960 return null
961 }
962 static String getLogoUrl(Object e) {
963 if (e instanceof ImageryInfo) return e.getAttributionImageURL()
964 return null
965 }
[11975]966 static String getPermissionReferenceUrl(Object e) {
967 if (e instanceof ImageryInfo) return e.getPermissionReferenceURL()
968 return e.get("properties").getString("license_url", null)
969 }
970 static Map<String,String> getDescriptions(Object e) {
971 Map<String,String> res = new HashMap<String, String>()
972 if (e instanceof ImageryInfo) {
973 String a = e.getDescription()
974 if (a) res.put("en", a)
975 } else {
976 String a = e.get("properties").getString("description", null)
977 if (a) res.put("en", a)
978 }
979 return res
980 }
981 static Boolean getValidGeoreference(Object e) {
982 if (e instanceof ImageryInfo) return e.isGeoreferenceValid()
983 return false
984 }
[12226]985 static Boolean getDefault(Object e) {
986 if (e instanceof ImageryInfo) return e.isDefaultEntry()
987 return e.get("properties").getBoolean("default", false)
988 }
[7726]989 String getDescription(Object o) {
990 def url = getUrl(o)
991 def cc = getCountryCode(o)
992 if (cc == null) {
993 def j = josmUrls.get(url)
994 if (j != null) cc = getCountryCode(j)
995 if (cc == null) {
[11582]996 def e = eliUrls.get(url)
[7726]997 if (e != null) cc = getCountryCode(e)
998 }
999 }
1000 if (cc == null) {
1001 cc = ''
1002 } else {
1003 cc = "[$cc] "
1004 }
1005 def d = cc + getName(o) + " - " + getUrl(o)
1006 if (options.shorten) {
1007 def MAXLEN = 140
1008 if (d.length() > MAXLEN) d = d.substring(0, MAXLEN-1) + "..."
1009 }
1010 return d
1011 }
1012}
Note: See TracBrowser for help on using the repository browser.