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

Last change on this file since 9505 was 9505, checked in by stoecker, 8 years ago

see #12313 - improve groovy script for EII/JOSM difference checks, add checking for best parameter, add output suppression

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