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

Last change on this file since 12711 was 12266, checked in by stoecker, 7 years ago

see #14655 - drop remaining SKIP types

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