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

Last change on this file since 11965 was 11965, checked in by stoecker, 7 years ago

ELI sync - unify filenames (also support loading in imagery index plugin)

  • Property svn:eol-style set to native
File size: 26.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2/**
3 * Compare and analyse the differences of the editor layer index and the JOSM imagery list.
4 * The goal is to keep both lists in sync.
5 *
6 * The editor layer index project (https://github.com/osmlab/editor-layer-index)
7 * provides also a version in the JOSM format, but the GEOJSON is the original source
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 *
15 * $ groovy -cp ../dist/josm-custom.jar SyncEditorLayerIndex.groovy
16 *
17 * Add option "-h" to show the available command line flags.
18 */
19import javax.json.Json
20import javax.json.JsonArray
21import javax.json.JsonObject
22import javax.json.JsonReader
23
24import org.openstreetmap.josm.data.imagery.ImageryInfo
25import org.openstreetmap.josm.data.imagery.Shape
26import org.openstreetmap.josm.io.imagery.ImageryReader
27
28class SyncEditorLayerIndex {
29
30 List<ImageryInfo> josmEntries;
31 JsonArray eliEntries;
32
33 def eliUrls = new HashMap<String, JsonObject>()
34 def josmUrls = new HashMap<String, ImageryInfo>()
35 def josmMirrors = new HashMap<String, ImageryInfo>()
36
37 static String eliInputFile = 'imagery_eli.geojson'
38 static String josmInputFile = 'imagery_josm.imagery.xml'
39 static String ignoreInputFile = 'imagery_josm.ignores.txt'
40 static FileWriter outputFile = null
41 static BufferedWriter outputStream = null
42 def skip = [:]
43
44 static def options
45
46 /**
47 * Main method.
48 */
49 static main(def args) {
50 parse_command_line_arguments(args)
51 def script = new SyncEditorLayerIndex()
52 script.loadSkip()
53 script.start()
54 script.loadJosmEntries()
55 if(options.josmxml) {
56 def file = new FileWriter(options.josmxml)
57 def stream = new BufferedWriter(file)
58 script.printentries(script.josmEntries, stream)
59 }
60 script.loadELIEntries()
61 if(options.elixml) {
62 def file = new FileWriter(options.elixml)
63 def stream = new BufferedWriter(file)
64 script.printentries(script.eliEntries, stream)
65 }
66 script.checkInOneButNotTheOther()
67 script.checkCommonEntries()
68 script.end()
69 if(outputStream != null) {
70 outputStream.close();
71 }
72 if(outputFile != null) {
73 outputFile.close();
74 }
75 }
76
77 /**
78 * Parse command line arguments.
79 */
80 static void parse_command_line_arguments(args) {
81 def cli = new CliBuilder(width: 160)
82 cli.o(longOpt:'output', args:1, argName: "output", "Output file, - prints to stdout (default: -)")
83 cli.e(longOpt:'eli_input', args:1, argName:"eli_input", "Input file for the editor layer index (geojson). Default is $eliInputFile (current directory).")
84 cli.j(longOpt:'josm_input', args:1, argName:"josm_input", "Input file for the JOSM imagery list (xml). Default is $josmInputFile (current directory).")
85 cli.i(longOpt:'ignore_input', args:1, argName:"ignore_input", "Input file for the ignore list. Default is $ignoreInputFile (current directory).")
86 cli.s(longOpt:'shorten', "shorten the output, so it is easier to read in a console window")
87 cli.n(longOpt:'noskip', argName:"noskip", "don't skip known entries")
88 cli.x(longOpt:'xhtmlbody', argName:"xhtmlbody", "create XHTML body for display in a web page")
89 cli.X(longOpt:'xhtml', argName:"xhtml", "create XHTML for display in a web page")
90 cli.p(longOpt:'elixml', args:1, argName:"elixml", "ELI entries for use in JOSM as XML file (incomplete)")
91 cli.q(longOpt:'josmxml', args:1, argName:"josmxml", "JOSM entries reoutput as XML file (incomplete)")
92 cli.m(longOpt:'noeli', argName:"noeli", "don't show output for ELI problems")
93 cli.h(longOpt:'help', "show this help")
94 options = cli.parse(args)
95
96 if (options.h) {
97 cli.usage()
98 System.exit(0)
99 }
100 if (options.eli_input) {
101 eliInputFile = options.eli_input
102 }
103 if (options.josm_input) {
104 josmInputFile = options.josm_input
105 }
106 if (options.ignore_input) {
107 ignoreInputFile = options.ignore_input
108 }
109 if (options.output && options.output != "-") {
110 outputFile = new FileWriter(options.output)
111 outputStream = new BufferedWriter(outputFile)
112 }
113 }
114
115 void loadSkip() {
116 FileReader fr = new FileReader(ignoreInputFile)
117 def line
118
119 while((line = fr.readLine()) != null) {
120 def res = (line =~ /^\|\| *(ELI|Ignore) *\|\| *\{\{\{(.+)\}\}\} *\|\|/)
121 if(res.count)
122 {
123 if(res[0][1].equals("Ignore")) {
124 skip[res[0][2]] = "green"
125 } else {
126 skip[res[0][2]] = "darkgoldenrod"
127 }
128 }
129 }
130 }
131
132 void myprintlnfinal(String s) {
133 if(outputStream != null) {
134 outputStream.write(s)
135 outputStream.newLine()
136 } else {
137 println s
138 }
139 }
140
141 void myprintln(String s) {
142 if(skip.containsKey(s)) {
143 String color = skip.get(s)
144 skip.remove(s)
145 if(options.xhtmlbody || options.xhtml) {
146 s = "<pre style=\"margin:3px;color:"+color+"\">"+s.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")+"</pre>"
147 }
148 if (!options.noskip) {
149 return
150 }
151 } else if(options.xhtmlbody || options.xhtml) {
152 String color = s.startsWith("***") ? "black" : ((s.startsWith("+ ") || s.startsWith("+++ ELI")) ? "blue" : "red")
153 s = "<pre style=\"margin:3px;color:"+color+"\">"+s.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")+"</pre>"
154 }
155 if ((s.startsWith("+ ") || s.startsWith("+++ ELI")) && options.noeli) {
156 return
157 }
158 myprintlnfinal(s)
159 }
160
161 void start() {
162 if (options.xhtml) {
163 myprintlnfinal "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
164 myprintlnfinal "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/><title>JOSM - ELI differences</title></head><body>\n"
165 }
166 }
167
168 void end() {
169 for (def s: skip.keySet()) {
170 myprintln "+++ Obsolete skip entry: " + s
171 }
172 if (options.xhtml) {
173 myprintlnfinal "</body></html>\n"
174 }
175 }
176
177 void loadELIEntries() {
178 FileReader fr = new FileReader(eliInputFile)
179 JsonReader jr = Json.createReader(fr)
180 eliEntries = jr.readObject().get("features")
181 jr.close()
182
183 for (def e : eliEntries) {
184 def url = getUrl(e)
185 if (url.contains("{z}")) {
186 myprintln "+++ ELI-URL uses {z} instead of {zoom}: "+url
187 url = url.replace("{z}","{zoom}")
188 }
189 if (eliUrls.containsKey(url)) {
190 myprintln "+++ ELI-URL is not unique: "+url
191 } else {
192 eliUrls.put(url, e)
193 }
194 }
195 myprintln "*** Loaded ${eliEntries.size()} entries (ELI). ***"
196 }
197
198 void printentries(def entries, def stream) {
199 stream.write "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
200 stream.write "<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n"
201 for (def e : entries) {
202 def best = "eli-best".equals(getQuality(e))
203 stream.write " <entry"+(best ? " eli-best=\"true\"" : "" )+">\n"
204 stream.write " <name>${getName(e)}</name>\n"
205 stream.write " <id>${getId(e)}</id>\n"
206 def minlat = 1000
207 def minlon = 1000
208 def maxlat = -1000
209 def maxlon = -1000
210 def shapes = ""
211 def sep = "\n "
212 for(def s: getShapes(e)) {
213 shapes += " <shape>"
214 def i = 0
215 for(def p: s.getPoints()) {
216 def lat = p.getLat()
217 def lon = p.getLon()
218 if(lat > maxlat) maxlat = lat
219 if(lon > maxlon) maxlon = lon
220 if(lat < minlat) minlat = lat
221 if(lon < minlon) minlon = lon
222 if(!(i++%3)) {
223 shapes += sep + " "
224 }
225 shapes += "<point lat='${String.format(Locale.ROOT, "%.7f",lat)}' lon='${String.format(Locale.ROOT, "%.7f",lon)}'/>"
226 }
227 shapes += sep + "</shape>\n"
228 }
229 if(shapes) {
230 stream.write " <bounds min-lat='${minlat}' min-lon='${minlon}' max-lat='${maxlat}' max-lon='${maxlon}'>\n"
231 stream.write shapes + " </bounds>\n"
232 stream.write " </entry>\n"
233 }
234 }
235 stream.write "</imagery>\n"
236 stream.close()
237 }
238
239 void loadJosmEntries() {
240 def reader = new ImageryReader(josmInputFile)
241 josmEntries = reader.parse()
242
243 for (def e : josmEntries) {
244 def url = getUrl(e)
245 if (url.contains("{z}")) {
246 myprintln "+++ JOSM-URL uses {z} instead of {zoom}: "+url
247 url = url.replace("{z}","{zoom}")
248 }
249 if (josmUrls.containsKey(url)) {
250 myprintln "+++ JOSM-URL is not unique: "+url
251 } else {
252 josmUrls.put(url, e)
253 }
254 for (def m : e.getMirrors()) {
255 url = getUrl(m)
256 m.origName = m.getOriginalName().replaceAll(" mirror server( \\d+)?","")
257 if (josmUrls.containsKey(url)) {
258 myprintln "+++ JOSM-Mirror-URL is not unique: "+url
259 } else {
260 josmUrls.put(url, m)
261 josmMirrors.put(url, m)
262 }
263 }
264 }
265 myprintln "*** Loaded ${josmEntries.size()} entries (JOSM). ***"
266 }
267
268 List inOneButNotTheOther(Map m1, Map m2) {
269 def l = []
270 for (def url : m1.keySet()) {
271 if (!m2.containsKey(url)) {
272 def name = getName(m1.get(url))
273 l += " "+getDescription(m1.get(url))
274 }
275 }
276 l.sort()
277 }
278
279 void checkInOneButNotTheOther() {
280 def l1 = inOneButNotTheOther(eliUrls, josmUrls)
281 myprintln "*** URLs found in ELI but not in JOSM (${l1.size()}): ***"
282 if (!l1.isEmpty()) {
283 for (def l : l1) {
284 myprintln "-" + l
285 }
286 }
287
288 def l2 = inOneButNotTheOther(josmUrls, eliUrls)
289 myprintln "*** URLs found in JOSM but not in ELI (${l2.size()}): ***"
290 if (!l2.isEmpty()) {
291 for (def l : l2) {
292 myprintln "+" + l
293 }
294 }
295 }
296
297 void checkCommonEntries() {
298 myprintln "*** Same URL, but different name: ***"
299 for (def url : eliUrls.keySet()) {
300 def e = eliUrls.get(url)
301 if (!josmUrls.containsKey(url)) continue
302 def j = josmUrls.get(url)
303 def ename = getName(e).replace("'","’")
304 def jname = getName(j).replace("'","’")
305 if (!ename.equals(jname)) {
306 myprintln "* Name differs ('${getName(e)}' != '${getName(j)}'): $url"
307 }
308 }
309
310 myprintln "*** Same URL, but different type: ***"
311 for (def url : eliUrls.keySet()) {
312 def e = eliUrls.get(url)
313 if (!josmUrls.containsKey(url)) continue
314 def j = josmUrls.get(url)
315 if (!getType(e).equals(getType(j))) {
316 myprintln "* Type differs (${getType(e)} != ${getType(j)}): ${getName(j)} - $url"
317 }
318 }
319
320 myprintln "*** Same URL, but different zoom bounds: ***"
321 for (def url : eliUrls.keySet()) {
322 def e = eliUrls.get(url)
323 if (!josmUrls.containsKey(url)) continue
324 def j = josmUrls.get(url)
325
326 Integer eMinZoom = getMinZoom(e)
327 Integer jMinZoom = getMinZoom(j)
328 if (eMinZoom != jMinZoom && !(eMinZoom == 0 && jMinZoom == null)) {
329 myprintln "* Minzoom differs (${eMinZoom} != ${jMinZoom}): ${getDescription(j)}"
330 }
331 Integer eMaxZoom = getMaxZoom(e)
332 Integer jMaxZoom = getMaxZoom(j)
333 if (eMaxZoom != jMaxZoom) {
334 myprintln "* Maxzoom differs (${eMaxZoom} != ${jMaxZoom}): ${getDescription(j)}"
335 }
336 }
337
338 myprintln "*** Same URL, but different country code: ***"
339 for (def url : eliUrls.keySet()) {
340 def e = eliUrls.get(url)
341 if (!josmUrls.containsKey(url)) continue
342 def j = josmUrls.get(url)
343 if (!getCountryCode(e).equals(getCountryCode(j))) {
344 myprintln "* Country code differs (${getCountryCode(e)} != ${getCountryCode(j)}): ${getDescription(j)}"
345 }
346 }
347 myprintln "*** Same URL, but different quality: ***"
348 for (def url : eliUrls.keySet()) {
349 def e = eliUrls.get(url)
350 if (!josmUrls.containsKey(url)) {
351 def q = getQuality(e)
352 if("eli-best".equals(q)) {
353 myprintln "- Quality best entry not in JOSM for ${getDescription(e)}"
354 }
355 continue
356 }
357 def j = josmUrls.get(url)
358 if (!getQuality(e).equals(getQuality(j))) {
359 myprintln "* Quality differs (${getQuality(e)} != ${getQuality(j)}): ${getDescription(j)}"
360 }
361 }
362 myprintln "*** Same URL, but different dates: ***"
363 for (def url : eliUrls.keySet()) {
364 def ed = getDate(eliUrls.get(url))
365 if (!josmUrls.containsKey(url)) continue
366 def j = josmUrls.get(url)
367 def jd = getDate(j)
368 // The forms 2015;- or -;2015 or 2015;2015 are handled equal to 2015
369 String ef = ed.replaceAll("\\A-;","").replaceAll(";-\\z","").replaceAll("\\A([0-9-]+);\\1\\z","\$1")
370 // ELI has a strange and inconsistent used end_date definition, so we try again with subtraction by one
371 String ed2 = ed
372 def reg = (ed =~ /^(.*;)(\d\d\d\d)(-(\d\d)(-(\d\d))?)?$/)
373 if(reg != null && reg.count == 1) {
374 Calendar cal = Calendar.getInstance()
375 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)
376 cal.add(Calendar.DAY_OF_MONTH, -1)
377 ed2 = reg[0][1] + cal.get(Calendar.YEAR)
378 if (reg[0][4] != null)
379 ed2 += "-" + String.format("%02d", cal.get(Calendar.MONTH)+1)
380 if (reg[0][6] != null)
381 ed2 += "-" + String.format("%02d", cal.get(Calendar.DAY_OF_MONTH))
382 }
383 String ef2 = ed2.replaceAll("\\A-;","").replaceAll(";-\\z","").replaceAll("\\A([0-9-]+);\\1\\z","\$1")
384 if (!ed.equals(jd) && !ef.equals(jd) && !ed2.equals(jd) && !ef2.equals(jd)) {
385 String t = "'${ed}'"
386 if (!ed.equals(ef)) {
387 t += " or '${ef}'"
388 }
389 if (jd.isEmpty()) {
390 myprintln "- Missing JOSM date (${t}): ${getDescription(j)}"
391 } else if (!ed.isEmpty()) {
392 myprintln "* Date differs (${t} != '${jd}'): ${getDescription(j)}"
393 } else if (!options.nomissingeli) {
394 myprintln "+ Missing ELI date ('${jd}'): ${getDescription(j)}"
395 }
396 }
397 }
398 myprintln "*** Mismatching shapes: ***"
399 for (def url : josmUrls.keySet()) {
400 def j = josmUrls.get(url)
401 def num = 1
402 for (def shape : getShapes(j)) {
403 def p = shape.getPoints()
404 if(!p[0].equals(p[p.size()-1])) {
405 myprintln "+++ JOSM shape $num unclosed: ${getDescription(j)}"
406 }
407 for (def nump = 1; nump < p.size(); ++nump) {
408 if (p[nump-1] == p[nump]) {
409 myprintln "+++ JOSM shape $num double point at ${nump-1}: ${getDescription(j)}"
410 }
411 }
412 ++num
413 }
414 }
415 for (def url : eliUrls.keySet()) {
416 def e = eliUrls.get(url)
417 def num = 1
418 def s = getShapes(e)
419 for (def shape : s) {
420 def p = shape.getPoints()
421 if(!p[0].equals(p[p.size()-1]) && !options.nomissingeli) {
422 myprintln "+++ ELI shape $num unclosed: ${getDescription(e)}"
423 }
424 for (def nump = 1; nump < p.size(); ++nump) {
425 if (p[nump-1] == p[nump]) {
426 myprintln "+++ ELI shape $num double point at ${nump-1}: ${getDescription(e)}"
427 }
428 }
429 ++num
430 }
431 if (!josmUrls.containsKey(url)) {
432 continue
433 }
434 def j = josmUrls.get(url)
435 def js = getShapes(j)
436 if(!s.size() && js.size()) {
437 if(!options.nomissingeli) {
438 myprintln "+ No ELI shape: ${getDescription(j)}"
439 }
440 } else if(!js.size() && s.size()) {
441 // don't report boundary like 5 point shapes as difference
442 if (s.size() != 1 || s[0].getPoints().size() != 5) {
443 myprintln "- No JOSM shape: ${getDescription(j)}"
444 }
445 } else if(s.size() != js.size()) {
446 myprintln "* Different number of shapes (${s.size()} != ${js.size()}): ${getDescription(j)}"
447 } else {
448 for(def nums = 0; nums < s.size(); ++nums) {
449 def ep = s[nums].getPoints()
450 def jp = js[nums].getPoints()
451 if(ep.size() != jp.size()) {
452 myprintln "* Different number of points for shape ${nums+1} (${ep.size()} ! = ${jp.size()})): ${getDescription(j)}"
453 } else {
454 for(def nump = 0; nump < ep.size(); ++nump) {
455 def ept = ep[nump]
456 def jpt = jp[nump]
457 if(Math.abs(ept.getLat()-jpt.getLat()) > 0.000001 || Math.abs(ept.getLon()-jpt.getLon()) > 0.000001) {
458 myprintln "* Different coordinate for point ${nump+1} of shape ${nums+1}: ${getDescription(j)}"
459 nump = ep.size()
460 num = s.size()
461 }
462 }
463 }
464 }
465 }
466 }
467 myprintln "*** Mismatching icons: ***"
468 for (def url : eliUrls.keySet()) {
469 def e = eliUrls.get(url)
470 if (!josmUrls.containsKey(url)) {
471 continue
472 }
473 def j = josmUrls.get(url)
474 def ij = getIcon(j)
475 def ie = getIcon(e)
476 if(ij != null && ie == null) {
477 if(!options.nomissingeli) {
478 myprintln "+ No ELI icon: ${getDescription(j)}"
479 }
480 } else if(ij == null && ie != null) {
481 myprintln "- No JOSM icon: ${getDescription(j)}"
482 } else if(!ij.equals(ie)) {
483 myprintln "* Different icons: ${getDescription(j)}"
484 }
485 }
486 myprintln "*** Miscellaneous checks: ***"
487 def josmIds = new HashMap<String, ImageryInfo>()
488 for (def url : josmUrls.keySet()) {
489 def j = josmUrls.get(url)
490 def id = getId(j)
491 if(josmMirrors.containsKey(url)) {
492 continue
493 }
494 if(id == null) {
495 myprintln "* No JOSM-ID: ${getDescription(j)}"
496 } else if(josmIds.containsKey(id)) {
497 myprintln "* JOSM-ID ${id} not unique: ${getDescription(j)}"
498 } else {
499 josmIds.put(id, j)
500 }
501 def d = getDate(j)
502 if(!d.isEmpty()) {
503 def reg = (d =~ /^(-|(\d\d\d\d)(-(\d\d)(-(\d\d))?)?)(;(-|(\d\d\d\d)(-(\d\d)(-(\d\d))?)?))?$/)
504 if(reg == null || reg.count != 1) {
505 myprintln "* JOSM-Date '${d}' is strange: ${getDescription(j)}"
506 } else {
507 try {
508 def first = verifyDate(reg[0][2],reg[0][4],reg[0][6])
509 def second = verifyDate(reg[0][9],reg[0][11],reg[0][13])
510 if(second.compareTo(first) < 0) {
511 myprintln "* JOSM-Date '${d}' is strange (second earlier than first): ${getDescription(j)}"
512 }
513 }
514 catch (Exception e) {
515 myprintln "* JOSM-Date '${d}' is strange (${e.getMessage()}): ${getDescription(j)}"
516 }
517 }
518 }
519 def js = getShapes(j)
520 if(js.size()) {
521 def minlat = 1000
522 def minlon = 1000
523 def maxlat = -1000
524 def maxlon = -1000
525 for(def s: js) {
526 for(def p: s.getPoints()) {
527 def lat = p.getLat()
528 def lon = p.getLon()
529 if(lat > maxlat) maxlat = lat
530 if(lon > maxlon) maxlon = lon
531 if(lat < minlat) minlat = lat
532 if(lon < minlon) minlon = lon
533 }
534 }
535 def b = j.getBounds()
536 if(b.getMinLat() != minlat || b.getMinLon() != minlon || b.getMaxLat() != maxlat || b.getMaxLon() != maxlon) {
537 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)}"
538 }
539 }
540 }
541 }
542
543 /**
544 * Utility functions that allow uniform access for both ImageryInfo and JsonObject.
545 */
546 static String getUrl(Object e) {
547 if (e instanceof ImageryInfo) return e.url
548 return e.get("properties").getString("url")
549 }
550 static String getDate(Object e) {
551 if (e instanceof ImageryInfo) return e.date ? e.date : ""
552 def p = e.get("properties")
553 def start = p.containsKey("start_date") ? p.getString("start_date") : ""
554 def end = p.containsKey("end_date") ? p.getString("end_date") : ""
555 if(!start.isEmpty() && !end.isEmpty())
556 return start+";"+end
557 else if(!start.isEmpty())
558 return start+";-"
559 else if(!end.isEmpty())
560 return "-;"+end
561 return ""
562 }
563 static Date verifyDate(String year, String month, String day) {
564 def date
565 if(year == null) {
566 date = "3000-01-01"
567 } else {
568 date = year + "-" + (month == null ? "01" : month) + "-" + (day == null ? "01" : day)
569 }
570 def df = new java.text.SimpleDateFormat("yyyy-MM-dd")
571 df.setLenient(false)
572 return df.parse(date)
573 }
574 static String getId(Object e) {
575 if (e instanceof ImageryInfo) return e.getId()
576 return e.get("properties").getString("id")
577 }
578 static String getName(Object e) {
579 if (e instanceof ImageryInfo) return e.getOriginalName()
580 return e.get("properties").getString("name")
581 }
582 static List<Shape> getShapes(Object e) {
583 if (e instanceof ImageryInfo) {
584 def bounds = e.getBounds()
585 if(bounds != null) {
586 return bounds.getShapes()
587 }
588 return []
589 }
590 if(!e.isNull("geometry")) {
591 def ex = e.get("geometry")
592 if(ex != null && !ex.isNull("coordinates")) {
593 def poly = ex.get("coordinates")
594 List<Shape> l = []
595 for(def shapes: poly) {
596 def s = new Shape()
597 for(def point: shapes) {
598 def lon = point[0].toString()
599 def lat = point[1].toString()
600 s.addPoint(lat, lon)
601 }
602 l.add(s)
603 }
604 return l
605 }
606 }
607 return []
608 }
609 static String getType(Object e) {
610 if (e instanceof ImageryInfo) return e.getImageryType().getTypeString()
611 return e.get("properties").getString("type")
612 }
613 static Integer getMinZoom(Object e) {
614 if (e instanceof ImageryInfo) {
615 int mz = e.getMinZoom()
616 return mz == 0 ? null : mz
617 } else {
618 def num = e.get("properties").getJsonNumber("min_zoom")
619 if (num == null) return null
620 return num.intValue()
621 }
622 }
623 static Integer getMaxZoom(Object e) {
624 if (e instanceof ImageryInfo) {
625 int mz = e.getMaxZoom()
626 return mz == 0 ? null : mz
627 } else {
628 def num = e.get("properties").getJsonNumber("max_zoom")
629 if (num == null) return null
630 return num.intValue()
631 }
632 }
633 static String getCountryCode(Object e) {
634 if (e instanceof ImageryInfo) return "".equals(e.getCountryCode()) ? null : e.getCountryCode()
635 return e.get("properties").getString("country_code", null)
636 }
637 static String getQuality(Object e) {
638 if (e instanceof ImageryInfo) return e.isBestMarked() ? "eli-best" : null
639 return (e.get("properties").containsKey("best")
640 && e.get("properties").getBoolean("best")) ? "eli-best" : null
641 }
642 static String getIcon(Object e) {
643 if (e instanceof ImageryInfo) return e.getIcon()
644 return e.get("properties").getString("icon", null)
645 }
646 String getDescription(Object o) {
647 def url = getUrl(o)
648 def cc = getCountryCode(o)
649 if (cc == null) {
650 def j = josmUrls.get(url)
651 if (j != null) cc = getCountryCode(j)
652 if (cc == null) {
653 def e = eliUrls.get(url)
654 if (e != null) cc = getCountryCode(e)
655 }
656 }
657 if (cc == null) {
658 cc = ''
659 } else {
660 cc = "[$cc] "
661 }
662 def d = cc + getName(o) + " - " + getUrl(o)
663 if (options.shorten) {
664 def MAXLEN = 140
665 if (d.length() > MAXLEN) d = d.substring(0, MAXLEN-1) + "..."
666 }
667 return d
668 }
669}
Note: See TracBrowser for help on using the repository browser.