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

Last change on this file since 13549 was 13549, checked in by Klumbumbus, 7 years ago

see #14655 - enable overlay test

  • Property svn:eol-style set to native
File size: 42.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) {
[13536]274 stream.write(" <entry"
275 + ("eli-best".equals(getQuality(e)) ? " eli-best=\"true\"" : "" )
276 + (getOverlay(e) ? " overlay=\"true\"" : "" )
277 + ">\n")
[11975]278 stream.write " <name>${cdata(getName(e), true)}</name>\n"
[11964]279 stream.write " <id>${getId(e)}</id>\n"
[11968]280 def t
281 if((t = getDate(e)))
282 stream.write " <date>$t</date>\n"
283 if((t = getCountryCode(e)))
284 stream.write " <country-code>$t</country-code>\n"
[12226]285 if((getDefault(e)))
286 stream.write " <default>true</default>\n"
[11975]287 stream.write maininfo(e, " ")
288 if((t = getAttributionText(e)))
289 stream.write " <attribution-text mandatory=\"true\">${cdata(t, true)}</attribution-text>\n"
290 if((t = getAttributionUrl(e)))
291 stream.write " <attribution-url>${cdata(t)}</attribution-url>\n"
[12261]292 if((t = getLogoImage(e)))
293 stream.write " <logo-image>${cdata(t, true)}</logo-image>\n"
294 if((t = getLogoUrl(e)))
295 stream.write " <logo-url>${cdata(t)}</logo-url>\n"
[11975]296 if((t = getTermsOfUseText(e)))
297 stream.write " <terms-of-use-text>${cdata(t, true)}</terms-of-use-text>\n"
298 if((t = getTermsOfUseUrl(e)))
299 stream.write " <terms-of-use-url>${cdata(t)}</terms-of-use-url>\n"
300 if((t = getPermissionReferenceUrl(e)))
301 stream.write " <permission-ref>${cdata(t)}</permission-ref>\n"
302 if((getValidGeoreference(e)))
303 stream.write " <valid-georeference>true</valid-georeference>\n"
[11968]304 if((t = getIcon(e)))
305 stream.write " <icon>${cdata(t)}</icon>\n"
[11975]306 for (def d : getDescriptions(e)) {
307 stream.write " <description lang=\"${d.getKey()}\">${d.getValue()}</description>\n"
308 }
[11967]309 for (def m : getMirrors(e)) {
310 stream.write " <mirror>\n"+maininfo(m, " ")+" </mirror>\n"
311 }
[11964]312 def minlat = 1000
313 def minlon = 1000
314 def maxlat = -1000
315 def maxlon = -1000
316 def shapes = ""
317 def sep = "\n "
318 for(def s: getShapes(e)) {
319 shapes += " <shape>"
320 def i = 0
321 for(def p: s.getPoints()) {
322 def lat = p.getLat()
323 def lon = p.getLon()
324 if(lat > maxlat) maxlat = lat
325 if(lon > maxlon) maxlon = lon
326 if(lat < minlat) minlat = lat
327 if(lon < minlon) minlon = lon
328 if(!(i++%3)) {
329 shapes += sep + " "
330 }
[11967]331 shapes += "<point lat='${df.format(lat)}' lon='${df.format(lon)}'/>"
[11964]332 }
333 shapes += sep + "</shape>\n"
334 }
335 if(shapes) {
[11967]336 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]337 stream.write shapes + " </bounds>\n"
338 }
[11967]339 stream.write " </entry>\n"
[11964]340 }
341 stream.write "</imagery>\n"
342 stream.close()
343 }
344
[7726]345 void loadJosmEntries() {
346 def reader = new ImageryReader(josmInputFile)
347 josmEntries = reader.parse()
[9667]348
[7726]349 for (def e : josmEntries) {
[12242]350 def url = getUrlStripped(e)
[9658]351 if (url.contains("{z}")) {
352 myprintln "+++ JOSM-URL uses {z} instead of {zoom}: "+url
353 url = url.replace("{z}","{zoom}")
354 }
[9505]355 if (josmUrls.containsKey(url)) {
356 myprintln "+++ JOSM-URL is not unique: "+url
357 } else {
[11420]358 josmUrls.put(url, e)
[7726]359 }
[9658]360 for (def m : e.getMirrors()) {
[12242]361 url = getUrlStripped(m)
[11574]362 m.origName = m.getOriginalName().replaceAll(" mirror server( \\d+)?","")
[9658]363 if (josmUrls.containsKey(url)) {
364 myprintln "+++ JOSM-Mirror-URL is not unique: "+url
365 } else {
[11420]366 josmUrls.put(url, m)
367 josmMirrors.put(url, m)
[9658]368 }
369 }
[7726]370 }
[9505]371 myprintln "*** Loaded ${josmEntries.size()} entries (JOSM). ***"
[7726]372 }
373
[13517]374 List inOneButNotTheOther(Map m1, Map m2, String code, String https) {
[7726]375 def l = []
[13518]376 def k = new LinkedList<String>(m1.keySet())
377 for (def url : k) {
[7726]378 if (!m2.containsKey(url)) {
[13517]379 String urlhttps = url.replace("http:","https:")
380 if(!https || !m2.containsKey(urlhttps))
381 {
382 def name = getName(m1.get(url))
383 l += code+" "+getDescription(m1.get(url))
384 }
385 else
386 {
387 l += https+" Missing https: "+getDescription(m1.get(url))
[13518]388 m1.put(urlhttps, m1.get(url))
389 m1.remove(url)
[13517]390 }
[7726]391 }
392 }
393 l.sort()
394 }
[9667]395
[7726]396 void checkInOneButNotTheOther() {
[13517]397 def l1 = inOneButNotTheOther(eliUrls, josmUrls, "-", "+")
[11582]398 myprintln "*** URLs found in ELI but not in JOSM (${l1.size()}): ***"
[9658]399 if (!l1.isEmpty()) {
[11412]400 for (def l : l1) {
[13517]401 myprintln l
[11412]402 }
[7726]403 }
404
[13517]405 def l2 = inOneButNotTheOther(josmUrls, eliUrls, "+", "")
[11582]406 myprintln "*** URLs found in JOSM but not in ELI (${l2.size()}): ***"
[9658]407 if (!l2.isEmpty()) {
[11412]408 for (def l : l2) {
[13517]409 myprintln l
[11412]410 }
[7726]411 }
412 }
[9667]413
[7726]414 void checkCommonEntries() {
[9505]415 myprintln "*** Same URL, but different name: ***"
[11582]416 for (def url : eliUrls.keySet()) {
417 def e = eliUrls.get(url)
[7726]418 if (!josmUrls.containsKey(url)) continue
419 def j = josmUrls.get(url)
[12061]420 def ename = getName(e).replace("'","\u2019")
421 def jname = getName(j).replace("'","\u2019")
[11951]422 if (!ename.equals(jname)) {
[12242]423 myprintln "* Name differs ('${getName(e)}' != '${getName(j)}'): ${getUrl(j)}"
[7726]424 }
425 }
[9667]426
[12226]427 myprintln "*** Same URL, but different Id: ***"
[12126]428 for (def url : eliUrls.keySet()) {
429 def e = eliUrls.get(url)
430 if (!josmUrls.containsKey(url)) continue
431 def j = josmUrls.get(url)
432 def ename = getId(e)
433 def jname = getId(j)
434 if (!ename.equals(jname)) {
[12245]435 myprintln "# Id differs ('${getId(e)}' != '${getId(j)}'): ${getUrl(j)}"
[12126]436 }
[12226]437 }
[12126]438
[9505]439 myprintln "*** Same URL, but different type: ***"
[11582]440 for (def url : eliUrls.keySet()) {
441 def e = eliUrls.get(url)
[7726]442 if (!josmUrls.containsKey(url)) continue
443 def j = josmUrls.get(url)
444 if (!getType(e).equals(getType(j))) {
[12242]445 myprintln "* Type differs (${getType(e)} != ${getType(j)}): ${getName(j)} - ${getUrl(j)}"
[7726]446 }
447 }
[9667]448
[9505]449 myprintln "*** Same URL, but different zoom bounds: ***"
[11582]450 for (def url : eliUrls.keySet()) {
451 def e = eliUrls.get(url)
[7726]452 if (!josmUrls.containsKey(url)) continue
453 def j = josmUrls.get(url)
454
455 Integer eMinZoom = getMinZoom(e)
456 Integer jMinZoom = getMinZoom(j)
[9518]457 if (eMinZoom != jMinZoom && !(eMinZoom == 0 && jMinZoom == null)) {
[11582]458 myprintln "* Minzoom differs (${eMinZoom} != ${jMinZoom}): ${getDescription(j)}"
[7726]459 }
460 Integer eMaxZoom = getMaxZoom(e)
461 Integer jMaxZoom = getMaxZoom(j)
462 if (eMaxZoom != jMaxZoom) {
[11582]463 myprintln "* Maxzoom differs (${eMaxZoom} != ${jMaxZoom}): ${getDescription(j)}"
[7726]464 }
465 }
[9667]466
[9505]467 myprintln "*** Same URL, but different country code: ***"
[11582]468 for (def url : eliUrls.keySet()) {
469 def e = eliUrls.get(url)
[7726]470 if (!josmUrls.containsKey(url)) continue
471 def j = josmUrls.get(url)
472 if (!getCountryCode(e).equals(getCountryCode(j))) {
[11582]473 myprintln "* Country code differs (${getCountryCode(e)} != ${getCountryCode(j)}): ${getDescription(j)}"
[7726]474 }
475 }
[11599]476 myprintln "*** Same URL, but different quality: ***"
[11582]477 for (def url : eliUrls.keySet()) {
478 def e = eliUrls.get(url)
[9515]479 if (!josmUrls.containsKey(url)) {
480 def q = getQuality(e)
[11582]481 if("eli-best".equals(q)) {
482 myprintln "- Quality best entry not in JOSM for ${getDescription(e)}"
[9515]483 }
484 continue
485 }
[9505]486 def j = josmUrls.get(url)
487 if (!getQuality(e).equals(getQuality(j))) {
[11582]488 myprintln "* Quality differs (${getQuality(e)} != ${getQuality(j)}): ${getDescription(j)}"
[9505]489 }
[11599]490 }
[11665]491 myprintln "*** Same URL, but different dates: ***"
[11582]492 for (def url : eliUrls.keySet()) {
[11612]493 def ed = getDate(eliUrls.get(url))
[11573]494 if (!josmUrls.containsKey(url)) continue
495 def j = josmUrls.get(url)
[11612]496 def jd = getDate(j)
497 // The forms 2015;- or -;2015 or 2015;2015 are handled equal to 2015
[11964]498 String ef = ed.replaceAll("\\A-;","").replaceAll(";-\\z","").replaceAll("\\A([0-9-]+);\\1\\z","\$1")
[11639]499 // ELI has a strange and inconsistent used end_date definition, so we try again with subtraction by one
[11964]500 String ed2 = ed
[11639]501 def reg = (ed =~ /^(.*;)(\d\d\d\d)(-(\d\d)(-(\d\d))?)?$/)
502 if(reg != null && reg.count == 1) {
[11964]503 Calendar cal = Calendar.getInstance()
[11639]504 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)
505 cal.add(Calendar.DAY_OF_MONTH, -1)
[11667]506 ed2 = reg[0][1] + cal.get(Calendar.YEAR)
[11639]507 if (reg[0][4] != null)
508 ed2 += "-" + String.format("%02d", cal.get(Calendar.MONTH)+1)
509 if (reg[0][6] != null)
510 ed2 += "-" + String.format("%02d", cal.get(Calendar.DAY_OF_MONTH))
511 }
[11964]512 String ef2 = ed2.replaceAll("\\A-;","").replaceAll(";-\\z","").replaceAll("\\A([0-9-]+);\\1\\z","\$1")
[11639]513 if (!ed.equals(jd) && !ef.equals(jd) && !ed2.equals(jd) && !ef2.equals(jd)) {
[11964]514 String t = "'${ed}'"
[11612]515 if (!ed.equals(ef)) {
[11964]516 t += " or '${ef}'"
[11612]517 }
[11666]518 if (jd.isEmpty()) {
519 myprintln "- Missing JOSM date (${t}): ${getDescription(j)}"
[11668]520 } else if (!ed.isEmpty()) {
[12145]521 myprintln "* Date differs ('${t}' != '${jd}'): ${getDescription(j)}"
[11668]522 } else if (!options.nomissingeli) {
[11666]523 myprintln "+ Missing ELI date ('${jd}'): ${getDescription(j)}"
524 }
[11573]525 }
[11665]526 }
[11981]527 myprintln "*** Same URL, but different information: ***"
528 for (def url : eliUrls.keySet()) {
529 if (!josmUrls.containsKey(url)) continue
530 def e = eliUrls.get(url)
531 def j = josmUrls.get(url)
532
533 def et = getDescriptions(e)
534 def jt = getDescriptions(j)
[12008]535 et = (et.size() > 0) ? et["en"] : ""
536 jt = (jt.size() > 0) ? jt["en"] : ""
[12086]537 if (!et.equals(jt)) {
[11981]538 if (!jt) {
[12179]539 myprintln "- Missing JOSM description (${et}): ${getDescription(j)}"
[11981]540 } else if (et) {
[12145]541 myprintln "* Description differs ('${et}' != '${jt}'): ${getDescription(j)}"
[11981]542 } else if (!options.nomissingeli) {
543 myprintln "+ Missing ELI description ('${jt}'): ${getDescription(j)}"
544 }
545 }
546
547 et = getPermissionReferenceUrl(e)
548 jt = getPermissionReferenceUrl(j)
549 if (!jt) jt = getTermsOfUseUrl(j)
550 if (!et.equals(jt)) {
551 if (!jt) {
[12266]552 myprintln "- Missing JOSM license URL (${et}): ${getDescription(j)}"
[11981]553 } else if (et) {
[12266]554 myprintln "* License URL differs ('${et}' != '${jt}'): ${getDescription(j)}"
[11981]555 } else if (!options.nomissingeli) {
556 myprintln "+ Missing ELI license URL ('${jt}'): ${getDescription(j)}"
557 }
558 }
559
560 et = getAttributionUrl(e)
561 jt = getAttributionUrl(j)
562 if (!et.equals(jt)) {
563 if (!jt) {
[12143]564 myprintln "- Missing JOSM attribution URL (${et}): ${getDescription(j)}"
[11981]565 } else if (et) {
[13518]566 def ethttps = et.replace("http:","https:")
567 if(jt.equals(ethttps)) {
568 myprintln "+ Attribution URL differs ('${et}' != '${jt}'): ${getDescription(j)}"
569 } else {
570 myprintln "* Attribution URL differs ('${et}' != '${jt}'): ${getDescription(j)}"
571 }
[11981]572 } else if (!options.nomissingeli) {
573 myprintln "+ Missing ELI attribution URL ('${jt}'): ${getDescription(j)}"
574 }
575 }
576
577 et = getAttributionText(e)
578 jt = getAttributionText(j)
579 if (!et.equals(jt)) {
580 if (!jt) {
[12143]581 myprintln "- Missing JOSM attribution text (${et}): ${getDescription(j)}"
[11981]582 } else if (et) {
[12266]583 myprintln "* Attribution text differs ('${et}' != '${jt}'): ${getDescription(j)}"
[11981]584 } else if (!options.nomissingeli) {
585 myprintln "+ Missing ELI attribution text ('${jt}'): ${getDescription(j)}"
586 }
587 }
588
589 et = getProjections(e)
590 jt = getProjections(j)
[11983]591 if (et) { et = new LinkedList(et); Collections.sort(et); et = String.join(" ", et) }
592 if (jt) { jt = new LinkedList(jt); Collections.sort(jt); jt = String.join(" ", jt) }
[11981]593 if (!et.equals(jt)) {
594 if (!jt) {
[12143]595 myprintln "- Missing JOSM projections (${et}): ${getDescription(j)}"
[11981]596 } else if (et) {
[13538]597 if("EPSG:3857 EPSG:4326".equals(et) || "EPSG:3857".equals(et) || "EPSG:4326".equals(et)) {
598 myprintln "+ ELI has minimal projections ('${et}' != '${jt}'): ${getDescription(j)}"
599 } else {
600 myprintln "* Projections differ ('${et}' != '${jt}'): ${getDescription(j)}"
601 }
[12144]602 } else if (!options.nomissingeli && !getType(e).equals("tms")) {
[11981]603 myprintln "+ Missing ELI projections ('${jt}'): ${getDescription(j)}"
604 }
605 }
[12226]606
607 et = getDefault(e)
608 jt = getDefault(j)
609 if (!et.equals(jt)) {
610 if (!jt) {
[12227]611 myprintln "- Missing JOSM default: ${getDescription(j)}"
[12226]612 } else if (!options.nomissingeli) {
613 myprintln "+ Missing ELI default: ${getDescription(j)}"
614 }
615 }
[13536]616 et = getOverlay(e)
617 jt = getOverlay(j)
618 if (!et.equals(jt)) {
619 if (!jt) {
[13549]620 myprintln "- Missing JOSM overlay flag: ${getDescription(j)}"
[13536]621 } else if (!options.nomissingeli) {
622 myprintln "+ Missing ELI overlay flag: ${getDescription(j)}"
623 }
624 }
[11981]625 }
[11410]626 myprintln "*** Mismatching shapes: ***"
627 for (def url : josmUrls.keySet()) {
628 def j = josmUrls.get(url)
629 def num = 1
630 for (def shape : getShapes(j)) {
631 def p = shape.getPoints()
632 if(!p[0].equals(p[p.size()-1])) {
633 myprintln "+++ JOSM shape $num unclosed: ${getDescription(j)}"
634 }
[11964]635 for (def nump = 1; nump < p.size(); ++nump) {
636 if (p[nump-1] == p[nump]) {
637 myprintln "+++ JOSM shape $num double point at ${nump-1}: ${getDescription(j)}"
638 }
639 }
[11410]640 ++num
641 }
642 }
[11582]643 for (def url : eliUrls.keySet()) {
644 def e = eliUrls.get(url)
[11410]645 def num = 1
646 def s = getShapes(e)
647 for (def shape : s) {
648 def p = shape.getPoints()
[11582]649 if(!p[0].equals(p[p.size()-1]) && !options.nomissingeli) {
650 myprintln "+++ ELI shape $num unclosed: ${getDescription(e)}"
[11410]651 }
[11964]652 for (def nump = 1; nump < p.size(); ++nump) {
653 if (p[nump-1] == p[nump]) {
654 myprintln "+++ ELI shape $num double point at ${nump-1}: ${getDescription(e)}"
655 }
656 }
[11410]657 ++num
658 }
659 if (!josmUrls.containsKey(url)) {
660 continue
661 }
662 def j = josmUrls.get(url)
[11411]663 def js = getShapes(j)
[11414]664 if(!s.size() && js.size()) {
[11582]665 if(!options.nomissingeli) {
666 myprintln "+ No ELI shape: ${getDescription(j)}"
[11414]667 }
[11413]668 } else if(!js.size() && s.size()) {
[11415]669 // don't report boundary like 5 point shapes as difference
670 if (s.size() != 1 || s[0].getPoints().size() != 5) {
671 myprintln "- No JOSM shape: ${getDescription(j)}"
672 }
[11414]673 } else if(s.size() != js.size()) {
674 myprintln "* Different number of shapes (${s.size()} != ${js.size()}): ${getDescription(j)}"
[11413]675 } else {
[11414]676 for(def nums = 0; nums < s.size(); ++nums) {
677 def ep = s[nums].getPoints()
678 def jp = js[nums].getPoints()
679 if(ep.size() != jp.size()) {
680 myprintln "* Different number of points for shape ${nums+1} (${ep.size()} ! = ${jp.size()})): ${getDescription(j)}"
681 } else {
682 for(def nump = 0; nump < ep.size(); ++nump) {
683 def ept = ep[nump]
684 def jpt = jp[nump]
685 if(Math.abs(ept.getLat()-jpt.getLat()) > 0.000001 || Math.abs(ept.getLon()-jpt.getLon()) > 0.000001) {
686 myprintln "* Different coordinate for point ${nump+1} of shape ${nums+1}: ${getDescription(j)}"
687 nump = ep.size()
688 num = s.size()
[11413]689 }
690 }
691 }
[11411]692 }
[11410]693 }
694 }
[11420]695 myprintln "*** Mismatching icons: ***"
[11582]696 for (def url : eliUrls.keySet()) {
697 def e = eliUrls.get(url)
[11420]698 if (!josmUrls.containsKey(url)) {
699 continue
700 }
701 def j = josmUrls.get(url)
702 def ij = getIcon(j)
703 def ie = getIcon(e)
704 if(ij != null && ie == null) {
[11582]705 if(!options.nomissingeli) {
706 myprintln "+ No ELI icon: ${getDescription(j)}"
[11420]707 }
708 } else if(ij == null && ie != null) {
709 myprintln "- No JOSM icon: ${getDescription(j)}"
710 } else if(!ij.equals(ie)) {
711 myprintln "* Different icons: ${getDescription(j)}"
712 }
713 }
714 myprintln "*** Miscellaneous checks: ***"
715 def josmIds = new HashMap<String, ImageryInfo>()
[13527]716 def all = Projections.getAllProjectionCodes()
[11420]717 for (def url : josmUrls.keySet()) {
718 def j = josmUrls.get(url)
719 def id = getId(j)
[13526]720 if("wms".equals(getType(j))) {
721 if(!getProjections(j)) {
722 myprintln "* WMS without projections: ${getDescription(j)}"
723 } else {
[13527]724 def unsupported = new LinkedList<String>()
725 def old = new LinkedList<String>()
[13530]726 for (def p : getProjectionsUnstripped(j)) {
[13526]727 if("CRS:84".equals(p)) {
728 if(!(url =~ /(?i)version=1\.3/)) {
[13533]729 myprintln "* CRS:84 without WMS 1.3: ${getDescription(j)}"
[13526]730 }
[13527]731 } else if(oldproj.containsKey(p)) {
732 old.add(p)
[13528]733 } else if(!all.contains(p) && !ignoreproj.contains(p)) {
[13526]734 unsupported.add(p)
735 }
736 }
737 if (unsupported) {
[13527]738 def s = String.join(", ", unsupported)
[13533]739 myprintln "* Projections ${s} not supported by JOSM: ${getDescription(j)}"
[13526]740 }
[13527]741 for (def o : old) {
[13533]742 myprintln "* Projection ${o} is an old unsupported code and has been replaced by ${oldproj.get(o)}: ${getDescription(j)}"
[13527]743 }
[13526]744 }
745 if((url =~ /(?i)version=1\.3/) && !(url =~ /[Cc][Rr][Ss]=\{proj\}/)) {
746 myprintln "* WMS 1.3 with strange CRS specification: ${getDescription(j)}"
747 }
748 if((url =~ /(?i)version=1\.1/) && !(url =~ /[Ss][Rr][Ss]=\{proj\}/)) {
749 myprintln "* WMS 1.1 with strange SRS specification: ${getDescription(j)}"
750 }
[13511]751 }
[13532]752 if(!(url =~ /^https?:\/\//) && !"scanex".equals(getType(j))) {
753 myprintln "* Strange URL: ${getDescription(j)}"
754 }
[11420]755 if(josmMirrors.containsKey(url)) {
[11964]756 continue
[11420]757 }
758 if(id == null) {
759 myprintln "* No JOSM-ID: ${getDescription(j)}"
760 } else if(josmIds.containsKey(id)) {
761 myprintln "* JOSM-ID ${id} not unique: ${getDescription(j)}"
762 } else {
[11964]763 josmIds.put(id, j)
[11420]764 }
[11572]765 def d = getDate(j)
[11573]766 if(!d.isEmpty()) {
[11639]767 def reg = (d =~ /^(-|(\d\d\d\d)(-(\d\d)(-(\d\d))?)?)(;(-|(\d\d\d\d)(-(\d\d)(-(\d\d))?)?))?$/)
[11572]768 if(reg == null || reg.count != 1) {
769 myprintln "* JOSM-Date '${d}' is strange: ${getDescription(j)}"
770 } else {
771 try {
[11964]772 def first = verifyDate(reg[0][2],reg[0][4],reg[0][6])
773 def second = verifyDate(reg[0][9],reg[0][11],reg[0][13])
[11572]774 if(second.compareTo(first) < 0) {
775 myprintln "* JOSM-Date '${d}' is strange (second earlier than first): ${getDescription(j)}"
776 }
777 }
778 catch (Exception e) {
779 myprintln "* JOSM-Date '${d}' is strange (${e.getMessage()}): ${getDescription(j)}"
780 }
781 }
[11603]782 }
[12261]783 if(getAttributionUrl(j) && !getAttributionText(j)) {
784 myprintln "* Attribution link without text: ${getDescription(j)}"
785 }
786 if(getLogoUrl(j) && !getLogoImage(j)) {
787 myprintln "* Logo link without image: ${getDescription(j)}"
788 }
789 if(getTermsOfUseText(j) && !getTermsOfUseUrl(j)) {
790 myprintln "* Terms of Use text without link: ${getDescription(j)}"
791 }
[11422]792 def js = getShapes(j)
793 if(js.size()) {
[11964]794 def minlat = 1000
795 def minlon = 1000
796 def maxlat = -1000
797 def maxlon = -1000
[11422]798 for(def s: js) {
799 for(def p: s.getPoints()) {
[11964]800 def lat = p.getLat()
801 def lon = p.getLon()
802 if(lat > maxlat) maxlat = lat
803 if(lon > maxlon) maxlon = lon
804 if(lat < minlat) minlat = lat
805 if(lon < minlon) minlon = lon
[11422]806 }
807 }
[11964]808 def b = j.getBounds()
[11422]809 if(b.getMinLat() != minlat || b.getMinLon() != minlon || b.getMaxLat() != maxlat || b.getMaxLon() != maxlon) {
[11423]810 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]811 }
812 }
[11420]813 }
[7726]814 }
[9667]815
[7726]816 /**
817 * Utility functions that allow uniform access for both ImageryInfo and JsonObject.
818 */
819 static String getUrl(Object e) {
820 if (e instanceof ImageryInfo) return e.url
[11412]821 return e.get("properties").getString("url")
[7726]822 }
[12242]823 static String getUrlStripped(Object e) {
824 return getUrl(e).replaceAll("\\?(apikey|access_token)=.*","")
825 }
[11572]826 static String getDate(Object e) {
[11573]827 if (e instanceof ImageryInfo) return e.date ? e.date : ""
828 def p = e.get("properties")
829 def start = p.containsKey("start_date") ? p.getString("start_date") : ""
830 def end = p.containsKey("end_date") ? p.getString("end_date") : ""
831 if(!start.isEmpty() && !end.isEmpty())
[11572]832 return start+";"+end
[11573]833 else if(!start.isEmpty())
[11612]834 return start+";-"
835 else if(!end.isEmpty())
836 return "-;"+end
[11964]837 return ""
[11572]838 }
839 static Date verifyDate(String year, String month, String day) {
840 def date
[11854]841 if(year == null) {
[11572]842 date = "3000-01-01"
[11854]843 } else {
[11572]844 date = year + "-" + (month == null ? "01" : month) + "-" + (day == null ? "01" : day)
[11854]845 }
[11572]846 def df = new java.text.SimpleDateFormat("yyyy-MM-dd")
847 df.setLenient(false)
848 return df.parse(date)
849 }
[11420]850 static String getId(Object e) {
851 if (e instanceof ImageryInfo) return e.getId()
852 return e.get("properties").getString("id")
853 }
[7726]854 static String getName(Object e) {
[10517]855 if (e instanceof ImageryInfo) return e.getOriginalName()
[11412]856 return e.get("properties").getString("name")
[7726]857 }
[11967]858 static List<Object> getMirrors(Object e) {
859 if (e instanceof ImageryInfo) return e.getMirrors()
860 return []
861 }
[11975]862 static List<Object> getProjections(Object e) {
[13530]863 def r = []
864 def u = getProjectionsUnstripped(e)
865 if(u) {
866 for (def p : u) {
867 if(!oldproj.containsKey(p) && !("CRS:84".equals(p) && !(getUrlStripped(e) =~ /(?i)version=1\.3/))) {
868 r += p
869 }
870 }
871 }
872 return r
873 }
874 static List<Object> getProjectionsUnstripped(Object e) {
[11975]875 def r
876 if (e instanceof ImageryInfo) {
877 r = e.getServerProjections()
878 } else {
[11981]879 def s = e.get("properties").get("available_projections")
880 if (s) {
881 r = []
[13530]882 for (def p : s) {
[11981]883 r += p.getString()
[13530]884 }
[11981]885 }
[11975]886 }
887 return r ? r : []
888 }
[11410]889 static List<Shape> getShapes(Object e) {
890 if (e instanceof ImageryInfo) {
[11964]891 def bounds = e.getBounds()
[11411]892 if(bounds != null) {
[11964]893 return bounds.getShapes()
[11411]894 }
895 return []
[11410]896 }
[11412]897 if(!e.isNull("geometry")) {
898 def ex = e.get("geometry")
899 if(ex != null && !ex.isNull("coordinates")) {
900 def poly = ex.get("coordinates")
[11410]901 List<Shape> l = []
902 for(def shapes: poly) {
903 def s = new Shape()
904 for(def point: shapes) {
905 def lon = point[0].toString()
906 def lat = point[1].toString()
907 s.addPoint(lat, lon)
908 }
909 l.add(s)
910 }
911 return l
912 }
913 }
914 return []
915 }
[7726]916 static String getType(Object e) {
917 if (e instanceof ImageryInfo) return e.getImageryType().getTypeString()
[11412]918 return e.get("properties").getString("type")
[7726]919 }
920 static Integer getMinZoom(Object e) {
921 if (e instanceof ImageryInfo) {
[12007]922 if("wms".equals(getType(e)) && e.getName() =~ / mirror/)
923 return null;
[7726]924 int mz = e.getMinZoom()
925 return mz == 0 ? null : mz
926 } else {
[11412]927 def num = e.get("properties").getJsonNumber("min_zoom")
[7726]928 if (num == null) return null
929 return num.intValue()
930 }
931 }
932 static Integer getMaxZoom(Object e) {
933 if (e instanceof ImageryInfo) {
[12007]934 if("wms".equals(getType(e)) && e.getName() =~ / mirror/)
935 return null;
[7726]936 int mz = e.getMaxZoom()
937 return mz == 0 ? null : mz
938 } else {
[11412]939 def num = e.get("properties").getJsonNumber("max_zoom")
[7726]940 if (num == null) return null
941 return num.intValue()
942 }
943 }
944 static String getCountryCode(Object e) {
945 if (e instanceof ImageryInfo) return "".equals(e.getCountryCode()) ? null : e.getCountryCode()
[11412]946 return e.get("properties").getString("country_code", null)
[7726]947 }
[9505]948 static String getQuality(Object e) {
[11575]949 if (e instanceof ImageryInfo) return e.isBestMarked() ? "eli-best" : null
[11603]950 return (e.get("properties").containsKey("best")
951 && e.get("properties").getBoolean("best")) ? "eli-best" : null
[9505]952 }
[13536]953 static Boolean getOverlay(Object e) {
954 if (e instanceof ImageryInfo) return e.isOverlay()
955 return (e.get("properties").containsKey("overlay")
956 && e.get("properties").getBoolean("overlay"))
957 }
[11420]958 static String getIcon(Object e) {
959 if (e instanceof ImageryInfo) return e.getIcon()
960 return e.get("properties").getString("icon", null)
961 }
[11975]962 static String getAttributionText(Object e) {
963 if (e instanceof ImageryInfo) return e.getAttributionText(0, null, null)
964 try {return e.get("properties").get("attribution").getString("text", null)} catch (NullPointerException ex) {return null}
965 }
966 static String getAttributionUrl(Object e) {
967 if (e instanceof ImageryInfo) return e.getAttributionLinkURL()
968 try {return e.get("properties").get("attribution").getString("url", null)} catch (NullPointerException ex) {return null}
969 }
970 static String getTermsOfUseText(Object e) {
971 if (e instanceof ImageryInfo) return e.getTermsOfUseText()
972 return null
973 }
974 static String getTermsOfUseUrl(Object e) {
975 if (e instanceof ImageryInfo) return e.getTermsOfUseURL()
976 return null
977 }
[12261]978 static String getLogoImage(Object e) {
979 if (e instanceof ImageryInfo) return e.getAttributionImageRaw()
980 return null
981 }
982 static String getLogoUrl(Object e) {
983 if (e instanceof ImageryInfo) return e.getAttributionImageURL()
984 return null
985 }
[11975]986 static String getPermissionReferenceUrl(Object e) {
987 if (e instanceof ImageryInfo) return e.getPermissionReferenceURL()
988 return e.get("properties").getString("license_url", null)
989 }
990 static Map<String,String> getDescriptions(Object e) {
991 Map<String,String> res = new HashMap<String, String>()
992 if (e instanceof ImageryInfo) {
993 String a = e.getDescription()
994 if (a) res.put("en", a)
995 } else {
996 String a = e.get("properties").getString("description", null)
997 if (a) res.put("en", a)
998 }
999 return res
1000 }
1001 static Boolean getValidGeoreference(Object e) {
1002 if (e instanceof ImageryInfo) return e.isGeoreferenceValid()
1003 return false
1004 }
[12226]1005 static Boolean getDefault(Object e) {
1006 if (e instanceof ImageryInfo) return e.isDefaultEntry()
1007 return e.get("properties").getBoolean("default", false)
1008 }
[7726]1009 String getDescription(Object o) {
1010 def url = getUrl(o)
1011 def cc = getCountryCode(o)
1012 if (cc == null) {
1013 def j = josmUrls.get(url)
1014 if (j != null) cc = getCountryCode(j)
1015 if (cc == null) {
[11582]1016 def e = eliUrls.get(url)
[7726]1017 if (e != null) cc = getCountryCode(e)
1018 }
1019 }
1020 if (cc == null) {
1021 cc = ''
1022 } else {
1023 cc = "[$cc] "
1024 }
1025 def d = cc + getName(o) + " - " + getUrl(o)
1026 if (options.shorten) {
1027 def MAXLEN = 140
1028 if (d.length() > MAXLEN) d = d.substring(0, MAXLEN-1) + "..."
1029 }
1030 return d
1031 }
1032}
Note: See TracBrowser for help on using the repository browser.