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