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

Last change on this file since 9515 was 9515, checked in by stoecker, 6 years ago

see #12313 - suppress some known outdated entries

  • Property svn:eol-style set to native
File size: 17.9 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        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
101        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
102        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
103        skipEntries["  Czech ÚHUL:ORTOFOTO tiles proxy - http://osm-{switch:a,b,c}.zby.cz/tiles_uhul.php/{zoom}/{x}/{y}.jpg"] = 1
104        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
105        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
106        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
107        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
108        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
109        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
110        skipEntries["  name differs: http://wms.openstreetmap.fr/tms/1.0.0/tours_2013/{zoom}/{x}/{y}"] = 3
111        skipEntries["  name differs: http://wms.openstreetmap.fr/tms/1.0.0/tours/{zoom}/{x}/{y}"] = 3
112        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
113        skipEntries["  name differs: http://wms.openstreetmap.fr/tms/1.0.0/iomhaiti/{zoom}/{x}/{y}"] = 3
114        skipEntries["  name differs: http://{switch:a,b,c}.layers.openstreetmap.fr/bano/{zoom}/{x}/{y}.png"] = 3
115        skipEntries["  name differs: http://ooc.openstreetmap.org/os1/{zoom}/{x}/{y}.jpg"] = 3
116        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
117        skipEntries["  name differs: http://tms.cadastre.openstreetmap.fr/*/tout/{z}/{x}/{y}.png"] = 3
118        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
119        skipEntries["  name differs: http://geo.nls.uk/mapdata2/os/25_inch/scotland_1/{zoom}/{x}/{y}.png"] = 3
120        skipEntries["  name differs: http://geo.nls.uk/mapdata3/os/6_inch_gb_1900/{zoom}/{x}/{y}.png"] = 3
121        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
122        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
123        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
124        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
125        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
126        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
127        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
128        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
129        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
130        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
131    }
132   
133    void myprintln(String s) {
134        if(skipEntries.containsKey(s)) {
135            skipCount = skipEntries.get(s)
136        }
137        if(skipCount) {
138            skipCount -= 1;
139            return
140        }
141        if(outputStream != null) {
142            outputStream.write(s);
143            outputStream.newLine();
144        } else {
145            println s;
146        }
147    }
148   
149    void loadEIIEntries() {
150        FileReader fr = new FileReader(eiiInputFile)
151        JsonReader jr = Json.createReader(fr)
152        eiiEntries = jr.readArray()
153        jr.close()
154       
155        for (def e : eiiEntries) {
156            def url = getUrl(e)
157            if (eiiUrls.containsKey(url)) {
158                myprintln "+++ EII-URL is not unique: "+url
159            } else {
160                eiiUrls.put(url, e)
161            }
162        }
163        myprintln "*** Loaded ${eiiEntries.size()} entries (EII). ***"
164    }
165
166    void loadJosmEntries() {
167        def reader = new ImageryReader(josmInputFile)
168        josmEntries = reader.parse()
169       
170        for (def e : josmEntries) {
171            def url = getUrl(e)
172            if (josmUrls.containsKey(url)) {
173                myprintln "+++ JOSM-URL is not unique: "+url
174            } else {
175              josmUrls.put(url, e)
176            }
177        }
178        myprintln "*** Loaded ${josmEntries.size()} entries (JOSM). ***"
179    }
180
181    List inOneButNotTheOther(Map m1, Map m2) {
182        def l = []
183        for (def url : m1.keySet()) {
184            if (!m2.containsKey(url)) {
185                def name = getName(m1.get(url))
186                l += "  "+getDescription(m1.get(url))
187            }
188        }
189        l.sort()
190    }
191   
192    void checkInOneButNotTheOther() {
193        def l1 = inOneButNotTheOther(eiiUrls, josmUrls)
194        myprintln "*** URLs found in EII but not in JOSM (${l1.size()}): ***"
195        if (l1.isEmpty()) {
196            myprintln "  -"
197        } else {
198            myprintln Utils.join("\n", l1)
199        }
200
201        if (options.nomissingeii)
202            return
203        def l2 = inOneButNotTheOther(josmUrls, eiiUrls)
204        myprintln "*** URLs found in JOSM but not in EII (${l2.size()}): ***"
205        if (l2.isEmpty()) {
206            myprintln "  -"
207        } else {
208            myprintln Utils.join("\n", l2)
209        }
210    }
211   
212    void checkCommonEntries() {
213        myprintln "*** Same URL, but different name: ***"
214        for (def url : eiiUrls.keySet()) {
215            def e = eiiUrls.get(url)
216            if (!josmUrls.containsKey(url)) continue
217            def j = josmUrls.get(url)
218            if (!getName(e).equals(getName(j))) {
219                myprintln "  name differs: $url"
220                myprintln "     (IEE):     ${getName(e)}"
221                myprintln "     (JOSM):    ${getName(j)}"
222            }
223        }
224       
225        myprintln "*** Same URL, but different type: ***"
226        for (def url : eiiUrls.keySet()) {
227            def e = eiiUrls.get(url)
228            if (!josmUrls.containsKey(url)) continue
229            def j = josmUrls.get(url)
230            if (!getType(e).equals(getType(j))) {
231                myprintln "  type differs: ${getName(j)} - $url"
232                myprintln "     (IEE):     ${getType(e)}"
233                myprintln "     (JOSM):    ${getType(j)}"
234            }
235        }
236       
237        myprintln "*** Same URL, but different zoom bounds: ***"
238        for (def url : eiiUrls.keySet()) {
239            def e = eiiUrls.get(url)
240            if (!josmUrls.containsKey(url)) continue
241            def j = josmUrls.get(url)
242
243            Integer eMinZoom = getMinZoom(e)
244            Integer jMinZoom = getMinZoom(j)
245            if (eMinZoom != jMinZoom) {
246                myprintln "  minzoom differs: ${getDescription(j)}"
247                myprintln "     (IEE):     ${eMinZoom}"
248                myprintln "     (JOSM):    ${jMinZoom}"
249            }
250            Integer eMaxZoom = getMaxZoom(e)
251            Integer jMaxZoom = getMaxZoom(j)
252            if (eMaxZoom != jMaxZoom) {
253                myprintln "  maxzoom differs: ${getDescription(j)}"
254                myprintln "     (IEE):     ${eMaxZoom}"
255                myprintln "     (JOSM):    ${jMaxZoom}"
256            }
257        }
258       
259        myprintln "*** Same URL, but different country code: ***"
260        for (def url : eiiUrls.keySet()) {
261            def e = eiiUrls.get(url)
262            if (!josmUrls.containsKey(url)) continue
263            def j = josmUrls.get(url)
264            if (!getCountryCode(e).equals(getCountryCode(j))) {
265                myprintln "  country code differs: ${getDescription(j)}"
266                myprintln "     (IEE):     ${getCountryCode(e)}"
267                myprintln "     (JOSM):    ${getCountryCode(j)}"
268            }
269        }
270        myprintln "*** Same URL, but different quality: ***"
271        for (def url : eiiUrls.keySet()) {
272            def e = eiiUrls.get(url)
273            if (!josmUrls.containsKey(url)) {
274              def q = getQuality(e)
275              if("best".equals(q)) {
276                myprintln "  quality best entry not in JOSM for ${getDescription(e)}"
277              }
278              continue
279            }
280            def j = josmUrls.get(url)
281            if (!getQuality(e).equals(getQuality(j))) {
282                myprintln "  quality differs: ${getDescription(j)}"
283                myprintln "     (IEE):     ${getQuality(e)}"
284                myprintln "     (JOSM):    ${getQuality(j)}"
285            }
286        }
287    }
288   
289    /**
290     * Utility functions that allow uniform access for both ImageryInfo and JsonObject.
291     */
292    static String getUrl(Object e) {
293        if (e instanceof ImageryInfo) return e.url
294        return e.getString("url")
295    }
296    static String getName(Object e) {
297        if (e instanceof ImageryInfo) return e.name
298        return e.getString("name")
299    }
300    static String getType(Object e) {
301        if (e instanceof ImageryInfo) return e.getImageryType().getTypeString()
302        return e.getString("type")
303    }
304    static Integer getMinZoom(Object e) {
305        if (e instanceof ImageryInfo) {
306            int mz = e.getMinZoom()
307            return mz == 0 ? null : mz
308        } else {
309            def ext = e.getJsonObject("extent")
310            if (ext == null) return null
311            def num = ext.getJsonNumber("min_zoom")
312            if (num == null) return null
313            return num.intValue()
314        }
315    }
316    static Integer getMaxZoom(Object e) {
317        if (e instanceof ImageryInfo) {
318            int mz = e.getMaxZoom()
319            return mz == 0 ? null : mz
320        } else {
321            def ext = e.getJsonObject("extent")
322            if (ext == null) return null
323            def num = ext.getJsonNumber("max_zoom")
324            if (num == null) return null
325            return num.intValue()
326        }
327    }
328    static String getCountryCode(Object e) {
329        if (e instanceof ImageryInfo) return "".equals(e.getCountryCode()) ? null : e.getCountryCode()
330        return e.getString("country_code", null)
331    }
332    static String getQuality(Object e) {
333        //if (e instanceof ImageryInfo) return "".equals(e.getQuality()) ? null : e.getQuality()
334        if (e instanceof ImageryInfo) return null
335        return e.get("best") ? "best" : null
336    }
337    String getDescription(Object o) {
338        def url = getUrl(o)
339        def cc = getCountryCode(o)
340        if (cc == null) {
341            def j = josmUrls.get(url)
342            if (j != null) cc = getCountryCode(j)
343            if (cc == null) {
344                def e = eiiUrls.get(url)
345                if (e != null) cc = getCountryCode(e)
346            }
347        }
348        if (cc == null) {
349            cc = ''
350        } else {
351            cc = "[$cc] "
352        }
353        def d = cc + getName(o) + " - " + getUrl(o)
354        if (options.shorten) {
355            def MAXLEN = 140
356            if (d.length() > MAXLEN) d = d.substring(0, MAXLEN-1) + "..."
357        }
358        return d
359    }
360
361}
Note: See TracBrowser for help on using the repository browser.