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