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

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

handle double quotes as if they were single

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