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 | */
|
---|
19 | import java.text.DecimalFormat
|
---|
20 | import javax.json.Json
|
---|
21 | import javax.json.JsonArray
|
---|
22 | import javax.json.JsonObject
|
---|
23 | import javax.json.JsonReader
|
---|
24 |
|
---|
25 | import org.openstreetmap.josm.data.imagery.ImageryInfo
|
---|
26 | import org.openstreetmap.josm.data.imagery.Shape
|
---|
27 | import org.openstreetmap.josm.io.imagery.ImageryReader
|
---|
28 |
|
---|
29 | class SyncEditorLayerIndex {
|
---|
30 |
|
---|
31 | List<ImageryInfo> josmEntries;
|
---|
32 | JsonArray eliEntries;
|
---|
33 |
|
---|
34 | def eliUrls = new HashMap<String, JsonObject>()
|
---|
35 | def josmUrls = new HashMap<String, ImageryInfo>()
|
---|
36 | def josmMirrors = new HashMap<String, ImageryInfo>()
|
---|
37 |
|
---|
38 | static String eliInputFile = 'imagery_eli.geojson'
|
---|
39 | static String josmInputFile = 'imagery_josm.imagery.xml'
|
---|
40 | static String ignoreInputFile = 'imagery_josm.ignores.txt'
|
---|
41 | static FileOutputStream outputFile = null
|
---|
42 | static OutputStreamWriter outputStream = null
|
---|
43 | def skip = [:]
|
---|
44 |
|
---|
45 | static def options
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Main method.
|
---|
49 | */
|
---|
50 | static main(def args) {
|
---|
51 | Locale.setDefault(Locale.ROOT);
|
---|
52 | parse_command_line_arguments(args)
|
---|
53 | def script = new SyncEditorLayerIndex()
|
---|
54 | script.loadSkip()
|
---|
55 | script.start()
|
---|
56 | script.loadJosmEntries()
|
---|
57 | if(options.josmxml) {
|
---|
58 | def file = new FileOutputStream(options.josmxml)
|
---|
59 | def stream = new OutputStreamWriter(file, "UTF-8")
|
---|
60 | script.printentries(script.josmEntries, stream)
|
---|
61 | stream.close();
|
---|
62 | file.close();
|
---|
63 | }
|
---|
64 | script.loadELIEntries()
|
---|
65 | if(options.elixml) {
|
---|
66 | def file = new FileOutputStream(options.elixml)
|
---|
67 | def stream = new OutputStreamWriter(file, "UTF-8")
|
---|
68 | script.printentries(script.eliEntries, stream)
|
---|
69 | stream.close();
|
---|
70 | file.close();
|
---|
71 | }
|
---|
72 | script.checkInOneButNotTheOther()
|
---|
73 | script.checkCommonEntries()
|
---|
74 | script.end()
|
---|
75 | if(outputStream != null) {
|
---|
76 | outputStream.close();
|
---|
77 | }
|
---|
78 | if(outputFile != null) {
|
---|
79 | outputFile.close();
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Parse command line arguments.
|
---|
85 | */
|
---|
86 | static void parse_command_line_arguments(args) {
|
---|
87 | def cli = new CliBuilder(width: 160)
|
---|
88 | cli.o(longOpt:'output', args:1, argName: "output", "Output file, - prints to stdout (default: -)")
|
---|
89 | cli.e(longOpt:'eli_input', args:1, argName:"eli_input", "Input file for the editor layer index (geojson). Default is $eliInputFile (current directory).")
|
---|
90 | cli.j(longOpt:'josm_input', args:1, argName:"josm_input", "Input file for the JOSM imagery list (xml). Default is $josmInputFile (current directory).")
|
---|
91 | cli.i(longOpt:'ignore_input', args:1, argName:"ignore_input", "Input file for the ignore list. Default is $ignoreInputFile (current directory).")
|
---|
92 | cli.s(longOpt:'shorten', "shorten the output, so it is easier to read in a console window")
|
---|
93 | cli.n(longOpt:'noskip', argName:"noskip", "don't skip known entries")
|
---|
94 | cli.x(longOpt:'xhtmlbody', argName:"xhtmlbody", "create XHTML body for display in a web page")
|
---|
95 | cli.X(longOpt:'xhtml', argName:"xhtml", "create XHTML for display in a web page")
|
---|
96 | cli.p(longOpt:'elixml', args:1, argName:"elixml", "ELI entries for use in JOSM as XML file (incomplete)")
|
---|
97 | cli.q(longOpt:'josmxml', args:1, argName:"josmxml", "JOSM entries reoutput as XML file (incomplete)")
|
---|
98 | cli.m(longOpt:'noeli', argName:"noeli", "don't show output for ELI problems")
|
---|
99 | cli.h(longOpt:'help', "show this help")
|
---|
100 | options = cli.parse(args)
|
---|
101 |
|
---|
102 | if (options.h) {
|
---|
103 | cli.usage()
|
---|
104 | System.exit(0)
|
---|
105 | }
|
---|
106 | if (options.eli_input) {
|
---|
107 | eliInputFile = options.eli_input
|
---|
108 | }
|
---|
109 | if (options.josm_input) {
|
---|
110 | josmInputFile = options.josm_input
|
---|
111 | }
|
---|
112 | if (options.ignore_input) {
|
---|
113 | ignoreInputFile = options.ignore_input
|
---|
114 | }
|
---|
115 | if (options.output && options.output != "-") {
|
---|
116 | outputFile = new FileOutputStream(options.output)
|
---|
117 | outputStream = new OutputStreamWriter(outputFile, "UTF-8")
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | void loadSkip() {
|
---|
122 | def fr = new InputStreamReader(new FileInputStream(ignoreInputFile), "UTF-8")
|
---|
123 | def line
|
---|
124 |
|
---|
125 | while((line = fr.readLine()) != null) {
|
---|
126 | def res = (line =~ /^\|\| *(ELI|Ignore) *\|\| *\{\{\{(.+)\}\}\} *\|\|/)
|
---|
127 | if(res.count)
|
---|
128 | {
|
---|
129 | if(res[0][1].equals("Ignore")) {
|
---|
130 | skip[res[0][2]] = "green"
|
---|
131 | } else {
|
---|
132 | skip[res[0][2]] = "darkgoldenrod"
|
---|
133 | }
|
---|
134 | }
|
---|
135 | }
|
---|
136 | }
|
---|
137 |
|
---|
138 | void myprintlnfinal(String s) {
|
---|
139 | if(outputStream != null) {
|
---|
140 | outputStream.write(s+System.getProperty("line.separator"))
|
---|
141 | } else {
|
---|
142 | println s
|
---|
143 | }
|
---|
144 | }
|
---|
145 |
|
---|
146 | void myprintln(String s) {
|
---|
147 | if(skip.containsKey(s)) {
|
---|
148 | String color = skip.get(s)
|
---|
149 | skip.remove(s)
|
---|
150 | if(options.xhtmlbody || options.xhtml) {
|
---|
151 | s = "<pre style=\"margin:3px;color:"+color+"\">"+s.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">")+"</pre>"
|
---|
152 | }
|
---|
153 | if (!options.noskip) {
|
---|
154 | return
|
---|
155 | }
|
---|
156 | } else if(options.xhtmlbody || options.xhtml) {
|
---|
157 | String color = s.startsWith("***") ? "black" : ((s.startsWith("+ ") || s.startsWith("+++ ELI")) ? "blue" : (s.startsWith("#") ? "indigo" : "red"))
|
---|
158 | s = "<pre style=\"margin:3px;color:"+color+"\">"+s.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">")+"</pre>"
|
---|
159 | }
|
---|
160 | if ((s.startsWith("+ ") || s.startsWith("+++ ELI") || s.startsWith("#")) && options.noeli) {
|
---|
161 | return
|
---|
162 | }
|
---|
163 | myprintlnfinal(s)
|
---|
164 | }
|
---|
165 |
|
---|
166 | void start() {
|
---|
167 | if (options.xhtml) {
|
---|
168 | myprintlnfinal "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
|
---|
169 | myprintlnfinal "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/><title>JOSM - ELI differences</title></head><body>\n"
|
---|
170 | }
|
---|
171 | }
|
---|
172 |
|
---|
173 | void end() {
|
---|
174 | for (def s: skip.keySet()) {
|
---|
175 | myprintln "+++ Obsolete skip entry: " + s
|
---|
176 | }
|
---|
177 | if (options.xhtml) {
|
---|
178 | myprintlnfinal "</body></html>\n"
|
---|
179 | }
|
---|
180 | }
|
---|
181 |
|
---|
182 | void loadELIEntries() {
|
---|
183 | FileReader fr = new FileReader(eliInputFile)
|
---|
184 | JsonReader jr = Json.createReader(fr)
|
---|
185 | eliEntries = jr.readObject().get("features")
|
---|
186 | jr.close()
|
---|
187 |
|
---|
188 | for (def e : eliEntries) {
|
---|
189 | def url = getUrlStripped(e)
|
---|
190 | if (url.contains("{z}")) {
|
---|
191 | myprintln "+++ ELI-URL uses {z} instead of {zoom}: "+url
|
---|
192 | url = url.replace("{z}","{zoom}")
|
---|
193 | }
|
---|
194 | if (eliUrls.containsKey(url)) {
|
---|
195 | myprintln "+++ ELI-URL is not unique: "+url
|
---|
196 | } else {
|
---|
197 | eliUrls.put(url, e)
|
---|
198 | }
|
---|
199 | }
|
---|
200 | myprintln "*** Loaded ${eliEntries.size()} entries (ELI). ***"
|
---|
201 | }
|
---|
202 | String cdata(def s, boolean escape = false) {
|
---|
203 | if(escape) {
|
---|
204 | return s.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">")
|
---|
205 | } else if(s =~ /[<>&]/)
|
---|
206 | return "<![CDATA[$s]]>"
|
---|
207 | return s
|
---|
208 | }
|
---|
209 |
|
---|
210 | String maininfo(def entry, String offset) {
|
---|
211 | String t = getType(entry)
|
---|
212 | String res = offset + "<type>$t</type>\n"
|
---|
213 | res += offset + "<url>${cdata(getUrl(entry))}</url>\n"
|
---|
214 | if(t == "tms") {
|
---|
215 | if(getMinZoom(entry) != null)
|
---|
216 | res += offset + "<min-zoom>${getMinZoom(entry)}</min-zoom>\n"
|
---|
217 | if(getMaxZoom(entry) != null)
|
---|
218 | res += offset + "<max-zoom>${getMaxZoom(entry)}</max-zoom>\n"
|
---|
219 | } else if (t == "wms") {
|
---|
220 | def p = getProjections(entry)
|
---|
221 | if (p) {
|
---|
222 | res += offset + "<projections>\n"
|
---|
223 | for (def c : p)
|
---|
224 | res += offset + " <code>$c</code>\n"
|
---|
225 | res += offset + "</projections>\n"
|
---|
226 | }
|
---|
227 | }
|
---|
228 | return res
|
---|
229 | }
|
---|
230 |
|
---|
231 | void printentries(def entries, def stream) {
|
---|
232 | DecimalFormat df = new DecimalFormat("#.#######")
|
---|
233 | df.setRoundingMode(java.math.RoundingMode.CEILING)
|
---|
234 | stream.write "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
---|
235 | stream.write "<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n"
|
---|
236 | for (def e : entries) {
|
---|
237 | def best = "eli-best".equals(getQuality(e))
|
---|
238 | stream.write " <entry"+(best ? " eli-best=\"true\"" : "" )+">\n"
|
---|
239 | stream.write " <name>${cdata(getName(e), true)}</name>\n"
|
---|
240 | stream.write " <id>${getId(e)}</id>\n"
|
---|
241 | def t
|
---|
242 | if((t = getDate(e)))
|
---|
243 | stream.write " <date>$t</date>\n"
|
---|
244 | if((t = getCountryCode(e)))
|
---|
245 | stream.write " <country-code>$t</country-code>\n"
|
---|
246 | if((getDefault(e)))
|
---|
247 | stream.write " <default>true</default>\n"
|
---|
248 | stream.write maininfo(e, " ")
|
---|
249 | if((t = getAttributionText(e)))
|
---|
250 | stream.write " <attribution-text mandatory=\"true\">${cdata(t, true)}</attribution-text>\n"
|
---|
251 | if((t = getAttributionUrl(e)))
|
---|
252 | stream.write " <attribution-url>${cdata(t)}</attribution-url>\n"
|
---|
253 | if((t = getLogoImage(e)))
|
---|
254 | stream.write " <logo-image>${cdata(t, true)}</logo-image>\n"
|
---|
255 | if((t = getLogoUrl(e)))
|
---|
256 | stream.write " <logo-url>${cdata(t)}</logo-url>\n"
|
---|
257 | if((t = getTermsOfUseText(e)))
|
---|
258 | stream.write " <terms-of-use-text>${cdata(t, true)}</terms-of-use-text>\n"
|
---|
259 | if((t = getTermsOfUseUrl(e)))
|
---|
260 | stream.write " <terms-of-use-url>${cdata(t)}</terms-of-use-url>\n"
|
---|
261 | if((t = getPermissionReferenceUrl(e)))
|
---|
262 | stream.write " <permission-ref>${cdata(t)}</permission-ref>\n"
|
---|
263 | if((getValidGeoreference(e)))
|
---|
264 | stream.write " <valid-georeference>true</valid-georeference>\n"
|
---|
265 | if((t = getIcon(e)))
|
---|
266 | stream.write " <icon>${cdata(t)}</icon>\n"
|
---|
267 | for (def d : getDescriptions(e)) {
|
---|
268 | stream.write " <description lang=\"${d.getKey()}\">${d.getValue()}</description>\n"
|
---|
269 | }
|
---|
270 | for (def m : getMirrors(e)) {
|
---|
271 | stream.write " <mirror>\n"+maininfo(m, " ")+" </mirror>\n"
|
---|
272 | }
|
---|
273 | def minlat = 1000
|
---|
274 | def minlon = 1000
|
---|
275 | def maxlat = -1000
|
---|
276 | def maxlon = -1000
|
---|
277 | def shapes = ""
|
---|
278 | def sep = "\n "
|
---|
279 | for(def s: getShapes(e)) {
|
---|
280 | shapes += " <shape>"
|
---|
281 | def i = 0
|
---|
282 | for(def p: s.getPoints()) {
|
---|
283 | def lat = p.getLat()
|
---|
284 | def lon = p.getLon()
|
---|
285 | if(lat > maxlat) maxlat = lat
|
---|
286 | if(lon > maxlon) maxlon = lon
|
---|
287 | if(lat < minlat) minlat = lat
|
---|
288 | if(lon < minlon) minlon = lon
|
---|
289 | if(!(i++%3)) {
|
---|
290 | shapes += sep + " "
|
---|
291 | }
|
---|
292 | shapes += "<point lat='${df.format(lat)}' lon='${df.format(lon)}'/>"
|
---|
293 | }
|
---|
294 | shapes += sep + "</shape>\n"
|
---|
295 | }
|
---|
296 | if(shapes) {
|
---|
297 | stream.write " <bounds min-lat='${df.format(minlat)}' min-lon='${df.format(minlon)}' max-lat='${df.format(maxlat)}' max-lon='${df.format(maxlon)}'>\n"
|
---|
298 | stream.write shapes + " </bounds>\n"
|
---|
299 | }
|
---|
300 | stream.write " </entry>\n"
|
---|
301 | }
|
---|
302 | stream.write "</imagery>\n"
|
---|
303 | stream.close()
|
---|
304 | }
|
---|
305 |
|
---|
306 | void loadJosmEntries() {
|
---|
307 | def reader = new ImageryReader(josmInputFile)
|
---|
308 | josmEntries = reader.parse()
|
---|
309 |
|
---|
310 | for (def e : josmEntries) {
|
---|
311 | def url = getUrlStripped(e)
|
---|
312 | if (url.contains("{z}")) {
|
---|
313 | myprintln "+++ JOSM-URL uses {z} instead of {zoom}: "+url
|
---|
314 | url = url.replace("{z}","{zoom}")
|
---|
315 | }
|
---|
316 | if (josmUrls.containsKey(url)) {
|
---|
317 | myprintln "+++ JOSM-URL is not unique: "+url
|
---|
318 | } else {
|
---|
319 | josmUrls.put(url, e)
|
---|
320 | }
|
---|
321 | for (def m : e.getMirrors()) {
|
---|
322 | url = getUrlStripped(m)
|
---|
323 | m.origName = m.getOriginalName().replaceAll(" mirror server( \\d+)?","")
|
---|
324 | if (josmUrls.containsKey(url)) {
|
---|
325 | myprintln "+++ JOSM-Mirror-URL is not unique: "+url
|
---|
326 | } else {
|
---|
327 | josmUrls.put(url, m)
|
---|
328 | josmMirrors.put(url, m)
|
---|
329 | }
|
---|
330 | }
|
---|
331 | }
|
---|
332 | myprintln "*** Loaded ${josmEntries.size()} entries (JOSM). ***"
|
---|
333 | }
|
---|
334 |
|
---|
335 | List inOneButNotTheOther(Map m1, Map m2) {
|
---|
336 | def l = []
|
---|
337 | for (def url : m1.keySet()) {
|
---|
338 | if (!m2.containsKey(url)) {
|
---|
339 | def name = getName(m1.get(url))
|
---|
340 | l += " "+getDescription(m1.get(url))
|
---|
341 | }
|
---|
342 | }
|
---|
343 | l.sort()
|
---|
344 | }
|
---|
345 |
|
---|
346 | void checkInOneButNotTheOther() {
|
---|
347 | def l1 = inOneButNotTheOther(eliUrls, josmUrls)
|
---|
348 | myprintln "*** URLs found in ELI but not in JOSM (${l1.size()}): ***"
|
---|
349 | if (!l1.isEmpty()) {
|
---|
350 | for (def l : l1) {
|
---|
351 | myprintln "-" + l
|
---|
352 | }
|
---|
353 | }
|
---|
354 |
|
---|
355 | def l2 = inOneButNotTheOther(josmUrls, eliUrls)
|
---|
356 | myprintln "*** URLs found in JOSM but not in ELI (${l2.size()}): ***"
|
---|
357 | if (!l2.isEmpty()) {
|
---|
358 | for (def l : l2) {
|
---|
359 | myprintln "+" + l
|
---|
360 | }
|
---|
361 | }
|
---|
362 | }
|
---|
363 |
|
---|
364 | void checkCommonEntries() {
|
---|
365 | myprintln "*** Same URL, but different name: ***"
|
---|
366 | for (def url : eliUrls.keySet()) {
|
---|
367 | def e = eliUrls.get(url)
|
---|
368 | if (!josmUrls.containsKey(url)) continue
|
---|
369 | def j = josmUrls.get(url)
|
---|
370 | def ename = getName(e).replace("'","\u2019")
|
---|
371 | def jname = getName(j).replace("'","\u2019")
|
---|
372 | if (!ename.equals(jname)) {
|
---|
373 | myprintln "* Name differs ('${getName(e)}' != '${getName(j)}'): ${getUrl(j)}"
|
---|
374 | }
|
---|
375 | }
|
---|
376 |
|
---|
377 | myprintln "*** Same URL, but different Id: ***"
|
---|
378 | for (def url : eliUrls.keySet()) {
|
---|
379 | def e = eliUrls.get(url)
|
---|
380 | if (!josmUrls.containsKey(url)) continue
|
---|
381 | def j = josmUrls.get(url)
|
---|
382 | def ename = getId(e)
|
---|
383 | def jname = getId(j)
|
---|
384 | if (!ename.equals(jname)) {
|
---|
385 | myprintln "# Id differs ('${getId(e)}' != '${getId(j)}'): ${getUrl(j)}"
|
---|
386 | }
|
---|
387 | }
|
---|
388 |
|
---|
389 | myprintln "*** Same URL, but different type: ***"
|
---|
390 | for (def url : eliUrls.keySet()) {
|
---|
391 | def e = eliUrls.get(url)
|
---|
392 | if (!josmUrls.containsKey(url)) continue
|
---|
393 | def j = josmUrls.get(url)
|
---|
394 | if (!getType(e).equals(getType(j))) {
|
---|
395 | myprintln "* Type differs (${getType(e)} != ${getType(j)}): ${getName(j)} - ${getUrl(j)}"
|
---|
396 | }
|
---|
397 | }
|
---|
398 |
|
---|
399 | myprintln "*** Same URL, but different zoom bounds: ***"
|
---|
400 | for (def url : eliUrls.keySet()) {
|
---|
401 | def e = eliUrls.get(url)
|
---|
402 | if (!josmUrls.containsKey(url)) continue
|
---|
403 | def j = josmUrls.get(url)
|
---|
404 |
|
---|
405 | Integer eMinZoom = getMinZoom(e)
|
---|
406 | Integer jMinZoom = getMinZoom(j)
|
---|
407 | if (eMinZoom != jMinZoom && !(eMinZoom == 0 && jMinZoom == null)) {
|
---|
408 | myprintln "* Minzoom differs (${eMinZoom} != ${jMinZoom}): ${getDescription(j)}"
|
---|
409 | }
|
---|
410 | Integer eMaxZoom = getMaxZoom(e)
|
---|
411 | Integer jMaxZoom = getMaxZoom(j)
|
---|
412 | if (eMaxZoom != jMaxZoom) {
|
---|
413 | myprintln "* Maxzoom differs (${eMaxZoom} != ${jMaxZoom}): ${getDescription(j)}"
|
---|
414 | }
|
---|
415 | }
|
---|
416 |
|
---|
417 | myprintln "*** Same URL, but different country code: ***"
|
---|
418 | for (def url : eliUrls.keySet()) {
|
---|
419 | def e = eliUrls.get(url)
|
---|
420 | if (!josmUrls.containsKey(url)) continue
|
---|
421 | def j = josmUrls.get(url)
|
---|
422 | if (!getCountryCode(e).equals(getCountryCode(j))) {
|
---|
423 | myprintln "* Country code differs (${getCountryCode(e)} != ${getCountryCode(j)}): ${getDescription(j)}"
|
---|
424 | }
|
---|
425 | }
|
---|
426 | myprintln "*** Same URL, but different quality: ***"
|
---|
427 | for (def url : eliUrls.keySet()) {
|
---|
428 | def e = eliUrls.get(url)
|
---|
429 | if (!josmUrls.containsKey(url)) {
|
---|
430 | def q = getQuality(e)
|
---|
431 | if("eli-best".equals(q)) {
|
---|
432 | myprintln "- Quality best entry not in JOSM for ${getDescription(e)}"
|
---|
433 | }
|
---|
434 | continue
|
---|
435 | }
|
---|
436 | def j = josmUrls.get(url)
|
---|
437 | if (!getQuality(e).equals(getQuality(j))) {
|
---|
438 | myprintln "* Quality differs (${getQuality(e)} != ${getQuality(j)}): ${getDescription(j)}"
|
---|
439 | }
|
---|
440 | }
|
---|
441 | myprintln "*** Same URL, but different dates: ***"
|
---|
442 | for (def url : eliUrls.keySet()) {
|
---|
443 | def ed = getDate(eliUrls.get(url))
|
---|
444 | if (!josmUrls.containsKey(url)) continue
|
---|
445 | def j = josmUrls.get(url)
|
---|
446 | def jd = getDate(j)
|
---|
447 | // The forms 2015;- or -;2015 or 2015;2015 are handled equal to 2015
|
---|
448 | String ef = ed.replaceAll("\\A-;","").replaceAll(";-\\z","").replaceAll("\\A([0-9-]+);\\1\\z","\$1")
|
---|
449 | // ELI has a strange and inconsistent used end_date definition, so we try again with subtraction by one
|
---|
450 | String ed2 = ed
|
---|
451 | def reg = (ed =~ /^(.*;)(\d\d\d\d)(-(\d\d)(-(\d\d))?)?$/)
|
---|
452 | if(reg != null && reg.count == 1) {
|
---|
453 | Calendar cal = Calendar.getInstance()
|
---|
454 | 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)
|
---|
455 | cal.add(Calendar.DAY_OF_MONTH, -1)
|
---|
456 | ed2 = reg[0][1] + cal.get(Calendar.YEAR)
|
---|
457 | if (reg[0][4] != null)
|
---|
458 | ed2 += "-" + String.format("%02d", cal.get(Calendar.MONTH)+1)
|
---|
459 | if (reg[0][6] != null)
|
---|
460 | ed2 += "-" + String.format("%02d", cal.get(Calendar.DAY_OF_MONTH))
|
---|
461 | }
|
---|
462 | String ef2 = ed2.replaceAll("\\A-;","").replaceAll(";-\\z","").replaceAll("\\A([0-9-]+);\\1\\z","\$1")
|
---|
463 | if (!ed.equals(jd) && !ef.equals(jd) && !ed2.equals(jd) && !ef2.equals(jd)) {
|
---|
464 | String t = "'${ed}'"
|
---|
465 | if (!ed.equals(ef)) {
|
---|
466 | t += " or '${ef}'"
|
---|
467 | }
|
---|
468 | if (jd.isEmpty()) {
|
---|
469 | myprintln "- Missing JOSM date (${t}): ${getDescription(j)}"
|
---|
470 | } else if (!ed.isEmpty()) {
|
---|
471 | myprintln "* Date differs ('${t}' != '${jd}'): ${getDescription(j)}"
|
---|
472 | } else if (!options.nomissingeli) {
|
---|
473 | myprintln "+ Missing ELI date ('${jd}'): ${getDescription(j)}"
|
---|
474 | }
|
---|
475 | }
|
---|
476 | }
|
---|
477 | myprintln "*** Same URL, but different information: ***"
|
---|
478 | for (def url : eliUrls.keySet()) {
|
---|
479 | if (!josmUrls.containsKey(url)) continue
|
---|
480 | def e = eliUrls.get(url)
|
---|
481 | def j = josmUrls.get(url)
|
---|
482 |
|
---|
483 | def et = getDescriptions(e)
|
---|
484 | def jt = getDescriptions(j)
|
---|
485 | et = (et.size() > 0) ? et["en"] : ""
|
---|
486 | jt = (jt.size() > 0) ? jt["en"] : ""
|
---|
487 | if (!et.equals(jt)) {
|
---|
488 | if (!jt) {
|
---|
489 | myprintln "- Missing JOSM description (${et}): ${getDescription(j)}"
|
---|
490 | } else if (et) {
|
---|
491 | myprintln "* Description differs ('${et}' != '${jt}'): ${getDescription(j)}"
|
---|
492 | } else if (!options.nomissingeli) {
|
---|
493 | myprintln "+ Missing ELI description ('${jt}'): ${getDescription(j)}"
|
---|
494 | }
|
---|
495 | }
|
---|
496 |
|
---|
497 | et = getPermissionReferenceUrl(e)
|
---|
498 | jt = getPermissionReferenceUrl(j)
|
---|
499 | if (!jt) jt = getTermsOfUseUrl(j)
|
---|
500 | if (!et.equals(jt)) {
|
---|
501 | if (!jt) {
|
---|
502 | myprintln "- Missing JOSM license URL (${et}): ${getDescription(j)}"
|
---|
503 | } else if (et) {
|
---|
504 | myprintln "* License URL differs ('${et}' != '${jt}'): ${getDescription(j)}"
|
---|
505 | } else if (!options.nomissingeli) {
|
---|
506 | myprintln "+ Missing ELI license URL ('${jt}'): ${getDescription(j)}"
|
---|
507 | }
|
---|
508 | }
|
---|
509 |
|
---|
510 | et = getAttributionUrl(e)
|
---|
511 | jt = getAttributionUrl(j)
|
---|
512 | if (!et.equals(jt)) {
|
---|
513 | if (!jt) {
|
---|
514 | myprintln "- Missing JOSM attribution URL (${et}): ${getDescription(j)}"
|
---|
515 | } else if (et) {
|
---|
516 | myprintln "* Attribution URL differs ('${et}' != '${jt}'): ${getDescription(j)}"
|
---|
517 | } else if (!options.nomissingeli) {
|
---|
518 | myprintln "+ Missing ELI attribution URL ('${jt}'): ${getDescription(j)}"
|
---|
519 | }
|
---|
520 | }
|
---|
521 |
|
---|
522 | et = getAttributionText(e)
|
---|
523 | jt = getAttributionText(j)
|
---|
524 | if (!et.equals(jt)) {
|
---|
525 | if (!jt) {
|
---|
526 | myprintln "- Missing JOSM attribution text (${et}): ${getDescription(j)}"
|
---|
527 | } else if (et) {
|
---|
528 | myprintln "* Attribution text differs ('${et}' != '${jt}'): ${getDescription(j)}"
|
---|
529 | } else if (!options.nomissingeli) {
|
---|
530 | myprintln "+ Missing ELI attribution text ('${jt}'): ${getDescription(j)}"
|
---|
531 | }
|
---|
532 | }
|
---|
533 |
|
---|
534 | et = getProjections(e)
|
---|
535 | jt = getProjections(j)
|
---|
536 | if (et) { et = new LinkedList(et); Collections.sort(et); et = String.join(" ", et) }
|
---|
537 | if (jt) { jt = new LinkedList(jt); Collections.sort(jt); jt = String.join(" ", jt) }
|
---|
538 | if (!et.equals(jt)) {
|
---|
539 | if (!jt) {
|
---|
540 | myprintln "- Missing JOSM projections (${et}): ${getDescription(j)}"
|
---|
541 | } else if (et) {
|
---|
542 | myprintln "* Projections differ ('${et}' != '${jt}'): ${getDescription(j)}"
|
---|
543 | } else if (!options.nomissingeli && !getType(e).equals("tms")) {
|
---|
544 | myprintln "+ Missing ELI projections ('${jt}'): ${getDescription(j)}"
|
---|
545 | }
|
---|
546 | }
|
---|
547 |
|
---|
548 | et = getDefault(e)
|
---|
549 | jt = getDefault(j)
|
---|
550 | if (!et.equals(jt)) {
|
---|
551 | if (!jt) {
|
---|
552 | myprintln "- Missing JOSM default: ${getDescription(j)}"
|
---|
553 | } else if (!options.nomissingeli) {
|
---|
554 | myprintln "+ Missing ELI default: ${getDescription(j)}"
|
---|
555 | }
|
---|
556 | }
|
---|
557 | }
|
---|
558 | myprintln "*** Mismatching shapes: ***"
|
---|
559 | for (def url : josmUrls.keySet()) {
|
---|
560 | def j = josmUrls.get(url)
|
---|
561 | def num = 1
|
---|
562 | for (def shape : getShapes(j)) {
|
---|
563 | def p = shape.getPoints()
|
---|
564 | if(!p[0].equals(p[p.size()-1])) {
|
---|
565 | myprintln "+++ JOSM shape $num unclosed: ${getDescription(j)}"
|
---|
566 | }
|
---|
567 | for (def nump = 1; nump < p.size(); ++nump) {
|
---|
568 | if (p[nump-1] == p[nump]) {
|
---|
569 | myprintln "+++ JOSM shape $num double point at ${nump-1}: ${getDescription(j)}"
|
---|
570 | }
|
---|
571 | }
|
---|
572 | ++num
|
---|
573 | }
|
---|
574 | }
|
---|
575 | for (def url : eliUrls.keySet()) {
|
---|
576 | def e = eliUrls.get(url)
|
---|
577 | def num = 1
|
---|
578 | def s = getShapes(e)
|
---|
579 | for (def shape : s) {
|
---|
580 | def p = shape.getPoints()
|
---|
581 | if(!p[0].equals(p[p.size()-1]) && !options.nomissingeli) {
|
---|
582 | myprintln "+++ ELI shape $num unclosed: ${getDescription(e)}"
|
---|
583 | }
|
---|
584 | for (def nump = 1; nump < p.size(); ++nump) {
|
---|
585 | if (p[nump-1] == p[nump]) {
|
---|
586 | myprintln "+++ ELI shape $num double point at ${nump-1}: ${getDescription(e)}"
|
---|
587 | }
|
---|
588 | }
|
---|
589 | ++num
|
---|
590 | }
|
---|
591 | if (!josmUrls.containsKey(url)) {
|
---|
592 | continue
|
---|
593 | }
|
---|
594 | def j = josmUrls.get(url)
|
---|
595 | def js = getShapes(j)
|
---|
596 | if(!s.size() && js.size()) {
|
---|
597 | if(!options.nomissingeli) {
|
---|
598 | myprintln "+ No ELI shape: ${getDescription(j)}"
|
---|
599 | }
|
---|
600 | } else if(!js.size() && s.size()) {
|
---|
601 | // don't report boundary like 5 point shapes as difference
|
---|
602 | if (s.size() != 1 || s[0].getPoints().size() != 5) {
|
---|
603 | myprintln "- No JOSM shape: ${getDescription(j)}"
|
---|
604 | }
|
---|
605 | } else if(s.size() != js.size()) {
|
---|
606 | myprintln "* Different number of shapes (${s.size()} != ${js.size()}): ${getDescription(j)}"
|
---|
607 | } else {
|
---|
608 | for(def nums = 0; nums < s.size(); ++nums) {
|
---|
609 | def ep = s[nums].getPoints()
|
---|
610 | def jp = js[nums].getPoints()
|
---|
611 | if(ep.size() != jp.size()) {
|
---|
612 | myprintln "* Different number of points for shape ${nums+1} (${ep.size()} ! = ${jp.size()})): ${getDescription(j)}"
|
---|
613 | } else {
|
---|
614 | for(def nump = 0; nump < ep.size(); ++nump) {
|
---|
615 | def ept = ep[nump]
|
---|
616 | def jpt = jp[nump]
|
---|
617 | if(Math.abs(ept.getLat()-jpt.getLat()) > 0.000001 || Math.abs(ept.getLon()-jpt.getLon()) > 0.000001) {
|
---|
618 | myprintln "* Different coordinate for point ${nump+1} of shape ${nums+1}: ${getDescription(j)}"
|
---|
619 | nump = ep.size()
|
---|
620 | num = s.size()
|
---|
621 | }
|
---|
622 | }
|
---|
623 | }
|
---|
624 | }
|
---|
625 | }
|
---|
626 | }
|
---|
627 | myprintln "*** Mismatching icons: ***"
|
---|
628 | for (def url : eliUrls.keySet()) {
|
---|
629 | def e = eliUrls.get(url)
|
---|
630 | if (!josmUrls.containsKey(url)) {
|
---|
631 | continue
|
---|
632 | }
|
---|
633 | def j = josmUrls.get(url)
|
---|
634 | def ij = getIcon(j)
|
---|
635 | def ie = getIcon(e)
|
---|
636 | if(ij != null && ie == null) {
|
---|
637 | if(!options.nomissingeli) {
|
---|
638 | myprintln "+ No ELI icon: ${getDescription(j)}"
|
---|
639 | }
|
---|
640 | } else if(ij == null && ie != null) {
|
---|
641 | myprintln "- No JOSM icon: ${getDescription(j)}"
|
---|
642 | } else if(!ij.equals(ie)) {
|
---|
643 | myprintln "* Different icons: ${getDescription(j)}"
|
---|
644 | }
|
---|
645 | }
|
---|
646 | myprintln "*** Miscellaneous checks: ***"
|
---|
647 | def josmIds = new HashMap<String, ImageryInfo>()
|
---|
648 | for (def url : josmUrls.keySet()) {
|
---|
649 | def j = josmUrls.get(url)
|
---|
650 | def id = getId(j)
|
---|
651 | if(josmMirrors.containsKey(url)) {
|
---|
652 | continue
|
---|
653 | }
|
---|
654 | if(id == null) {
|
---|
655 | myprintln "* No JOSM-ID: ${getDescription(j)}"
|
---|
656 | } else if(josmIds.containsKey(id)) {
|
---|
657 | myprintln "* JOSM-ID ${id} not unique: ${getDescription(j)}"
|
---|
658 | } else {
|
---|
659 | josmIds.put(id, j)
|
---|
660 | }
|
---|
661 | def d = getDate(j)
|
---|
662 | if(!d.isEmpty()) {
|
---|
663 | def reg = (d =~ /^(-|(\d\d\d\d)(-(\d\d)(-(\d\d))?)?)(;(-|(\d\d\d\d)(-(\d\d)(-(\d\d))?)?))?$/)
|
---|
664 | if(reg == null || reg.count != 1) {
|
---|
665 | myprintln "* JOSM-Date '${d}' is strange: ${getDescription(j)}"
|
---|
666 | } else {
|
---|
667 | try {
|
---|
668 | def first = verifyDate(reg[0][2],reg[0][4],reg[0][6])
|
---|
669 | def second = verifyDate(reg[0][9],reg[0][11],reg[0][13])
|
---|
670 | if(second.compareTo(first) < 0) {
|
---|
671 | myprintln "* JOSM-Date '${d}' is strange (second earlier than first): ${getDescription(j)}"
|
---|
672 | }
|
---|
673 | }
|
---|
674 | catch (Exception e) {
|
---|
675 | myprintln "* JOSM-Date '${d}' is strange (${e.getMessage()}): ${getDescription(j)}"
|
---|
676 | }
|
---|
677 | }
|
---|
678 | }
|
---|
679 | if(getAttributionUrl(j) && !getAttributionText(j)) {
|
---|
680 | myprintln "* Attribution link without text: ${getDescription(j)}"
|
---|
681 | }
|
---|
682 | if(getLogoUrl(j) && !getLogoImage(j)) {
|
---|
683 | myprintln "* Logo link without image: ${getDescription(j)}"
|
---|
684 | }
|
---|
685 | if(getTermsOfUseText(j) && !getTermsOfUseUrl(j)) {
|
---|
686 | myprintln "* Terms of Use text without link: ${getDescription(j)}"
|
---|
687 | }
|
---|
688 | def js = getShapes(j)
|
---|
689 | if(js.size()) {
|
---|
690 | def minlat = 1000
|
---|
691 | def minlon = 1000
|
---|
692 | def maxlat = -1000
|
---|
693 | def maxlon = -1000
|
---|
694 | for(def s: js) {
|
---|
695 | for(def p: s.getPoints()) {
|
---|
696 | def lat = p.getLat()
|
---|
697 | def lon = p.getLon()
|
---|
698 | if(lat > maxlat) maxlat = lat
|
---|
699 | if(lon > maxlon) maxlon = lon
|
---|
700 | if(lat < minlat) minlat = lat
|
---|
701 | if(lon < minlon) minlon = lon
|
---|
702 | }
|
---|
703 | }
|
---|
704 | def b = j.getBounds()
|
---|
705 | if(b.getMinLat() != minlat || b.getMinLon() != minlon || b.getMaxLat() != maxlat || b.getMaxLon() != maxlon) {
|
---|
706 | 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)}"
|
---|
707 | }
|
---|
708 | }
|
---|
709 | }
|
---|
710 | }
|
---|
711 |
|
---|
712 | /**
|
---|
713 | * Utility functions that allow uniform access for both ImageryInfo and JsonObject.
|
---|
714 | */
|
---|
715 | static String getUrl(Object e) {
|
---|
716 | if (e instanceof ImageryInfo) return e.url
|
---|
717 | return e.get("properties").getString("url")
|
---|
718 | }
|
---|
719 | static String getUrlStripped(Object e) {
|
---|
720 | return getUrl(e).replaceAll("\\?(apikey|access_token)=.*","")
|
---|
721 | }
|
---|
722 | static String getDate(Object e) {
|
---|
723 | if (e instanceof ImageryInfo) return e.date ? e.date : ""
|
---|
724 | def p = e.get("properties")
|
---|
725 | def start = p.containsKey("start_date") ? p.getString("start_date") : ""
|
---|
726 | def end = p.containsKey("end_date") ? p.getString("end_date") : ""
|
---|
727 | if(!start.isEmpty() && !end.isEmpty())
|
---|
728 | return start+";"+end
|
---|
729 | else if(!start.isEmpty())
|
---|
730 | return start+";-"
|
---|
731 | else if(!end.isEmpty())
|
---|
732 | return "-;"+end
|
---|
733 | return ""
|
---|
734 | }
|
---|
735 | static Date verifyDate(String year, String month, String day) {
|
---|
736 | def date
|
---|
737 | if(year == null) {
|
---|
738 | date = "3000-01-01"
|
---|
739 | } else {
|
---|
740 | date = year + "-" + (month == null ? "01" : month) + "-" + (day == null ? "01" : day)
|
---|
741 | }
|
---|
742 | def df = new java.text.SimpleDateFormat("yyyy-MM-dd")
|
---|
743 | df.setLenient(false)
|
---|
744 | return df.parse(date)
|
---|
745 | }
|
---|
746 | static String getId(Object e) {
|
---|
747 | if (e instanceof ImageryInfo) return e.getId()
|
---|
748 | return e.get("properties").getString("id")
|
---|
749 | }
|
---|
750 | static String getName(Object e) {
|
---|
751 | if (e instanceof ImageryInfo) return e.getOriginalName()
|
---|
752 | return e.get("properties").getString("name")
|
---|
753 | }
|
---|
754 | static List<Object> getMirrors(Object e) {
|
---|
755 | if (e instanceof ImageryInfo) return e.getMirrors()
|
---|
756 | return []
|
---|
757 | }
|
---|
758 | static List<Object> getProjections(Object e) {
|
---|
759 | def r
|
---|
760 | if (e instanceof ImageryInfo) {
|
---|
761 | r = e.getServerProjections()
|
---|
762 | } else {
|
---|
763 | def s = e.get("properties").get("available_projections")
|
---|
764 | if (s) {
|
---|
765 | r = []
|
---|
766 | for (def p : s)
|
---|
767 | r += p.getString()
|
---|
768 | }
|
---|
769 | }
|
---|
770 | return r ? r : []
|
---|
771 | }
|
---|
772 | static List<Shape> getShapes(Object e) {
|
---|
773 | if (e instanceof ImageryInfo) {
|
---|
774 | def bounds = e.getBounds()
|
---|
775 | if(bounds != null) {
|
---|
776 | return bounds.getShapes()
|
---|
777 | }
|
---|
778 | return []
|
---|
779 | }
|
---|
780 | if(!e.isNull("geometry")) {
|
---|
781 | def ex = e.get("geometry")
|
---|
782 | if(ex != null && !ex.isNull("coordinates")) {
|
---|
783 | def poly = ex.get("coordinates")
|
---|
784 | List<Shape> l = []
|
---|
785 | for(def shapes: poly) {
|
---|
786 | def s = new Shape()
|
---|
787 | for(def point: shapes) {
|
---|
788 | def lon = point[0].toString()
|
---|
789 | def lat = point[1].toString()
|
---|
790 | s.addPoint(lat, lon)
|
---|
791 | }
|
---|
792 | l.add(s)
|
---|
793 | }
|
---|
794 | return l
|
---|
795 | }
|
---|
796 | }
|
---|
797 | return []
|
---|
798 | }
|
---|
799 | static String getType(Object e) {
|
---|
800 | if (e instanceof ImageryInfo) return e.getImageryType().getTypeString()
|
---|
801 | return e.get("properties").getString("type")
|
---|
802 | }
|
---|
803 | static Integer getMinZoom(Object e) {
|
---|
804 | if (e instanceof ImageryInfo) {
|
---|
805 | if("wms".equals(getType(e)) && e.getName() =~ / mirror/)
|
---|
806 | return null;
|
---|
807 | int mz = e.getMinZoom()
|
---|
808 | return mz == 0 ? null : mz
|
---|
809 | } else {
|
---|
810 | def num = e.get("properties").getJsonNumber("min_zoom")
|
---|
811 | if (num == null) return null
|
---|
812 | return num.intValue()
|
---|
813 | }
|
---|
814 | }
|
---|
815 | static Integer getMaxZoom(Object e) {
|
---|
816 | if (e instanceof ImageryInfo) {
|
---|
817 | if("wms".equals(getType(e)) && e.getName() =~ / mirror/)
|
---|
818 | return null;
|
---|
819 | int mz = e.getMaxZoom()
|
---|
820 | return mz == 0 ? null : mz
|
---|
821 | } else {
|
---|
822 | def num = e.get("properties").getJsonNumber("max_zoom")
|
---|
823 | if (num == null) return null
|
---|
824 | return num.intValue()
|
---|
825 | }
|
---|
826 | }
|
---|
827 | static String getCountryCode(Object e) {
|
---|
828 | if (e instanceof ImageryInfo) return "".equals(e.getCountryCode()) ? null : e.getCountryCode()
|
---|
829 | return e.get("properties").getString("country_code", null)
|
---|
830 | }
|
---|
831 | static String getQuality(Object e) {
|
---|
832 | if (e instanceof ImageryInfo) return e.isBestMarked() ? "eli-best" : null
|
---|
833 | return (e.get("properties").containsKey("best")
|
---|
834 | && e.get("properties").getBoolean("best")) ? "eli-best" : null
|
---|
835 | }
|
---|
836 | static String getIcon(Object e) {
|
---|
837 | if (e instanceof ImageryInfo) return e.getIcon()
|
---|
838 | return e.get("properties").getString("icon", null)
|
---|
839 | }
|
---|
840 | static String getAttributionText(Object e) {
|
---|
841 | if (e instanceof ImageryInfo) return e.getAttributionText(0, null, null)
|
---|
842 | try {return e.get("properties").get("attribution").getString("text", null)} catch (NullPointerException ex) {return null}
|
---|
843 | }
|
---|
844 | static String getAttributionUrl(Object e) {
|
---|
845 | if (e instanceof ImageryInfo) return e.getAttributionLinkURL()
|
---|
846 | try {return e.get("properties").get("attribution").getString("url", null)} catch (NullPointerException ex) {return null}
|
---|
847 | }
|
---|
848 | static String getTermsOfUseText(Object e) {
|
---|
849 | if (e instanceof ImageryInfo) return e.getTermsOfUseText()
|
---|
850 | return null
|
---|
851 | }
|
---|
852 | static String getTermsOfUseUrl(Object e) {
|
---|
853 | if (e instanceof ImageryInfo) return e.getTermsOfUseURL()
|
---|
854 | return null
|
---|
855 | }
|
---|
856 | static String getLogoImage(Object e) {
|
---|
857 | if (e instanceof ImageryInfo) return e.getAttributionImageRaw()
|
---|
858 | return null
|
---|
859 | }
|
---|
860 | static String getLogoUrl(Object e) {
|
---|
861 | if (e instanceof ImageryInfo) return e.getAttributionImageURL()
|
---|
862 | return null
|
---|
863 | }
|
---|
864 | static String getPermissionReferenceUrl(Object e) {
|
---|
865 | if (e instanceof ImageryInfo) return e.getPermissionReferenceURL()
|
---|
866 | return e.get("properties").getString("license_url", null)
|
---|
867 | }
|
---|
868 | static Map<String,String> getDescriptions(Object e) {
|
---|
869 | Map<String,String> res = new HashMap<String, String>()
|
---|
870 | if (e instanceof ImageryInfo) {
|
---|
871 | String a = e.getDescription()
|
---|
872 | if (a) res.put("en", a)
|
---|
873 | } else {
|
---|
874 | String a = e.get("properties").getString("description", null)
|
---|
875 | if (a) res.put("en", a)
|
---|
876 | }
|
---|
877 | return res
|
---|
878 | }
|
---|
879 | static Boolean getValidGeoreference(Object e) {
|
---|
880 | if (e instanceof ImageryInfo) return e.isGeoreferenceValid()
|
---|
881 | return false
|
---|
882 | }
|
---|
883 | static Boolean getDefault(Object e) {
|
---|
884 | if (e instanceof ImageryInfo) return e.isDefaultEntry()
|
---|
885 | return e.get("properties").getBoolean("default", false)
|
---|
886 | }
|
---|
887 | String getDescription(Object o) {
|
---|
888 | def url = getUrl(o)
|
---|
889 | def cc = getCountryCode(o)
|
---|
890 | if (cc == null) {
|
---|
891 | def j = josmUrls.get(url)
|
---|
892 | if (j != null) cc = getCountryCode(j)
|
---|
893 | if (cc == null) {
|
---|
894 | def e = eliUrls.get(url)
|
---|
895 | if (e != null) cc = getCountryCode(e)
|
---|
896 | }
|
---|
897 | }
|
---|
898 | if (cc == null) {
|
---|
899 | cc = ''
|
---|
900 | } else {
|
---|
901 | cc = "[$cc] "
|
---|
902 | }
|
---|
903 | def d = cc + getName(o) + " - " + getUrl(o)
|
---|
904 | if (options.shorten) {
|
---|
905 | def MAXLEN = 140
|
---|
906 | if (d.length() > MAXLEN) d = d.substring(0, MAXLEN-1) + "..."
|
---|
907 | }
|
---|
908 | return d
|
---|
909 | }
|
---|
910 | }
|
---|