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