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