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