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