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

Last change on this file since 13775 was 13775, checked in by Don-vip, 6 years ago

fix preferences initialization

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