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