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