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

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

typo

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