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

Last change on this file since 14133 was 14020, checked in by Don-vip, 7 years ago

remove import requiring Groovy >= 2.3

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