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