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

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

see #12313 - update and ignore more differences

  • Property svn:eol-style set to native
File size: 21.5 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.loadJosmEntries()
56        script.loadEIIEntries()
57        script.checkInOneButNotTheOther()
58        script.checkCommonEntries()
59        if(outputStream != null) {
60            outputStream.close();
61        }
62        if(outputFile != null) {
63            outputFile.close();
64        }
65    }
66
67    /**
68     * Parse command line arguments.
69     */
70    static void parse_command_line_arguments(args) {
71        def cli = new CliBuilder()
72        cli.o(longOpt:'output', args:1, argName: "output", "Output file, - prints to stdout (default: -)")
73        cli.e(longOpt:'eii_input', args:1, argName:"eii_input", "Input file for the editor imagery index (json). Default is $eiiInputFile (current directory).")
74        cli.j(longOpt:'josm_input', args:1, argName:"josm_input", "Input file for the JOSM imagery list (xml). Default is $josmInputFile (current directory).")
75        cli.s(longOpt:'shorten', "shorten the output, so it is easier to read in a console window")
76        cli.n(longOpt:'noskip', argName:"noskip", "don't skip known entries")
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        if (options.noskip)
99            return;
100        /* TMS proxies for our wms */
101        skipEntries["  Czech CUZK:KM tiles proxy - http://osm-{switch:a,b,c}.zby.cz/tiles_cuzk.php/{zoom}/{x}/{y}.png"] = 1
102        skipEntries["  [CH] Stadt Zürich Luftbild 2011 - http://mapproxy.sosm.ch:8080/tiles/zh_luftbild2011/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
103        skipEntries["  [CH] Übersichtsplan Zürich - http://mapproxy.sosm.ch:8080/tiles/zh_uebersichtsplan/EPSG900913/{zoom}/{x}/{y}.png?origin=nw"] = 1
104        skipEntries["  [CH] Kanton Solothurn 25cm (SOGIS 2011-2014) - http://mapproxy.osm.ch:8080/tiles/sogis2014/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
105        /* URL style mismatch */
106        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://cyberjapandata.gsi.go.jp/xyz/ort/{z}/{x}/{y}.jpg"] = 1
107        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://tms.cadastre.openstreetmap.fr/*/tout/{z}/{x}/{y}.png"] = 1
108        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
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.openstreetmap.lu/tiles/ortho2010/EPSG900913/{z}/{x}/{y}.jpeg"] = 1
113        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.openstreetmap.lu/tiles/ortho2013/EPSG900913/{z}/{x}/{y}.jpeg"] = 1
114        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.sosm.ch:8080/tiles/zh_luftbild2011/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
115        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.openmap.lt/ort10lt/g/{z}/{x}/{y}.jpeg"] = 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["  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
120        skipEntries["  Czech ÚHUL:ORTOFOTO tiles proxy - http://osm-{switch:a,b,c}.zby.cz/tiles_uhul.php/{zoom}/{x}/{y}.jpg"] = 1
121        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
122        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
123        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
124        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
125        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
126        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
127        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
128        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
129        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
130        skipEntries["  name differs: http://wms.openstreetmap.fr/tms/1.0.0/tours_2013/{zoom}/{x}/{y}"] = 3
131        skipEntries["  name differs: http://wms.openstreetmap.fr/tms/1.0.0/tours/{zoom}/{x}/{y}"] = 3
132        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
133        skipEntries["  name differs: http://wms.openstreetmap.fr/tms/1.0.0/iomhaiti/{zoom}/{x}/{y}"] = 3
134        skipEntries["  name differs: http://{switch:a,b,c}.layers.openstreetmap.fr/bano/{zoom}/{x}/{y}.png"] = 3
135        skipEntries["  name differs: http://ooc.openstreetmap.org/os1/{zoom}/{x}/{y}.jpg"] = 3
136        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
137        skipEntries["  name differs: http://tms.cadastre.openstreetmap.fr/*/tout/{z}/{x}/{y}.png"] = 3
138        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
139        skipEntries["  name differs: http://geo.nls.uk/mapdata2/os/25_inch/scotland_1/{zoom}/{x}/{y}.png"] = 3
140        skipEntries["  name differs: http://geo.nls.uk/mapdata3/os/6_inch_gb_1900/{zoom}/{x}/{y}.png"] = 3
141        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
142        skipEntries["  name differs: http://geoserver.infobex.hu/Budapest2014/IST/{zoom}/{x}/{y}.jpg"] = 3
143        skipEntries["  name differs: http://mapproxy.openmap.lt/ort10lt/g/{zoom}/{x}/{y}.jpeg"] = 3
144        skipEntries["  name differs: http://e.tile.openstreetmap.hu/ortofoto2000/{zoom}/{x}/{y}.jpg"] = 3
145        skipEntries["  name differs: http://tms.cadastre.openstreetmap.fr/*/tout/{zoom}/{x}/{y}.png"] = 3
146        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
147        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
148        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
149        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
150        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
151        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
152        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
153        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
154        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
155        skipEntries["  country code differs: [LT] ORT10LT (Lithuania) - http://mapproxy.openmap.lt/ort10lt/g/{zoom}/{x}/{y}.jpeg"] = 3
156    }
157
158    void myprintln(String s) {
159        if(skipEntries.containsKey(s)) {
160            skipCount = skipEntries.get(s)
161        }
162        if(skipCount) {
163            skipCount -= 1;
164            return
165        }
166        if(outputStream != null) {
167            outputStream.write(s);
168            outputStream.newLine();
169        } else {
170            println s;
171        }
172    }
173
174    void loadEIIEntries() {
175        FileReader fr = new FileReader(eiiInputFile)
176        JsonReader jr = Json.createReader(fr)
177        eiiEntries = jr.readArray()
178        jr.close()
179
180        for (def e : eiiEntries) {
181            def url = getUrl(e)
182            if (url.contains("{z}")) {
183                myprintln "+++ EII-URL uses {z} instead of {zoom}: "+url
184                url = url.replace("{z}","{zoom}")
185            }
186            if (eiiUrls.containsKey(url)) {
187                myprintln "+++ EII-URL is not unique: "+url
188            } else {
189                eiiUrls.put(url, e)
190            }
191        }
192        myprintln "*** Loaded ${eiiEntries.size()} entries (EII). ***"
193    }
194
195    void loadJosmEntries() {
196        def reader = new ImageryReader(josmInputFile)
197        josmEntries = reader.parse()
198       
199        for (def e : josmEntries) {
200            def url = getUrl(e)
201            if (josmUrls.containsKey(url)) {
202                myprintln "+++ JOSM-URL is not unique: "+url
203            } else {
204              josmUrls.put(url, e)
205            }
206        }
207        myprintln "*** Loaded ${josmEntries.size()} entries (JOSM). ***"
208    }
209
210    List inOneButNotTheOther(Map m1, Map m2) {
211        def l = []
212        for (def url : m1.keySet()) {
213            if (!m2.containsKey(url)) {
214                def name = getName(m1.get(url))
215                l += "  "+getDescription(m1.get(url))
216            }
217        }
218        l.sort()
219    }
220   
221    void checkInOneButNotTheOther() {
222        def l1 = inOneButNotTheOther(eiiUrls, josmUrls)
223        myprintln "*** URLs found in EII but not in JOSM (${l1.size()}): ***"
224        if (l1.isEmpty()) {
225            myprintln "  -"
226        } else {
227            for (def l : l1)
228                myprintln l
229        }
230
231        if (options.nomissingeii)
232            return
233        def l2 = inOneButNotTheOther(josmUrls, eiiUrls)
234        myprintln "*** URLs found in JOSM but not in EII (${l2.size()}): ***"
235        if (l2.isEmpty()) {
236            myprintln "  -"
237        } else {
238            for (def l : l2)
239                myprintln l
240        }
241    }
242   
243    void checkCommonEntries() {
244        myprintln "*** Same URL, but different name: ***"
245        for (def url : eiiUrls.keySet()) {
246            def e = eiiUrls.get(url)
247            if (!josmUrls.containsKey(url)) continue
248            def j = josmUrls.get(url)
249            if (!getName(e).equals(getName(j))) {
250                myprintln "  name differs: $url"
251                myprintln "     (IEE):     ${getName(e)}"
252                myprintln "     (JOSM):    ${getName(j)}"
253            }
254        }
255       
256        myprintln "*** Same URL, but different type: ***"
257        for (def url : eiiUrls.keySet()) {
258            def e = eiiUrls.get(url)
259            if (!josmUrls.containsKey(url)) continue
260            def j = josmUrls.get(url)
261            if (!getType(e).equals(getType(j))) {
262                myprintln "  type differs: ${getName(j)} - $url"
263                myprintln "     (IEE):     ${getType(e)}"
264                myprintln "     (JOSM):    ${getType(j)}"
265            }
266        }
267       
268        myprintln "*** Same URL, but different zoom bounds: ***"
269        for (def url : eiiUrls.keySet()) {
270            def e = eiiUrls.get(url)
271            if (!josmUrls.containsKey(url)) continue
272            def j = josmUrls.get(url)
273
274            Integer eMinZoom = getMinZoom(e)
275            Integer jMinZoom = getMinZoom(j)
276            if (eMinZoom != jMinZoom  && !(eMinZoom == 0 && jMinZoom == null)) {
277                myprintln "  minzoom differs: ${getDescription(j)}"
278                myprintln "     (IEE):     ${eMinZoom}"
279                myprintln "     (JOSM):    ${jMinZoom}"
280            }
281            Integer eMaxZoom = getMaxZoom(e)
282            Integer jMaxZoom = getMaxZoom(j)
283            if (eMaxZoom != jMaxZoom) {
284                myprintln "  maxzoom differs: ${getDescription(j)}"
285                myprintln "     (IEE):     ${eMaxZoom}"
286                myprintln "     (JOSM):    ${jMaxZoom}"
287            }
288        }
289       
290        myprintln "*** Same URL, but different country code: ***"
291        for (def url : eiiUrls.keySet()) {
292            def e = eiiUrls.get(url)
293            if (!josmUrls.containsKey(url)) continue
294            def j = josmUrls.get(url)
295            if (!getCountryCode(e).equals(getCountryCode(j))) {
296                myprintln "  country code differs: ${getDescription(j)}"
297                myprintln "     (IEE):     ${getCountryCode(e)}"
298                myprintln "     (JOSM):    ${getCountryCode(j)}"
299            }
300        }
301        myprintln "*** Same URL, but different quality: ***"
302        for (def url : eiiUrls.keySet()) {
303            def e = eiiUrls.get(url)
304            if (!josmUrls.containsKey(url)) {
305              def q = getQuality(e)
306              if("best".equals(q)) {
307                myprintln "  quality best entry not in JOSM for ${getDescription(e)}"
308              }
309              continue
310            }
311            def j = josmUrls.get(url)
312            if (!getQuality(e).equals(getQuality(j))) {
313                myprintln "  quality differs: ${getDescription(j)}"
314                myprintln "     (IEE):     ${getQuality(e)}"
315                myprintln "     (JOSM):    ${getQuality(j)}"
316            }
317        }
318    }
319   
320    /**
321     * Utility functions that allow uniform access for both ImageryInfo and JsonObject.
322     */
323    static String getUrl(Object e) {
324        if (e instanceof ImageryInfo) return e.url
325        return e.getString("url")
326    }
327    static String getName(Object e) {
328        if (e instanceof ImageryInfo) return e.name
329        return e.getString("name")
330    }
331    static String getType(Object e) {
332        if (e instanceof ImageryInfo) return e.getImageryType().getTypeString()
333        return e.getString("type")
334    }
335    static Integer getMinZoom(Object e) {
336        if (e instanceof ImageryInfo) {
337            int mz = e.getMinZoom()
338            return mz == 0 ? null : mz
339        } else {
340            def ext = e.getJsonObject("extent")
341            if (ext == null) return null
342            def num = ext.getJsonNumber("min_zoom")
343            if (num == null) return null
344            return num.intValue()
345        }
346    }
347    static Integer getMaxZoom(Object e) {
348        if (e instanceof ImageryInfo) {
349            int mz = e.getMaxZoom()
350            return mz == 0 ? null : mz
351        } else {
352            def ext = e.getJsonObject("extent")
353            if (ext == null) return null
354            def num = ext.getJsonNumber("max_zoom")
355            if (num == null) return null
356            return num.intValue()
357        }
358    }
359    static String getCountryCode(Object e) {
360        if (e instanceof ImageryInfo) return "".equals(e.getCountryCode()) ? null : e.getCountryCode()
361        return e.getString("country_code", null)
362    }
363    static String getQuality(Object e) {
364        //if (e instanceof ImageryInfo) return "".equals(e.getQuality()) ? null : e.getQuality()
365        if (e instanceof ImageryInfo) return null
366        return e.get("best") ? "best" : null
367    }
368    String getDescription(Object o) {
369        def url = getUrl(o)
370        def cc = getCountryCode(o)
371        if (cc == null) {
372            def j = josmUrls.get(url)
373            if (j != null) cc = getCountryCode(j)
374            if (cc == null) {
375                def e = eiiUrls.get(url)
376                if (e != null) cc = getCountryCode(e)
377            }
378        }
379        if (cc == null) {
380            cc = ''
381        } else {
382            cc = "[$cc] "
383        }
384        def d = cc + getName(o) + " - " + getUrl(o)
385        if (options.shorten) {
386            def MAXLEN = 140
387            if (d.length() > MAXLEN) d = d.substring(0, MAXLEN-1) + "..."
388        }
389        return d
390    }
391
392}
Note: See TracBrowser for help on using the repository browser.