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