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

Last change on this file since 10493 was 10222, checked in by Don-vip, 4 years ago

findbugs - fix/suppress most of warnings reported in unit tests + enable low confidence warnings for core

  • Property svn:eol-style set to native
File size: 25.8 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
27import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
28
29class SyncEditorImageryIndex {
30
31    List<ImageryInfo> josmEntries;
32    JsonArray eiiEntries;
33
34    def eiiUrls = new HashMap<String, JsonObject>()
35    def josmUrls = new HashMap<String, ImageryInfo>()
36
37    static String eiiInputFile = 'imagery.json'
38    static String josmInputFile = 'maps.xml'
39    static FileWriter outputFile = null
40    static BufferedWriter outputStream = null
41    static int skipCount = 0;
42    static def skipEntries = [:]
43
44    static def options
45
46    /**
47     * Main method.
48     */
49    static main(def args) {
50        parse_command_line_arguments(args)
51        def script = new SyncEditorImageryIndex()
52        script.loadSkip()
53        script.start()
54        script.loadJosmEntries()
55        script.loadEIIEntries()
56        script.checkInOneButNotTheOther()
57        script.checkCommonEntries()
58        script.end()
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(width: 160)
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.x(longOpt:'xhtmlbody', argName:"xhtmlbody", "create XHTML body for display in a web page")
78        cli.X(longOpt:'xhtml', argName:"xhtml", "create XHTML for display in a web page")
79        cli.m(longOpt:'nomissingeii', argName:"nomissingeii", "don't show missing editor imagery index entries")
80        cli.h(longOpt:'help', "show this help")
81        options = cli.parse(args)
82
83        if (options.h) {
84            cli.usage()
85            System.exit(0)
86        }
87        if (options.eii_input) {
88            eiiInputFile = options.eii_input
89        }
90        if (options.josm_input) {
91            josmInputFile = options.josm_input
92        }
93        if (options.output && options.output != "-") {
94            outputFile = new FileWriter(options.output)
95            outputStream = new BufferedWriter(outputFile)
96        }
97    }
98
99    void loadSkip() {
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://mapproxy.osm.ch:8080/tiles/AGIS2014/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
109        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.osm.ch:8080/tiles/sogis2014/EPSG900913/{z}/{x}/{y}.png?origin=nw"] = 1
110        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.openmap.lt/ort10lt/g/{z}/{x}/{y}.jpeg"] = 1
111        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.openstreetmap.lu/tiles/ortho2010/EPSG900913/{z}/{x}/{y}.jpeg"] = 1
112        skipEntries["+++ EII-URL uses {z} instead of {zoom}: http://mapproxy.openstreetmap.lu/tiles/ortho2013/EPSG900913/{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
118        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
119        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
120        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
121        skipEntries["-  Czech ÚHUL:ORTOFOTO tiles proxy - http://osm-{switch:a,b,c}.zby.cz/tiles_uhul.php/{zoom}/{x}/{y}.jpg"] = 1
122        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
123        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
124        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
125        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
126        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
127        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
128        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
129        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
130        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
131        skipEntries["  name differs: http://wms.openstreetmap.fr/tms/1.0.0/tours_2013/{zoom}/{x}/{y}"] = 3
132        skipEntries["  name differs: http://wms.openstreetmap.fr/tms/1.0.0/tours/{zoom}/{x}/{y}"] = 3
133        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
134        skipEntries["  name differs: http://wms.openstreetmap.fr/tms/1.0.0/iomhaiti/{zoom}/{x}/{y}"] = 3
135        skipEntries["  name differs: http://{switch:a,b,c}.layers.openstreetmap.fr/bano/{zoom}/{x}/{y}.png"] = 3
136        skipEntries["  name differs: http://ooc.openstreetmap.org/os1/{zoom}/{x}/{y}.jpg"] = 3
137        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
138        skipEntries["  name differs: http://tms.cadastre.openstreetmap.fr/*/tout/{zoom}/{x}/{y}.png"] = 3
139        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
140        skipEntries["  name differs: http://geo.nls.uk/mapdata2/os/25_inch/scotland_1/{zoom}/{x}/{y}.png"] = 3
141        skipEntries["  name differs: http://geo.nls.uk/mapdata3/os/6_inch_gb_1900/{zoom}/{x}/{y}.png"] = 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://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
146        skipEntries["  name differs: http://tools.geofabrik.de/osmi/tiles/routing/{zoom}/{x}/{y}.png"] = 3
147        skipEntries["  name differs: http://e.tile.openstreetmap.hu/ortofoto2005/{zoom}/{x}/{y}.jpg"] = 3
148        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
149        skipEntries["  name differs: http://tools.geofabrik.de/osmi/tiles/addresses/{zoom}/{x}/{y}.png"] = 3
150        skipEntries["  name differs: http://{switch:a,b,c}.www.toolserver.org/tiles/bw-mapnik/{zoom}/{x}/{y}.png"] = 3
151        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
152        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
153        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
154        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
155        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
156        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
157        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
158        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
159        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
160        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
161        skipEntries["  country code differs: [EU] OSM Inspector: Boundaries (EU) - http://tools.geofabrik.de/osmi/tiles/boundaries/{zoom}/{x}/{y}.png"] = 3
162        skipEntries["  country code differs: [LT] ORT10LT (Lithuania) - http://mapproxy.openmap.lt/ort10lt/g/{zoom}/{x}/{y}.jpeg"] = 3
163        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
164        skipEntries["  country code differs: [HU] Szeged ortophoto 2011 - http://e.tile.openstreetmap.hu/szeged-2011-10cm/{zoom}/{x}/{y}.png"] = 3
165        skipEntries["  country code differs: [HU] Danube flood ortophoto 2013 - http://e.tile.openstreetmap.hu/dunai-arviz-2013/{zoom}/{x}/{y}.jpg"] = 3
166        skipEntries["  country code differs: [HU] Budapest district XII ortophoto 2013 - http://turistautak.openstreetmap.hu/kolesar/wms/Budapest-XII/?FORMAT=image/jpeg&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&LAYERS=Ortofot%C3%B3%202013&STYLES=&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"] = 3
167        skipEntries["  country code differs: [HU] Törökbálint ortophoto 2013 - http://terkep.torokbalint.hu/mapproxy/service?FORMAT=image/jpeg&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&LAYERS=ORTO_2013_5CM_2013SZEPT_TAKARASSAL_512_512&STYLES=&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"] = 3
168
169
170    }
171
172    void myprintlnfinal(String s) {
173        if(outputStream != null) {
174            outputStream.write(s);
175            outputStream.newLine();
176        } else {
177            println s;
178        }
179    }
180
181    @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
182    void myprintln(String s) {
183        if(skipEntries.containsKey(s)) {
184            skipCount = skipEntries.get(s)
185            skipEntries.remove(s)
186        }
187        if(skipCount) {
188            skipCount -= 1;
189            if(options.xhtmlbody || options.xhtml) {
190                s = "<pre style=\"margin:3px;color:green\">"+s.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")+"</pre>"
191            }
192            if (!options.noskip) {
193                return;
194            }
195        } else if(options.xhtmlbody || options.xhtml) {
196            String color = s.startsWith("***") ? "black" : (s.startsWith("+ ") ? "blue" : "red")
197            s = "<pre style=\"margin:3px;color:"+color+"\">"+s.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")+"</pre>"
198        }
199        myprintlnfinal(s)
200    }
201
202    void start() {
203        if (options.xhtml) {
204            myprintlnfinal "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
205            myprintlnfinal "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/><title>JOSM - EII differences</title></head><body>\n"
206        }
207    }
208
209    void end() {
210        for (def s: skipEntries.keySet()) {
211            myprintln "+++ Obsolete skip entry: " + s
212        }
213        if (options.xhtml) {
214            myprintlnfinal "</body></html>\n"
215        }
216    }
217
218    void loadEIIEntries() {
219        FileReader fr = new FileReader(eiiInputFile)
220        JsonReader jr = Json.createReader(fr)
221        eiiEntries = jr.readArray()
222        jr.close()
223
224        for (def e : eiiEntries) {
225            def url = getUrl(e)
226            if (url.contains("{z}")) {
227                myprintln "+++ EII-URL uses {z} instead of {zoom}: "+url
228                url = url.replace("{z}","{zoom}")
229            }
230            if (eiiUrls.containsKey(url)) {
231                myprintln "+++ EII-URL is not unique: "+url
232            } else {
233                eiiUrls.put(url, e)
234            }
235        }
236        myprintln "*** Loaded ${eiiEntries.size()} entries (EII). ***"
237    }
238
239    void loadJosmEntries() {
240        def reader = new ImageryReader(josmInputFile)
241        josmEntries = reader.parse()
242
243        for (def e : josmEntries) {
244            def url = getUrl(e)
245            if (url.contains("{z}")) {
246                myprintln "+++ JOSM-URL uses {z} instead of {zoom}: "+url
247                url = url.replace("{z}","{zoom}")
248            }
249            if (josmUrls.containsKey(url)) {
250                myprintln "+++ JOSM-URL is not unique: "+url
251            } else {
252              josmUrls.put(url, e)
253            }
254            for (def m : e.getMirrors()) {
255                url = getUrl(m)
256                if (josmUrls.containsKey(url)) {
257                    myprintln "+++ JOSM-Mirror-URL is not unique: "+url
258                } else {
259                  josmUrls.put(url, m)
260                }
261            }
262        }
263        myprintln "*** Loaded ${josmEntries.size()} entries (JOSM). ***"
264    }
265
266    List inOneButNotTheOther(Map m1, Map m2) {
267        def l = []
268        for (def url : m1.keySet()) {
269            if (!m2.containsKey(url)) {
270                def name = getName(m1.get(url))
271                l += "  "+getDescription(m1.get(url))
272            }
273        }
274        l.sort()
275    }
276
277    void checkInOneButNotTheOther() {
278        def l1 = inOneButNotTheOther(eiiUrls, josmUrls)
279        myprintln "*** URLs found in EII but not in JOSM (${l1.size()}): ***"
280        if (!l1.isEmpty()) {
281            for (def l : l1)
282                myprintln "-"+l
283        }
284
285        if (options.nomissingeii)
286            return
287        def l2 = inOneButNotTheOther(josmUrls, eiiUrls)
288        myprintln "*** URLs found in JOSM but not in EII (${l2.size()}): ***"
289        if (!l2.isEmpty()) {
290            for (def l : l2)
291                myprintln "+" + l
292        }
293    }
294
295    void checkCommonEntries() {
296        myprintln "*** Same URL, but different name: ***"
297        for (def url : eiiUrls.keySet()) {
298            def e = eiiUrls.get(url)
299            if (!josmUrls.containsKey(url)) continue
300            def j = josmUrls.get(url)
301            if (!getName(e).equals(getName(j))) {
302                myprintln "  name differs: $url"
303                myprintln "     (IEE):     ${getName(e)}"
304                myprintln "     (JOSM):    ${getName(j)}"
305            }
306        }
307
308        myprintln "*** Same URL, but different type: ***"
309        for (def url : eiiUrls.keySet()) {
310            def e = eiiUrls.get(url)
311            if (!josmUrls.containsKey(url)) continue
312            def j = josmUrls.get(url)
313            if (!getType(e).equals(getType(j))) {
314                myprintln "  type differs: ${getName(j)} - $url"
315                myprintln "     (IEE):     ${getType(e)}"
316                myprintln "     (JOSM):    ${getType(j)}"
317            }
318        }
319
320        myprintln "*** Same URL, but different zoom bounds: ***"
321        for (def url : eiiUrls.keySet()) {
322            def e = eiiUrls.get(url)
323            if (!josmUrls.containsKey(url)) continue
324            def j = josmUrls.get(url)
325
326            Integer eMinZoom = getMinZoom(e)
327            Integer jMinZoom = getMinZoom(j)
328            if (eMinZoom != jMinZoom  && !(eMinZoom == 0 && jMinZoom == null)) {
329                myprintln "  minzoom differs: ${getDescription(j)}"
330                myprintln "     (IEE):     ${eMinZoom}"
331                myprintln "     (JOSM):    ${jMinZoom}"
332            }
333            Integer eMaxZoom = getMaxZoom(e)
334            Integer jMaxZoom = getMaxZoom(j)
335            if (eMaxZoom != jMaxZoom) {
336                myprintln "  maxzoom differs: ${getDescription(j)}"
337                myprintln "     (IEE):     ${eMaxZoom}"
338                myprintln "     (JOSM):    ${jMaxZoom}"
339            }
340        }
341
342        myprintln "*** Same URL, but different country code: ***"
343        for (def url : eiiUrls.keySet()) {
344            def e = eiiUrls.get(url)
345            if (!josmUrls.containsKey(url)) continue
346            def j = josmUrls.get(url)
347            if (!getCountryCode(e).equals(getCountryCode(j))) {
348                myprintln "  country code differs: ${getDescription(j)}"
349                myprintln "     (IEE):     ${getCountryCode(e)}"
350                myprintln "     (JOSM):    ${getCountryCode(j)}"
351            }
352        }
353        /*myprintln "*** Same URL, but different quality: ***"
354        for (def url : eiiUrls.keySet()) {
355            def e = eiiUrls.get(url)
356            if (!josmUrls.containsKey(url)) {
357              def q = getQuality(e)
358              if("best".equals(q)) {
359                myprintln "  quality best entry not in JOSM for ${getDescription(e)}"
360              }
361              continue
362            }
363            def j = josmUrls.get(url)
364            if (!getQuality(e).equals(getQuality(j))) {
365                myprintln "  quality differs: ${getDescription(j)}"
366                myprintln "     (IEE):     ${getQuality(e)}"
367                myprintln "     (JOSM):    ${getQuality(j)}"
368            }
369        }*/
370    }
371
372    /**
373     * Utility functions that allow uniform access for both ImageryInfo and JsonObject.
374     */
375    static String getUrl(Object e) {
376        if (e instanceof ImageryInfo) return e.url
377        return e.getString("url")
378    }
379    static String getName(Object e) {
380        if (e instanceof ImageryInfo) return e.name
381        return e.getString("name")
382    }
383    static String getType(Object e) {
384        if (e instanceof ImageryInfo) return e.getImageryType().getTypeString()
385        return e.getString("type")
386    }
387    static Integer getMinZoom(Object e) {
388        if (e instanceof ImageryInfo) {
389            int mz = e.getMinZoom()
390            return mz == 0 ? null : mz
391        } else {
392            def ext = e.getJsonObject("extent")
393            if (ext == null) return null
394            def num = ext.getJsonNumber("min_zoom")
395            if (num == null) return null
396            return num.intValue()
397        }
398    }
399    static Integer getMaxZoom(Object e) {
400        if (e instanceof ImageryInfo) {
401            int mz = e.getMaxZoom()
402            return mz == 0 ? null : mz
403        } else {
404            def ext = e.getJsonObject("extent")
405            if (ext == null) return null
406            def num = ext.getJsonNumber("max_zoom")
407            if (num == null) return null
408            return num.intValue()
409        }
410    }
411    static String getCountryCode(Object e) {
412        if (e instanceof ImageryInfo) return "".equals(e.getCountryCode()) ? null : e.getCountryCode()
413        return e.getString("country_code", null)
414    }
415    static String getQuality(Object e) {
416        //if (e instanceof ImageryInfo) return "".equals(e.getQuality()) ? null : e.getQuality()
417        if (e instanceof ImageryInfo) return null
418        return e.get("best") ? "best" : null
419    }
420    String getDescription(Object o) {
421        def url = getUrl(o)
422        def cc = getCountryCode(o)
423        if (cc == null) {
424            def j = josmUrls.get(url)
425            if (j != null) cc = getCountryCode(j)
426            if (cc == null) {
427                def e = eiiUrls.get(url)
428                if (e != null) cc = getCountryCode(e)
429            }
430        }
431        if (cc == null) {
432            cc = ''
433        } else {
434            cc = "[$cc] "
435        }
436        def d = cc + getName(o) + " - " + getUrl(o)
437        if (options.shorten) {
438            def MAXLEN = 140
439            if (d.length() > MAXLEN) d = d.substring(0, MAXLEN-1) + "..."
440        }
441        return d
442    }
443}
Note: See TracBrowser for help on using the repository browser.