source: josm/trunk/scripts/SyncEditorImageryIndex.groovy @ 10515

Last change on this file since 10515 was 10515, checked in by stoecker, 7 years ago

fix ImageCompare webpage, fix #13106

  • Property svn:eol-style set to native
File size: 23.3 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 javax.json.Json
20import javax.json.JsonArray
21import javax.json.JsonObject
22import javax.json.JsonReader
23
24import org.openstreetmap.josm.data.imagery.ImageryInfo
25import org.openstreetmap.josm.io.imagery.ImageryReader
26
27class SyncEditorImageryIndex {
28
29    List<ImageryInfo> josmEntries;
30    JsonArray eiiEntries;
31
32    def eiiUrls = new HashMap<String, JsonObject>()
33    def josmUrls = new HashMap<String, ImageryInfo>()
34
35    static String eiiInputFile = 'imagery.json'
36    static String josmInputFile = 'maps.xml'
37    static FileWriter outputFile = null
38    static BufferedWriter outputStream = null
39    int skipCount = 0;
40    def skipEntries = [:]
41
42    static def options
43
44    /**
45     * Main method.
46     */
47    static main(def args) {
48        parse_command_line_arguments(args)
49        def script = new SyncEditorImageryIndex()
50        script.loadSkip()
51        script.start()
52        script.loadJosmEntries()
53        script.loadEIIEntries()
54        script.checkInOneButNotTheOther()
55        script.checkCommonEntries()
56        script.end()
57        if(outputStream != null) {
58            outputStream.close();
59        }
60        if(outputFile != null) {
61            outputFile.close();
62        }
63    }
64
65    /**
66     * Parse command line arguments.
67     */
68    static void parse_command_line_arguments(args) {
69        def cli = new CliBuilder(width: 160)
70        cli.o(longOpt:'output', args:1, argName: "output", "Output file, - prints to stdout (default: -)")
71        cli.e(longOpt:'eii_input', args:1, argName:"eii_input", "Input file for the editor imagery index (json). Default is $eiiInputFile (current directory).")
72        cli.j(longOpt:'josm_input', args:1, argName:"josm_input", "Input file for the JOSM imagery list (xml). Default is $josmInputFile (current directory).")
73        cli.s(longOpt:'shorten', "shorten the output, so it is easier to read in a console window")
74        cli.n(longOpt:'noskip', argName:"noskip", "don't skip known entries")
75        cli.x(longOpt:'xhtmlbody', argName:"xhtmlbody", "create XHTML body for display in a web page")
76        cli.X(longOpt:'xhtml', argName:"xhtml", "create XHTML for display in a web page")
77        cli.m(longOpt:'nomissingeii', argName:"nomissingeii", "don't show missing editor imagery index entries")
78        cli.h(longOpt:'help', "show this help")
79        options = cli.parse(args)
80
81        if (options.h) {
82            cli.usage()
83            System.exit(0)
84        }
85        if (options.eii_input) {
86            eiiInputFile = options.eii_input
87        }
88        if (options.josm_input) {
89            josmInputFile = options.josm_input
90        }
91        if (options.output && options.output != "-") {
92            outputFile = new FileWriter(options.output)
93            outputStream = new BufferedWriter(outputFile)
94        }
95    }
96
97    void loadSkip() {
98        /* TMS proxies for our wms */
99        skipEntries["-  [CH] Stadt Zürich Luftbild 2011 - http://mapproxy.sosm.ch:8080/tiles/zh_luftbild2011/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
100        skipEntries["-  [CH] Übersichtsplan Zürich - http://mapproxy.sosm.ch:8080/tiles/zh_uebersichtsplan/EPSG900913/{zoom}/{x}/{y}.png?origin=nw"] = 1
101        skipEntries["-  [CH] Kanton Solothurn 25cm (SOGIS 2011-2014) - http://mapproxy.osm.ch:8080/tiles/sogis2014/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
102        /* URL style mismatch */
103        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://{switch:a,b,c,d}.tile.stamen.com/terrain-background/{z}/{x}/{y}.jpg"] = 1
104        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://whoots.mapwarper.net/tms/{z}/{x}/{y}/MD_SixInchImagery/http://geodata.md.gov/imap/services/Imagery/MD_SixInchImagery/MapServer/WmsServer"] = 1
105        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://whoots.mapwarper.net/tms/{z}/{x}/{y}/Infrared2015/http://geodata.state.nj.us/imagerywms/Infrared2015"] = 1
106        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://whoots.mapwarper.net/tms/{z}/{x}/{y}/Natural2015/http://geodata.state.nj.us/imagerywms/Natural2015"] = 1
107        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://cyberjapandata.gsi.go.jp/xyz/ort/{z}/{x}/{y}.jpg"] = 1
108        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://tms.cadastre.openstreetmap.fr/*/tout/{z}/{x}/{y}.png"] = 1
109        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.osm.ch:8080/tiles/AGIS2014/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
110        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.osm.ch:8080/tiles/sogis2014/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
111        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.openmap.lt/ort10lt/g/{z}/{x}/{y}.jpeg"] = 1
112        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.sosm.ch:8080/tiles/zh_luftbild2011/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.osm.ch:8080/tiles/KTZUERICH2015/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
115        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://geoservices.buergernetz.bz.it/geoserver/gwc/service/wmts/?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=P_BZ_BASEMAP_TOPO&STYLE=default&TILEMATRIXSET=GoogleMapsCompatible&TILEMATRIX=GoogleMapsCompatible%3A{z}&TILEROW={y}&TILECOL={x}&FORMAT=image%2Fjpeg"] = 1
116
117        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
118        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
119        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
120        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
121        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
122        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
123        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
124        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
125        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
126        skipEntries["  name differs: http://wms.openstreetmap.fr/tms/1.0.0/tours_2013/{zoom}/{x}/{y}"] = 3
127        skipEntries["  name differs: http://wms.openstreetmap.fr/tms/1.0.0/tours/{zoom}/{x}/{y}"] = 3
128        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
129        skipEntries["  name differs: http://wms.openstreetmap.fr/tms/1.0.0/iomhaiti/{zoom}/{x}/{y}"] = 3
130        skipEntries["  name differs: http://{switch:a,b,c}.layers.openstreetmap.fr/bano/{zoom}/{x}/{y}.png"] = 3
131        skipEntries["  name differs: http://ooc.openstreetmap.org/os1/{zoom}/{x}/{y}.jpg"] = 3
132        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
133        skipEntries["  name differs: http://tms.cadastre.openstreetmap.fr/*/tout/{zoom}/{x}/{y}.png"] = 3
134        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
135        skipEntries["  name differs: http://geo.nls.uk/mapdata2/os/25_inch/scotland_1/{zoom}/{x}/{y}.png"] = 3
136        skipEntries["  name differs: http://geo.nls.uk/mapdata3/os/6_inch_gb_1900/{zoom}/{x}/{y}.png"] = 3
137        skipEntries["  name differs: http://geoserver.infobex.hu/Budapest2014/IST/{zoom}/{x}/{y}.jpg"] = 3
138        skipEntries["  name differs: http://mapproxy.openmap.lt/ort10lt/g/{zoom}/{x}/{y}.jpeg"] = 3
139        skipEntries["  name differs: http://e.tile.openstreetmap.hu/ortofoto2000/{zoom}/{x}/{y}.jpg"] = 3
140        skipEntries["  name differs: http://tools.geofabrik.de/osmi/tiles/routing/{zoom}/{x}/{y}.png"] = 3
141        skipEntries["  name differs: http://e.tile.openstreetmap.hu/ortofoto2005/{zoom}/{x}/{y}.jpg"] = 3
142        skipEntries["  name differs: http://tools.geofabrik.de/osmi/tiles/addresses/{zoom}/{x}/{y}.png"] = 3
143        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
144        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
145        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
146        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
147        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
148        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
149        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
150        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
151        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
152        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
153        skipEntries["  country code differs: [EU] OSM Inspector: Boundaries (EU) - http://tools.geofabrik.de/osmi/tiles/boundaries/{zoom}/{x}/{y}.png"] = 3
154        skipEntries["  country code differs: [TH] Cambodia, Laos, Thailand, Vietnam bilingual - http://{switch:a,b,c,d}.tile.osm-tools.org/osm_then/{zoom}/{x}/{y}.png"] = 3
155    }
156
157    void myprintlnfinal(String s) {
158        if(outputStream != null) {
159            outputStream.write(s);
160            outputStream.newLine();
161        } else {
162            println s;
163        }
164    }
165
166    void myprintln(String s) {
167        if(skipEntries.containsKey(s)) {
168            skipCount = skipEntries.get(s)
169            skipEntries.remove(s)
170        }
171        if(skipCount) {
172            skipCount -= 1;
173            if(options.xhtmlbody || options.xhtml) {
174                s = "<pre style=\"margin:3px;color:green\">"+s.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")+"</pre>"
175            }
176            if (!options.noskip) {
177                return;
178            }
179        } else if(options.xhtmlbody || options.xhtml) {
180            String color = s.startsWith("***") ? "black" : (s.startsWith("+ ") ? "blue" : "red")
181            s = "<pre style=\"margin:3px;color:"+color+"\">"+s.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")+"</pre>"
182        }
183        myprintlnfinal(s)
184    }
185
186    void start() {
187        if (options.xhtml) {
188            myprintlnfinal "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
189            myprintlnfinal "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/><title>JOSM - EII differences</title></head><body>\n"
190        }
191    }
192
193    void end() {
194        for (def s: skipEntries.keySet()) {
195            myprintln "+++ Obsolete skip entry: " + s
196        }
197        if (options.xhtml) {
198            myprintlnfinal "</body></html>\n"
199        }
200    }
201
202    void loadEIIEntries() {
203        FileReader fr = new FileReader(eiiInputFile)
204        JsonReader jr = Json.createReader(fr)
205        eiiEntries = jr.readArray()
206        jr.close()
207
208        for (def e : eiiEntries) {
209            def url = getUrl(e)
210            if (url.contains("{z}")) {
211                myprintln "+++ EII-URL uses {z} instead of {zoom}: "+url
212                url = url.replace("{z}","{zoom}")
213            }
214            if (eiiUrls.containsKey(url)) {
215                myprintln "+++ EII-URL is not unique: "+url
216            } else {
217                eiiUrls.put(url, e)
218            }
219        }
220        myprintln "*** Loaded ${eiiEntries.size()} entries (EII). ***"
221    }
222
223    void loadJosmEntries() {
224        def reader = new ImageryReader(josmInputFile)
225        josmEntries = reader.parse()
226
227        for (def e : josmEntries) {
228            def url = getUrl(e)
229            if (url.contains("{z}")) {
230                myprintln "+++ JOSM-URL uses {z} instead of {zoom}: "+url
231                url = url.replace("{z}","{zoom}")
232            }
233            if (josmUrls.containsKey(url)) {
234                myprintln "+++ JOSM-URL is not unique: "+url
235            } else {
236              josmUrls.put(url, e)
237            }
238            for (def m : e.getMirrors()) {
239                url = getUrl(m)
240                if (josmUrls.containsKey(url)) {
241                    myprintln "+++ JOSM-Mirror-URL is not unique: "+url
242                } else {
243                  josmUrls.put(url, m)
244                }
245            }
246        }
247        myprintln "*** Loaded ${josmEntries.size()} entries (JOSM). ***"
248    }
249
250    List inOneButNotTheOther(Map m1, Map m2) {
251        def l = []
252        for (def url : m1.keySet()) {
253            if (!m2.containsKey(url)) {
254                def name = getName(m1.get(url))
255                l += "  "+getDescription(m1.get(url))
256            }
257        }
258        l.sort()
259    }
260
261    void checkInOneButNotTheOther() {
262        def l1 = inOneButNotTheOther(eiiUrls, josmUrls)
263        myprintln "*** URLs found in EII but not in JOSM (${l1.size()}): ***"
264        if (!l1.isEmpty()) {
265            for (def l : l1)
266                myprintln "-"+l
267        }
268
269        if (options.nomissingeii)
270            return
271        def l2 = inOneButNotTheOther(josmUrls, eiiUrls)
272        myprintln "*** URLs found in JOSM but not in EII (${l2.size()}): ***"
273        if (!l2.isEmpty()) {
274            for (def l : l2)
275                myprintln "+" + l
276        }
277    }
278
279    void checkCommonEntries() {
280        myprintln "*** Same URL, but different name: ***"
281        for (def url : eiiUrls.keySet()) {
282            def e = eiiUrls.get(url)
283            if (!josmUrls.containsKey(url)) continue
284            def j = josmUrls.get(url)
285            if (!getName(e).equals(getName(j))) {
286                myprintln "  name differs: $url"
287                myprintln "     (IEE):     ${getName(e)}"
288                myprintln "     (JOSM):    ${getName(j)}"
289            }
290        }
291
292        myprintln "*** Same URL, but different type: ***"
293        for (def url : eiiUrls.keySet()) {
294            def e = eiiUrls.get(url)
295            if (!josmUrls.containsKey(url)) continue
296            def j = josmUrls.get(url)
297            if (!getType(e).equals(getType(j))) {
298                myprintln "  type differs: ${getName(j)} - $url"
299                myprintln "     (IEE):     ${getType(e)}"
300                myprintln "     (JOSM):    ${getType(j)}"
301            }
302        }
303
304        myprintln "*** Same URL, but different zoom bounds: ***"
305        for (def url : eiiUrls.keySet()) {
306            def e = eiiUrls.get(url)
307            if (!josmUrls.containsKey(url)) continue
308            def j = josmUrls.get(url)
309
310            Integer eMinZoom = getMinZoom(e)
311            Integer jMinZoom = getMinZoom(j)
312            if (eMinZoom != jMinZoom  && !(eMinZoom == 0 && jMinZoom == null)) {
313                myprintln "  minzoom differs: ${getDescription(j)}"
314                myprintln "     (IEE):     ${eMinZoom}"
315                myprintln "     (JOSM):    ${jMinZoom}"
316            }
317            Integer eMaxZoom = getMaxZoom(e)
318            Integer jMaxZoom = getMaxZoom(j)
319            if (eMaxZoom != jMaxZoom) {
320                myprintln "  maxzoom differs: ${getDescription(j)}"
321                myprintln "     (IEE):     ${eMaxZoom}"
322                myprintln "     (JOSM):    ${jMaxZoom}"
323            }
324        }
325
326        myprintln "*** Same URL, but different country code: ***"
327        for (def url : eiiUrls.keySet()) {
328            def e = eiiUrls.get(url)
329            if (!josmUrls.containsKey(url)) continue
330            def j = josmUrls.get(url)
331            if (!getCountryCode(e).equals(getCountryCode(j))) {
332                myprintln "  country code differs: ${getDescription(j)}"
333                myprintln "     (IEE):     ${getCountryCode(e)}"
334                myprintln "     (JOSM):    ${getCountryCode(j)}"
335            }
336        }
337        /*myprintln "*** Same URL, but different quality: ***"
338        for (def url : eiiUrls.keySet()) {
339            def e = eiiUrls.get(url)
340            if (!josmUrls.containsKey(url)) {
341              def q = getQuality(e)
342              if("best".equals(q)) {
343                myprintln "  quality best entry not in JOSM for ${getDescription(e)}"
344              }
345              continue
346            }
347            def j = josmUrls.get(url)
348            if (!getQuality(e).equals(getQuality(j))) {
349                myprintln "  quality differs: ${getDescription(j)}"
350                myprintln "     (IEE):     ${getQuality(e)}"
351                myprintln "     (JOSM):    ${getQuality(j)}"
352            }
353        }*/
354    }
355
356    /**
357     * Utility functions that allow uniform access for both ImageryInfo and JsonObject.
358     */
359    static String getUrl(Object e) {
360        if (e instanceof ImageryInfo) return e.url
361        return e.getString("url")
362    }
363    static String getName(Object e) {
364        if (e instanceof ImageryInfo) return e.name
365        return e.getString("name")
366    }
367    static String getType(Object e) {
368        if (e instanceof ImageryInfo) return e.getImageryType().getTypeString()
369        return e.getString("type")
370    }
371    static Integer getMinZoom(Object e) {
372        if (e instanceof ImageryInfo) {
373            int mz = e.getMinZoom()
374            return mz == 0 ? null : mz
375        } else {
376            def ext = e.getJsonObject("extent")
377            if (ext == null) return null
378            def num = ext.getJsonNumber("min_zoom")
379            if (num == null) return null
380            return num.intValue()
381        }
382    }
383    static Integer getMaxZoom(Object e) {
384        if (e instanceof ImageryInfo) {
385            int mz = e.getMaxZoom()
386            return mz == 0 ? null : mz
387        } else {
388            def ext = e.getJsonObject("extent")
389            if (ext == null) return null
390            def num = ext.getJsonNumber("max_zoom")
391            if (num == null) return null
392            return num.intValue()
393        }
394    }
395    static String getCountryCode(Object e) {
396        if (e instanceof ImageryInfo) return "".equals(e.getCountryCode()) ? null : e.getCountryCode()
397        return e.getString("country_code", null)
398    }
399    static String getQuality(Object e) {
400        //if (e instanceof ImageryInfo) return "".equals(e.getQuality()) ? null : e.getQuality()
401        if (e instanceof ImageryInfo) return null
402        return e.get("best") ? "best" : null
403    }
404    String getDescription(Object o) {
405        def url = getUrl(o)
406        def cc = getCountryCode(o)
407        if (cc == null) {
408            def j = josmUrls.get(url)
409            if (j != null) cc = getCountryCode(j)
410            if (cc == null) {
411                def e = eiiUrls.get(url)
412                if (e != null) cc = getCountryCode(e)
413            }
414        }
415        if (cc == null) {
416            cc = ''
417        } else {
418            cc = "[$cc] "
419        }
420        def d = cc + getName(o) + " - " + getUrl(o)
421        if (options.shorten) {
422            def MAXLEN = 140
423            if (d.length() > MAXLEN) d = d.substring(0, MAXLEN-1) + "..."
424        }
425        return d
426    }
427}
Note: See TracBrowser for help on using the repository browser.