1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | import static java.nio.charset.StandardCharsets.UTF_8;
|
---|
3 | import static org.apache.commons.lang3.StringUtils.isBlank;
|
---|
4 | import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
---|
5 |
|
---|
6 | import java.io.BufferedReader;
|
---|
7 | import java.io.BufferedWriter;
|
---|
8 | import java.io.IOException;
|
---|
9 | import java.io.OutputStreamWriter;
|
---|
10 | import java.io.Writer;
|
---|
11 | import java.lang.reflect.Field;
|
---|
12 | import java.net.MalformedURLException;
|
---|
13 | import java.net.URL;
|
---|
14 | import java.nio.charset.Charset;
|
---|
15 | import java.nio.file.Files;
|
---|
16 | import java.nio.file.Paths;
|
---|
17 | import java.text.DecimalFormat;
|
---|
18 | import java.text.ParseException;
|
---|
19 | import java.text.SimpleDateFormat;
|
---|
20 | import java.util.ArrayList;
|
---|
21 | import java.util.Arrays;
|
---|
22 | import java.util.Calendar;
|
---|
23 | import java.util.Collection;
|
---|
24 | import java.util.Collections;
|
---|
25 | import java.util.Date;
|
---|
26 | import java.util.HashMap;
|
---|
27 | import java.util.LinkedList;
|
---|
28 | import java.util.List;
|
---|
29 | import java.util.Locale;
|
---|
30 | import java.util.Map;
|
---|
31 | import java.util.Map.Entry;
|
---|
32 | import java.util.Objects;
|
---|
33 | import java.util.Set;
|
---|
34 | import java.util.function.BiConsumer;
|
---|
35 | import java.util.function.Function;
|
---|
36 | import java.util.regex.Matcher;
|
---|
37 | import java.util.regex.Pattern;
|
---|
38 | import java.util.stream.Collectors;
|
---|
39 |
|
---|
40 | import javax.json.Json;
|
---|
41 | import javax.json.JsonArray;
|
---|
42 | import javax.json.JsonNumber;
|
---|
43 | import javax.json.JsonObject;
|
---|
44 | import javax.json.JsonReader;
|
---|
45 | import javax.json.JsonString;
|
---|
46 | import javax.json.JsonValue;
|
---|
47 |
|
---|
48 | import org.openstreetmap.gui.jmapviewer.Coordinate;
|
---|
49 | import org.openstreetmap.josm.data.Preferences;
|
---|
50 | import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
---|
51 | import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds;
|
---|
52 | import org.openstreetmap.josm.data.imagery.Shape;
|
---|
53 | import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
|
---|
54 | import org.openstreetmap.josm.data.preferences.JosmUrls;
|
---|
55 | import org.openstreetmap.josm.data.projection.Projections;
|
---|
56 | import org.openstreetmap.josm.data.sources.SourceInfo;
|
---|
57 | import org.openstreetmap.josm.data.validation.routines.DomainValidator;
|
---|
58 | import org.openstreetmap.josm.io.imagery.ImageryReader;
|
---|
59 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
60 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
61 | import org.openstreetmap.josm.tools.JosmRuntimeException;
|
---|
62 | import org.openstreetmap.josm.tools.Logging;
|
---|
63 | import org.openstreetmap.josm.tools.OptionParser;
|
---|
64 | import org.openstreetmap.josm.tools.OptionParser.OptionCount;
|
---|
65 | import org.openstreetmap.josm.tools.ReflectionUtils;
|
---|
66 | import org.xml.sax.SAXException;
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Compare and analyse the differences of the editor layer index and the JOSM imagery list.
|
---|
70 | * The goal is to keep both lists in sync.
|
---|
71 | *
|
---|
72 | * The editor layer index project (https://github.com/osmlab/editor-layer-index)
|
---|
73 | * provides also a version in the JOSM format, but the GEOJSON is the original source
|
---|
74 | * format, so we read that.
|
---|
75 | *
|
---|
76 | * How to run:
|
---|
77 | * -----------
|
---|
78 | *
|
---|
79 | * Main JOSM binary needs to be in classpath, e.g.
|
---|
80 | *
|
---|
81 | * $ java -cp ../dist/josm-custom.jar SyncEditorLayerIndex
|
---|
82 | *
|
---|
83 | * Add option "-h" to show the available command line flags.
|
---|
84 | */
|
---|
85 | @SuppressWarnings("unchecked")
|
---|
86 | public class SyncEditorLayerIndex {
|
---|
87 |
|
---|
88 | private static final int MAXLEN = 140;
|
---|
89 |
|
---|
90 | private List<ImageryInfo> josmEntries;
|
---|
91 | private JsonArray eliEntries;
|
---|
92 |
|
---|
93 | private final Map<String, JsonObject> eliUrls = new HashMap<>();
|
---|
94 | private final Map<String, ImageryInfo> josmUrls = new HashMap<>();
|
---|
95 | private final Map<String, ImageryInfo> josmMirrors = new HashMap<>();
|
---|
96 | private static final Map<String, String> oldproj = new HashMap<>();
|
---|
97 | private static final List<String> ignoreproj = new LinkedList<>();
|
---|
98 |
|
---|
99 | private static String eliInputFile = "imagery_eli.geojson";
|
---|
100 | private static String josmInputFile = "imagery_josm.imagery.xml";
|
---|
101 | private static String ignoreInputFile = "imagery_josm.ignores.txt";
|
---|
102 | private static Writer outputStream;
|
---|
103 | private static String optionOutput;
|
---|
104 | private static boolean optionShorten;
|
---|
105 | private static boolean optionNoSkip;
|
---|
106 | private static boolean optionXhtmlBody;
|
---|
107 | private static boolean optionXhtml;
|
---|
108 | private static String optionEliXml;
|
---|
109 | private static String optionJosmXml;
|
---|
110 | private static String optionEncoding;
|
---|
111 | private static boolean optionNoEli;
|
---|
112 | private Map<String, String> skip = new HashMap<>();
|
---|
113 | private Map<String, String> skipStart = new HashMap<>();
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * Main method.
|
---|
117 | * @param args program arguments
|
---|
118 | * @throws IOException if any I/O error occurs
|
---|
119 | * @throws ReflectiveOperationException if any reflective operation error occurs
|
---|
120 | * @throws SAXException if any SAX error occurs
|
---|
121 | */
|
---|
122 | public static void main(String[] args) throws IOException, SAXException, ReflectiveOperationException {
|
---|
123 | Locale.setDefault(Locale.ROOT);
|
---|
124 | parseCommandLineArguments(args);
|
---|
125 | Config.setUrlsProvider(JosmUrls.getInstance());
|
---|
126 | Preferences pref = new Preferences(JosmBaseDirectories.getInstance());
|
---|
127 | Config.setPreferencesInstance(pref);
|
---|
128 | pref.init(false);
|
---|
129 | SyncEditorLayerIndex script = new SyncEditorLayerIndex();
|
---|
130 | script.setupProj();
|
---|
131 | script.loadSkip();
|
---|
132 | script.start();
|
---|
133 | script.loadJosmEntries();
|
---|
134 | if (optionJosmXml != null) {
|
---|
135 | try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(optionJosmXml), UTF_8)) {
|
---|
136 | script.printentries(script.josmEntries, writer);
|
---|
137 | }
|
---|
138 | }
|
---|
139 | script.loadELIEntries();
|
---|
140 | if (optionEliXml != null) {
|
---|
141 | try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(optionEliXml), UTF_8)) {
|
---|
142 | script.printentries(script.eliEntries, writer);
|
---|
143 | }
|
---|
144 | }
|
---|
145 | script.checkInOneButNotTheOther();
|
---|
146 | script.checkCommonEntries();
|
---|
147 | script.end();
|
---|
148 | if (outputStream != null) {
|
---|
149 | outputStream.close();
|
---|
150 | }
|
---|
151 | }
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * Displays help on the console
|
---|
155 | */
|
---|
156 | private static void showHelp() {
|
---|
157 | System.out.println(getHelp());
|
---|
158 | System.exit(0);
|
---|
159 | }
|
---|
160 |
|
---|
161 | static String getHelp() {
|
---|
162 | return "usage: java -cp build SyncEditorLayerIndex\n" +
|
---|
163 | "-c,--encoding <encoding> output encoding (defaults to UTF-8 or cp850 on Windows)\n" +
|
---|
164 | "-e,--eli_input <eli_input> Input file for the editor layer index (geojson). " +
|
---|
165 | "Default is imagery_eli.geojson (current directory).\n" +
|
---|
166 | "-h,--help show this help\n" +
|
---|
167 | "-i,--ignore_input <ignore_input> Input file for the ignore list. Default is imagery_josm.ignores.txt (current directory).\n" +
|
---|
168 | "-j,--josm_input <josm_input> Input file for the JOSM imagery list (xml). " +
|
---|
169 | "Default is imagery_josm.imagery.xml (current directory).\n" +
|
---|
170 | "-m,--noeli don't show output for ELI problems\n" +
|
---|
171 | "-n,--noskip don't skip known entries\n" +
|
---|
172 | "-o,--output <output> Output file, - prints to stdout (default: -)\n" +
|
---|
173 | "-p,--elixml <elixml> ELI entries for use in JOSM as XML file (incomplete)\n" +
|
---|
174 | "-q,--josmxml <josmxml> JOSM entries reoutput as XML file (incomplete)\n" +
|
---|
175 | "-s,--shorten shorten the output, so it is easier to read in a console window\n" +
|
---|
176 | "-x,--xhtmlbody create XHTML body for display in a web page\n" +
|
---|
177 | "-X,--xhtml create XHTML for display in a web page\n";
|
---|
178 | }
|
---|
179 |
|
---|
180 | /**
|
---|
181 | * Parse command line arguments.
|
---|
182 | * @param args program arguments
|
---|
183 | * @throws IOException in case of I/O error
|
---|
184 | */
|
---|
185 | static void parseCommandLineArguments(String[] args) throws IOException {
|
---|
186 | new OptionParser("JOSM/ELI synchronization script")
|
---|
187 | .addFlagParameter("help", SyncEditorLayerIndex::showHelp)
|
---|
188 | .addShortAlias("help", "h")
|
---|
189 | .addArgumentParameter("output", OptionCount.OPTIONAL, x -> optionOutput = x)
|
---|
190 | .addShortAlias("output", "o")
|
---|
191 | .addArgumentParameter("eli_input", OptionCount.OPTIONAL, x -> eliInputFile = x)
|
---|
192 | .addShortAlias("eli_input", "e")
|
---|
193 | .addArgumentParameter("josm_input", OptionCount.OPTIONAL, x -> josmInputFile = x)
|
---|
194 | .addShortAlias("josm_input", "j")
|
---|
195 | .addArgumentParameter("ignore_input", OptionCount.OPTIONAL, x -> ignoreInputFile = x)
|
---|
196 | .addShortAlias("ignore_input", "i")
|
---|
197 | .addFlagParameter("shorten", () -> optionShorten = true)
|
---|
198 | .addShortAlias("shorten", "s")
|
---|
199 | .addFlagParameter("noskip", () -> optionNoSkip = true)
|
---|
200 | .addShortAlias("noskip", "n")
|
---|
201 | .addFlagParameter("xhtmlbody", () -> optionXhtmlBody = true)
|
---|
202 | .addShortAlias("xhtmlbody", "x")
|
---|
203 | .addFlagParameter("xhtml", () -> optionXhtml = true)
|
---|
204 | .addShortAlias("xhtml", "X")
|
---|
205 | .addArgumentParameter("elixml", OptionCount.OPTIONAL, x -> optionEliXml = x)
|
---|
206 | .addShortAlias("elixml", "p")
|
---|
207 | .addArgumentParameter("josmxml", OptionCount.OPTIONAL, x -> optionJosmXml = x)
|
---|
208 | .addShortAlias("josmxml", "q")
|
---|
209 | .addFlagParameter("noeli", () -> optionNoEli = true)
|
---|
210 | .addShortAlias("noeli", "m")
|
---|
211 | .addArgumentParameter("encoding", OptionCount.OPTIONAL, x -> optionEncoding = x)
|
---|
212 | .addShortAlias("encoding", "c")
|
---|
213 | .parseOptionsOrExit(Arrays.asList(args));
|
---|
214 |
|
---|
215 | if (optionOutput != null && !"-".equals(optionOutput)) {
|
---|
216 | outputStream = Files.newBufferedWriter(Paths.get(optionOutput), optionEncoding != null ? Charset.forName(optionEncoding) : UTF_8);
|
---|
217 | } else if (optionEncoding != null) {
|
---|
218 | outputStream = new OutputStreamWriter(System.out, optionEncoding);
|
---|
219 | }
|
---|
220 | }
|
---|
221 |
|
---|
222 | void setupProj() {
|
---|
223 | oldproj.put("EPSG:3359", "EPSG:3404");
|
---|
224 | oldproj.put("EPSG:3785", "EPSG:3857");
|
---|
225 | oldproj.put("EPSG:31297", "EPGS:31287");
|
---|
226 | oldproj.put("EPSG:31464", "EPSG:31468");
|
---|
227 | oldproj.put("EPSG:54004", "EPSG:3857");
|
---|
228 | oldproj.put("EPSG:102100", "EPSG:3857");
|
---|
229 | oldproj.put("EPSG:102113", "EPSG:3857");
|
---|
230 | oldproj.put("EPSG:900913", "EPGS:3857");
|
---|
231 | ignoreproj.add("EPSG:4267");
|
---|
232 | ignoreproj.add("EPSG:5221");
|
---|
233 | ignoreproj.add("EPSG:5514");
|
---|
234 | ignoreproj.add("EPSG:32019");
|
---|
235 | ignoreproj.add("EPSG:102066");
|
---|
236 | ignoreproj.add("EPSG:102067");
|
---|
237 | ignoreproj.add("EPSG:102685");
|
---|
238 | ignoreproj.add("EPSG:102711");
|
---|
239 | }
|
---|
240 |
|
---|
241 | void loadSkip() throws IOException {
|
---|
242 | final Pattern pattern = Pattern.compile("^\\|\\| *(ELI|Ignore) *\\|\\| *\\{\\{\\{(.+)\\}\\}\\} *\\|\\|");
|
---|
243 | try (BufferedReader fr = Files.newBufferedReader(Paths.get(ignoreInputFile), UTF_8)) {
|
---|
244 | String line;
|
---|
245 |
|
---|
246 | while ((line = fr.readLine()) != null) {
|
---|
247 | Matcher res = pattern.matcher(line);
|
---|
248 | if (res.matches()) {
|
---|
249 | String s = res.group(2);
|
---|
250 | if (s.endsWith("...")) {
|
---|
251 | s = s.substring(0, s.length() - 3);
|
---|
252 | if ("Ignore".equals(res.group(1))) {
|
---|
253 | skipStart.put(s, "green");
|
---|
254 | } else {
|
---|
255 | skipStart.put(s, "darkgoldenrod");
|
---|
256 | }
|
---|
257 | } else {
|
---|
258 | if ("Ignore".equals(res.group(1))) {
|
---|
259 | skip.put(s, "green");
|
---|
260 | } else {
|
---|
261 | skip.put(s, "darkgoldenrod");
|
---|
262 | }
|
---|
263 | }
|
---|
264 | }
|
---|
265 | }
|
---|
266 | }
|
---|
267 | }
|
---|
268 |
|
---|
269 | void myprintlnfinal(String s) {
|
---|
270 | if (outputStream != null) {
|
---|
271 | try {
|
---|
272 | outputStream.write(s + System.getProperty("line.separator"));
|
---|
273 | } catch (IOException e) {
|
---|
274 | throw new JosmRuntimeException(e);
|
---|
275 | }
|
---|
276 | } else {
|
---|
277 | System.out.println(s);
|
---|
278 | }
|
---|
279 | }
|
---|
280 |
|
---|
281 | String isSkipString(String s) {
|
---|
282 | if (skip.containsKey(s))
|
---|
283 | return skip.get(s);
|
---|
284 | for (Entry<String, String> str : skipStart.entrySet()) {
|
---|
285 | if (s.startsWith(str.getKey())) {
|
---|
286 | skipStart.remove(str.getKey());
|
---|
287 | return str.getValue();
|
---|
288 | }
|
---|
289 | }
|
---|
290 | return null;
|
---|
291 | }
|
---|
292 |
|
---|
293 | void myprintln(String s) {
|
---|
294 | String color;
|
---|
295 | if ((color = isSkipString(s)) != null) {
|
---|
296 | skip.remove(s);
|
---|
297 | if (optionXhtmlBody || optionXhtml) {
|
---|
298 | s = "<pre style=\"margin:3px;color:"+color+"\">"
|
---|
299 | + s.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">")+"</pre>";
|
---|
300 | }
|
---|
301 | if (!optionNoSkip) {
|
---|
302 | return;
|
---|
303 | }
|
---|
304 | } else if (optionXhtmlBody || optionXhtml) {
|
---|
305 | color =
|
---|
306 | s.startsWith("***") ? "black" :
|
---|
307 | ((s.startsWith("+ ") || s.startsWith("+++ ELI")) ? "blue" :
|
---|
308 | (s.startsWith("#") ? "indigo" :
|
---|
309 | (s.startsWith("!") ? "orange" : "red")));
|
---|
310 | s = "<pre style=\"margin:3px;color:"+color+"\">"+s.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">")+"</pre>";
|
---|
311 | }
|
---|
312 | if ((s.startsWith("+ ") || s.startsWith("+++ ELI") || s.startsWith("#")) && optionNoEli) {
|
---|
313 | return;
|
---|
314 | }
|
---|
315 | myprintlnfinal(s);
|
---|
316 | }
|
---|
317 |
|
---|
318 | void start() {
|
---|
319 | if (optionXhtml) {
|
---|
320 | myprintlnfinal(
|
---|
321 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n");
|
---|
322 | myprintlnfinal(
|
---|
323 | "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>"+
|
---|
324 | "<title>JOSM - ELI differences</title></head><body>\n");
|
---|
325 | }
|
---|
326 | }
|
---|
327 |
|
---|
328 | void end() {
|
---|
329 | for (String s : skip.keySet()) {
|
---|
330 | myprintln("+++ Obsolete skip entry: " + s);
|
---|
331 | }
|
---|
332 | for (String s : skipStart.keySet()) {
|
---|
333 | myprintln("+++ Obsolete skip entry: " + s + "...");
|
---|
334 | }
|
---|
335 | if (optionXhtml) {
|
---|
336 | myprintlnfinal("</body></html>\n");
|
---|
337 | }
|
---|
338 | }
|
---|
339 |
|
---|
340 | void loadELIEntries() throws IOException {
|
---|
341 | try (JsonReader jr = Json.createReader(Files.newBufferedReader(Paths.get(eliInputFile), UTF_8))) {
|
---|
342 | eliEntries = jr.readObject().getJsonArray("features");
|
---|
343 | }
|
---|
344 |
|
---|
345 | for (JsonValue e : eliEntries) {
|
---|
346 | String url = getUrlStripped(e);
|
---|
347 | if (url.contains("{z}")) {
|
---|
348 | myprintln("+++ ELI-URL uses {z} instead of {zoom}: "+getDescription(e));
|
---|
349 | url = url.replace("{z}", "{zoom}");
|
---|
350 | }
|
---|
351 | if (eliUrls.containsKey(url)) {
|
---|
352 | myprintln("+++ ELI-URL is not unique: "+url);
|
---|
353 | } else {
|
---|
354 | eliUrls.put(url, e.asJsonObject());
|
---|
355 | }
|
---|
356 | JsonArray s = e.asJsonObject().get("properties").asJsonObject().getJsonArray("available_projections");
|
---|
357 | if (s != null) {
|
---|
358 | String urlLc = url.toLowerCase(Locale.ENGLISH);
|
---|
359 | List<String> old = new LinkedList<>();
|
---|
360 | for (JsonValue p : s) {
|
---|
361 | String proj = ((JsonString) p).getString();
|
---|
362 | if (oldproj.containsKey(proj) || ("CRS:84".equals(proj) && !urlLc.contains("version=1.3"))) {
|
---|
363 | old.add(proj);
|
---|
364 | }
|
---|
365 | }
|
---|
366 | if (!old.isEmpty()) {
|
---|
367 | myprintln("+ ELI Projections "+String.join(", ", old)+" not useful: "+getDescription(e));
|
---|
368 | }
|
---|
369 | }
|
---|
370 | }
|
---|
371 | myprintln("*** Loaded "+eliEntries.size()+" entries (ELI). ***");
|
---|
372 | }
|
---|
373 |
|
---|
374 | String cdata(String s) {
|
---|
375 | return cdata(s, false);
|
---|
376 | }
|
---|
377 |
|
---|
378 | String cdata(String s, boolean escape) {
|
---|
379 | if (escape) {
|
---|
380 | return s.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
---|
381 | } else if (s.matches(".*[<>&].*"))
|
---|
382 | return "<![CDATA["+s+"]]>";
|
---|
383 | return s;
|
---|
384 | }
|
---|
385 |
|
---|
386 | String maininfo(Object entry, String offset) {
|
---|
387 | String t = getType(entry);
|
---|
388 | String res = offset + "<type>"+t+"</type>\n";
|
---|
389 | res += offset + "<url>"+cdata(getUrl(entry))+"</url>\n";
|
---|
390 | if (getMinZoom(entry) != null)
|
---|
391 | res += offset + "<min-zoom>"+getMinZoom(entry)+"</min-zoom>\n";
|
---|
392 | if (getMaxZoom(entry) != null)
|
---|
393 | res += offset + "<max-zoom>"+getMaxZoom(entry)+"</max-zoom>\n";
|
---|
394 | if ("wms".equals(t)) {
|
---|
395 | List<String> p = getProjections(entry);
|
---|
396 | if (p != null) {
|
---|
397 | res += offset + "<projections>\n";
|
---|
398 | for (String c : p) {
|
---|
399 | res += offset + " <code>"+c+"</code>\n";
|
---|
400 | }
|
---|
401 | res += offset + "</projections>\n";
|
---|
402 | }
|
---|
403 | }
|
---|
404 | return res;
|
---|
405 | }
|
---|
406 |
|
---|
407 | void printentries(List<?> entries, Writer stream) throws IOException {
|
---|
408 | DecimalFormat df = new DecimalFormat("#.#######");
|
---|
409 | df.setRoundingMode(java.math.RoundingMode.CEILING);
|
---|
410 | stream.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
|
---|
411 | stream.write("<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n");
|
---|
412 | for (Object e : entries) {
|
---|
413 | stream.write(" <entry"
|
---|
414 | + ("eli-best".equals(getQuality(e)) ? " eli-best=\"true\"" : "")
|
---|
415 | + (getOverlay(e) ? " overlay=\"true\"" : "")
|
---|
416 | + ">\n");
|
---|
417 | String t;
|
---|
418 | if (isNotBlank(t = getName(e)))
|
---|
419 | stream.write(" <name>"+cdata(t, true)+"</name>\n");
|
---|
420 | if (isNotBlank(t = getId(e)))
|
---|
421 | stream.write(" <id>"+t+"</id>\n");
|
---|
422 | if (isNotBlank(t = getCategory(e)))
|
---|
423 | stream.write(" <category>"+t+"</category>\n");
|
---|
424 | if (isNotBlank(t = getDate(e)))
|
---|
425 | stream.write(" <date>"+t+"</date>\n");
|
---|
426 | if (isNotBlank(t = getCountryCode(e)))
|
---|
427 | stream.write(" <country-code>"+t+"</country-code>\n");
|
---|
428 | if ((getDefault(e)))
|
---|
429 | stream.write(" <default>true</default>\n");
|
---|
430 | stream.write(maininfo(e, " "));
|
---|
431 | if (isNotBlank(t = getAttributionText(e)))
|
---|
432 | stream.write(" <attribution-text mandatory=\"true\">"+cdata(t, true)+"</attribution-text>\n");
|
---|
433 | if (isNotBlank(t = getAttributionUrl(e)))
|
---|
434 | stream.write(" <attribution-url>"+cdata(t)+"</attribution-url>\n");
|
---|
435 | if (isNotBlank(t = getLogoImage(e)))
|
---|
436 | stream.write(" <logo-image>"+cdata(t, true)+"</logo-image>\n");
|
---|
437 | if (isNotBlank(t = getLogoUrl(e)))
|
---|
438 | stream.write(" <logo-url>"+cdata(t)+"</logo-url>\n");
|
---|
439 | if (isNotBlank(t = getTermsOfUseText(e)))
|
---|
440 | stream.write(" <terms-of-use-text>"+cdata(t, true)+"</terms-of-use-text>\n");
|
---|
441 | if (isNotBlank(t = getTermsOfUseUrl(e)))
|
---|
442 | stream.write(" <terms-of-use-url>"+cdata(t)+"</terms-of-use-url>\n");
|
---|
443 | if (isNotBlank(t = getPermissionReferenceUrl(e)))
|
---|
444 | stream.write(" <permission-ref>"+cdata(t)+"</permission-ref>\n");
|
---|
445 | if (isNotBlank(t = getPrivacyPolicyUrl(e)))
|
---|
446 | stream.write(" <privacy-policy-url>"+cdata(t)+"</privacy-policy-url>\n");
|
---|
447 | if ((getValidGeoreference(e)))
|
---|
448 | stream.write(" <valid-georeference>true</valid-georeference>\n");
|
---|
449 | if (isNotBlank(t = getIcon(e)))
|
---|
450 | stream.write(" <icon>"+cdata(t)+"</icon>\n");
|
---|
451 | for (Entry<String, String> d : getDescriptions(e).entrySet()) {
|
---|
452 | stream.write(" <description lang=\""+d.getKey()+"\">"+d.getValue()+"</description>\n");
|
---|
453 | }
|
---|
454 | for (ImageryInfo m : getMirrors(e)) {
|
---|
455 | stream.write(" <mirror>\n"+maininfo(m, " ")+" </mirror>\n");
|
---|
456 | }
|
---|
457 | double minlat = 1000;
|
---|
458 | double minlon = 1000;
|
---|
459 | double maxlat = -1000;
|
---|
460 | double maxlon = -1000;
|
---|
461 | String shapes = "";
|
---|
462 | String sep = "\n ";
|
---|
463 | try {
|
---|
464 | for (Shape s: getShapes(e)) {
|
---|
465 | shapes += " <shape>";
|
---|
466 | int i = 0;
|
---|
467 | for (Coordinate p: s.getPoints()) {
|
---|
468 | double lat = p.getLat();
|
---|
469 | double lon = p.getLon();
|
---|
470 | if (lat > maxlat) maxlat = lat;
|
---|
471 | if (lon > maxlon) maxlon = lon;
|
---|
472 | if (lat < minlat) minlat = lat;
|
---|
473 | if (lon < minlon) minlon = lon;
|
---|
474 | if ((i++ % 3) == 0) {
|
---|
475 | shapes += sep + " ";
|
---|
476 | }
|
---|
477 | shapes += "<point lat='"+df.format(lat)+"' lon='"+df.format(lon)+"'/>";
|
---|
478 | }
|
---|
479 | shapes += sep + "</shape>\n";
|
---|
480 | }
|
---|
481 | } catch (IllegalArgumentException ignored) {
|
---|
482 | Logging.trace(ignored);
|
---|
483 | }
|
---|
484 | if (!shapes.isEmpty()) {
|
---|
485 | stream.write(" <bounds min-lat='"+df.format(minlat)
|
---|
486 | +"' min-lon='"+df.format(minlon)
|
---|
487 | +"' max-lat='"+df.format(maxlat)
|
---|
488 | +"' max-lon='"+df.format(maxlon)+"'>\n");
|
---|
489 | stream.write(shapes + " </bounds>\n");
|
---|
490 | }
|
---|
491 | stream.write(" </entry>\n");
|
---|
492 | }
|
---|
493 | stream.write("</imagery>\n");
|
---|
494 | stream.close();
|
---|
495 | }
|
---|
496 |
|
---|
497 | void loadJosmEntries() throws IOException, SAXException, ReflectiveOperationException {
|
---|
498 | try (ImageryReader reader = new ImageryReader(josmInputFile)) {
|
---|
499 | josmEntries = reader.parse();
|
---|
500 | }
|
---|
501 |
|
---|
502 | for (ImageryInfo e : josmEntries) {
|
---|
503 | if (isBlank(getUrl(e))) {
|
---|
504 | myprintln("+++ JOSM-Entry without URL: " + getDescription(e));
|
---|
505 | continue;
|
---|
506 | }
|
---|
507 | if (isBlank(e.getDate()) && e.getDate() != null) {
|
---|
508 | myprintln("+++ JOSM-Entry with empty Date: " + getDescription(e));
|
---|
509 | continue;
|
---|
510 | }
|
---|
511 | if (isBlank(getName(e))) {
|
---|
512 | myprintln("+++ JOSM-Entry without Name: " + getDescription(e));
|
---|
513 | continue;
|
---|
514 | }
|
---|
515 | String url = getUrlStripped(e);
|
---|
516 | if (url.contains("{z}")) {
|
---|
517 | myprintln("+++ JOSM-URL uses {z} instead of {zoom}: "+getDescription(e));
|
---|
518 | url = url.replace("{z}", "{zoom}");
|
---|
519 | }
|
---|
520 | if (josmUrls.containsKey(url)) {
|
---|
521 | myprintln("+++ JOSM-URL is not unique: "+url);
|
---|
522 | } else {
|
---|
523 | josmUrls.put(url, e);
|
---|
524 | }
|
---|
525 | for (ImageryInfo m : e.getMirrors()) {
|
---|
526 | url = getUrlStripped(m);
|
---|
527 | Field origNameField = SourceInfo.class.getDeclaredField("origName");
|
---|
528 | ReflectionUtils.setObjectsAccessible(origNameField);
|
---|
529 | origNameField.set(m, m.getOriginalName().replaceAll(" mirror server( \\d+)?", ""));
|
---|
530 | if (josmUrls.containsKey(url)) {
|
---|
531 | myprintln("+++ JOSM-Mirror-URL is not unique: "+url);
|
---|
532 | } else {
|
---|
533 | josmUrls.put(url, m);
|
---|
534 | josmMirrors.put(url, m);
|
---|
535 | }
|
---|
536 | }
|
---|
537 | }
|
---|
538 | myprintln("*** Loaded "+josmEntries.size()+" entries (JOSM). ***");
|
---|
539 | }
|
---|
540 |
|
---|
541 | // catch reordered arguments, make them uppercase, and switches to WMS version 1.3.0
|
---|
542 | String unifyWMS(String url) {
|
---|
543 | String[] x = url.replaceAll("(?i)VERSION=[0-9.]+", "VERSION=x")
|
---|
544 | .replaceAll("(?i)SRS=", "CRS=")
|
---|
545 | .replaceAll("(?i)BBOX=", "BBOX=")
|
---|
546 | .replaceAll("(?i)FORMAT=", "FORMAT=")
|
---|
547 | .replaceAll("(?i)LAYERS=", "LAYERS=")
|
---|
548 | .replaceAll("(?i)MAP=", "MAP=")
|
---|
549 | .replaceAll("(?i)REQUEST=", "REQUEST=")
|
---|
550 | .replaceAll("(?i)SERVICE=", "SERVICE=")
|
---|
551 | .replaceAll("(?i)STYLES=", "STYLES=")
|
---|
552 | .replaceAll("(?i)TRANSPARENT=FALSE", "TRANSPARENT=FALSE")
|
---|
553 | .replaceAll("(?i)TRANSPARENT=TRUE", "TRANSPARENT=TRUE")
|
---|
554 | .replaceAll("(?i)WIDTH=", "WIDTH=")
|
---|
555 | .replaceAll("(?i)HEIGHT=", "HEIGHT=")
|
---|
556 | .split("\\?");
|
---|
557 | return x[0] +"?" + Arrays.stream(x[1].split("&"))
|
---|
558 | .filter(s -> !s.endsWith("=")) // filter empty params
|
---|
559 | .sorted()
|
---|
560 | .collect(Collectors.joining("&"));
|
---|
561 | }
|
---|
562 |
|
---|
563 | void checkInOneButNotTheOther() {
|
---|
564 | List<String> le = new LinkedList<>(eliUrls.keySet());
|
---|
565 | List<String> lj = new LinkedList<>(josmUrls.keySet());
|
---|
566 |
|
---|
567 | for (String url : new LinkedList<>(le)) {
|
---|
568 | if (lj.contains(url)) {
|
---|
569 | le.remove(url);
|
---|
570 | lj.remove(url);
|
---|
571 | }
|
---|
572 | }
|
---|
573 |
|
---|
574 | if (!le.isEmpty() && !lj.isEmpty()) {
|
---|
575 | List<String> ke = new LinkedList<>(le);
|
---|
576 | for (String urle : ke) {
|
---|
577 | JsonObject e = eliUrls.get(urle);
|
---|
578 | String ide = getId(e);
|
---|
579 | String urlhttps = urle.replace("http:", "https:");
|
---|
580 | if (lj.contains(urlhttps)) {
|
---|
581 | myprintln("+ Missing https: "+getDescription(e));
|
---|
582 | eliUrls.put(urlhttps, eliUrls.get(urle));
|
---|
583 | eliUrls.remove(urle);
|
---|
584 | le.remove(urle);
|
---|
585 | lj.remove(urlhttps);
|
---|
586 | } else if (isNotBlank(ide)) {
|
---|
587 | checkUrlsEquality(ide, e, urle, le, lj);
|
---|
588 | }
|
---|
589 | }
|
---|
590 | }
|
---|
591 |
|
---|
592 | myprintln("*** URLs found in ELI but not in JOSM ("+le.size()+"): ***");
|
---|
593 | Collections.sort(le);
|
---|
594 | if (!le.isEmpty()) {
|
---|
595 | for (String l : le) {
|
---|
596 | myprintln("- " + getDescription(eliUrls.get(l)));
|
---|
597 | }
|
---|
598 | }
|
---|
599 | myprintln("*** URLs found in JOSM but not in ELI ("+lj.size()+"): ***");
|
---|
600 | Collections.sort(lj);
|
---|
601 | if (!lj.isEmpty()) {
|
---|
602 | for (String l : lj) {
|
---|
603 | myprintln("+ " + getDescription(josmUrls.get(l)));
|
---|
604 | }
|
---|
605 | }
|
---|
606 | }
|
---|
607 |
|
---|
608 | void checkUrlsEquality(String ide, JsonObject e, String urle, List<String> le, List<String> lj) {
|
---|
609 | for (String urlj : new LinkedList<>(lj)) {
|
---|
610 | ImageryInfo j = josmUrls.get(urlj);
|
---|
611 | String idj = getId(j);
|
---|
612 |
|
---|
613 | if (checkUrlEquality(ide, "id", idj, e, j, urle, urlj, le, lj)) {
|
---|
614 | return;
|
---|
615 | }
|
---|
616 | Collection<String> old = j.getOldIds();
|
---|
617 | if (old != null) {
|
---|
618 | for (String oidj : old) {
|
---|
619 | if (checkUrlEquality(ide, "oldid", oidj, e, j, urle, urlj, le, lj)) {
|
---|
620 | return;
|
---|
621 | }
|
---|
622 | }
|
---|
623 | }
|
---|
624 | }
|
---|
625 | }
|
---|
626 |
|
---|
627 | boolean checkUrlEquality(
|
---|
628 | String ide, String idtype, String idj, JsonObject e, ImageryInfo j, String urle, String urlj, List<String> le, List<String> lj) {
|
---|
629 | if (ide.equals(idj) && Objects.equals(getType(j), getType(e))) {
|
---|
630 | if (getType(j).equals("wms") && unifyWMS(urle).equals(unifyWMS(urlj))) {
|
---|
631 | myprintln("# WMS-URL for "+idtype+" "+idj+" modified: "+getDescription(j));
|
---|
632 | } else {
|
---|
633 | myprintln("* URL for "+idtype+" "+idj+" differs ("+urle+"): "+getDescription(j));
|
---|
634 | }
|
---|
635 | le.remove(urle);
|
---|
636 | lj.remove(urlj);
|
---|
637 | // replace key for this entry with JOSM URL
|
---|
638 | eliUrls.remove(urle);
|
---|
639 | eliUrls.put(urlj, e);
|
---|
640 | return true;
|
---|
641 | }
|
---|
642 | return false;
|
---|
643 | }
|
---|
644 |
|
---|
645 | void checkCommonEntries() {
|
---|
646 | doSameUrlButDifferentName();
|
---|
647 | doSameUrlButDifferentId();
|
---|
648 | doSameUrlButDifferentType();
|
---|
649 | doSameUrlButDifferentZoomBounds();
|
---|
650 | doSameUrlButDifferentCountryCode();
|
---|
651 | doSameUrlButDifferentQuality();
|
---|
652 | doSameUrlButDifferentDates();
|
---|
653 | doSameUrlButDifferentInformation();
|
---|
654 | doMismatchingShapes();
|
---|
655 | doMismatchingIcons();
|
---|
656 | doMismatchingCategories();
|
---|
657 | doMiscellaneousChecks();
|
---|
658 | }
|
---|
659 |
|
---|
660 | void doSameUrlButDifferentName() {
|
---|
661 | myprintln("*** Same URL, but different name: ***");
|
---|
662 | for (String url : eliUrls.keySet()) {
|
---|
663 | JsonObject e = eliUrls.get(url);
|
---|
664 | if (!josmUrls.containsKey(url)) continue;
|
---|
665 | ImageryInfo j = josmUrls.get(url);
|
---|
666 | String ename = getName(e).replace("'", "\u2019");
|
---|
667 | String jname = getName(j).replace("'", "\u2019");
|
---|
668 | if (!ename.equals(jname)) {
|
---|
669 | myprintln("* Name differs ('"+getName(e)+"' != '"+getName(j)+"'): "+getUrl(j));
|
---|
670 | }
|
---|
671 | }
|
---|
672 | }
|
---|
673 |
|
---|
674 | void doSameUrlButDifferentId() {
|
---|
675 | myprintln("*** Same URL, but different Id: ***");
|
---|
676 | for (String url : eliUrls.keySet()) {
|
---|
677 | JsonObject e = eliUrls.get(url);
|
---|
678 | if (!josmUrls.containsKey(url)) continue;
|
---|
679 | ImageryInfo j = josmUrls.get(url);
|
---|
680 | String ename = getId(e);
|
---|
681 | String jname = getId(j);
|
---|
682 | if (!Objects.equals(ename, jname)) {
|
---|
683 | myprintln("# Id differs ('"+getId(e)+"' != '"+getId(j)+"'): "+getUrl(j));
|
---|
684 | }
|
---|
685 | }
|
---|
686 | }
|
---|
687 |
|
---|
688 | void doSameUrlButDifferentType() {
|
---|
689 | myprintln("*** Same URL, but different type: ***");
|
---|
690 | for (String url : eliUrls.keySet()) {
|
---|
691 | JsonObject e = eliUrls.get(url);
|
---|
692 | if (!josmUrls.containsKey(url)) continue;
|
---|
693 | ImageryInfo j = josmUrls.get(url);
|
---|
694 | if (!Objects.equals(getType(e), getType(j))) {
|
---|
695 | myprintln("* Type differs ("+getType(e)+" != "+getType(j)+"): "+getName(j)+" - "+getUrl(j));
|
---|
696 | }
|
---|
697 | }
|
---|
698 | }
|
---|
699 |
|
---|
700 | void doSameUrlButDifferentZoomBounds() {
|
---|
701 | myprintln("*** Same URL, but different zoom bounds: ***");
|
---|
702 | for (String url : eliUrls.keySet()) {
|
---|
703 | JsonObject e = eliUrls.get(url);
|
---|
704 | if (!josmUrls.containsKey(url)) continue;
|
---|
705 | ImageryInfo j = josmUrls.get(url);
|
---|
706 |
|
---|
707 | Integer eMinZoom = getMinZoom(e);
|
---|
708 | Integer jMinZoom = getMinZoom(j);
|
---|
709 | /* dont warn for entries copied from the base of the mirror */
|
---|
710 | if (eMinZoom == null && "wms".equals(getType(j)) && j.getName().contains(" mirror"))
|
---|
711 | jMinZoom = null;
|
---|
712 | if (!Objects.equals(eMinZoom, jMinZoom) && !(Objects.equals(eMinZoom, 0) && jMinZoom == null)) {
|
---|
713 | myprintln("* Minzoom differs ("+eMinZoom+" != "+jMinZoom+"): "+getDescription(j));
|
---|
714 | }
|
---|
715 | Integer eMaxZoom = getMaxZoom(e);
|
---|
716 | Integer jMaxZoom = getMaxZoom(j);
|
---|
717 | /* dont warn for entries copied from the base of the mirror */
|
---|
718 | if (eMaxZoom == null && "wms".equals(getType(j)) && j.getName().contains(" mirror"))
|
---|
719 | jMaxZoom = null;
|
---|
720 | if (!Objects.equals(eMaxZoom, jMaxZoom)) {
|
---|
721 | myprintln("* Maxzoom differs ("+eMaxZoom+" != "+jMaxZoom+"): "+getDescription(j));
|
---|
722 | }
|
---|
723 | }
|
---|
724 | }
|
---|
725 |
|
---|
726 | void doSameUrlButDifferentCountryCode() {
|
---|
727 | myprintln("*** Same URL, but different country code: ***");
|
---|
728 | for (String url : eliUrls.keySet()) {
|
---|
729 | JsonObject e = eliUrls.get(url);
|
---|
730 | if (!josmUrls.containsKey(url)) continue;
|
---|
731 | ImageryInfo j = josmUrls.get(url);
|
---|
732 | String cce = getCountryCode(e);
|
---|
733 | if ("ZZ".equals(cce)) { /* special ELI country code */
|
---|
734 | cce = null;
|
---|
735 | }
|
---|
736 | if (cce != null && !cce.equals(getCountryCode(j))) {
|
---|
737 | myprintln("* Country code differs ("+getCountryCode(e)+" != "+getCountryCode(j)+"): "+getDescription(j));
|
---|
738 | }
|
---|
739 | }
|
---|
740 | }
|
---|
741 |
|
---|
742 | void doSameUrlButDifferentQuality() {
|
---|
743 | myprintln("*** Same URL, but different quality: ***");
|
---|
744 | for (String url : eliUrls.keySet()) {
|
---|
745 | JsonObject e = eliUrls.get(url);
|
---|
746 | if (!josmUrls.containsKey(url)) {
|
---|
747 | String q = getQuality(e);
|
---|
748 | if ("eli-best".equals(q)) {
|
---|
749 | myprintln("- Quality best entry not in JOSM for "+getDescription(e));
|
---|
750 | }
|
---|
751 | continue;
|
---|
752 | }
|
---|
753 | ImageryInfo j = josmUrls.get(url);
|
---|
754 | if (!Objects.equals(getQuality(e), getQuality(j))) {
|
---|
755 | myprintln("* Quality differs ("+getQuality(e)+" != "+getQuality(j)+"): "+getDescription(j));
|
---|
756 | }
|
---|
757 | }
|
---|
758 | }
|
---|
759 |
|
---|
760 | void doSameUrlButDifferentDates() {
|
---|
761 | myprintln("*** Same URL, but different dates: ***");
|
---|
762 | Pattern pattern = Pattern.compile("^(.*;)(\\d\\d\\d\\d)(-(\\d\\d)(-(\\d\\d))?)?$");
|
---|
763 | for (String url : eliUrls.keySet()) {
|
---|
764 | String ed = getDate(eliUrls.get(url));
|
---|
765 | if (!josmUrls.containsKey(url)) continue;
|
---|
766 | ImageryInfo j = josmUrls.get(url);
|
---|
767 | String jd = getDate(j);
|
---|
768 | // The forms 2015;- or -;2015 or 2015;2015 are handled equal to 2015
|
---|
769 | String ef = ed.replaceAll("\\A-;", "").replaceAll(";-\\z", "").replaceAll("\\A([0-9-]+);\\1\\z", "$1");
|
---|
770 | // ELI has a strange and inconsistent used end_date definition, so we try again with subtraction by one
|
---|
771 | String ed2 = ed;
|
---|
772 | Matcher m = pattern.matcher(ed);
|
---|
773 | if (m.matches()) {
|
---|
774 | Calendar cal = Calendar.getInstance();
|
---|
775 | cal.set(Integer.valueOf(m.group(2)),
|
---|
776 | m.group(4) == null ? 0 : Integer.valueOf(m.group(4))-1,
|
---|
777 | m.group(6) == null ? 1 : Integer.valueOf(m.group(6)));
|
---|
778 | cal.add(Calendar.DAY_OF_MONTH, -1);
|
---|
779 | ed2 = m.group(1) + cal.get(Calendar.YEAR);
|
---|
780 | if (m.group(4) != null)
|
---|
781 | ed2 += "-" + String.format("%02d", cal.get(Calendar.MONTH)+1);
|
---|
782 | if (m.group(6) != null)
|
---|
783 | ed2 += "-" + String.format("%02d", cal.get(Calendar.DAY_OF_MONTH));
|
---|
784 | }
|
---|
785 | String ef2 = ed2.replaceAll("\\A-;", "").replaceAll(";-\\z", "").replaceAll("\\A([0-9-]+);\\1\\z", "$1");
|
---|
786 | if (!ed.equals(jd) && !ef.equals(jd) && !ed2.equals(jd) && !ef2.equals(jd)) {
|
---|
787 | String t = "'"+ed+"'";
|
---|
788 | if (!ed.equals(ef)) {
|
---|
789 | t += " or '"+ef+"'";
|
---|
790 | }
|
---|
791 | if (jd.isEmpty()) {
|
---|
792 | myprintln("- Missing JOSM date ("+t+"): "+getDescription(j));
|
---|
793 | } else if (!ed.isEmpty()) {
|
---|
794 | myprintln("* Date differs ('"+t+"' != '"+jd+"'): "+getDescription(j));
|
---|
795 | } else if (!optionNoEli) {
|
---|
796 | myprintln("+ Missing ELI date ('"+jd+"'): "+getDescription(j));
|
---|
797 | }
|
---|
798 | }
|
---|
799 | }
|
---|
800 | }
|
---|
801 |
|
---|
802 | void doSameUrlButDifferentInformation() {
|
---|
803 | myprintln("*** Same URL, but different information: ***");
|
---|
804 | for (String url : eliUrls.keySet()) {
|
---|
805 | if (!josmUrls.containsKey(url)) continue;
|
---|
806 | JsonObject e = eliUrls.get(url);
|
---|
807 | ImageryInfo j = josmUrls.get(url);
|
---|
808 |
|
---|
809 | compareDescriptions(e, j);
|
---|
810 | comparePrivacyPolicyUrls(e, j);
|
---|
811 | comparePermissionReferenceUrls(e, j);
|
---|
812 | compareAttributionUrls(e, j);
|
---|
813 | compareAttributionTexts(e, j);
|
---|
814 | compareProjections(e, j);
|
---|
815 | compareDefaults(e, j);
|
---|
816 | compareOverlays(e, j);
|
---|
817 | compareNoTileHeaders(e, j);
|
---|
818 | }
|
---|
819 | }
|
---|
820 |
|
---|
821 | void compareDescriptions(JsonObject e, ImageryInfo j) {
|
---|
822 | String et = getDescriptions(e).getOrDefault("en", "");
|
---|
823 | String jt = getDescriptions(j).getOrDefault("en", "");
|
---|
824 | if (!et.equals(jt)) {
|
---|
825 | if (jt.isEmpty()) {
|
---|
826 | myprintln("- Missing JOSM description ("+et+"): "+getDescription(j));
|
---|
827 | } else if (!et.isEmpty()) {
|
---|
828 | myprintln("* Description differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
|
---|
829 | } else if (!optionNoEli) {
|
---|
830 | myprintln("+ Missing ELI description ('"+jt+"'): "+getDescription(j));
|
---|
831 | }
|
---|
832 | }
|
---|
833 | }
|
---|
834 |
|
---|
835 | void comparePrivacyPolicyUrls(JsonObject e, ImageryInfo j) {
|
---|
836 | String et = getPrivacyPolicyUrl(e);
|
---|
837 | String jt = getPrivacyPolicyUrl(j);
|
---|
838 | if (!Objects.equals(et, jt)) {
|
---|
839 | if (isBlank(jt)) {
|
---|
840 | myprintln("- Missing JOSM privacy policy URL ("+et+"): "+getDescription(j));
|
---|
841 | } else if (isNotBlank(et)) {
|
---|
842 | myprintln("* Privacy policy URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
|
---|
843 | } else if (!optionNoEli) {
|
---|
844 | myprintln("+ Missing ELI privacy policy URL ('"+jt+"'): "+getDescription(j));
|
---|
845 | }
|
---|
846 | }
|
---|
847 | }
|
---|
848 |
|
---|
849 | void comparePermissionReferenceUrls(JsonObject e, ImageryInfo j) {
|
---|
850 | String et = getPermissionReferenceUrl(e);
|
---|
851 | String jt = getPermissionReferenceUrl(j);
|
---|
852 | String jt2 = getTermsOfUseUrl(j);
|
---|
853 | if (isBlank(jt)) jt = jt2;
|
---|
854 | if (!Objects.equals(et, jt)) {
|
---|
855 | if (isBlank(jt)) {
|
---|
856 | myprintln("- Missing JOSM license URL ("+et+"): "+getDescription(j));
|
---|
857 | } else if (isNotBlank(et)) {
|
---|
858 | String ethttps = et.replace("http:", "https:");
|
---|
859 | if (isBlank(jt2) || !(jt2.equals(ethttps) || jt2.equals(et+"/") || jt2.equals(ethttps+"/"))) {
|
---|
860 | if (jt.equals(ethttps) || jt.equals(et+"/") || jt.equals(ethttps+"/")) {
|
---|
861 | myprintln("+ License URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
|
---|
862 | } else {
|
---|
863 | String ja = getAttributionUrl(j);
|
---|
864 | if (ja != null && (ja.equals(et) || ja.equals(ethttps) || ja.equals(et+"/") || ja.equals(ethttps+"/"))) {
|
---|
865 | myprintln("+ ELI License URL in JOSM Attribution: "+getDescription(j));
|
---|
866 | } else {
|
---|
867 | myprintln("* License URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
|
---|
868 | }
|
---|
869 | }
|
---|
870 | }
|
---|
871 | } else if (!optionNoEli) {
|
---|
872 | myprintln("+ Missing ELI license URL ('"+jt+"'): "+getDescription(j));
|
---|
873 | }
|
---|
874 | }
|
---|
875 | }
|
---|
876 |
|
---|
877 | void compareAttributionUrls(JsonObject e, ImageryInfo j) {
|
---|
878 | String et = getAttributionUrl(e);
|
---|
879 | String jt = getAttributionUrl(j);
|
---|
880 | if (!Objects.equals(et, jt)) {
|
---|
881 | if (isBlank(jt)) {
|
---|
882 | myprintln("- Missing JOSM attribution URL ("+et+"): "+getDescription(j));
|
---|
883 | } else if (isNotBlank(et)) {
|
---|
884 | String ethttps = et.replace("http:", "https:");
|
---|
885 | if (jt.equals(ethttps) || jt.equals(et+"/") || jt.equals(ethttps+"/")) {
|
---|
886 | myprintln("+ Attribution URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
|
---|
887 | } else {
|
---|
888 | myprintln("* Attribution URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
|
---|
889 | }
|
---|
890 | } else if (!optionNoEli) {
|
---|
891 | myprintln("+ Missing ELI attribution URL ('"+jt+"'): "+getDescription(j));
|
---|
892 | }
|
---|
893 | }
|
---|
894 | }
|
---|
895 |
|
---|
896 | void compareAttributionTexts(JsonObject e, ImageryInfo j) {
|
---|
897 | String et = getAttributionText(e);
|
---|
898 | String jt = getAttributionText(j);
|
---|
899 | if (!Objects.equals(et, jt)) {
|
---|
900 | if (isBlank(jt)) {
|
---|
901 | myprintln("- Missing JOSM attribution text ("+et+"): "+getDescription(j));
|
---|
902 | } else if (isNotBlank(et)) {
|
---|
903 | myprintln("* Attribution text differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
|
---|
904 | } else if (!optionNoEli) {
|
---|
905 | myprintln("+ Missing ELI attribution text ('"+jt+"'): "+getDescription(j));
|
---|
906 | }
|
---|
907 | }
|
---|
908 | }
|
---|
909 |
|
---|
910 | void compareProjections(JsonObject e, ImageryInfo j) {
|
---|
911 | String et = getProjections(e).stream().sorted().collect(Collectors.joining(" "));
|
---|
912 | String jt = getProjections(j).stream().sorted().collect(Collectors.joining(" "));
|
---|
913 | if (!Objects.equals(et, jt)) {
|
---|
914 | if (isBlank(jt)) {
|
---|
915 | String t = getType(e);
|
---|
916 | if ("wms_endpoint".equals(t) || "tms".equals(t)) {
|
---|
917 | myprintln("+ ELI projections for type "+t+": "+getDescription(j));
|
---|
918 | } else {
|
---|
919 | myprintln("- Missing JOSM projections ("+et+"): "+getDescription(j));
|
---|
920 | }
|
---|
921 | } else if (isNotBlank(et)) {
|
---|
922 | if ("EPSG:3857 EPSG:4326".equals(et) || "EPSG:3857".equals(et) || "EPSG:4326".equals(et)) {
|
---|
923 | myprintln("+ ELI has minimal projections ('"+et+"' != '"+jt+"'): "+getDescription(j));
|
---|
924 | } else {
|
---|
925 | myprintln("* Projections differ ('"+et+"' != '"+jt+"'): "+getDescription(j));
|
---|
926 | }
|
---|
927 | } else if (!optionNoEli && !"tms".equals(getType(e))) {
|
---|
928 | myprintln("+ Missing ELI projections ('"+jt+"'): "+getDescription(j));
|
---|
929 | }
|
---|
930 | }
|
---|
931 | }
|
---|
932 |
|
---|
933 | void compareDefaults(JsonObject e, ImageryInfo j) {
|
---|
934 | boolean ed = getDefault(e);
|
---|
935 | boolean jd = getDefault(j);
|
---|
936 | if (ed != jd) {
|
---|
937 | if (!jd) {
|
---|
938 | myprintln("- Missing JOSM default: "+getDescription(j));
|
---|
939 | } else if (!optionNoEli) {
|
---|
940 | myprintln("+ Missing ELI default: "+getDescription(j));
|
---|
941 | }
|
---|
942 | }
|
---|
943 | }
|
---|
944 |
|
---|
945 | void compareOverlays(JsonObject e, ImageryInfo j) {
|
---|
946 | boolean eo = getOverlay(e);
|
---|
947 | boolean jo = getOverlay(j);
|
---|
948 | if (eo != jo) {
|
---|
949 | if (!jo) {
|
---|
950 | myprintln("- Missing JOSM overlay flag: "+getDescription(j));
|
---|
951 | } else if (!optionNoEli) {
|
---|
952 | myprintln("+ Missing ELI overlay flag: "+getDescription(j));
|
---|
953 | }
|
---|
954 | }
|
---|
955 | }
|
---|
956 |
|
---|
957 | void compareNoTileHeaders(JsonObject e, ImageryInfo j) {
|
---|
958 | Map<String, Set<String>> eh = getNoTileHeader(e);
|
---|
959 | Map<String, Set<String>> jh = getNoTileHeader(j);
|
---|
960 | if (!Objects.equals(eh, jh)) {
|
---|
961 | if (jh == null || jh.isEmpty()) {
|
---|
962 | myprintln("- Missing JOSM no tile headers ("+eh+"): "+getDescription(j));
|
---|
963 | } else if (eh != null && !eh.isEmpty()) {
|
---|
964 | myprintln("* No tile headers differ ('"+eh+"' != '"+jh+"'): "+getDescription(j));
|
---|
965 | } else if (!optionNoEli) {
|
---|
966 | myprintln("+ Missing ELI no tile headers ('"+jh+"'): "+getDescription(j));
|
---|
967 | }
|
---|
968 | }
|
---|
969 | }
|
---|
970 |
|
---|
971 | void doMismatchingShapes() {
|
---|
972 | myprintln("*** Mismatching shapes: ***");
|
---|
973 | for (String url : josmUrls.keySet()) {
|
---|
974 | ImageryInfo j = josmUrls.get(url);
|
---|
975 | int num = 1;
|
---|
976 | for (Shape shape : getShapes(j)) {
|
---|
977 | List<Coordinate> p = shape.getPoints();
|
---|
978 | if (!p.get(0).equals(p.get(p.size()-1))) {
|
---|
979 | myprintln("+++ JOSM shape "+num+" unclosed: "+getDescription(j));
|
---|
980 | }
|
---|
981 | for (int nump = 1; nump < p.size(); ++nump) {
|
---|
982 | if (Objects.equals(p.get(nump-1), p.get(nump))) {
|
---|
983 | myprintln("+++ JOSM shape "+num+" double point at "+(nump-1)+": "+getDescription(j));
|
---|
984 | }
|
---|
985 | }
|
---|
986 | ++num;
|
---|
987 | }
|
---|
988 | }
|
---|
989 | for (String url : eliUrls.keySet()) {
|
---|
990 | JsonObject e = eliUrls.get(url);
|
---|
991 | int num = 1;
|
---|
992 | List<Shape> s = null;
|
---|
993 | try {
|
---|
994 | s = getShapes(e);
|
---|
995 | for (Shape shape : s) {
|
---|
996 | List<Coordinate> p = shape.getPoints();
|
---|
997 | if (!p.get(0).equals(p.get(p.size()-1)) && !optionNoEli) {
|
---|
998 | myprintln("+++ ELI shape "+num+" unclosed: "+getDescription(e));
|
---|
999 | }
|
---|
1000 | for (int nump = 1; nump < p.size(); ++nump) {
|
---|
1001 | if (Objects.equals(p.get(nump-1), p.get(nump))) {
|
---|
1002 | myprintln("+++ ELI shape "+num+" double point at "+(nump-1)+": "+getDescription(e));
|
---|
1003 | }
|
---|
1004 | }
|
---|
1005 | ++num;
|
---|
1006 | }
|
---|
1007 | } catch (IllegalArgumentException err) {
|
---|
1008 | String desc = getDescription(e);
|
---|
1009 | myprintln("+++ ELI shape contains invalid data for "+desc+": "+err.getMessage());
|
---|
1010 | }
|
---|
1011 | if (s == null || !josmUrls.containsKey(url)) {
|
---|
1012 | continue;
|
---|
1013 | }
|
---|
1014 | ImageryInfo j = josmUrls.get(url);
|
---|
1015 | List<Shape> js = getShapes(j);
|
---|
1016 | if (s.isEmpty() && !js.isEmpty()) {
|
---|
1017 | if (!optionNoEli) {
|
---|
1018 | myprintln("+ No ELI shape: "+getDescription(j));
|
---|
1019 | }
|
---|
1020 | } else if (js.isEmpty() && !s.isEmpty()) {
|
---|
1021 | // don't report boundary like 5 point shapes as difference
|
---|
1022 | if (s.size() != 1 || s.get(0).getPoints().size() != 5) {
|
---|
1023 | myprintln("- No JOSM shape: "+getDescription(j));
|
---|
1024 | }
|
---|
1025 | } else if (s.size() != js.size()) {
|
---|
1026 | myprintln("* Different number of shapes ("+s.size()+" != "+js.size()+"): "+getDescription(j));
|
---|
1027 | } else {
|
---|
1028 | boolean[] edone = new boolean[s.size()];
|
---|
1029 | boolean[] jdone = new boolean[js.size()];
|
---|
1030 | for (int enums = 0; enums < s.size(); ++enums) {
|
---|
1031 | List<Coordinate> ep = s.get(enums).getPoints();
|
---|
1032 | for (int jnums = 0; jnums < js.size() && !edone[enums]; ++jnums) {
|
---|
1033 | List<Coordinate> jp = js.get(jnums).getPoints();
|
---|
1034 | if (ep.size() == jp.size() && !jdone[jnums]) {
|
---|
1035 | boolean err = false;
|
---|
1036 | for (int nump = 0; nump < ep.size() && !err; ++nump) {
|
---|
1037 | Coordinate ept = ep.get(nump);
|
---|
1038 | Coordinate jpt = jp.get(nump);
|
---|
1039 | if (differentCoordinate(ept.getLat(), jpt.getLat()) || differentCoordinate(ept.getLon(), jpt.getLon()))
|
---|
1040 | err = true;
|
---|
1041 | }
|
---|
1042 | if (!err) {
|
---|
1043 | edone[enums] = true;
|
---|
1044 | jdone[jnums] = true;
|
---|
1045 | break;
|
---|
1046 | }
|
---|
1047 | }
|
---|
1048 | }
|
---|
1049 | }
|
---|
1050 | for (int enums = 0; enums < s.size(); ++enums) {
|
---|
1051 | List<Coordinate> ep = s.get(enums).getPoints();
|
---|
1052 | for (int jnums = 0; jnums < js.size() && !edone[enums]; ++jnums) {
|
---|
1053 | List<Coordinate> jp = js.get(jnums).getPoints();
|
---|
1054 | if (ep.size() == jp.size() && !jdone[jnums]) {
|
---|
1055 | boolean err = false;
|
---|
1056 | for (int nump = 0; nump < ep.size() && !err; ++nump) {
|
---|
1057 | Coordinate ept = ep.get(nump);
|
---|
1058 | Coordinate jpt = jp.get(nump);
|
---|
1059 | if (differentCoordinate(ept.getLat(), jpt.getLat()) || differentCoordinate(ept.getLon(), jpt.getLon())) {
|
---|
1060 | String numtxt = Integer.toString(enums+1);
|
---|
1061 | if (enums != jnums) {
|
---|
1062 | numtxt += '/' + Integer.toString(jnums+1);
|
---|
1063 | }
|
---|
1064 | myprintln("* Different coordinate for point "+(nump+1)+" of shape "+numtxt+": "+getDescription(j));
|
---|
1065 | break;
|
---|
1066 | }
|
---|
1067 | }
|
---|
1068 | edone[enums] = true;
|
---|
1069 | jdone[jnums] = true;
|
---|
1070 | break;
|
---|
1071 | }
|
---|
1072 | }
|
---|
1073 | }
|
---|
1074 | for (int enums = 0; enums < s.size(); ++enums) {
|
---|
1075 | List<Coordinate> ep = s.get(enums).getPoints();
|
---|
1076 | for (int jnums = 0; jnums < js.size() && !edone[enums]; ++jnums) {
|
---|
1077 | List<Coordinate> jp = js.get(jnums).getPoints();
|
---|
1078 | if (!jdone[jnums]) {
|
---|
1079 | String numtxt = Integer.toString(enums+1);
|
---|
1080 | if (enums != jnums) {
|
---|
1081 | numtxt += '/' + Integer.toString(jnums+1);
|
---|
1082 | }
|
---|
1083 | myprintln("* Different number of points for shape "+numtxt+" ("+ep.size()+" ! = "+jp.size()+"): "
|
---|
1084 | + getDescription(j));
|
---|
1085 | edone[enums] = true;
|
---|
1086 | jdone[jnums] = true;
|
---|
1087 | break;
|
---|
1088 | }
|
---|
1089 | }
|
---|
1090 | }
|
---|
1091 | }
|
---|
1092 | }
|
---|
1093 | }
|
---|
1094 |
|
---|
1095 | private boolean differentCoordinate(double v1, double v2) {
|
---|
1096 | double epsilon = 0.00001;
|
---|
1097 | return Math.abs(v1 - v2) > epsilon;
|
---|
1098 | }
|
---|
1099 |
|
---|
1100 | void doMismatchingIcons() {
|
---|
1101 | myprintln("*** Mismatching icons: ***");
|
---|
1102 | doMismatching(this::compareIcons);
|
---|
1103 | }
|
---|
1104 |
|
---|
1105 | void doMismatchingCategories() {
|
---|
1106 | myprintln("*** Mismatching categories: ***");
|
---|
1107 | doMismatching(this::compareCategories);
|
---|
1108 | }
|
---|
1109 |
|
---|
1110 | void doMismatching(BiConsumer<ImageryInfo, JsonObject> comparator) {
|
---|
1111 | for (String url : eliUrls.keySet()) {
|
---|
1112 | if (josmUrls.containsKey(url)) {
|
---|
1113 | comparator.accept(josmUrls.get(url), eliUrls.get(url));
|
---|
1114 | }
|
---|
1115 | }
|
---|
1116 | }
|
---|
1117 |
|
---|
1118 | void compareIcons(ImageryInfo j, JsonObject e) {
|
---|
1119 | String ij = getIcon(j);
|
---|
1120 | String ie = getIcon(e);
|
---|
1121 | boolean ijok = isNotBlank(ij);
|
---|
1122 | boolean ieok = isNotBlank(ie);
|
---|
1123 | if (ijok && !ieok) {
|
---|
1124 | if (!optionNoEli) {
|
---|
1125 | myprintln("+ No ELI icon: "+getDescription(j));
|
---|
1126 | }
|
---|
1127 | } else if (!ijok && ieok) {
|
---|
1128 | myprintln("- No JOSM icon: "+getDescription(j));
|
---|
1129 | } else if (ijok && ieok && !Objects.equals(ij, ie) && !(
|
---|
1130 | (ie.startsWith("https://osmlab.github.io/editor-layer-index/")
|
---|
1131 | || ie.startsWith("https://raw.githubusercontent.com/osmlab/editor-layer-index/")) &&
|
---|
1132 | ij.startsWith("data:"))) {
|
---|
1133 | String iehttps = ie.replace("http:", "https:");
|
---|
1134 | if (ij.equals(iehttps)) {
|
---|
1135 | myprintln("+ Different icons: "+getDescription(j));
|
---|
1136 | } else {
|
---|
1137 | myprintln("* Different icons: "+getDescription(j));
|
---|
1138 | }
|
---|
1139 | }
|
---|
1140 | }
|
---|
1141 |
|
---|
1142 | void compareCategories(ImageryInfo j, JsonObject e) {
|
---|
1143 | String cj = getCategory(j);
|
---|
1144 | String ce = getCategory(e);
|
---|
1145 | boolean cjok = isNotBlank(cj);
|
---|
1146 | boolean ceok = isNotBlank(ce);
|
---|
1147 | if (cjok && !ceok) {
|
---|
1148 | if (!optionNoEli) {
|
---|
1149 | myprintln("+ No ELI category: "+getDescription(j));
|
---|
1150 | }
|
---|
1151 | } else if (!cjok && ceok) {
|
---|
1152 | myprintln("- No JOSM category: "+getDescription(j));
|
---|
1153 | } else if (cjok && ceok && !Objects.equals(cj, ce)) {
|
---|
1154 | myprintln("* Different categories ('"+ce+"' != '"+cj+"'): "+getDescription(j));
|
---|
1155 | }
|
---|
1156 | }
|
---|
1157 |
|
---|
1158 | void doMiscellaneousChecks() {
|
---|
1159 | myprintln("*** Miscellaneous checks: ***");
|
---|
1160 | Map<String, ImageryInfo> josmIds = new HashMap<>();
|
---|
1161 | Collection<String> all = Projections.getAllProjectionCodes();
|
---|
1162 | DomainValidator dv = DomainValidator.getInstance();
|
---|
1163 | for (String url : josmUrls.keySet()) {
|
---|
1164 | ImageryInfo j = josmUrls.get(url);
|
---|
1165 | String id = getId(j);
|
---|
1166 | if ("wms".equals(getType(j))) {
|
---|
1167 | String urlLc = url.toLowerCase(Locale.ENGLISH);
|
---|
1168 | if (getProjections(j).isEmpty()) {
|
---|
1169 | myprintln("* WMS without projections: "+getDescription(j));
|
---|
1170 | } else {
|
---|
1171 | List<String> unsupported = new LinkedList<>();
|
---|
1172 | List<String> old = new LinkedList<>();
|
---|
1173 | for (String p : getProjectionsUnstripped(j)) {
|
---|
1174 | if ("CRS:84".equals(p)) {
|
---|
1175 | if (!urlLc.contains("version=1.3")) {
|
---|
1176 | myprintln("* CRS:84 without WMS 1.3: "+getDescription(j));
|
---|
1177 | }
|
---|
1178 | } else if (oldproj.containsKey(p)) {
|
---|
1179 | old.add(p);
|
---|
1180 | } else if (!all.contains(p) && !ignoreproj.contains(p)) {
|
---|
1181 | unsupported.add(p);
|
---|
1182 | }
|
---|
1183 | }
|
---|
1184 | if (!unsupported.isEmpty()) {
|
---|
1185 | myprintln("* Projections "+String.join(", ", unsupported)+" not supported by JOSM: "+getDescription(j));
|
---|
1186 | }
|
---|
1187 | for (String o : old) {
|
---|
1188 | myprintln("* Projection "+o+" is an old unsupported code and has been replaced by "+oldproj.get(o)+": "
|
---|
1189 | + getDescription(j));
|
---|
1190 | }
|
---|
1191 | }
|
---|
1192 | if (urlLc.contains("version=1.3") && !urlLc.contains("crs={proj}")) {
|
---|
1193 | myprintln("* WMS 1.3 with strange CRS specification: "+getDescription(j));
|
---|
1194 | } else if (urlLc.contains("version=1.1") && !urlLc.contains("srs={proj}")) {
|
---|
1195 | myprintln("* WMS 1.1 with strange SRS specification: "+getDescription(j));
|
---|
1196 | }
|
---|
1197 | }
|
---|
1198 | List<String> urls = new LinkedList<>();
|
---|
1199 | if (!"scanex".equals(getType(j))) {
|
---|
1200 | urls.add(url);
|
---|
1201 | }
|
---|
1202 | String jt = getPermissionReferenceUrl(j);
|
---|
1203 | if (isNotBlank(jt) && !"Public Domain".equalsIgnoreCase(jt))
|
---|
1204 | urls.add(jt);
|
---|
1205 | jt = getTermsOfUseUrl(j);
|
---|
1206 | if (isNotBlank(jt))
|
---|
1207 | urls.add(jt);
|
---|
1208 | jt = getAttributionUrl(j);
|
---|
1209 | if (isNotBlank(jt))
|
---|
1210 | urls.add(jt);
|
---|
1211 | jt = getIcon(j);
|
---|
1212 | if (isNotBlank(jt)) {
|
---|
1213 | if (!jt.startsWith("data:image/"))
|
---|
1214 | urls.add(jt);
|
---|
1215 | else {
|
---|
1216 | try {
|
---|
1217 | new ImageProvider(jt).get();
|
---|
1218 | } catch (RuntimeException e) {
|
---|
1219 | myprintln("* Strange Icon: "+getDescription(j));
|
---|
1220 | }
|
---|
1221 | }
|
---|
1222 | }
|
---|
1223 | Pattern patternU = Pattern.compile("^https?://([^/]+?)(:\\d+)?(/.*)?");
|
---|
1224 | for (String u : urls) {
|
---|
1225 | if (!patternU.matcher(u).matches() || u.matches(".*[ \t]+$")) {
|
---|
1226 | myprintln("* Strange URL '"+u+"': "+getDescription(j));
|
---|
1227 | } else {
|
---|
1228 | try {
|
---|
1229 | URL jurl = new URL(u.replaceAll("\\{switch:[^\\}]*\\}", "x"));
|
---|
1230 | String domain = jurl.getHost();
|
---|
1231 | int port = jurl.getPort();
|
---|
1232 | if (!(domain.matches("^\\d+\\.\\d+\\.\\d+\\.\\d+$")) && !dv.isValid(domain))
|
---|
1233 | myprintln("* Strange Domain '"+domain+"': "+getDescription(j));
|
---|
1234 | else if (80 == port || 443 == port) {
|
---|
1235 | myprintln("* Useless port '"+port+"': "+getDescription(j));
|
---|
1236 | }
|
---|
1237 | } catch (MalformedURLException e) {
|
---|
1238 | myprintln("* Malformed URL '"+u+"': "+getDescription(j)+" => "+e.getMessage());
|
---|
1239 | }
|
---|
1240 | }
|
---|
1241 | }
|
---|
1242 |
|
---|
1243 | if (josmMirrors.containsKey(url)) {
|
---|
1244 | continue;
|
---|
1245 | }
|
---|
1246 | if (isBlank(id)) {
|
---|
1247 | myprintln("* No JOSM-ID: "+getDescription(j));
|
---|
1248 | } else if (josmIds.containsKey(id)) {
|
---|
1249 | myprintln("* JOSM-ID "+id+" not unique: "+getDescription(j));
|
---|
1250 | } else {
|
---|
1251 | josmIds.put(id, j);
|
---|
1252 | }
|
---|
1253 | String d = getDate(j);
|
---|
1254 | if (isNotBlank(d)) {
|
---|
1255 | Pattern patternD = Pattern.compile("^(-|(\\d\\d\\d\\d)(-(\\d\\d)(-(\\d\\d))?)?)(;(-|(\\d\\d\\d\\d)(-(\\d\\d)(-(\\d\\d))?)?))?$");
|
---|
1256 | Matcher m = patternD.matcher(d);
|
---|
1257 | if (!m.matches()) {
|
---|
1258 | myprintln("* JOSM-Date '"+d+"' is strange: "+getDescription(j));
|
---|
1259 | } else {
|
---|
1260 | try {
|
---|
1261 | Date first = verifyDate(m.group(2), m.group(4), m.group(6));
|
---|
1262 | Date second = verifyDate(m.group(9), m.group(11), m.group(13));
|
---|
1263 | if (second.compareTo(first) < 0) {
|
---|
1264 | myprintln("* JOSM-Date '"+d+"' is strange (second earlier than first): "+getDescription(j));
|
---|
1265 | }
|
---|
1266 | } catch (Exception e) {
|
---|
1267 | myprintln("* JOSM-Date '"+d+"' is strange ("+e.getMessage()+"): "+getDescription(j));
|
---|
1268 | }
|
---|
1269 | }
|
---|
1270 | }
|
---|
1271 | if (isNotBlank(getAttributionUrl(j)) && isBlank(getAttributionText(j))) {
|
---|
1272 | myprintln("* Attribution link without text: "+getDescription(j));
|
---|
1273 | }
|
---|
1274 | if (isNotBlank(getLogoUrl(j)) && isBlank(getLogoImage(j))) {
|
---|
1275 | myprintln("* Logo link without image: "+getDescription(j));
|
---|
1276 | }
|
---|
1277 | if (isNotBlank(getTermsOfUseText(j)) && isBlank(getTermsOfUseUrl(j))) {
|
---|
1278 | myprintln("* Terms of Use text without link: "+getDescription(j));
|
---|
1279 | }
|
---|
1280 | List<Shape> js = getShapes(j);
|
---|
1281 | if (!js.isEmpty()) {
|
---|
1282 | double minlat = 1000;
|
---|
1283 | double minlon = 1000;
|
---|
1284 | double maxlat = -1000;
|
---|
1285 | double maxlon = -1000;
|
---|
1286 | for (Shape s: js) {
|
---|
1287 | for (Coordinate p: s.getPoints()) {
|
---|
1288 | double lat = p.getLat();
|
---|
1289 | double lon = p.getLon();
|
---|
1290 | if (lat > maxlat) maxlat = lat;
|
---|
1291 | if (lon > maxlon) maxlon = lon;
|
---|
1292 | if (lat < minlat) minlat = lat;
|
---|
1293 | if (lon < minlon) minlon = lon;
|
---|
1294 | }
|
---|
1295 | }
|
---|
1296 | ImageryBounds b = j.getBounds();
|
---|
1297 | if (differentCoordinate(b.getMinLat(), minlat)
|
---|
1298 | || differentCoordinate(b.getMinLon(), minlon)
|
---|
1299 | || differentCoordinate(b.getMaxLat(), maxlat)
|
---|
1300 | || differentCoordinate(b.getMaxLon(), maxlon)) {
|
---|
1301 | myprintln("* Bounds do not match shape (is "+b.getMinLat()+","+b.getMinLon()+","+b.getMaxLat()+","+b.getMaxLon()
|
---|
1302 | + ", calculated <bounds min-lat='"+minlat+"' min-lon='"+minlon+"' max-lat='"+maxlat+"' max-lon='"+maxlon+"'>): "
|
---|
1303 | + getDescription(j));
|
---|
1304 | }
|
---|
1305 | }
|
---|
1306 | List<String> knownCategories = Arrays.asList(
|
---|
1307 | "photo", "elevation", "map", "historicmap", "osmbasedmap", "historicphoto", "qa", "other");
|
---|
1308 | String cat = getCategory(j);
|
---|
1309 | if (isBlank(cat)) {
|
---|
1310 | myprintln("* No category: "+getDescription(j));
|
---|
1311 | } else if (!knownCategories.contains(cat)) {
|
---|
1312 | myprintln("* Strange category "+cat+": "+getDescription(j));
|
---|
1313 | }
|
---|
1314 | }
|
---|
1315 | }
|
---|
1316 |
|
---|
1317 | /*
|
---|
1318 | * Utility functions that allow uniform access for both ImageryInfo and JsonObject.
|
---|
1319 | */
|
---|
1320 |
|
---|
1321 | static String getUrl(Object e) {
|
---|
1322 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getUrl();
|
---|
1323 | return ((Map<String, JsonObject>) e).get("properties").getString("url");
|
---|
1324 | }
|
---|
1325 |
|
---|
1326 | static String getUrlStripped(Object e) {
|
---|
1327 | return getUrl(e).replaceAll("\\?(apikey|access_token)=.*", "");
|
---|
1328 | }
|
---|
1329 |
|
---|
1330 | static String getDate(Object e) {
|
---|
1331 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getDate() != null ? ((ImageryInfo) e).getDate() : "";
|
---|
1332 | JsonObject p = ((Map<String, JsonObject>) e).get("properties");
|
---|
1333 | String start = p.containsKey("start_date") ? p.getString("start_date") : "";
|
---|
1334 | String end = p.containsKey("end_date") ? p.getString("end_date") : "";
|
---|
1335 | if (!start.isEmpty() && !end.isEmpty())
|
---|
1336 | return start+";"+end;
|
---|
1337 | else if (!start.isEmpty())
|
---|
1338 | return start+";-";
|
---|
1339 | else if (!end.isEmpty())
|
---|
1340 | return "-;"+end;
|
---|
1341 | return "";
|
---|
1342 | }
|
---|
1343 |
|
---|
1344 | static Date verifyDate(String year, String month, String day) throws ParseException {
|
---|
1345 | String date;
|
---|
1346 | if (year == null) {
|
---|
1347 | date = "3000-01-01";
|
---|
1348 | } else {
|
---|
1349 | date = year + "-" + (month == null ? "01" : month) + "-" + (day == null ? "01" : day);
|
---|
1350 | }
|
---|
1351 | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
---|
1352 | df.setLenient(false);
|
---|
1353 | return df.parse(date);
|
---|
1354 | }
|
---|
1355 |
|
---|
1356 | static String getId(Object e) {
|
---|
1357 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getId();
|
---|
1358 | return ((Map<String, JsonObject>) e).get("properties").getString("id");
|
---|
1359 | }
|
---|
1360 |
|
---|
1361 | static String getName(Object e) {
|
---|
1362 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getOriginalName();
|
---|
1363 | return ((Map<String, JsonObject>) e).get("properties").getString("name");
|
---|
1364 | }
|
---|
1365 |
|
---|
1366 | static List<ImageryInfo> getMirrors(Object e) {
|
---|
1367 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getMirrors();
|
---|
1368 | return Collections.emptyList();
|
---|
1369 | }
|
---|
1370 |
|
---|
1371 | static List<String> getProjections(Object e) {
|
---|
1372 | List<String> r = new ArrayList<>();
|
---|
1373 | List<String> u = getProjectionsUnstripped(e);
|
---|
1374 | if (u != null) {
|
---|
1375 | for (String p : u) {
|
---|
1376 | if (!oldproj.containsKey(p) && !("CRS:84".equals(p) && !(getUrlStripped(e).matches("(?i)version=1\\.3")))) {
|
---|
1377 | r.add(p);
|
---|
1378 | }
|
---|
1379 | }
|
---|
1380 | }
|
---|
1381 | return r;
|
---|
1382 | }
|
---|
1383 |
|
---|
1384 | static List<String> getProjectionsUnstripped(Object e) {
|
---|
1385 | List<String> r = null;
|
---|
1386 | if (e instanceof ImageryInfo) {
|
---|
1387 | r = ((ImageryInfo) e).getServerProjections();
|
---|
1388 | } else {
|
---|
1389 | JsonValue s = ((Map<String, JsonObject>) e).get("properties").get("available_projections");
|
---|
1390 | if (s != null) {
|
---|
1391 | r = new ArrayList<>();
|
---|
1392 | for (JsonValue p : s.asJsonArray()) {
|
---|
1393 | r.add(((JsonString) p).getString());
|
---|
1394 | }
|
---|
1395 | }
|
---|
1396 | }
|
---|
1397 | return r != null ? r : Collections.emptyList();
|
---|
1398 | }
|
---|
1399 |
|
---|
1400 | static void addJsonShapes(List<Shape> l, JsonArray a) {
|
---|
1401 | if (a.get(0).asJsonArray().get(0) instanceof JsonArray) {
|
---|
1402 | for (JsonValue sub: a.asJsonArray()) {
|
---|
1403 | addJsonShapes(l, sub.asJsonArray());
|
---|
1404 | }
|
---|
1405 | } else {
|
---|
1406 | Shape s = new Shape();
|
---|
1407 | for (JsonValue point: a.asJsonArray()) {
|
---|
1408 | JsonArray ar = point.asJsonArray();
|
---|
1409 | String lon = ar.getJsonNumber(0).toString();
|
---|
1410 | String lat = ar.getJsonNumber(1).toString();
|
---|
1411 | s.addPoint(lat, lon);
|
---|
1412 | }
|
---|
1413 | l.add(s);
|
---|
1414 | }
|
---|
1415 | }
|
---|
1416 |
|
---|
1417 | static List<Shape> getShapes(Object e) {
|
---|
1418 | if (e instanceof ImageryInfo) {
|
---|
1419 | ImageryBounds bounds = ((ImageryInfo) e).getBounds();
|
---|
1420 | if (bounds != null) {
|
---|
1421 | return bounds.getShapes();
|
---|
1422 | }
|
---|
1423 | return Collections.emptyList();
|
---|
1424 | }
|
---|
1425 | JsonValue ex = ((Map<String, JsonValue>) e).get("geometry");
|
---|
1426 | if (ex != null && !JsonValue.NULL.equals(ex) && !ex.asJsonObject().isNull("coordinates")) {
|
---|
1427 | JsonArray poly = ex.asJsonObject().getJsonArray("coordinates");
|
---|
1428 | List<Shape> l = new ArrayList<>();
|
---|
1429 | for (JsonValue shapes: poly) {
|
---|
1430 | addJsonShapes(l, shapes.asJsonArray());
|
---|
1431 | }
|
---|
1432 | return l;
|
---|
1433 | }
|
---|
1434 | return Collections.emptyList();
|
---|
1435 | }
|
---|
1436 |
|
---|
1437 | static String getType(Object e) {
|
---|
1438 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getImageryType().getTypeString();
|
---|
1439 | return ((Map<String, JsonObject>) e).get("properties").getString("type");
|
---|
1440 | }
|
---|
1441 |
|
---|
1442 | static Integer getMinZoom(Object e) {
|
---|
1443 | if (e instanceof ImageryInfo) {
|
---|
1444 | int mz = ((ImageryInfo) e).getMinZoom();
|
---|
1445 | return mz == 0 ? null : mz;
|
---|
1446 | } else {
|
---|
1447 | JsonNumber num = ((Map<String, JsonObject>) e).get("properties").getJsonNumber("min_zoom");
|
---|
1448 | if (num == null) return null;
|
---|
1449 | return num.intValue();
|
---|
1450 | }
|
---|
1451 | }
|
---|
1452 |
|
---|
1453 | static Integer getMaxZoom(Object e) {
|
---|
1454 | if (e instanceof ImageryInfo) {
|
---|
1455 | int mz = ((ImageryInfo) e).getMaxZoom();
|
---|
1456 | return mz == 0 ? null : mz;
|
---|
1457 | } else {
|
---|
1458 | JsonNumber num = ((Map<String, JsonObject>) e).get("properties").getJsonNumber("max_zoom");
|
---|
1459 | if (num == null) return null;
|
---|
1460 | return num.intValue();
|
---|
1461 | }
|
---|
1462 | }
|
---|
1463 |
|
---|
1464 | static String getCountryCode(Object e) {
|
---|
1465 | if (e instanceof ImageryInfo) return "".equals(((ImageryInfo) e).getCountryCode()) ? null : ((ImageryInfo) e).getCountryCode();
|
---|
1466 | return ((Map<String, JsonObject>) e).get("properties").getString("country_code", null);
|
---|
1467 | }
|
---|
1468 |
|
---|
1469 | static String getQuality(Object e) {
|
---|
1470 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).isBestMarked() ? "eli-best" : null;
|
---|
1471 | return (((Map<String, JsonObject>) e).get("properties").containsKey("best")
|
---|
1472 | && ((Map<String, JsonObject>) e).get("properties").getBoolean("best")) ? "eli-best" : null;
|
---|
1473 | }
|
---|
1474 |
|
---|
1475 | static boolean getOverlay(Object e) {
|
---|
1476 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).isOverlay();
|
---|
1477 | return (((Map<String, JsonObject>) e).get("properties").containsKey("overlay")
|
---|
1478 | && ((Map<String, JsonObject>) e).get("properties").getBoolean("overlay"));
|
---|
1479 | }
|
---|
1480 |
|
---|
1481 | static String getIcon(Object e) {
|
---|
1482 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getIcon();
|
---|
1483 | return ((Map<String, JsonObject>) e).get("properties").getString("icon", null);
|
---|
1484 | }
|
---|
1485 |
|
---|
1486 | static String getAttributionText(Object e) {
|
---|
1487 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getAttributionText(0, null, null);
|
---|
1488 | try {
|
---|
1489 | return ((Map<String, JsonObject>) e).get("properties").getJsonObject("attribution").getString("text", null);
|
---|
1490 | } catch (NullPointerException ex) {
|
---|
1491 | return null;
|
---|
1492 | }
|
---|
1493 | }
|
---|
1494 |
|
---|
1495 | static String getAttributionUrl(Object e) {
|
---|
1496 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getAttributionLinkURL();
|
---|
1497 | try {
|
---|
1498 | return ((Map<String, JsonObject>) e).get("properties").getJsonObject("attribution").getString("url", null);
|
---|
1499 | } catch (NullPointerException ex) {
|
---|
1500 | return null;
|
---|
1501 | }
|
---|
1502 | }
|
---|
1503 |
|
---|
1504 | static String getTermsOfUseText(Object e) {
|
---|
1505 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getTermsOfUseText();
|
---|
1506 | return null;
|
---|
1507 | }
|
---|
1508 |
|
---|
1509 | static String getTermsOfUseUrl(Object e) {
|
---|
1510 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getTermsOfUseURL();
|
---|
1511 | return null;
|
---|
1512 | }
|
---|
1513 |
|
---|
1514 | static String getCategory(Object e) {
|
---|
1515 | if (e instanceof ImageryInfo) {
|
---|
1516 | return ((ImageryInfo) e).getImageryCategoryOriginalString();
|
---|
1517 | }
|
---|
1518 | return ((Map<String, JsonObject>) e).get("properties").getString("category", null);
|
---|
1519 | }
|
---|
1520 |
|
---|
1521 | static String getLogoImage(Object e) {
|
---|
1522 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getAttributionImageRaw();
|
---|
1523 | return null;
|
---|
1524 | }
|
---|
1525 |
|
---|
1526 | static String getLogoUrl(Object e) {
|
---|
1527 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getAttributionImageURL();
|
---|
1528 | return null;
|
---|
1529 | }
|
---|
1530 |
|
---|
1531 | static String getPermissionReferenceUrl(Object e) {
|
---|
1532 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getPermissionReferenceURL();
|
---|
1533 | return ((Map<String, JsonObject>) e).get("properties").getString("license_url", null);
|
---|
1534 | }
|
---|
1535 |
|
---|
1536 | static String getPrivacyPolicyUrl(Object e) {
|
---|
1537 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getPrivacyPolicyURL();
|
---|
1538 | return ((Map<String, JsonObject>) e).get("properties").getString("privacy_policy_url", null);
|
---|
1539 | }
|
---|
1540 |
|
---|
1541 | static Map<String, Set<String>> getNoTileHeader(Object e) {
|
---|
1542 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getNoTileHeaders();
|
---|
1543 | JsonObject nth = ((Map<String, JsonObject>) e).get("properties").getJsonObject("no_tile_header");
|
---|
1544 | return nth == null ? null : nth.keySet().stream().collect(Collectors.toMap(
|
---|
1545 | Function.identity(),
|
---|
1546 | k -> nth.getJsonArray(k).stream().map(x -> ((JsonString) x).getString()).collect(Collectors.toSet())));
|
---|
1547 | }
|
---|
1548 |
|
---|
1549 | static Map<String, String> getDescriptions(Object e) {
|
---|
1550 | Map<String, String> res = new HashMap<>();
|
---|
1551 | if (e instanceof ImageryInfo) {
|
---|
1552 | String a = ((ImageryInfo) e).getDescription();
|
---|
1553 | if (a != null) res.put("en", a);
|
---|
1554 | } else {
|
---|
1555 | String a = ((Map<String, JsonObject>) e).get("properties").getString("description", null);
|
---|
1556 | if (a != null) res.put("en", a.replaceAll("''", "'"));
|
---|
1557 | }
|
---|
1558 | return res;
|
---|
1559 | }
|
---|
1560 |
|
---|
1561 | static boolean getValidGeoreference(Object e) {
|
---|
1562 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).isGeoreferenceValid();
|
---|
1563 | return false;
|
---|
1564 | }
|
---|
1565 |
|
---|
1566 | static boolean getDefault(Object e) {
|
---|
1567 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).isDefaultEntry();
|
---|
1568 | return ((Map<String, JsonObject>) e).get("properties").getBoolean("default", false);
|
---|
1569 | }
|
---|
1570 |
|
---|
1571 | String getDescription(Object o) {
|
---|
1572 | String url = getUrl(o);
|
---|
1573 | String cc = getCountryCode(o);
|
---|
1574 | if (cc == null) {
|
---|
1575 | ImageryInfo j = josmUrls.get(url);
|
---|
1576 | if (j != null) cc = getCountryCode(j);
|
---|
1577 | if (cc == null) {
|
---|
1578 | JsonObject e = eliUrls.get(url);
|
---|
1579 | if (e != null) cc = getCountryCode(e);
|
---|
1580 | }
|
---|
1581 | }
|
---|
1582 | if (cc == null) {
|
---|
1583 | cc = "";
|
---|
1584 | } else {
|
---|
1585 | cc = "["+cc+"] ";
|
---|
1586 | }
|
---|
1587 | String name = getName(o);
|
---|
1588 | String id = getId(o);
|
---|
1589 | String d = cc;
|
---|
1590 | if (name != null && !name.isEmpty()) {
|
---|
1591 | d += name;
|
---|
1592 | if (id != null && !id.isEmpty())
|
---|
1593 | d += " ["+id+"]";
|
---|
1594 | } else if (url != null && !url.isEmpty())
|
---|
1595 | d += url;
|
---|
1596 | if (optionShorten) {
|
---|
1597 | if (d.length() > MAXLEN) d = d.substring(0, MAXLEN-1) + "...";
|
---|
1598 | }
|
---|
1599 | return d;
|
---|
1600 | }
|
---|
1601 | }
|
---|