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