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