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