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

Last change on this file since 13551 was 13551, checked in by stoecker, 6 years ago

some imagery sanity checks

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