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

Last change on this file since 11234 was 11234, checked in by Klumbumbus, 4 years ago

see #12706 - update EII ignore list

  • Property svn:eol-style set to native
File size: 25.1 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       
103        /* URL style mismatch */
104        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://{switch:a,b,c,d}.tile.stamen.com/terrain-background/{z}/{x}/{y}.jpg"] = 1
105        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
106        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
107        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
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://mapproxy.osm.ch:8080/tiles/AGIS2014/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
111        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.osm.ch:8080/tiles/sogis2014/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
112        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.openmap.lt/ort10lt/g/{z}/{x}/{y}.jpeg"] = 1
113        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.sosm.ch:8080/tiles/zh_luftbild2011/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
114        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.openmap.lt/ort10lt/g/{z}/{x}/{y}.jpeg"] = 1
115        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.osm.ch:8080/tiles/KTZUERICH2015/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
116        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
117        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.osm.ch:8080/tiles/KTBASELSTADT2015/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
118        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.osm.ch:8080/tiles/bern2016/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
119        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.osm.ch:8080/tiles/BAYERNDOP80/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
120        skipEntries["+++ EII-URL uses {z} instead of {zoom}: https://api.mapbox.com/styles/v1/wille/cirnnxni1000jg8nfppc8g7pm/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1Ijoid2lsbGUiLCJhIjoicFNVWk5VWSJ9.hluCd0YGvYHNlFi_utWe2g"] = 1
121       
122        /* various reasons */
123        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
124        skipEntries["-  OpenStreetMap (Standard Black & White) - http://{switch:a,b,c}.www.toolserver.org/tiles/bw-mapnik/{zoom}/{x}/{y}.png"] = 1
125        skipEntries["-  OpenStreetMap (Standard) - http://{switch:a,b,c}.tile.openstreetmap.org/{zoom}/{x}/{y}.png"] = 1
126        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
127        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
128        skipEntries["-  [CZ] Czech CUZK:KM tiles proxy - http://osm-{switch:a,b,c}.zby.cz/tiles_cuzk.php/{zoom}/{x}/{y}.png"] = 1
129        skipEntries["-  [CZ] 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
130        skipEntries["-  [CZ] Czech ÚHUL:ORTOFOTO tiles proxy - http://osm-{switch:a,b,c}.zby.cz/tiles_uhul.php/{zoom}/{x}/{y}.jpg"] = 1
131        skipEntries["-  [DE] 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["-  [DE] 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
133        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
134        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
135        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
136        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
137       
138        /* name differs */
139        skipEntries["  name differs: http://wms.openstreetmap.fr/tms/1.0.0/tours_2013/{zoom}/{x}/{y}"] = 3
140        skipEntries["  name differs: http://wms.openstreetmap.fr/tms/1.0.0/tours/{zoom}/{x}/{y}"] = 3
141        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
142        skipEntries["  name differs: http://wms.openstreetmap.fr/tms/1.0.0/iomhaiti/{zoom}/{x}/{y}"] = 3
143        skipEntries["  name differs: http://{switch:a,b,c}.layers.openstreetmap.fr/bano/{zoom}/{x}/{y}.png"] = 3
144        skipEntries["  name differs: http://ooc.openstreetmap.org/os1/{zoom}/{x}/{y}.jpg"] = 3
145        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
146        skipEntries["  name differs: http://tms.cadastre.openstreetmap.fr/*/tout/{zoom}/{x}/{y}.png"] = 3
147        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
148        skipEntries["  name differs: http://geo.nls.uk/mapdata2/os/25_inch/scotland_1/{zoom}/{x}/{y}.png"] = 3
149        skipEntries["  name differs: http://geo.nls.uk/mapdata3/os/6_inch_gb_1900/{zoom}/{x}/{y}.png"] = 3
150        skipEntries["  name differs: http://geoserver.infobex.hu/Budapest2014/IST/{zoom}/{x}/{y}.jpg"] = 3
151        skipEntries["  name differs: http://mapproxy.openmap.lt/ort10lt/g/{zoom}/{x}/{y}.jpeg"] = 3
152        skipEntries["  name differs: http://e.tile.openstreetmap.hu/ortofoto2000/{zoom}/{x}/{y}.jpg"] = 3
153        skipEntries["  name differs: http://e.tile.openstreetmap.hu/ortofoto2005/{zoom}/{x}/{y}.jpg"] = 3
154        skipEntries["  name differs: http://gis3.stuttgart.de/wss/service/wms_Luftbilder2011_jpg_internet/guest?FORMAT=image/jpeg&VERSION=1.3.0&SERVICE=WMS&REQUEST=GetMap&Layers=0,1,2,3,4,5,6,7,8&STYLES=default,default,default,default,default,default,default,default,default&CRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"] = 3
155        skipEntries["  name differs: https://secure.erlangen.de/arcgiser/services/Luftbilder2013/MapServer/WmsServer?FORMAT=image/bmp&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&LAYERS=Erlangen_ratio5_6.25cm.jp2&STYLES=&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"] = 3
156        skipEntries["  name differs: http://{switch:a,b,c}.gps-tile.openstreetmap.org/lines/{zoom}/{x}/{y}.png"] = 3
157        skipEntries["  name differs: https://{switch:a,b,c}.tile.thunderforest.com/cycle/{zoom}/{x}/{y}.png"] = 3
158        skipEntries["  name differs: https://secure.erlangen.de/arcgiser/services/Luftbild2016/MapServer/WmsServer?FORMAT=image/bmp&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&LAYERS=0&STYLES=&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"] = 3
159       
160        /* maxzoom or minzoom differs */
161        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
162        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
163        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
164        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
165        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
166        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
167        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
168        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
169        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
170        /* country code differs */
171       
172        }
173
174    void myprintlnfinal(String s) {
175        if(outputStream != null) {
176            outputStream.write(s);
177            outputStream.newLine();
178        } else {
179            println s;
180        }
181    }
182
183    void myprintln(String s) {
184        if(skipEntries.containsKey(s)) {
185            skipCount = skipEntries.get(s)
186            skipEntries.remove(s)
187        }
188        if(skipCount) {
189            skipCount -= 1;
190            if(options.xhtmlbody || options.xhtml) {
191                s = "<pre style=\"margin:3px;color:green\">"+s.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")+"</pre>"
192            }
193            if (!options.noskip) {
194                return;
195            }
196        } else if(options.xhtmlbody || options.xhtml) {
197            String color = s.startsWith("***") ? "black" : (s.startsWith("+ ") ? "blue" : "red")
198            s = "<pre style=\"margin:3px;color:"+color+"\">"+s.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")+"</pre>"
199        }
200        myprintlnfinal(s)
201    }
202
203    void start() {
204        if (options.xhtml) {
205            myprintlnfinal "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
206            myprintlnfinal "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/><title>JOSM - EII differences</title></head><body>\n"
207        }
208    }
209
210    void end() {
211        for (def s: skipEntries.keySet()) {
212            myprintln "+++ Obsolete skip entry: " + s
213        }
214        if (options.xhtml) {
215            myprintlnfinal "</body></html>\n"
216        }
217    }
218
219    void loadEIIEntries() {
220        FileReader fr = new FileReader(eiiInputFile)
221        JsonReader jr = Json.createReader(fr)
222        eiiEntries = jr.readArray()
223        jr.close()
224
225        for (def e : eiiEntries) {
226            def url = getUrl(e)
227            if (url.contains("{z}")) {
228                myprintln "+++ EII-URL uses {z} instead of {zoom}: "+url
229                url = url.replace("{z}","{zoom}")
230            }
231            if (eiiUrls.containsKey(url)) {
232                myprintln "+++ EII-URL is not unique: "+url
233            } else {
234                eiiUrls.put(url, e)
235            }
236        }
237        myprintln "*** Loaded ${eiiEntries.size()} entries (EII). ***"
238    }
239
240    void loadJosmEntries() {
241        def reader = new ImageryReader(josmInputFile)
242        josmEntries = reader.parse()
243
244        for (def e : josmEntries) {
245            def url = getUrl(e)
246            if (url.contains("{z}")) {
247                myprintln "+++ JOSM-URL uses {z} instead of {zoom}: "+url
248                url = url.replace("{z}","{zoom}")
249            }
250            if (josmUrls.containsKey(url)) {
251                myprintln "+++ JOSM-URL is not unique: "+url
252            } else {
253              josmUrls.put(url, e)
254            }
255            for (def m : e.getMirrors()) {
256                url = getUrl(m)
257                if (josmUrls.containsKey(url)) {
258                    myprintln "+++ JOSM-Mirror-URL is not unique: "+url
259                } else {
260                  josmUrls.put(url, m)
261                }
262            }
263        }
264        myprintln "*** Loaded ${josmEntries.size()} entries (JOSM). ***"
265    }
266
267    List inOneButNotTheOther(Map m1, Map m2) {
268        def l = []
269        for (def url : m1.keySet()) {
270            if (!m2.containsKey(url)) {
271                def name = getName(m1.get(url))
272                l += "  "+getDescription(m1.get(url))
273            }
274        }
275        l.sort()
276    }
277
278    void checkInOneButNotTheOther() {
279        def l1 = inOneButNotTheOther(eiiUrls, josmUrls)
280        myprintln "*** URLs found in EII but not in JOSM (${l1.size()}): ***"
281        if (!l1.isEmpty()) {
282            for (def l : l1)
283                myprintln "-"+l
284        }
285
286        if (options.nomissingeii)
287            return
288        def l2 = inOneButNotTheOther(josmUrls, eiiUrls)
289        myprintln "*** URLs found in JOSM but not in EII (${l2.size()}): ***"
290        if (!l2.isEmpty()) {
291            for (def l : l2)
292                myprintln "+" + l
293        }
294    }
295
296    void checkCommonEntries() {
297        myprintln "*** Same URL, but different name: ***"
298        for (def url : eiiUrls.keySet()) {
299            def e = eiiUrls.get(url)
300            if (!josmUrls.containsKey(url)) continue
301            def j = josmUrls.get(url)
302            if (!getName(e).equals(getName(j))) {
303                myprintln "  name differs: $url"
304                myprintln "     (IEE):     ${getName(e)}"
305                myprintln "     (JOSM):    ${getName(j)}"
306            }
307        }
308
309        myprintln "*** Same URL, but different type: ***"
310        for (def url : eiiUrls.keySet()) {
311            def e = eiiUrls.get(url)
312            if (!josmUrls.containsKey(url)) continue
313            def j = josmUrls.get(url)
314            if (!getType(e).equals(getType(j))) {
315                myprintln "  type differs: ${getName(j)} - $url"
316                myprintln "     (IEE):     ${getType(e)}"
317                myprintln "     (JOSM):    ${getType(j)}"
318            }
319        }
320
321        myprintln "*** Same URL, but different zoom bounds: ***"
322        for (def url : eiiUrls.keySet()) {
323            def e = eiiUrls.get(url)
324            if (!josmUrls.containsKey(url)) continue
325            def j = josmUrls.get(url)
326
327            Integer eMinZoom = getMinZoom(e)
328            Integer jMinZoom = getMinZoom(j)
329            if (eMinZoom != jMinZoom  && !(eMinZoom == 0 && jMinZoom == null)) {
330                myprintln "  minzoom differs: ${getDescription(j)}"
331                myprintln "     (IEE):     ${eMinZoom}"
332                myprintln "     (JOSM):    ${jMinZoom}"
333            }
334            Integer eMaxZoom = getMaxZoom(e)
335            Integer jMaxZoom = getMaxZoom(j)
336            if (eMaxZoom != jMaxZoom) {
337                myprintln "  maxzoom differs: ${getDescription(j)}"
338                myprintln "     (IEE):     ${eMaxZoom}"
339                myprintln "     (JOSM):    ${jMaxZoom}"
340            }
341        }
342
343        myprintln "*** Same URL, but different country code: ***"
344        for (def url : eiiUrls.keySet()) {
345            def e = eiiUrls.get(url)
346            if (!josmUrls.containsKey(url)) continue
347            def j = josmUrls.get(url)
348            if (!getCountryCode(e).equals(getCountryCode(j))) {
349                myprintln "  country code differs: ${getDescription(j)}"
350                myprintln "     (IEE):     ${getCountryCode(e)}"
351                myprintln "     (JOSM):    ${getCountryCode(j)}"
352            }
353        }
354        /*myprintln "*** Same URL, but different quality: ***"
355        for (def url : eiiUrls.keySet()) {
356            def e = eiiUrls.get(url)
357            if (!josmUrls.containsKey(url)) {
358              def q = getQuality(e)
359              if("best".equals(q)) {
360                myprintln "  quality best entry not in JOSM for ${getDescription(e)}"
361              }
362              continue
363            }
364            def j = josmUrls.get(url)
365            if (!getQuality(e).equals(getQuality(j))) {
366                myprintln "  quality differs: ${getDescription(j)}"
367                myprintln "     (IEE):     ${getQuality(e)}"
368                myprintln "     (JOSM):    ${getQuality(j)}"
369            }
370        }*/
371    }
372
373    /**
374     * Utility functions that allow uniform access for both ImageryInfo and JsonObject.
375     */
376    static String getUrl(Object e) {
377        if (e instanceof ImageryInfo) return e.url
378        return e.getString("url")
379    }
380    static String getName(Object e) {
381        if (e instanceof ImageryInfo) return e.getOriginalName()
382        return e.getString("name")
383    }
384    static String getType(Object e) {
385        if (e instanceof ImageryInfo) return e.getImageryType().getTypeString()
386        return e.getString("type")
387    }
388    static Integer getMinZoom(Object e) {
389        if (e instanceof ImageryInfo) {
390            int mz = e.getMinZoom()
391            return mz == 0 ? null : mz
392        } else {
393            def ext = e.getJsonObject("extent")
394            if (ext == null) return null
395            def num = ext.getJsonNumber("min_zoom")
396            if (num == null) return null
397            return num.intValue()
398        }
399    }
400    static Integer getMaxZoom(Object e) {
401        if (e instanceof ImageryInfo) {
402            int mz = e.getMaxZoom()
403            return mz == 0 ? null : mz
404        } else {
405            def ext = e.getJsonObject("extent")
406            if (ext == null) return null
407            def num = ext.getJsonNumber("max_zoom")
408            if (num == null) return null
409            return num.intValue()
410        }
411    }
412    static String getCountryCode(Object e) {
413        if (e instanceof ImageryInfo) return "".equals(e.getCountryCode()) ? null : e.getCountryCode()
414        return e.getString("country_code", null)
415    }
416    static String getQuality(Object e) {
417        //if (e instanceof ImageryInfo) return "".equals(e.getQuality()) ? null : e.getQuality()
418        if (e instanceof ImageryInfo) return null
419        return e.get("best") ? "best" : null
420    }
421    String getDescription(Object o) {
422        def url = getUrl(o)
423        def cc = getCountryCode(o)
424        if (cc == null) {
425            def j = josmUrls.get(url)
426            if (j != null) cc = getCountryCode(j)
427            if (cc == null) {
428                def e = eiiUrls.get(url)
429                if (e != null) cc = getCountryCode(e)
430            }
431        }
432        if (cc == null) {
433            cc = ''
434        } else {
435            cc = "[$cc] "
436        }
437        def d = cc + getName(o) + " - " + getUrl(o)
438        if (options.shorten) {
439            def MAXLEN = 140
440            if (d.length() > MAXLEN) d = d.substring(0, MAXLEN-1) + "..."
441        }
442        return d
443    }
444}
Note: See TracBrowser for help on using the repository browser.