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