source: josm/trunk/scripts/sync_editor_imagery_index.groovy @ 9669

Last change on this file since 9669 was 9667, checked in by stoecker, 3 years ago

small style fix

  • Property svn:eol-style set to native
File size: 23.2 KB
Line 
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 *
15 * $ groovy -cp ../dist/josm-custom.jar sync_editor-imagery-index.groovy
16 *
17 * Add option "-h" to show the available command line flags.
18 */
19import java.io.FileReader
20import java.util.List
21
22import javax.json.Json
23import javax.json.JsonArray
24import javax.json.JsonObject
25import javax.json.JsonReader
26
27import org.openstreetmap.josm.io.imagery.ImageryReader
28import org.openstreetmap.josm.data.imagery.ImageryInfo
29import org.openstreetmap.josm.tools.Utils
30
31class sync_editor_imagery_index {
32
33    List<ImageryInfo> josmEntries;
34    JsonArray eiiEntries;
35
36    def eiiUrls = new HashMap<String, JsonObject>()
37    def josmUrls = new HashMap<String, ImageryInfo>()
38
39    static String eiiInputFile = 'imagery.json'
40    static String josmInputFile = 'maps.xml'
41    static FileWriter outputFile = null
42    static BufferedWriter outputStream = null
43    static int skipCount = 0;
44    static def skipEntries = [:]
45
46    static def options
47
48    /**
49     * Main method.
50     */
51    static main(def args) {
52        parse_command_line_arguments(args)
53        def script = new sync_editor_imagery_index()
54        script.loadSkip()
55        script.start()
56        script.loadJosmEntries()
57        script.loadEIIEntries()
58        script.checkInOneButNotTheOther()
59        script.checkCommonEntries()
60        script.end()
61        if(outputStream != null) {
62            outputStream.close();
63        }
64        if(outputFile != null) {
65            outputFile.close();
66        }
67    }
68
69    /**
70     * Parse command line arguments.
71     */
72    static void parse_command_line_arguments(args) {
73        def cli = new CliBuilder(width: 160)
74        cli.o(longOpt:'output', args:1, argName: "output", "Output file, - prints to stdout (default: -)")
75        cli.e(longOpt:'eii_input', args:1, argName:"eii_input", "Input file for the editor imagery index (json). Default is $eiiInputFile (current directory).")
76        cli.j(longOpt:'josm_input', args:1, argName:"josm_input", "Input file for the JOSM imagery list (xml). Default is $josmInputFile (current directory).")
77        cli.s(longOpt:'shorten', "shorten the output, so it is easier to read in a console window")
78        cli.n(longOpt:'noskip', argName:"noskip", "don't skip known entries")
79        cli.x(longOpt:'xhtmlbody', argName:"xhtmlbody", "create XHTML body for display in a web page")
80        cli.X(longOpt:'xhtml', argName:"xhtml", "create XHTML for display in a web page")
81        cli.m(longOpt:'nomissingeii', argName:"nomissingeii", "don't show missing editor imagery index entries")
82        cli.h(longOpt:'help', "show this help")
83        options = cli.parse(args)
84
85        if (options.h) {
86            cli.usage()
87            System.exit(0)
88        }
89        if (options.eii_input) {
90            eiiInputFile = options.eii_input
91        }
92        if (options.josm_input) {
93            josmInputFile = options.josm_input
94        }
95        if (options.output && options.output != "-") {
96            outputFile = new FileWriter(options.output)
97            outputStream = new BufferedWriter(outputFile)
98        }
99    }
100
101    void loadSkip() {
102        /* TMS proxies for our wms */
103        skipEntries["-  Czech CUZK:KM tiles proxy - http://osm-{switch:a,b,c}.zby.cz/tiles_cuzk.php/{zoom}/{x}/{y}.png"] = 1
104        skipEntries["-  [CH] Stadt Zürich Luftbild 2011 - http://mapproxy.sosm.ch:8080/tiles/zh_luftbild2011/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
105        skipEntries["-  [CH] Übersichtsplan Zürich - http://mapproxy.sosm.ch:8080/tiles/zh_uebersichtsplan/EPSG900913/{zoom}/{x}/{y}.png?origin=nw"] = 1
106        skipEntries["-  [CH] Kanton Solothurn 25cm (SOGIS 2011-2014) - http://mapproxy.osm.ch:8080/tiles/sogis2014/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
107        /* URL style mismatch */
108        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://cyberjapandata.gsi.go.jp/xyz/ort/{z}/{x}/{y}.jpg"] = 1
109        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://tms.cadastre.openstreetmap.fr/*/tout/{z}/{x}/{y}.png"] = 1
110        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://sdi.provincia.bz.it/geoserver/gwc/service/tms/1.0.0/WMTS_TOPOMAP_APB-PAB@GoogleMapsCompatible@png8/{z}/{x}/{-y}.png"] = 1
111        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.osm.ch:8080/tiles/AGIS2014/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
112        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.osm.ch:8080/tiles/sogis2014/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
113        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.openmap.lt/ort10lt/g/{z}/{x}/{y}.jpeg"] = 1
114        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.openstreetmap.lu/tiles/ortho2010/EPSG900913/{z}/{x}/{y}.jpeg"] = 1
115        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.openstreetmap.lu/tiles/ortho2013/EPSG900913/{z}/{x}/{y}.jpeg"] = 1
116        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.sosm.ch:8080/tiles/zh_luftbild2011/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
117        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.openmap.lt/ort10lt/g/{z}/{x}/{y}.jpeg"] = 1
118
119        skipEntries["+++ EII-URL is not unique: http://geolittoral.application.equipement.gouv.fr/wms/metropole?FORMAT=image/jpeg&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&Layers=ortholittorale&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"] = 1
120        skipEntries["-  Streets NRW Geofabrik.de - http://tools.geofabrik.de/osmi/view/strassennrw/wxs?REQUEST=GetMap&SERVICE=wms&VERSION=1.1.1&FORMAT=image/png&SRS={proj}&STYLES=&LAYERS=unzugeordnete_strassen,kreisstrassen_ast,kreisstrassen,landesstrassen_ast,landesstrassen,bundesstrassen_ast,bundesstrassen,autobahnen_ast,autobahnen,endpunkte&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"] = 1
121        skipEntries["-  Czech UHUL:ORTOFOTO - http://geoportal2.uhul.cz/cgi-bin/oprl.asp?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&SRS={proj}&LAYERS=Ortofoto_cb&STYLES=default&FORMAT=image/jpeg&TRANSPARENT=TRUE&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"] = 1
122        skipEntries["-  Czech ÚHUL:ORTOFOTO tiles proxy - http://osm-{switch:a,b,c}.zby.cz/tiles_uhul.php/{zoom}/{x}/{y}.jpg"] = 1
123        skipEntries["-  [CH] Kanton Solothurn 25cm (SOGIS 2011-2014) - http://www.sogis1.so.ch/cgi-bin/sogis/sogis_orthofoto.wms?FORMAT=image/jpeg&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&LAYERS=Orthofoto_SO&STYLES=&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"] = 1
124        skipEntries["-  [CH] Kanton Solothurn Infrarot 12.5cm (SOGIS 2011) - http://www.sogis1.so.ch/cgi-bin/sogis/sogis_ortho.wms?FORMAT=image/jpeg&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&Layers=Orthofoto11_CIR&STYLES=&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"] = 1
125        skipEntries["-  [CH] Stadt Bern 10cm/25cm (2008) - http://map.bern.ch/arcgis/services/Orthofoto_2008/MapServer/WMSServer?FORMAT=image/jpeg&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&Layers=0,1&STYLES=&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"] = 1
126        skipEntries["-  [EE] Estonia Basemap (Maaamet) - http://kaart.maaamet.ee/wms/alus-geo?FORMAT=image/jpeg&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&Layers=pohi_vr2&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"] = 1
127        skipEntries["-  [EE] Estonia Forestry (Maaamet) - http://kaart.maaamet.ee/wms/alus-geo?FORMAT=image/jpeg&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&Layers=cir_ngr&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"] = 1
128        skipEntries["-  [EE] Estonia Hillshading (Maaamet) - http://kaart.maaamet.ee/wms/alus-geo?FORMAT=image/jpeg&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&Layers=reljeef&STYLES=&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"] = 1
129        skipEntries["-  [EE] Estonia Ortho (Maaamet) - http://kaart.maaamet.ee/wms/alus-geo?VERSION=1.1.1&REQUEST=GetMap&LAYERS=of10000&SRS={proj}&FORMAT=image/jpeg&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"] = 1
130        skipEntries["-  Hamburg (DK5) - http://gateway.hamburg.de/OGCFassade/HH_WMS_Geobasisdaten.aspx?FORMAT=image/jpeg&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&LAYERS=1&STYLES=&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"] = 1
131        skipEntries["-  Hamburg (40 cm) - http://gateway.hamburg.de/OGCFassade/HH_WMS_DOP40.aspx?FORMAT=image/jpeg&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&LAYERS=0&STYLES=&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"] = 1
132        skipEntries["  name differs: http://wms.openstreetmap.fr/tms/1.0.0/tours_2013/{zoom}/{x}/{y}"] = 3
133        skipEntries["  name differs: http://wms.openstreetmap.fr/tms/1.0.0/tours/{zoom}/{x}/{y}"] = 3
134        skipEntries["  name differs: https://secure.erlangen.de/arcgiser/services/Luftbilder2011/MapServer/WmsServer?FORMAT=image/bmp&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&LAYERS=Erlangen_ratio10_5cm_gk4.jp2&STYLES=&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"] = 3
135        skipEntries["  name differs: http://wms.openstreetmap.fr/tms/1.0.0/iomhaiti/{zoom}/{x}/{y}"] = 3
136        skipEntries["  name differs: http://{switch:a,b,c}.layers.openstreetmap.fr/bano/{zoom}/{x}/{y}.png"] = 3
137        skipEntries["  name differs: http://ooc.openstreetmap.org/os1/{zoom}/{x}/{y}.jpg"] = 3
138        skipEntries["  name differs: http://www.gisnet.lv/cgi-bin/osm_latvia?FORMAT=image/jpeg&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&Layers=piekraste&SRS={proj}&WIDTH={width}&height={height}&BBOX={bbox}"] = 3
139        skipEntries["  name differs: http://tms.cadastre.openstreetmap.fr/*/tout/{zoom}/{x}/{y}.png"] = 3
140        skipEntries["  name differs: http://{switch:a,b,c}.tiles.mapbox.com/v4/enf.e0b8291e/{zoom}/{x}/{y}.png?access_token=pk.eyJ1Ijoib3BlbnN0cmVldG1hcCIsImEiOiJhNVlHd29ZIn0.ti6wATGDWOmCnCYen-Ip7Q"] = 3
141        skipEntries["  name differs: http://geo.nls.uk/mapdata2/os/25_inch/scotland_1/{zoom}/{x}/{y}.png"] = 3
142        skipEntries["  name differs: http://geo.nls.uk/mapdata3/os/6_inch_gb_1900/{zoom}/{x}/{y}.png"] = 3
143        skipEntries["  name differs: http://geoserver.infobex.hu/Budapest2014/IST/{zoom}/{x}/{y}.jpg"] = 3
144        skipEntries["  name differs: http://mapproxy.openmap.lt/ort10lt/g/{zoom}/{x}/{y}.jpeg"] = 3
145        skipEntries["  name differs: http://e.tile.openstreetmap.hu/ortofoto2000/{zoom}/{x}/{y}.jpg"] = 3
146        skipEntries["  maxzoom differs: [DE] Bavaria (2 m) - http://geodaten.bayern.de/ogc/ogc_dop200_oa.cgi?FORMAT=image/jpeg&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&Layers=adv_dop200c&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"] = 3
147        skipEntries["  minzoom differs: [AU] LPI NSW Administrative Boundaries County - http://maps.six.nsw.gov.au/arcgis/services/public/NSW_Administrative_Boundaries/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&CRS={proj}&BBOX={bbox}&WIDTH={width}&HEIGHT={height}&LAYERS=County&STYLES=&FORMAT=image/png32&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE"] = 3
148        skipEntries["  minzoom differs: [AU] LPI NSW Administrative Boundaries NPWS Reserve - http://maps.six.nsw.gov.au/arcgis/services/public/NSW_Administrative_Boundaries/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&CRS={proj}&BBOX={bbox}&WIDTH={width}&HEIGHT={height}&LAYERS=NPWSReserve&STYLES=&FORMAT=image/png32&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE"] = 3
149        skipEntries["  minzoom differs: [AU] LPI NSW Administrative Boundaries Parish - http://maps.six.nsw.gov.au/arcgis/services/public/NSW_Administrative_Boundaries/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&CRS={proj}&BBOX={bbox}&WIDTH={width}&HEIGHT={height}&LAYERS=Parish&STYLES=&FORMAT=image/png32&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE"] = 3
150        skipEntries["  minzoom differs: [AU] LPI NSW Administrative Boundaries Suburb - http://maps.six.nsw.gov.au/arcgis/services/public/NSW_Administrative_Boundaries/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&CRS={proj}&BBOX={bbox}&WIDTH={width}&HEIGHT={height}&LAYERS=Suburb&STYLES=&FORMAT=image/png32&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE"] = 3
151        skipEntries["  minzoom differs: [AU] LPI NSW Imagery - http://maps.six.nsw.gov.au/arcgis/rest/services/public/NSW_Imagery/MapServer/tile/{zoom}/{y}/{x}"] = 3
152        skipEntries["  minzoom differs: [AU] LPI NSW Topographic Map - http://maps.six.nsw.gov.au/arcgis/rest/services/public/NSW_Topo_Map/MapServer/tile/{zoom}/{y}/{x}"] = 3
153        skipEntries["  minzoom differs: [AU] LPI NSW Administrative Boundaries State Forest - http://maps.six.nsw.gov.au/arcgis/services/public/NSW_Administrative_Boundaries/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&CRS={proj}&BBOX={bbox}&WIDTH={width}&HEIGHT={height}&LAYERS=StateForest&STYLES=&FORMAT=image/png32&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE"] = 3
154        skipEntries["  minzoom differs: [AU] LPI NSW Administrative Boundaries LGA - http://maps.six.nsw.gov.au/arcgis/services/public/NSW_Administrative_Boundaries/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&CRS={proj}&BBOX={bbox}&WIDTH={width}&HEIGHT={height}&LAYERS=LocalGovernmentArea&STYLES=&FORMAT=image/png32&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE"] = 3
155        skipEntries["  minzoom differs: [AU] LPI NSW Base Map - http://maps.six.nsw.gov.au/arcgis/rest/services/public/NSW_Base_Map/MapServer/tile/{zoom}/{y}/{x}"] = 3
156        skipEntries["  country code differs: [LT] ORT10LT (Lithuania) - http://mapproxy.openmap.lt/ort10lt/g/{zoom}/{x}/{y}.jpeg"] = 3
157    }
158
159    void myprintlnfinal(String s) {
160        if(outputStream != null) {
161            outputStream.write(s);
162            outputStream.newLine();
163        } else {
164            println s;
165        }
166    }
167
168    void myprintln(String s) {
169        if(skipEntries.containsKey(s)) {
170            skipCount = skipEntries.get(s)
171            skipEntries.remove(s)
172        }
173        if(skipCount) {
174            skipCount -= 1;
175            if(options.xhtmlbody || options.xhtml) {
176                s = "<pre style=\"margin:3px;color:green\">"+s.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")+"</pre>"
177            }
178            if (!options.noskip) {
179                return;
180            }
181        } else if(options.xhtmlbody || options.xhtml) {
182            String color = s.startsWith("***") ? "black" : (s.startsWith("+ ") ? "blue" : "red")
183            s = "<pre style=\"margin:3px;color:"+color+"\">"+s.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")+"</pre>"
184        }
185        myprintlnfinal(s)
186    }
187
188    void start() {
189        if (options.xhtml) {
190            myprintlnfinal "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
191            myprintlnfinal "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/><title>JOSM - EII differences</title></head><body>\n"
192        }
193    }
194
195    void end() {
196        for (def s: skipEntries.keySet()) {
197            myprintln "+++ Obsolete skip entry: " + s
198        }
199        if (options.xhtml) {
200            myprintlnfinal "</body></html>\n"
201        }
202    }
203
204    void loadEIIEntries() {
205        FileReader fr = new FileReader(eiiInputFile)
206        JsonReader jr = Json.createReader(fr)
207        eiiEntries = jr.readArray()
208        jr.close()
209
210        for (def e : eiiEntries) {
211            def url = getUrl(e)
212            if (url.contains("{z}")) {
213                myprintln "+++ EII-URL uses {z} instead of {zoom}: "+url
214                url = url.replace("{z}","{zoom}")
215            }
216            if (eiiUrls.containsKey(url)) {
217                myprintln "+++ EII-URL is not unique: "+url
218            } else {
219                eiiUrls.put(url, e)
220            }
221        }
222        myprintln "*** Loaded ${eiiEntries.size()} entries (EII). ***"
223    }
224
225    void loadJosmEntries() {
226        def reader = new ImageryReader(josmInputFile)
227        josmEntries = reader.parse()
228
229        for (def e : josmEntries) {
230            def url = getUrl(e)
231            if (url.contains("{z}")) {
232                myprintln "+++ JOSM-URL uses {z} instead of {zoom}: "+url
233                url = url.replace("{z}","{zoom}")
234            }
235            if (josmUrls.containsKey(url)) {
236                myprintln "+++ JOSM-URL is not unique: "+url
237            } else {
238              josmUrls.put(url, e)
239            }
240            for (def m : e.getMirrors()) {
241                url = getUrl(m)
242                if (josmUrls.containsKey(url)) {
243                    myprintln "+++ JOSM-Mirror-URL is not unique: "+url
244                } else {
245                  josmUrls.put(url, m)
246                }
247            }
248        }
249        myprintln "*** Loaded ${josmEntries.size()} entries (JOSM). ***"
250    }
251
252    List inOneButNotTheOther(Map m1, Map m2) {
253        def l = []
254        for (def url : m1.keySet()) {
255            if (!m2.containsKey(url)) {
256                def name = getName(m1.get(url))
257                l += "  "+getDescription(m1.get(url))
258            }
259        }
260        l.sort()
261    }
262
263    void checkInOneButNotTheOther() {
264        def l1 = inOneButNotTheOther(eiiUrls, josmUrls)
265        myprintln "*** URLs found in EII but not in JOSM (${l1.size()}): ***"
266        if (!l1.isEmpty()) {
267            for (def l : l1)
268                myprintln "-"+l
269        }
270
271        if (options.nomissingeii)
272            return
273        def l2 = inOneButNotTheOther(josmUrls, eiiUrls)
274        myprintln "*** URLs found in JOSM but not in EII (${l2.size()}): ***"
275        if (!l2.isEmpty()) {
276            for (def l : l2)
277                myprintln "+" + l
278        }
279    }
280
281    void checkCommonEntries() {
282        myprintln "*** Same URL, but different name: ***"
283        for (def url : eiiUrls.keySet()) {
284            def e = eiiUrls.get(url)
285            if (!josmUrls.containsKey(url)) continue
286            def j = josmUrls.get(url)
287            if (!getName(e).equals(getName(j))) {
288                myprintln "  name differs: $url"
289                myprintln "     (IEE):     ${getName(e)}"
290                myprintln "     (JOSM):    ${getName(j)}"
291            }
292        }
293
294        myprintln "*** Same URL, but different type: ***"
295        for (def url : eiiUrls.keySet()) {
296            def e = eiiUrls.get(url)
297            if (!josmUrls.containsKey(url)) continue
298            def j = josmUrls.get(url)
299            if (!getType(e).equals(getType(j))) {
300                myprintln "  type differs: ${getName(j)} - $url"
301                myprintln "     (IEE):     ${getType(e)}"
302                myprintln "     (JOSM):    ${getType(j)}"
303            }
304        }
305
306        myprintln "*** Same URL, but different zoom bounds: ***"
307        for (def url : eiiUrls.keySet()) {
308            def e = eiiUrls.get(url)
309            if (!josmUrls.containsKey(url)) continue
310            def j = josmUrls.get(url)
311
312            Integer eMinZoom = getMinZoom(e)
313            Integer jMinZoom = getMinZoom(j)
314            if (eMinZoom != jMinZoom  && !(eMinZoom == 0 && jMinZoom == null)) {
315                myprintln "  minzoom differs: ${getDescription(j)}"
316                myprintln "     (IEE):     ${eMinZoom}"
317                myprintln "     (JOSM):    ${jMinZoom}"
318            }
319            Integer eMaxZoom = getMaxZoom(e)
320            Integer jMaxZoom = getMaxZoom(j)
321            if (eMaxZoom != jMaxZoom) {
322                myprintln "  maxzoom differs: ${getDescription(j)}"
323                myprintln "     (IEE):     ${eMaxZoom}"
324                myprintln "     (JOSM):    ${jMaxZoom}"
325            }
326        }
327
328        myprintln "*** Same URL, but different country code: ***"
329        for (def url : eiiUrls.keySet()) {
330            def e = eiiUrls.get(url)
331            if (!josmUrls.containsKey(url)) continue
332            def j = josmUrls.get(url)
333            if (!getCountryCode(e).equals(getCountryCode(j))) {
334                myprintln "  country code differs: ${getDescription(j)}"
335                myprintln "     (IEE):     ${getCountryCode(e)}"
336                myprintln "     (JOSM):    ${getCountryCode(j)}"
337            }
338        }
339        myprintln "*** Same URL, but different quality: ***"
340        for (def url : eiiUrls.keySet()) {
341            def e = eiiUrls.get(url)
342            if (!josmUrls.containsKey(url)) {
343              def q = getQuality(e)
344              if("best".equals(q)) {
345                myprintln "  quality best entry not in JOSM for ${getDescription(e)}"
346              }
347              continue
348            }
349            def j = josmUrls.get(url)
350            if (!getQuality(e).equals(getQuality(j))) {
351                myprintln "  quality differs: ${getDescription(j)}"
352                myprintln "     (IEE):     ${getQuality(e)}"
353                myprintln "     (JOSM):    ${getQuality(j)}"
354            }
355        }
356    }
357
358    /**
359     * Utility functions that allow uniform access for both ImageryInfo and JsonObject.
360     */
361    static String getUrl(Object e) {
362        if (e instanceof ImageryInfo) return e.url
363        return e.getString("url")
364    }
365    static String getName(Object e) {
366        if (e instanceof ImageryInfo) return e.name
367        return e.getString("name")
368    }
369    static String getType(Object e) {
370        if (e instanceof ImageryInfo) return e.getImageryType().getTypeString()
371        return e.getString("type")
372    }
373    static Integer getMinZoom(Object e) {
374        if (e instanceof ImageryInfo) {
375            int mz = e.getMinZoom()
376            return mz == 0 ? null : mz
377        } else {
378            def ext = e.getJsonObject("extent")
379            if (ext == null) return null
380            def num = ext.getJsonNumber("min_zoom")
381            if (num == null) return null
382            return num.intValue()
383        }
384    }
385    static Integer getMaxZoom(Object e) {
386        if (e instanceof ImageryInfo) {
387            int mz = e.getMaxZoom()
388            return mz == 0 ? null : mz
389        } else {
390            def ext = e.getJsonObject("extent")
391            if (ext == null) return null
392            def num = ext.getJsonNumber("max_zoom")
393            if (num == null) return null
394            return num.intValue()
395        }
396    }
397    static String getCountryCode(Object e) {
398        if (e instanceof ImageryInfo) return "".equals(e.getCountryCode()) ? null : e.getCountryCode()
399        return e.getString("country_code", null)
400    }
401    static String getQuality(Object e) {
402        //if (e instanceof ImageryInfo) return "".equals(e.getQuality()) ? null : e.getQuality()
403        if (e instanceof ImageryInfo) return null
404        return e.get("best") ? "best" : null
405    }
406    String getDescription(Object o) {
407        def url = getUrl(o)
408        def cc = getCountryCode(o)
409        if (cc == null) {
410            def j = josmUrls.get(url)
411            if (j != null) cc = getCountryCode(j)
412            if (cc == null) {
413                def e = eiiUrls.get(url)
414                if (e != null) cc = getCountryCode(e)
415            }
416        }
417        if (cc == null) {
418            cc = ''
419        } else {
420            cc = "[$cc] "
421        }
422        def d = cc + getName(o) + " - " + getUrl(o)
423        if (options.shorten) {
424            def MAXLEN = 140
425            if (d.length() > MAXLEN) d = d.substring(0, MAXLEN-1) + "..."
426        }
427        return d
428    }
429
430}
Note: See TracBrowser for help on using the repository browser.