[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 {
|
---|
| 285 | outputStream.write(s + System.getProperty("line.separator"));
|
---|
| 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 | }
|
---|
[19137] | 388 | void loadELIUsers() throws IOException {
|
---|
| 389 | try (JsonReader jr = Json.createReader(Files.newBufferedReader(Paths.get(idInputFile), UTF_8))) {
|
---|
| 390 | idEntries = jr.readArray();
|
---|
| 391 | }
|
---|
| 392 | for (JsonValue e : idEntries) {
|
---|
| 393 | String url = getUrlStripped(e);
|
---|
| 394 | if (!eliUrls.containsKey(url))
|
---|
| 395 | myprintln("+++ iD-URL not in ELI: "+url);
|
---|
| 396 | idUrls.put(url, e.asJsonObject());
|
---|
| 397 | }
|
---|
| 398 | myprintln("*** Loaded "+idEntries.size()+" entries (iD). ***");
|
---|
| 399 | try (JsonReader jr = Json.createReader(Files.newBufferedReader(Paths.get(rapidInputFile), UTF_8))) {
|
---|
| 400 | rapidEntries = jr.readArray();
|
---|
| 401 | }
|
---|
| 402 | for (JsonValue e : rapidEntries) {
|
---|
| 403 | String url = getUrlStripped(e);
|
---|
| 404 | if (!eliUrls.containsKey(url))
|
---|
| 405 | myprintln("+++ Rapid-URL not in ELI: "+url);
|
---|
| 406 | rapidUrls.put(url, e.asJsonObject());
|
---|
| 407 | }
|
---|
| 408 | myprintln("*** Loaded "+rapidEntries.size()+" entries (Rapid). ***");
|
---|
| 409 | }
|
---|
[15033] | 410 |
|
---|
| 411 | String cdata(String s) {
|
---|
| 412 | return cdata(s, false);
|
---|
[11968] | 413 | }
|
---|
[7726] | 414 |
|
---|
[15033] | 415 | String cdata(String s, boolean escape) {
|
---|
| 416 | if (escape) {
|
---|
| 417 | return s.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
---|
[15712] | 418 | } else if (s.matches(".*[<>&].*"))
|
---|
[15033] | 419 | return "<![CDATA["+s+"]]>";
|
---|
| 420 | return s;
|
---|
| 421 | }
|
---|
| 422 |
|
---|
| 423 | String maininfo(Object entry, String offset) {
|
---|
| 424 | String t = getType(entry);
|
---|
| 425 | String res = offset + "<type>"+t+"</type>\n";
|
---|
| 426 | res += offset + "<url>"+cdata(getUrl(entry))+"</url>\n";
|
---|
| 427 | if (getMinZoom(entry) != null)
|
---|
| 428 | res += offset + "<min-zoom>"+getMinZoom(entry)+"</min-zoom>\n";
|
---|
| 429 | if (getMaxZoom(entry) != null)
|
---|
| 430 | res += offset + "<max-zoom>"+getMaxZoom(entry)+"</max-zoom>\n";
|
---|
| 431 | if ("wms".equals(t)) {
|
---|
| 432 | List<String> p = getProjections(entry);
|
---|
| 433 | if (p != null) {
|
---|
| 434 | res += offset + "<projections>\n";
|
---|
[15034] | 435 | for (String c : p) {
|
---|
[15033] | 436 | res += offset + " <code>"+c+"</code>\n";
|
---|
[15034] | 437 | }
|
---|
[15033] | 438 | res += offset + "</projections>\n";
|
---|
[11975] | 439 | }
|
---|
[11967] | 440 | }
|
---|
[15033] | 441 | return res;
|
---|
[11967] | 442 | }
|
---|
[12061] | 443 |
|
---|
[16098] | 444 | void printentries(List<?> entries, Writer stream) throws IOException {
|
---|
[15033] | 445 | DecimalFormat df = new DecimalFormat("#.#######");
|
---|
| 446 | df.setRoundingMode(java.math.RoundingMode.CEILING);
|
---|
| 447 | stream.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
|
---|
| 448 | stream.write("<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n");
|
---|
| 449 | for (Object e : entries) {
|
---|
[13536] | 450 | stream.write(" <entry"
|
---|
[15034] | 451 | + ("eli-best".equals(getQuality(e)) ? " eli-best=\"true\"" : "")
|
---|
| 452 | + (getOverlay(e) ? " overlay=\"true\"" : "")
|
---|
[15033] | 453 | + ">\n");
|
---|
| 454 | String t;
|
---|
| 455 | if (isNotBlank(t = getName(e)))
|
---|
| 456 | stream.write(" <name>"+cdata(t, true)+"</name>\n");
|
---|
| 457 | if (isNotBlank(t = getId(e)))
|
---|
| 458 | stream.write(" <id>"+t+"</id>\n");
|
---|
| 459 | if (isNotBlank(t = getCategory(e)))
|
---|
| 460 | stream.write(" <category>"+t+"</category>\n");
|
---|
| 461 | if (isNotBlank(t = getDate(e)))
|
---|
| 462 | stream.write(" <date>"+t+"</date>\n");
|
---|
| 463 | if (isNotBlank(t = getCountryCode(e)))
|
---|
| 464 | stream.write(" <country-code>"+t+"</country-code>\n");
|
---|
| 465 | if ((getDefault(e)))
|
---|
| 466 | stream.write(" <default>true</default>\n");
|
---|
| 467 | stream.write(maininfo(e, " "));
|
---|
| 468 | if (isNotBlank(t = getAttributionText(e)))
|
---|
| 469 | stream.write(" <attribution-text mandatory=\"true\">"+cdata(t, true)+"</attribution-text>\n");
|
---|
| 470 | if (isNotBlank(t = getAttributionUrl(e)))
|
---|
| 471 | stream.write(" <attribution-url>"+cdata(t)+"</attribution-url>\n");
|
---|
| 472 | if (isNotBlank(t = getLogoImage(e)))
|
---|
| 473 | stream.write(" <logo-image>"+cdata(t, true)+"</logo-image>\n");
|
---|
| 474 | if (isNotBlank(t = getLogoUrl(e)))
|
---|
| 475 | stream.write(" <logo-url>"+cdata(t)+"</logo-url>\n");
|
---|
| 476 | if (isNotBlank(t = getTermsOfUseText(e)))
|
---|
| 477 | stream.write(" <terms-of-use-text>"+cdata(t, true)+"</terms-of-use-text>\n");
|
---|
| 478 | if (isNotBlank(t = getTermsOfUseUrl(e)))
|
---|
| 479 | stream.write(" <terms-of-use-url>"+cdata(t)+"</terms-of-use-url>\n");
|
---|
| 480 | if (isNotBlank(t = getPermissionReferenceUrl(e)))
|
---|
| 481 | stream.write(" <permission-ref>"+cdata(t)+"</permission-ref>\n");
|
---|
[16127] | 482 | if (isNotBlank(t = getPrivacyPolicyUrl(e)))
|
---|
| 483 | stream.write(" <privacy-policy-url>"+cdata(t)+"</privacy-policy-url>\n");
|
---|
[15033] | 484 | if ((getValidGeoreference(e)))
|
---|
| 485 | stream.write(" <valid-georeference>true</valid-georeference>\n");
|
---|
| 486 | if (isNotBlank(t = getIcon(e)))
|
---|
| 487 | stream.write(" <icon>"+cdata(t)+"</icon>\n");
|
---|
| 488 | for (Entry<String, String> d : getDescriptions(e).entrySet()) {
|
---|
[19137] | 489 | stream.write(" <description lang=\""+d.getKey()+"\">"+cdata(d.getValue(), true)+"</description>\n");
|
---|
[11975] | 490 | }
|
---|
[15033] | 491 | for (ImageryInfo m : getMirrors(e)) {
|
---|
| 492 | stream.write(" <mirror>\n"+maininfo(m, " ")+" </mirror>\n");
|
---|
[11967] | 493 | }
|
---|
[15033] | 494 | double minlat = 1000;
|
---|
| 495 | double minlon = 1000;
|
---|
| 496 | double maxlat = -1000;
|
---|
| 497 | double maxlon = -1000;
|
---|
| 498 | String shapes = "";
|
---|
| 499 | String sep = "\n ";
|
---|
[13771] | 500 | try {
|
---|
[15033] | 501 | for (Shape s: getShapes(e)) {
|
---|
| 502 | shapes += " <shape>";
|
---|
| 503 | int i = 0;
|
---|
| 504 | for (Coordinate p: s.getPoints()) {
|
---|
| 505 | double lat = p.getLat();
|
---|
| 506 | double lon = p.getLon();
|
---|
| 507 | if (lat > maxlat) maxlat = lat;
|
---|
| 508 | if (lon > maxlon) maxlon = lon;
|
---|
| 509 | if (lat < minlat) minlat = lat;
|
---|
| 510 | if (lon < minlon) minlon = lon;
|
---|
[15034] | 511 | if ((i++ % 3) == 0) {
|
---|
[15033] | 512 | shapes += sep + " ";
|
---|
[13771] | 513 | }
|
---|
[15033] | 514 | shapes += "<point lat='"+df.format(lat)+"' lon='"+df.format(lon)+"'/>";
|
---|
[11964] | 515 | }
|
---|
[15033] | 516 | shapes += sep + "</shape>\n";
|
---|
[11964] | 517 | }
|
---|
[19106] | 518 | } catch (IllegalArgumentException illegalArgumentException) {
|
---|
| 519 | Logging.trace(illegalArgumentException);
|
---|
[11964] | 520 | }
|
---|
[15033] | 521 | if (!shapes.isEmpty()) {
|
---|
[15034] | 522 | stream.write(" <bounds min-lat='"+df.format(minlat)
|
---|
| 523 | +"' min-lon='"+df.format(minlon)
|
---|
| 524 | +"' max-lat='"+df.format(maxlat)
|
---|
| 525 | +"' max-lon='"+df.format(maxlon)+"'>\n");
|
---|
[15033] | 526 | stream.write(shapes + " </bounds>\n");
|
---|
[11964] | 527 | }
|
---|
[15033] | 528 | stream.write(" </entry>\n");
|
---|
[11964] | 529 | }
|
---|
[15033] | 530 | stream.write("</imagery>\n");
|
---|
| 531 | stream.close();
|
---|
[11964] | 532 | }
|
---|
| 533 |
|
---|
[15033] | 534 | void loadJosmEntries() throws IOException, SAXException, ReflectiveOperationException {
|
---|
| 535 | try (ImageryReader reader = new ImageryReader(josmInputFile)) {
|
---|
| 536 | josmEntries = reader.parse();
|
---|
| 537 | }
|
---|
[9667] | 538 |
|
---|
[15033] | 539 | for (ImageryInfo e : josmEntries) {
|
---|
[18989] | 540 | if (!e.isValid()) {
|
---|
| 541 | myprintln("~~~ JOSM-Entry missing fields (" + String.join(", ", e.getMissingFields()) + "): " + getDescription(e));
|
---|
| 542 | }
|
---|
[15033] | 543 | if (isBlank(getUrl(e))) {
|
---|
[18382] | 544 | myprintln("~~~ JOSM-Entry without URL: " + getDescription(e));
|
---|
[15033] | 545 | continue;
|
---|
[14554] | 546 | }
|
---|
[16373] | 547 | if (isBlank(e.getDate()) && e.getDate() != null) {
|
---|
[18382] | 548 | myprintln("~~~ JOSM-Entry with empty Date: " + getDescription(e));
|
---|
[16373] | 549 | continue;
|
---|
| 550 | }
|
---|
[15033] | 551 | if (isBlank(getName(e))) {
|
---|
[18382] | 552 | myprintln("~~~ JOSM-Entry without Name: " + getDescription(e));
|
---|
[15033] | 553 | continue;
|
---|
[14554] | 554 | }
|
---|
[15033] | 555 | String url = getUrlStripped(e);
|
---|
[9658] | 556 | if (url.contains("{z}")) {
|
---|
[18382] | 557 | myprintln("~~~ JOSM-URL uses {z} instead of {zoom}: "+getDescription(e));
|
---|
[15034] | 558 | url = url.replace("{z}", "{zoom}");
|
---|
[9658] | 559 | }
|
---|
[9505] | 560 | if (josmUrls.containsKey(url)) {
|
---|
[18382] | 561 | myprintln("~~~ JOSM-URL is not unique: "+url);
|
---|
[9505] | 562 | } else {
|
---|
[15033] | 563 | josmUrls.put(url, e);
|
---|
[7726] | 564 | }
|
---|
[15033] | 565 | for (ImageryInfo m : e.getMirrors()) {
|
---|
| 566 | url = getUrlStripped(m);
|
---|
[16650] | 567 | Field origNameField = SourceInfo.class.getDeclaredField("origName");
|
---|
[15033] | 568 | ReflectionUtils.setObjectsAccessible(origNameField);
|
---|
[15034] | 569 | origNameField.set(m, m.getOriginalName().replaceAll(" mirror server( \\d+)?", ""));
|
---|
[9658] | 570 | if (josmUrls.containsKey(url)) {
|
---|
[18382] | 571 | myprintln("~~~ JOSM-Mirror-URL is not unique: "+url);
|
---|
[9658] | 572 | } else {
|
---|
[15033] | 573 | josmUrls.put(url, m);
|
---|
| 574 | josmMirrors.put(url, m);
|
---|
[9658] | 575 | }
|
---|
| 576 | }
|
---|
[7726] | 577 | }
|
---|
[15033] | 578 | myprintln("*** Loaded "+josmEntries.size()+" entries (JOSM). ***");
|
---|
[7726] | 579 | }
|
---|
| 580 |
|
---|
[17453] | 581 | // catch reordered arguments, make them uppercase, and switches to WMS version 1.3.0
|
---|
[17328] | 582 | String unifyWMS(String url) {
|
---|
[17453] | 583 | String[] x = url.replaceAll("(?i)VERSION=[0-9.]+", "VERSION=x")
|
---|
| 584 | .replaceAll("(?i)SRS=", "CRS=")
|
---|
| 585 | .replaceAll("(?i)BBOX=", "BBOX=")
|
---|
| 586 | .replaceAll("(?i)FORMAT=", "FORMAT=")
|
---|
| 587 | .replaceAll("(?i)LAYERS=", "LAYERS=")
|
---|
| 588 | .replaceAll("(?i)MAP=", "MAP=")
|
---|
| 589 | .replaceAll("(?i)REQUEST=", "REQUEST=")
|
---|
| 590 | .replaceAll("(?i)SERVICE=", "SERVICE=")
|
---|
| 591 | .replaceAll("(?i)STYLES=", "STYLES=")
|
---|
| 592 | .replaceAll("(?i)TRANSPARENT=FALSE", "TRANSPARENT=FALSE")
|
---|
| 593 | .replaceAll("(?i)TRANSPARENT=TRUE", "TRANSPARENT=TRUE")
|
---|
| 594 | .replaceAll("(?i)WIDTH=", "WIDTH=")
|
---|
| 595 | .replaceAll("(?i)HEIGHT=", "HEIGHT=")
|
---|
| 596 | .split("\\?");
|
---|
[17454] | 597 | return x[0] +"?" + Arrays.stream(x[1].split("&"))
|
---|
| 598 | .filter(s -> !s.endsWith("=")) // filter empty params
|
---|
| 599 | .sorted()
|
---|
| 600 | .collect(Collectors.joining("&"));
|
---|
[17328] | 601 | }
|
---|
| 602 |
|
---|
[15692] | 603 | void checkInOneButNotTheOther() {
|
---|
[15033] | 604 | List<String> le = new LinkedList<>(eliUrls.keySet());
|
---|
| 605 | List<String> lj = new LinkedList<>(josmUrls.keySet());
|
---|
[13593] | 606 |
|
---|
[17453] | 607 | for (String url : new LinkedList<>(le)) {
|
---|
[15033] | 608 | if (lj.contains(url)) {
|
---|
| 609 | le.remove(url);
|
---|
| 610 | lj.remove(url);
|
---|
[13593] | 611 | }
|
---|
| 612 | }
|
---|
| 613 |
|
---|
[15033] | 614 | if (!le.isEmpty() && !lj.isEmpty()) {
|
---|
[17453] | 615 | List<String> ke = new LinkedList<>(le);
|
---|
[15033] | 616 | for (String urle : ke) {
|
---|
| 617 | JsonObject e = eliUrls.get(urle);
|
---|
| 618 | String ide = getId(e);
|
---|
[15034] | 619 | String urlhttps = urle.replace("http:", "https:");
|
---|
[15033] | 620 | if (lj.contains(urlhttps)) {
|
---|
| 621 | myprintln("+ Missing https: "+getDescription(e));
|
---|
| 622 | eliUrls.put(urlhttps, eliUrls.get(urle));
|
---|
| 623 | eliUrls.remove(urle);
|
---|
| 624 | le.remove(urle);
|
---|
| 625 | lj.remove(urlhttps);
|
---|
| 626 | } else if (isNotBlank(ide)) {
|
---|
[17453] | 627 | checkUrlsEquality(ide, e, urle, le, lj);
|
---|
[13517] | 628 | }
|
---|
[7726] | 629 | }
|
---|
| 630 | }
|
---|
[13714] | 631 |
|
---|
[15033] | 632 | myprintln("*** URLs found in ELI but not in JOSM ("+le.size()+"): ***");
|
---|
| 633 | Collections.sort(le);
|
---|
[13593] | 634 | if (!le.isEmpty()) {
|
---|
[15033] | 635 | for (String l : le) {
|
---|
[19137] | 636 | String e = "";
|
---|
| 637 | if(idUrls.get(l) != null && rapidUrls.get(l) != null)
|
---|
| 638 | e = " **iD+Rapid**";
|
---|
| 639 | else if(idUrls.get(l) != null)
|
---|
| 640 | e = " **iD**";
|
---|
| 641 | else if(rapidUrls.get(l) != null)
|
---|
| 642 | e = " **Rapid**";
|
---|
| 643 | myprintln("- " + getDescription(eliUrls.get(l)) + e);
|
---|
[11412] | 644 | }
|
---|
[7726] | 645 | }
|
---|
[15033] | 646 | myprintln("*** URLs found in JOSM but not in ELI ("+lj.size()+"): ***");
|
---|
| 647 | Collections.sort(lj);
|
---|
[13593] | 648 | if (!lj.isEmpty()) {
|
---|
[15033] | 649 | for (String l : lj) {
|
---|
| 650 | myprintln("+ " + getDescription(josmUrls.get(l)));
|
---|
[11412] | 651 | }
|
---|
[7726] | 652 | }
|
---|
| 653 | }
|
---|
[9667] | 654 |
|
---|
[17453] | 655 | void checkUrlsEquality(String ide, JsonObject e, String urle, List<String> le, List<String> lj) {
|
---|
| 656 | for (String urlj : new LinkedList<>(lj)) {
|
---|
| 657 | ImageryInfo j = josmUrls.get(urlj);
|
---|
| 658 | String idj = getId(j);
|
---|
| 659 |
|
---|
| 660 | if (checkUrlEquality(ide, "id", idj, e, j, urle, urlj, le, lj)) {
|
---|
| 661 | return;
|
---|
| 662 | }
|
---|
| 663 | Collection<String> old = j.getOldIds();
|
---|
| 664 | if (old != null) {
|
---|
| 665 | for (String oidj : old) {
|
---|
| 666 | if (checkUrlEquality(ide, "oldid", oidj, e, j, urle, urlj, le, lj)) {
|
---|
| 667 | return;
|
---|
| 668 | }
|
---|
| 669 | }
|
---|
| 670 | }
|
---|
| 671 | }
|
---|
| 672 | }
|
---|
| 673 |
|
---|
| 674 | boolean checkUrlEquality(
|
---|
| 675 | String ide, String idtype, String idj, JsonObject e, ImageryInfo j, String urle, String urlj, List<String> le, List<String> lj) {
|
---|
| 676 | if (ide.equals(idj) && Objects.equals(getType(j), getType(e))) {
|
---|
| 677 | if (getType(j).equals("wms") && unifyWMS(urle).equals(unifyWMS(urlj))) {
|
---|
| 678 | myprintln("# WMS-URL for "+idtype+" "+idj+" modified: "+getDescription(j));
|
---|
| 679 | } else {
|
---|
| 680 | myprintln("* URL for "+idtype+" "+idj+" differs ("+urle+"): "+getDescription(j));
|
---|
| 681 | }
|
---|
| 682 | le.remove(urle);
|
---|
| 683 | lj.remove(urlj);
|
---|
| 684 | // replace key for this entry with JOSM URL
|
---|
| 685 | eliUrls.remove(urle);
|
---|
| 686 | eliUrls.put(urlj, e);
|
---|
| 687 | return true;
|
---|
| 688 | }
|
---|
| 689 | return false;
|
---|
| 690 | }
|
---|
| 691 |
|
---|
[15692] | 692 | void checkCommonEntries() {
|
---|
[15034] | 693 | doSameUrlButDifferentName();
|
---|
| 694 | doSameUrlButDifferentId();
|
---|
| 695 | doSameUrlButDifferentType();
|
---|
| 696 | doSameUrlButDifferentZoomBounds();
|
---|
| 697 | doSameUrlButDifferentCountryCode();
|
---|
| 698 | doSameUrlButDifferentQuality();
|
---|
| 699 | doSameUrlButDifferentDates();
|
---|
| 700 | doSameUrlButDifferentInformation();
|
---|
| 701 | doMismatchingShapes();
|
---|
| 702 | doMismatchingIcons();
|
---|
[15692] | 703 | doMismatchingCategories();
|
---|
[15034] | 704 | doMiscellaneousChecks();
|
---|
| 705 | }
|
---|
| 706 |
|
---|
[15692] | 707 | void doSameUrlButDifferentName() {
|
---|
[15033] | 708 | myprintln("*** Same URL, but different name: ***");
|
---|
| 709 | for (String url : eliUrls.keySet()) {
|
---|
| 710 | JsonObject e = eliUrls.get(url);
|
---|
| 711 | if (!josmUrls.containsKey(url)) continue;
|
---|
| 712 | ImageryInfo j = josmUrls.get(url);
|
---|
[15034] | 713 | String ename = getName(e).replace("'", "\u2019");
|
---|
| 714 | String jname = getName(j).replace("'", "\u2019");
|
---|
[11951] | 715 | if (!ename.equals(jname)) {
|
---|
[15033] | 716 | myprintln("* Name differs ('"+getName(e)+"' != '"+getName(j)+"'): "+getUrl(j));
|
---|
[7726] | 717 | }
|
---|
| 718 | }
|
---|
[15034] | 719 | }
|
---|
[9667] | 720 |
|
---|
[15692] | 721 | void doSameUrlButDifferentId() {
|
---|
[15033] | 722 | myprintln("*** Same URL, but different Id: ***");
|
---|
| 723 | for (String url : eliUrls.keySet()) {
|
---|
| 724 | JsonObject e = eliUrls.get(url);
|
---|
| 725 | if (!josmUrls.containsKey(url)) continue;
|
---|
| 726 | ImageryInfo j = josmUrls.get(url);
|
---|
| 727 | String ename = getId(e);
|
---|
| 728 | String jname = getId(j);
|
---|
| 729 | if (!Objects.equals(ename, jname)) {
|
---|
| 730 | myprintln("# Id differs ('"+getId(e)+"' != '"+getId(j)+"'): "+getUrl(j));
|
---|
[12126] | 731 | }
|
---|
[12226] | 732 | }
|
---|
[15034] | 733 | }
|
---|
[12126] | 734 |
|
---|
[15692] | 735 | void doSameUrlButDifferentType() {
|
---|
[15033] | 736 | myprintln("*** Same URL, but different type: ***");
|
---|
| 737 | for (String url : eliUrls.keySet()) {
|
---|
| 738 | JsonObject e = eliUrls.get(url);
|
---|
| 739 | if (!josmUrls.containsKey(url)) continue;
|
---|
| 740 | ImageryInfo j = josmUrls.get(url);
|
---|
| 741 | if (!Objects.equals(getType(e), getType(j))) {
|
---|
| 742 | myprintln("* Type differs ("+getType(e)+" != "+getType(j)+"): "+getName(j)+" - "+getUrl(j));
|
---|
[7726] | 743 | }
|
---|
| 744 | }
|
---|
[15034] | 745 | }
|
---|
[9667] | 746 |
|
---|
[15692] | 747 | void doSameUrlButDifferentZoomBounds() {
|
---|
[15033] | 748 | myprintln("*** Same URL, but different zoom bounds: ***");
|
---|
| 749 | for (String url : eliUrls.keySet()) {
|
---|
| 750 | JsonObject e = eliUrls.get(url);
|
---|
| 751 | if (!josmUrls.containsKey(url)) continue;
|
---|
| 752 | ImageryInfo j = josmUrls.get(url);
|
---|
[7726] | 753 |
|
---|
[15033] | 754 | Integer eMinZoom = getMinZoom(e);
|
---|
| 755 | Integer jMinZoom = getMinZoom(j);
|
---|
[13997] | 756 | /* dont warn for entries copied from the base of the mirror */
|
---|
[15033] | 757 | if (eMinZoom == null && "wms".equals(getType(j)) && j.getName().contains(" mirror"))
|
---|
[13997] | 758 | jMinZoom = null;
|
---|
[15033] | 759 | if (!Objects.equals(eMinZoom, jMinZoom) && !(Objects.equals(eMinZoom, 0) && jMinZoom == null)) {
|
---|
| 760 | myprintln("* Minzoom differs ("+eMinZoom+" != "+jMinZoom+"): "+getDescription(j));
|
---|
[7726] | 761 | }
|
---|
[15033] | 762 | Integer eMaxZoom = getMaxZoom(e);
|
---|
| 763 | Integer jMaxZoom = getMaxZoom(j);
|
---|
[13997] | 764 | /* dont warn for entries copied from the base of the mirror */
|
---|
[15033] | 765 | if (eMaxZoom == null && "wms".equals(getType(j)) && j.getName().contains(" mirror"))
|
---|
[13997] | 766 | jMaxZoom = null;
|
---|
[15033] | 767 | if (!Objects.equals(eMaxZoom, jMaxZoom)) {
|
---|
| 768 | myprintln("* Maxzoom differs ("+eMaxZoom+" != "+jMaxZoom+"): "+getDescription(j));
|
---|
[7726] | 769 | }
|
---|
| 770 | }
|
---|
[15034] | 771 | }
|
---|
[9667] | 772 |
|
---|
[15692] | 773 | void doSameUrlButDifferentCountryCode() {
|
---|
[15033] | 774 | myprintln("*** Same URL, but different country code: ***");
|
---|
| 775 | for (String url : eliUrls.keySet()) {
|
---|
| 776 | JsonObject e = eliUrls.get(url);
|
---|
| 777 | if (!josmUrls.containsKey(url)) continue;
|
---|
| 778 | ImageryInfo j = josmUrls.get(url);
|
---|
| 779 | String cce = getCountryCode(e);
|
---|
[13931] | 780 | if ("ZZ".equals(cce)) { /* special ELI country code */
|
---|
[15033] | 781 | cce = null;
|
---|
[13931] | 782 | }
|
---|
[15033] | 783 | if (cce != null && !cce.equals(getCountryCode(j))) {
|
---|
| 784 | myprintln("* Country code differs ("+getCountryCode(e)+" != "+getCountryCode(j)+"): "+getDescription(j));
|
---|
[7726] | 785 | }
|
---|
| 786 | }
|
---|
[15034] | 787 | }
|
---|
| 788 |
|
---|
[15692] | 789 | void doSameUrlButDifferentQuality() {
|
---|
[15033] | 790 | myprintln("*** Same URL, but different quality: ***");
|
---|
| 791 | for (String url : eliUrls.keySet()) {
|
---|
| 792 | JsonObject e = eliUrls.get(url);
|
---|
[9515] | 793 | if (!josmUrls.containsKey(url)) {
|
---|
[15033] | 794 | String q = getQuality(e);
|
---|
| 795 | if ("eli-best".equals(q)) {
|
---|
| 796 | myprintln("- Quality best entry not in JOSM for "+getDescription(e));
|
---|
[9515] | 797 | }
|
---|
[15033] | 798 | continue;
|
---|
[9515] | 799 | }
|
---|
[15033] | 800 | ImageryInfo j = josmUrls.get(url);
|
---|
| 801 | if (!Objects.equals(getQuality(e), getQuality(j))) {
|
---|
| 802 | myprintln("* Quality differs ("+getQuality(e)+" != "+getQuality(j)+"): "+getDescription(j));
|
---|
[9505] | 803 | }
|
---|
[11599] | 804 | }
|
---|
[15034] | 805 | }
|
---|
| 806 |
|
---|
[15692] | 807 | void doSameUrlButDifferentDates() {
|
---|
[15033] | 808 | myprintln("*** Same URL, but different dates: ***");
|
---|
| 809 | Pattern pattern = Pattern.compile("^(.*;)(\\d\\d\\d\\d)(-(\\d\\d)(-(\\d\\d))?)?$");
|
---|
| 810 | for (String url : eliUrls.keySet()) {
|
---|
| 811 | String ed = getDate(eliUrls.get(url));
|
---|
| 812 | if (!josmUrls.containsKey(url)) continue;
|
---|
| 813 | ImageryInfo j = josmUrls.get(url);
|
---|
| 814 | String jd = getDate(j);
|
---|
[11612] | 815 | // The forms 2015;- or -;2015 or 2015;2015 are handled equal to 2015
|
---|
[15034] | 816 | String ef = ed.replaceAll("\\A-;", "").replaceAll(";-\\z", "").replaceAll("\\A([0-9-]+);\\1\\z", "$1");
|
---|
[11639] | 817 | // ELI has a strange and inconsistent used end_date definition, so we try again with subtraction by one
|
---|
[15033] | 818 | String ed2 = ed;
|
---|
| 819 | Matcher m = pattern.matcher(ed);
|
---|
| 820 | if (m.matches()) {
|
---|
| 821 | Calendar cal = Calendar.getInstance();
|
---|
[19106] | 822 | cal.set(Integer.parseInt(m.group(2)),
|
---|
| 823 | m.group(4) == null ? 0 : Integer.parseInt(m.group(4))-1,
|
---|
| 824 | m.group(6) == null ? 1 : Integer.parseInt(m.group(6)));
|
---|
[15033] | 825 | cal.add(Calendar.DAY_OF_MONTH, -1);
|
---|
| 826 | ed2 = m.group(1) + cal.get(Calendar.YEAR);
|
---|
| 827 | if (m.group(4) != null)
|
---|
| 828 | ed2 += "-" + String.format("%02d", cal.get(Calendar.MONTH)+1);
|
---|
| 829 | if (m.group(6) != null)
|
---|
| 830 | ed2 += "-" + String.format("%02d", cal.get(Calendar.DAY_OF_MONTH));
|
---|
[11639] | 831 | }
|
---|
[15034] | 832 | String ef2 = ed2.replaceAll("\\A-;", "").replaceAll(";-\\z", "").replaceAll("\\A([0-9-]+);\\1\\z", "$1");
|
---|
[11639] | 833 | if (!ed.equals(jd) && !ef.equals(jd) && !ed2.equals(jd) && !ef2.equals(jd)) {
|
---|
[15033] | 834 | String t = "'"+ed+"'";
|
---|
[11612] | 835 | if (!ed.equals(ef)) {
|
---|
[15033] | 836 | t += " or '"+ef+"'";
|
---|
[11612] | 837 | }
|
---|
[11666] | 838 | if (jd.isEmpty()) {
|
---|
[15033] | 839 | myprintln("- Missing JOSM date ("+t+"): "+getDescription(j));
|
---|
[11668] | 840 | } else if (!ed.isEmpty()) {
|
---|
[15033] | 841 | myprintln("* Date differs ('"+t+"' != '"+jd+"'): "+getDescription(j));
|
---|
| 842 | } else if (!optionNoEli) {
|
---|
| 843 | myprintln("+ Missing ELI date ('"+jd+"'): "+getDescription(j));
|
---|
[11666] | 844 | }
|
---|
[11573] | 845 | }
|
---|
[11665] | 846 | }
|
---|
[15034] | 847 | }
|
---|
| 848 |
|
---|
[15692] | 849 | void doSameUrlButDifferentInformation() {
|
---|
[15033] | 850 | myprintln("*** Same URL, but different information: ***");
|
---|
| 851 | for (String url : eliUrls.keySet()) {
|
---|
| 852 | if (!josmUrls.containsKey(url)) continue;
|
---|
| 853 | JsonObject e = eliUrls.get(url);
|
---|
| 854 | ImageryInfo j = josmUrls.get(url);
|
---|
[11981] | 855 |
|
---|
[15082] | 856 | compareDescriptions(e, j);
|
---|
[16127] | 857 | comparePrivacyPolicyUrls(e, j);
|
---|
[15082] | 858 | comparePermissionReferenceUrls(e, j);
|
---|
| 859 | compareAttributionUrls(e, j);
|
---|
| 860 | compareAttributionTexts(e, j);
|
---|
| 861 | compareProjections(e, j);
|
---|
| 862 | compareDefaults(e, j);
|
---|
| 863 | compareOverlays(e, j);
|
---|
| 864 | compareNoTileHeaders(e, j);
|
---|
| 865 | }
|
---|
| 866 | }
|
---|
| 867 |
|
---|
[15692] | 868 | void compareDescriptions(JsonObject e, ImageryInfo j) {
|
---|
[15082] | 869 | String et = getDescriptions(e).getOrDefault("en", "");
|
---|
| 870 | String jt = getDescriptions(j).getOrDefault("en", "");
|
---|
| 871 | if (!et.equals(jt)) {
|
---|
| 872 | if (jt.isEmpty()) {
|
---|
| 873 | myprintln("- Missing JOSM description ("+et+"): "+getDescription(j));
|
---|
| 874 | } else if (!et.isEmpty()) {
|
---|
| 875 | myprintln("* Description differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
|
---|
| 876 | } else if (!optionNoEli) {
|
---|
| 877 | myprintln("+ Missing ELI description ('"+jt+"'): "+getDescription(j));
|
---|
[11981] | 878 | }
|
---|
[15082] | 879 | }
|
---|
| 880 | }
|
---|
[11981] | 881 |
|
---|
[16127] | 882 | void comparePrivacyPolicyUrls(JsonObject e, ImageryInfo j) {
|
---|
| 883 | String et = getPrivacyPolicyUrl(e);
|
---|
| 884 | String jt = getPrivacyPolicyUrl(j);
|
---|
| 885 | if (!Objects.equals(et, jt)) {
|
---|
| 886 | if (isBlank(jt)) {
|
---|
| 887 | myprintln("- Missing JOSM privacy policy URL ("+et+"): "+getDescription(j));
|
---|
| 888 | } else if (isNotBlank(et)) {
|
---|
[17053] | 889 | myprintln("* Privacy policy URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
|
---|
[16127] | 890 | } else if (!optionNoEli) {
|
---|
| 891 | myprintln("+ Missing ELI privacy policy URL ('"+jt+"'): "+getDescription(j));
|
---|
| 892 | }
|
---|
| 893 | }
|
---|
| 894 | }
|
---|
| 895 |
|
---|
[15692] | 896 | void comparePermissionReferenceUrls(JsonObject e, ImageryInfo j) {
|
---|
[15082] | 897 | String et = getPermissionReferenceUrl(e);
|
---|
| 898 | String jt = getPermissionReferenceUrl(j);
|
---|
| 899 | String jt2 = getTermsOfUseUrl(j);
|
---|
| 900 | if (isBlank(jt)) jt = jt2;
|
---|
| 901 | if (!Objects.equals(et, jt)) {
|
---|
| 902 | if (isBlank(jt)) {
|
---|
| 903 | myprintln("- Missing JOSM license URL ("+et+"): "+getDescription(j));
|
---|
| 904 | } else if (isNotBlank(et)) {
|
---|
| 905 | String ethttps = et.replace("http:", "https:");
|
---|
| 906 | if (isBlank(jt2) || !(jt2.equals(ethttps) || jt2.equals(et+"/") || jt2.equals(ethttps+"/"))) {
|
---|
| 907 | if (jt.equals(ethttps) || jt.equals(et+"/") || jt.equals(ethttps+"/")) {
|
---|
| 908 | myprintln("+ License URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
|
---|
| 909 | } else {
|
---|
| 910 | String ja = getAttributionUrl(j);
|
---|
| 911 | if (ja != null && (ja.equals(et) || ja.equals(ethttps) || ja.equals(et+"/") || ja.equals(ethttps+"/"))) {
|
---|
| 912 | myprintln("+ ELI License URL in JOSM Attribution: "+getDescription(j));
|
---|
[13578] | 913 | } else {
|
---|
[15082] | 914 | myprintln("* License URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
|
---|
[13578] | 915 | }
|
---|
[13551] | 916 | }
|
---|
[11981] | 917 | }
|
---|
[15082] | 918 | } else if (!optionNoEli) {
|
---|
| 919 | myprintln("+ Missing ELI license URL ('"+jt+"'): "+getDescription(j));
|
---|
[11981] | 920 | }
|
---|
[15082] | 921 | }
|
---|
| 922 | }
|
---|
[11981] | 923 |
|
---|
[15692] | 924 | void compareAttributionUrls(JsonObject e, ImageryInfo j) {
|
---|
[15082] | 925 | String et = getAttributionUrl(e);
|
---|
| 926 | String jt = getAttributionUrl(j);
|
---|
| 927 | if (!Objects.equals(et, jt)) {
|
---|
| 928 | if (isBlank(jt)) {
|
---|
| 929 | myprintln("- Missing JOSM attribution URL ("+et+"): "+getDescription(j));
|
---|
| 930 | } else if (isNotBlank(et)) {
|
---|
| 931 | String ethttps = et.replace("http:", "https:");
|
---|
| 932 | if (jt.equals(ethttps) || jt.equals(et+"/") || jt.equals(ethttps+"/")) {
|
---|
| 933 | myprintln("+ Attribution URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
|
---|
| 934 | } else {
|
---|
| 935 | myprintln("* Attribution URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
|
---|
[11981] | 936 | }
|
---|
[15082] | 937 | } else if (!optionNoEli) {
|
---|
| 938 | myprintln("+ Missing ELI attribution URL ('"+jt+"'): "+getDescription(j));
|
---|
[11981] | 939 | }
|
---|
[15082] | 940 | }
|
---|
| 941 | }
|
---|
[11981] | 942 |
|
---|
[15692] | 943 | void compareAttributionTexts(JsonObject e, ImageryInfo j) {
|
---|
[15082] | 944 | String et = getAttributionText(e);
|
---|
| 945 | String jt = getAttributionText(j);
|
---|
| 946 | if (!Objects.equals(et, jt)) {
|
---|
| 947 | if (isBlank(jt)) {
|
---|
| 948 | myprintln("- Missing JOSM attribution text ("+et+"): "+getDescription(j));
|
---|
| 949 | } else if (isNotBlank(et)) {
|
---|
| 950 | myprintln("* Attribution text differs ('"+et+"' != '"+jt+"'): "+getDescription(j));
|
---|
| 951 | } else if (!optionNoEli) {
|
---|
| 952 | myprintln("+ Missing ELI attribution text ('"+jt+"'): "+getDescription(j));
|
---|
[11981] | 953 | }
|
---|
[15082] | 954 | }
|
---|
| 955 | }
|
---|
[11981] | 956 |
|
---|
[15692] | 957 | void compareProjections(JsonObject e, ImageryInfo j) {
|
---|
[15082] | 958 | String et = getProjections(e).stream().sorted().collect(Collectors.joining(" "));
|
---|
| 959 | String jt = getProjections(j).stream().sorted().collect(Collectors.joining(" "));
|
---|
| 960 | if (!Objects.equals(et, jt)) {
|
---|
| 961 | if (isBlank(jt)) {
|
---|
| 962 | String t = getType(e);
|
---|
| 963 | if ("wms_endpoint".equals(t) || "tms".equals(t)) {
|
---|
| 964 | myprintln("+ ELI projections for type "+t+": "+getDescription(j));
|
---|
| 965 | } else {
|
---|
| 966 | myprintln("- Missing JOSM projections ("+et+"): "+getDescription(j));
|
---|
[11981] | 967 | }
|
---|
[15082] | 968 | } else if (isNotBlank(et)) {
|
---|
| 969 | if ("EPSG:3857 EPSG:4326".equals(et) || "EPSG:3857".equals(et) || "EPSG:4326".equals(et)) {
|
---|
| 970 | myprintln("+ ELI has minimal projections ('"+et+"' != '"+jt+"'): "+getDescription(j));
|
---|
| 971 | } else {
|
---|
| 972 | myprintln("* Projections differ ('"+et+"' != '"+jt+"'): "+getDescription(j));
|
---|
| 973 | }
|
---|
| 974 | } else if (!optionNoEli && !"tms".equals(getType(e))) {
|
---|
| 975 | myprintln("+ Missing ELI projections ('"+jt+"'): "+getDescription(j));
|
---|
[11981] | 976 | }
|
---|
[15082] | 977 | }
|
---|
| 978 | }
|
---|
[12226] | 979 |
|
---|
[15692] | 980 | void compareDefaults(JsonObject e, ImageryInfo j) {
|
---|
[15082] | 981 | boolean ed = getDefault(e);
|
---|
| 982 | boolean jd = getDefault(j);
|
---|
| 983 | if (ed != jd) {
|
---|
| 984 | if (!jd) {
|
---|
| 985 | myprintln("- Missing JOSM default: "+getDescription(j));
|
---|
| 986 | } else if (!optionNoEli) {
|
---|
| 987 | myprintln("+ Missing ELI default: "+getDescription(j));
|
---|
[12226] | 988 | }
|
---|
[15082] | 989 | }
|
---|
| 990 | }
|
---|
| 991 |
|
---|
[15692] | 992 | void compareOverlays(JsonObject e, ImageryInfo j) {
|
---|
[15082] | 993 | boolean eo = getOverlay(e);
|
---|
| 994 | boolean jo = getOverlay(j);
|
---|
| 995 | if (eo != jo) {
|
---|
| 996 | if (!jo) {
|
---|
| 997 | myprintln("- Missing JOSM overlay flag: "+getDescription(j));
|
---|
| 998 | } else if (!optionNoEli) {
|
---|
| 999 | myprintln("+ Missing ELI overlay flag: "+getDescription(j));
|
---|
[13536] | 1000 | }
|
---|
[11981] | 1001 | }
|
---|
[15034] | 1002 | }
|
---|
| 1003 |
|
---|
[15692] | 1004 | void compareNoTileHeaders(JsonObject e, ImageryInfo j) {
|
---|
[15082] | 1005 | Map<String, Set<String>> eh = getNoTileHeader(e);
|
---|
| 1006 | Map<String, Set<String>> jh = getNoTileHeader(j);
|
---|
| 1007 | if (!Objects.equals(eh, jh)) {
|
---|
[18208] | 1008 | if (Utils.isEmpty(jh)) {
|
---|
[15082] | 1009 | myprintln("- Missing JOSM no tile headers ("+eh+"): "+getDescription(j));
|
---|
[18211] | 1010 | } else if (!Utils.isEmpty(eh)) {
|
---|
[15082] | 1011 | myprintln("* No tile headers differ ('"+eh+"' != '"+jh+"'): "+getDescription(j));
|
---|
| 1012 | } else if (!optionNoEli) {
|
---|
| 1013 | myprintln("+ Missing ELI no tile headers ('"+jh+"'): "+getDescription(j));
|
---|
| 1014 | }
|
---|
| 1015 | }
|
---|
| 1016 | }
|
---|
| 1017 |
|
---|
[15692] | 1018 | void doMismatchingShapes() {
|
---|
[15033] | 1019 | myprintln("*** Mismatching shapes: ***");
|
---|
| 1020 | for (String url : josmUrls.keySet()) {
|
---|
| 1021 | ImageryInfo j = josmUrls.get(url);
|
---|
| 1022 | int num = 1;
|
---|
| 1023 | for (Shape shape : getShapes(j)) {
|
---|
| 1024 | List<Coordinate> p = shape.getPoints();
|
---|
[15034] | 1025 | if (!p.get(0).equals(p.get(p.size()-1))) {
|
---|
[18382] | 1026 | myprintln("~~~ JOSM shape "+num+" unclosed: "+getDescription(j));
|
---|
[11410] | 1027 | }
|
---|
[15033] | 1028 | for (int nump = 1; nump < p.size(); ++nump) {
|
---|
| 1029 | if (Objects.equals(p.get(nump-1), p.get(nump))) {
|
---|
[18382] | 1030 | myprintln("~~~ JOSM shape "+num+" double point at "+(nump-1)+": "+getDescription(j));
|
---|
[11964] | 1031 | }
|
---|
| 1032 | }
|
---|
[15033] | 1033 | ++num;
|
---|
[11410] | 1034 | }
|
---|
| 1035 | }
|
---|
[15033] | 1036 | for (String url : eliUrls.keySet()) {
|
---|
| 1037 | JsonObject e = eliUrls.get(url);
|
---|
| 1038 | int num = 1;
|
---|
| 1039 | List<Shape> s = null;
|
---|
[13771] | 1040 | try {
|
---|
[15033] | 1041 | s = getShapes(e);
|
---|
| 1042 | for (Shape shape : s) {
|
---|
| 1043 | List<Coordinate> p = shape.getPoints();
|
---|
[15034] | 1044 | if (!p.get(0).equals(p.get(p.size()-1)) && !optionNoEli) {
|
---|
[15033] | 1045 | myprintln("+++ ELI shape "+num+" unclosed: "+getDescription(e));
|
---|
[11964] | 1046 | }
|
---|
[15033] | 1047 | for (int nump = 1; nump < p.size(); ++nump) {
|
---|
| 1048 | if (Objects.equals(p.get(nump-1), p.get(nump))) {
|
---|
| 1049 | myprintln("+++ ELI shape "+num+" double point at "+(nump-1)+": "+getDescription(e));
|
---|
[13771] | 1050 | }
|
---|
| 1051 | }
|
---|
[15033] | 1052 | ++num;
|
---|
[11964] | 1053 | }
|
---|
[15033] | 1054 | } catch (IllegalArgumentException err) {
|
---|
| 1055 | String desc = getDescription(e);
|
---|
[17301] | 1056 | myprintln("+++ ELI shape contains invalid data for "+desc+": "+err.getMessage());
|
---|
[11410] | 1057 | }
|
---|
[13780] | 1058 | if (s == null || !josmUrls.containsKey(url)) {
|
---|
[15033] | 1059 | continue;
|
---|
[11410] | 1060 | }
|
---|
[15033] | 1061 | ImageryInfo j = josmUrls.get(url);
|
---|
| 1062 | List<Shape> js = getShapes(j);
|
---|
| 1063 | if (s.isEmpty() && !js.isEmpty()) {
|
---|
| 1064 | if (!optionNoEli) {
|
---|
| 1065 | myprintln("+ No ELI shape: "+getDescription(j));
|
---|
[11414] | 1066 | }
|
---|
[15034] | 1067 | } else if (js.isEmpty() && !s.isEmpty()) {
|
---|
[11415] | 1068 | // don't report boundary like 5 point shapes as difference
|
---|
[15033] | 1069 | if (s.size() != 1 || s.get(0).getPoints().size() != 5) {
|
---|
| 1070 | myprintln("- No JOSM shape: "+getDescription(j));
|
---|
[11415] | 1071 | }
|
---|
[15034] | 1072 | } else if (s.size() != js.size()) {
|
---|
[15033] | 1073 | myprintln("* Different number of shapes ("+s.size()+" != "+js.size()+"): "+getDescription(j));
|
---|
[11413] | 1074 | } else {
|
---|
[15033] | 1075 | boolean[] edone = new boolean[s.size()];
|
---|
| 1076 | boolean[] jdone = new boolean[js.size()];
|
---|
| 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 (ep.size() == jp.size() && !jdone[jnums]) {
|
---|
[14576] | 1082 | boolean err = false;
|
---|
[15034] | 1083 | for (int nump = 0; nump < ep.size() && !err; ++nump) {
|
---|
[15033] | 1084 | Coordinate ept = ep.get(nump);
|
---|
| 1085 | Coordinate jpt = jp.get(nump);
|
---|
[17737] | 1086 | if (differentCoordinate(ept.getLat(), jpt.getLat()) || differentCoordinate(ept.getLon(), jpt.getLon()))
|
---|
[15033] | 1087 | err = true;
|
---|
[11413] | 1088 | }
|
---|
[15034] | 1089 | if (!err) {
|
---|
[15033] | 1090 | edone[enums] = true;
|
---|
| 1091 | jdone[jnums] = true;
|
---|
| 1092 | break;
|
---|
[14576] | 1093 | }
|
---|
[11413] | 1094 | }
|
---|
| 1095 | }
|
---|
[11411] | 1096 | }
|
---|
[15033] | 1097 | for (int enums = 0; enums < s.size(); ++enums) {
|
---|
| 1098 | List<Coordinate> ep = s.get(enums).getPoints();
|
---|
| 1099 | for (int jnums = 0; jnums < js.size() && !edone[enums]; ++jnums) {
|
---|
| 1100 | List<Coordinate> jp = js.get(jnums).getPoints();
|
---|
| 1101 | if (ep.size() == jp.size() && !jdone[jnums]) {
|
---|
[14576] | 1102 | boolean err = false;
|
---|
[15033] | 1103 | for (int nump = 0; nump < ep.size() && !err; ++nump) {
|
---|
| 1104 | Coordinate ept = ep.get(nump);
|
---|
| 1105 | Coordinate jpt = jp.get(nump);
|
---|
[17737] | 1106 | if (differentCoordinate(ept.getLat(), jpt.getLat()) || differentCoordinate(ept.getLon(), jpt.getLon())) {
|
---|
[15033] | 1107 | String numtxt = Integer.toString(enums+1);
|
---|
| 1108 | if (enums != jnums) {
|
---|
| 1109 | numtxt += '/' + Integer.toString(jnums+1);
|
---|
| 1110 | }
|
---|
| 1111 | myprintln("* Different coordinate for point "+(nump+1)+" of shape "+numtxt+": "+getDescription(j));
|
---|
| 1112 | break;
|
---|
[14576] | 1113 | }
|
---|
| 1114 | }
|
---|
[15033] | 1115 | edone[enums] = true;
|
---|
| 1116 | jdone[jnums] = true;
|
---|
| 1117 | break;
|
---|
[14576] | 1118 | }
|
---|
| 1119 | }
|
---|
| 1120 | }
|
---|
[15033] | 1121 | for (int enums = 0; enums < s.size(); ++enums) {
|
---|
| 1122 | List<Coordinate> ep = s.get(enums).getPoints();
|
---|
| 1123 | for (int jnums = 0; jnums < js.size() && !edone[enums]; ++jnums) {
|
---|
| 1124 | List<Coordinate> jp = js.get(jnums).getPoints();
|
---|
| 1125 | if (!jdone[jnums]) {
|
---|
| 1126 | String numtxt = Integer.toString(enums+1);
|
---|
| 1127 | if (enums != jnums) {
|
---|
| 1128 | numtxt += '/' + Integer.toString(jnums+1);
|
---|
| 1129 | }
|
---|
[15699] | 1130 | myprintln("* Different number of points for shape "+numtxt+" ("+ep.size()+" ! = "+jp.size()+"): "
|
---|
[15034] | 1131 | + getDescription(j));
|
---|
[15033] | 1132 | edone[enums] = true;
|
---|
| 1133 | jdone[jnums] = true;
|
---|
| 1134 | break;
|
---|
[14576] | 1135 | }
|
---|
| 1136 | }
|
---|
| 1137 | }
|
---|
[11410] | 1138 | }
|
---|
| 1139 | }
|
---|
[15034] | 1140 | }
|
---|
| 1141 |
|
---|
[17737] | 1142 | private boolean differentCoordinate(double v1, double v2) {
|
---|
| 1143 | double epsilon = 0.00001;
|
---|
| 1144 | return Math.abs(v1 - v2) > epsilon;
|
---|
| 1145 | }
|
---|
| 1146 |
|
---|
[15692] | 1147 | void doMismatchingIcons() {
|
---|
[15033] | 1148 | myprintln("*** Mismatching icons: ***");
|
---|
[15692] | 1149 | doMismatching(this::compareIcons);
|
---|
| 1150 | }
|
---|
| 1151 |
|
---|
| 1152 | void doMismatchingCategories() {
|
---|
| 1153 | myprintln("*** Mismatching categories: ***");
|
---|
| 1154 | doMismatching(this::compareCategories);
|
---|
| 1155 | }
|
---|
| 1156 |
|
---|
| 1157 | void doMismatching(BiConsumer<ImageryInfo, JsonObject> comparator) {
|
---|
[15033] | 1158 | for (String url : eliUrls.keySet()) {
|
---|
[15692] | 1159 | if (josmUrls.containsKey(url)) {
|
---|
| 1160 | comparator.accept(josmUrls.get(url), eliUrls.get(url));
|
---|
[11420] | 1161 | }
|
---|
[15692] | 1162 | }
|
---|
| 1163 | }
|
---|
| 1164 |
|
---|
| 1165 | void compareIcons(ImageryInfo j, JsonObject e) {
|
---|
| 1166 | String ij = getIcon(j);
|
---|
| 1167 | String ie = getIcon(e);
|
---|
| 1168 | boolean ijok = isNotBlank(ij);
|
---|
| 1169 | boolean ieok = isNotBlank(ie);
|
---|
| 1170 | if (ijok && !ieok) {
|
---|
| 1171 | if (!optionNoEli) {
|
---|
| 1172 | myprintln("+ No ELI icon: "+getDescription(j));
|
---|
[11420] | 1173 | }
|
---|
[15692] | 1174 | } else if (!ijok && ieok) {
|
---|
| 1175 | myprintln("- No JOSM icon: "+getDescription(j));
|
---|
| 1176 | } else if (ijok && ieok && !Objects.equals(ij, ie) && !(
|
---|
| 1177 | (ie.startsWith("https://osmlab.github.io/editor-layer-index/")
|
---|
| 1178 | || ie.startsWith("https://raw.githubusercontent.com/osmlab/editor-layer-index/")) &&
|
---|
| 1179 | ij.startsWith("data:"))) {
|
---|
| 1180 | String iehttps = ie.replace("http:", "https:");
|
---|
| 1181 | if (ij.equals(iehttps)) {
|
---|
| 1182 | myprintln("+ Different icons: "+getDescription(j));
|
---|
| 1183 | } else {
|
---|
| 1184 | myprintln("* Different icons: "+getDescription(j));
|
---|
| 1185 | }
|
---|
[11420] | 1186 | }
|
---|
[15034] | 1187 | }
|
---|
| 1188 |
|
---|
[15692] | 1189 | void compareCategories(ImageryInfo j, JsonObject e) {
|
---|
| 1190 | String cj = getCategory(j);
|
---|
| 1191 | String ce = getCategory(e);
|
---|
| 1192 | boolean cjok = isNotBlank(cj);
|
---|
| 1193 | boolean ceok = isNotBlank(ce);
|
---|
| 1194 | if (cjok && !ceok) {
|
---|
| 1195 | if (!optionNoEli) {
|
---|
| 1196 | myprintln("+ No ELI category: "+getDescription(j));
|
---|
| 1197 | }
|
---|
| 1198 | } else if (!cjok && ceok) {
|
---|
| 1199 | myprintln("- No JOSM category: "+getDescription(j));
|
---|
| 1200 | } else if (cjok && ceok && !Objects.equals(cj, ce)) {
|
---|
[15699] | 1201 | myprintln("* Different categories ('"+ce+"' != '"+cj+"'): "+getDescription(j));
|
---|
[15692] | 1202 | }
|
---|
| 1203 | }
|
---|
| 1204 |
|
---|
| 1205 | void doMiscellaneousChecks() {
|
---|
[15033] | 1206 | myprintln("*** Miscellaneous checks: ***");
|
---|
| 1207 | Map<String, ImageryInfo> josmIds = new HashMap<>();
|
---|
| 1208 | Collection<String> all = Projections.getAllProjectionCodes();
|
---|
[13551] | 1209 | DomainValidator dv = DomainValidator.getInstance();
|
---|
[15033] | 1210 | for (String url : josmUrls.keySet()) {
|
---|
| 1211 | ImageryInfo j = josmUrls.get(url);
|
---|
| 1212 | String id = getId(j);
|
---|
| 1213 | if ("wms".equals(getType(j))) {
|
---|
| 1214 | String urlLc = url.toLowerCase(Locale.ENGLISH);
|
---|
| 1215 | if (getProjections(j).isEmpty()) {
|
---|
[18382] | 1216 | myprintln("~ WMS without projections: "+getDescription(j));
|
---|
[13526] | 1217 | } else {
|
---|
[15033] | 1218 | List<String> unsupported = new LinkedList<>();
|
---|
| 1219 | List<String> old = new LinkedList<>();
|
---|
| 1220 | for (String p : getProjectionsUnstripped(j)) {
|
---|
| 1221 | if ("CRS:84".equals(p)) {
|
---|
| 1222 | if (!urlLc.contains("version=1.3")) {
|
---|
[18382] | 1223 | myprintln("~ CRS:84 without WMS 1.3: "+getDescription(j));
|
---|
[13526] | 1224 | }
|
---|
[15033] | 1225 | } else if (oldproj.containsKey(p)) {
|
---|
| 1226 | old.add(p);
|
---|
| 1227 | } else if (!all.contains(p) && !ignoreproj.contains(p)) {
|
---|
| 1228 | unsupported.add(p);
|
---|
[13526] | 1229 | }
|
---|
| 1230 | }
|
---|
[15033] | 1231 | if (!unsupported.isEmpty()) {
|
---|
[18382] | 1232 | myprintln("~ Projections "+String.join(", ", unsupported)+" not supported by JOSM: "+getDescription(j));
|
---|
[13526] | 1233 | }
|
---|
[15033] | 1234 | for (String o : old) {
|
---|
[18382] | 1235 | myprintln("~ Projection "+o+" is an old unsupported code and has been replaced by "+oldproj.get(o)+": "
|
---|
[15034] | 1236 | + getDescription(j));
|
---|
[13527] | 1237 | }
|
---|
[13526] | 1238 | }
|
---|
[15033] | 1239 | if (urlLc.contains("version=1.3") && !urlLc.contains("crs={proj}")) {
|
---|
[18382] | 1240 | myprintln("~ WMS 1.3 with strange CRS specification: "+getDescription(j));
|
---|
[15033] | 1241 | } else if (urlLc.contains("version=1.1") && !urlLc.contains("srs={proj}")) {
|
---|
[18382] | 1242 | myprintln("~ WMS 1.1 with strange SRS specification: "+getDescription(j));
|
---|
[13526] | 1243 | }
|
---|
[13511] | 1244 | }
|
---|
[15033] | 1245 | List<String> urls = new LinkedList<>();
|
---|
| 1246 | if (!"scanex".equals(getType(j))) {
|
---|
| 1247 | urls.add(url);
|
---|
[13532] | 1248 | }
|
---|
[15033] | 1249 | String jt = getPermissionReferenceUrl(j);
|
---|
| 1250 | if (isNotBlank(jt) && !"Public Domain".equalsIgnoreCase(jt))
|
---|
| 1251 | urls.add(jt);
|
---|
| 1252 | jt = getTermsOfUseUrl(j);
|
---|
| 1253 | if (isNotBlank(jt))
|
---|
| 1254 | urls.add(jt);
|
---|
| 1255 | jt = getAttributionUrl(j);
|
---|
| 1256 | if (isNotBlank(jt))
|
---|
| 1257 | urls.add(jt);
|
---|
| 1258 | jt = getIcon(j);
|
---|
[15439] | 1259 | if (isNotBlank(jt)) {
|
---|
[15440] | 1260 | if (!jt.startsWith("data:image/"))
|
---|
[15439] | 1261 | urls.add(jt);
|
---|
| 1262 | else {
|
---|
[15440] | 1263 | try {
|
---|
| 1264 | new ImageProvider(jt).get();
|
---|
| 1265 | } catch (RuntimeException e) {
|
---|
[18382] | 1266 | myprintln("~ Strange Icon: "+getDescription(j));
|
---|
[15439] | 1267 | }
|
---|
| 1268 | }
|
---|
| 1269 | }
|
---|
[15163] | 1270 | Pattern patternU = Pattern.compile("^https?://([^/]+?)(:\\d+)?(/.*)?");
|
---|
[15033] | 1271 | for (String u : urls) {
|
---|
[15163] | 1272 | if (!patternU.matcher(u).matches() || u.matches(".*[ \t]+$")) {
|
---|
[18382] | 1273 | myprintln("~ Strange URL '"+u+"': "+getDescription(j));
|
---|
[15033] | 1274 | } else {
|
---|
[15163] | 1275 | try {
|
---|
[19106] | 1276 | URL jurl = new URL(u.replaceAll("\\{switch:[^}]*}", "x"));
|
---|
[15163] | 1277 | String domain = jurl.getHost();
|
---|
| 1278 | int port = jurl.getPort();
|
---|
| 1279 | if (!(domain.matches("^\\d+\\.\\d+\\.\\d+\\.\\d+$")) && !dv.isValid(domain))
|
---|
[18382] | 1280 | myprintln("~ Strange Domain '"+domain+"': "+getDescription(j));
|
---|
[15163] | 1281 | else if (80 == port || 443 == port) {
|
---|
[18382] | 1282 | myprintln("~ Useless port '"+port+"': "+getDescription(j));
|
---|
[15163] | 1283 | }
|
---|
| 1284 | } catch (MalformedURLException e) {
|
---|
[18382] | 1285 | myprintln("~ Malformed URL '"+u+"': "+getDescription(j)+" => "+e.getMessage());
|
---|
[13554] | 1286 | }
|
---|
[13551] | 1287 | }
|
---|
| 1288 | }
|
---|
| 1289 |
|
---|
[15033] | 1290 | if (josmMirrors.containsKey(url)) {
|
---|
| 1291 | continue;
|
---|
[11420] | 1292 | }
|
---|
[15033] | 1293 | if (isBlank(id)) {
|
---|
[18382] | 1294 | myprintln("~ No JOSM-ID: "+getDescription(j));
|
---|
[15033] | 1295 | } else if (josmIds.containsKey(id)) {
|
---|
[18382] | 1296 | myprintln("~ JOSM-ID "+id+" not unique: "+getDescription(j));
|
---|
[11420] | 1297 | } else {
|
---|
[15033] | 1298 | josmIds.put(id, j);
|
---|
[11420] | 1299 | }
|
---|
[15033] | 1300 | String d = getDate(j);
|
---|
| 1301 | if (isNotBlank(d)) {
|
---|
| 1302 | Pattern patternD = Pattern.compile("^(-|(\\d\\d\\d\\d)(-(\\d\\d)(-(\\d\\d))?)?)(;(-|(\\d\\d\\d\\d)(-(\\d\\d)(-(\\d\\d))?)?))?$");
|
---|
| 1303 | Matcher m = patternD.matcher(d);
|
---|
| 1304 | if (!m.matches()) {
|
---|
[18382] | 1305 | myprintln("~ JOSM-Date '"+d+"' is strange: "+getDescription(j));
|
---|
[11572] | 1306 | } else {
|
---|
| 1307 | try {
|
---|
[15033] | 1308 | Date first = verifyDate(m.group(2), m.group(4), m.group(6));
|
---|
| 1309 | Date second = verifyDate(m.group(9), m.group(11), m.group(13));
|
---|
| 1310 | if (second.compareTo(first) < 0) {
|
---|
[18382] | 1311 | myprintln("~ JOSM-Date '"+d+"' is strange (second earlier than first): "+getDescription(j));
|
---|
[11572] | 1312 | }
|
---|
[15034] | 1313 | } catch (Exception e) {
|
---|
[18382] | 1314 | myprintln("~ JOSM-Date '"+d+"' is strange ("+e.getMessage()+"): "+getDescription(j));
|
---|
[11572] | 1315 | }
|
---|
| 1316 | }
|
---|
[11603] | 1317 | }
|
---|
[15033] | 1318 | if (isNotBlank(getAttributionUrl(j)) && isBlank(getAttributionText(j))) {
|
---|
[18382] | 1319 | myprintln("~ Attribution link without text: "+getDescription(j));
|
---|
[12261] | 1320 | }
|
---|
[15033] | 1321 | if (isNotBlank(getLogoUrl(j)) && isBlank(getLogoImage(j))) {
|
---|
[18382] | 1322 | myprintln("~ Logo link without image: "+getDescription(j));
|
---|
[12261] | 1323 | }
|
---|
[15033] | 1324 | if (isNotBlank(getTermsOfUseText(j)) && isBlank(getTermsOfUseUrl(j))) {
|
---|
[18382] | 1325 | myprintln("~ Terms of Use text without link: "+getDescription(j));
|
---|
[12261] | 1326 | }
|
---|
[15033] | 1327 | List<Shape> js = getShapes(j);
|
---|
| 1328 | if (!js.isEmpty()) {
|
---|
| 1329 | double minlat = 1000;
|
---|
| 1330 | double minlon = 1000;
|
---|
| 1331 | double maxlat = -1000;
|
---|
| 1332 | double maxlon = -1000;
|
---|
| 1333 | for (Shape s: js) {
|
---|
| 1334 | for (Coordinate p: s.getPoints()) {
|
---|
| 1335 | double lat = p.getLat();
|
---|
| 1336 | double lon = p.getLon();
|
---|
[15034] | 1337 | if (lat > maxlat) maxlat = lat;
|
---|
| 1338 | if (lon > maxlon) maxlon = lon;
|
---|
| 1339 | if (lat < minlat) minlat = lat;
|
---|
| 1340 | if (lon < minlon) minlon = lon;
|
---|
[11422] | 1341 | }
|
---|
| 1342 | }
|
---|
[15033] | 1343 | ImageryBounds b = j.getBounds();
|
---|
[17737] | 1344 | if (differentCoordinate(b.getMinLat(), minlat)
|
---|
| 1345 | || differentCoordinate(b.getMinLon(), minlon)
|
---|
| 1346 | || differentCoordinate(b.getMaxLat(), maxlat)
|
---|
| 1347 | || differentCoordinate(b.getMaxLon(), maxlon)) {
|
---|
[18382] | 1348 | myprintln("~ Bounds do not match shape (is "+b.getMinLat()+","+b.getMinLon()+","+b.getMaxLat()+","+b.getMaxLon()
|
---|
[15034] | 1349 | + ", calculated <bounds min-lat='"+minlat+"' min-lon='"+minlon+"' max-lat='"+maxlat+"' max-lon='"+maxlon+"'>): "
|
---|
| 1350 | + getDescription(j));
|
---|
[11422] | 1351 | }
|
---|
| 1352 | }
|
---|
[15658] | 1353 | List<String> knownCategories = Arrays.asList(
|
---|
| 1354 | "photo", "elevation", "map", "historicmap", "osmbasedmap", "historicphoto", "qa", "other");
|
---|
[15033] | 1355 | String cat = getCategory(j);
|
---|
| 1356 | if (isBlank(cat)) {
|
---|
[18382] | 1357 | myprintln("~ No category: "+getDescription(j));
|
---|
[15033] | 1358 | } else if (!knownCategories.contains(cat)) {
|
---|
[18382] | 1359 | myprintln("~ Strange category "+cat+": "+getDescription(j));
|
---|
[13792] | 1360 | }
|
---|
[11420] | 1361 | }
|
---|
[7726] | 1362 | }
|
---|
[9667] | 1363 |
|
---|
[15033] | 1364 | /*
|
---|
[7726] | 1365 | * Utility functions that allow uniform access for both ImageryInfo and JsonObject.
|
---|
| 1366 | */
|
---|
[15033] | 1367 |
|
---|
[7726] | 1368 | static String getUrl(Object e) {
|
---|
[15033] | 1369 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getUrl();
|
---|
[19137] | 1370 | JsonObject p = ((Map<String, JsonObject>) e).get("properties");
|
---|
| 1371 | if (p != null)
|
---|
| 1372 | return p.getString("url");
|
---|
| 1373 | else
|
---|
| 1374 | return ((JsonObject)e).getString("template");
|
---|
[7726] | 1375 | }
|
---|
[15033] | 1376 |
|
---|
[12242] | 1377 | static String getUrlStripped(Object e) {
|
---|
[15034] | 1378 | return getUrl(e).replaceAll("\\?(apikey|access_token)=.*", "");
|
---|
[12242] | 1379 | }
|
---|
[15033] | 1380 |
|
---|
[11572] | 1381 | static String getDate(Object e) {
|
---|
[15033] | 1382 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getDate() != null ? ((ImageryInfo) e).getDate() : "";
|
---|
| 1383 | JsonObject p = ((Map<String, JsonObject>) e).get("properties");
|
---|
| 1384 | String start = p.containsKey("start_date") ? p.getString("start_date") : "";
|
---|
| 1385 | String end = p.containsKey("end_date") ? p.getString("end_date") : "";
|
---|
[15034] | 1386 | if (!start.isEmpty() && !end.isEmpty())
|
---|
[15033] | 1387 | return start+";"+end;
|
---|
[15034] | 1388 | else if (!start.isEmpty())
|
---|
[15033] | 1389 | return start+";-";
|
---|
[15034] | 1390 | else if (!end.isEmpty())
|
---|
[15033] | 1391 | return "-;"+end;
|
---|
| 1392 | return "";
|
---|
[11572] | 1393 | }
|
---|
[15033] | 1394 |
|
---|
| 1395 | static Date verifyDate(String year, String month, String day) throws ParseException {
|
---|
| 1396 | String date;
|
---|
[15034] | 1397 | if (year == null) {
|
---|
[15033] | 1398 | date = "3000-01-01";
|
---|
[11854] | 1399 | } else {
|
---|
[15033] | 1400 | date = year + "-" + (month == null ? "01" : month) + "-" + (day == null ? "01" : day);
|
---|
[11854] | 1401 | }
|
---|
[15033] | 1402 | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
---|
| 1403 | df.setLenient(false);
|
---|
| 1404 | return df.parse(date);
|
---|
[11572] | 1405 | }
|
---|
[15033] | 1406 |
|
---|
[11420] | 1407 | static String getId(Object e) {
|
---|
[15033] | 1408 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getId();
|
---|
| 1409 | return ((Map<String, JsonObject>) e).get("properties").getString("id");
|
---|
[11420] | 1410 | }
|
---|
[15033] | 1411 |
|
---|
[7726] | 1412 | static String getName(Object e) {
|
---|
[15033] | 1413 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getOriginalName();
|
---|
| 1414 | return ((Map<String, JsonObject>) e).get("properties").getString("name");
|
---|
[7726] | 1415 | }
|
---|
[15033] | 1416 |
|
---|
| 1417 | static List<ImageryInfo> getMirrors(Object e) {
|
---|
| 1418 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getMirrors();
|
---|
| 1419 | return Collections.emptyList();
|
---|
[11967] | 1420 | }
|
---|
[15033] | 1421 |
|
---|
| 1422 | static List<String> getProjections(Object e) {
|
---|
| 1423 | List<String> r = new ArrayList<>();
|
---|
| 1424 | List<String> u = getProjectionsUnstripped(e);
|
---|
[19106] | 1425 | for (String p : u) {
|
---|
| 1426 | if (!oldproj.containsKey(p) && !("CRS:84".equals(p) && !(getUrlStripped(e).matches("(?i)version=1\\.3")))) {
|
---|
| 1427 | r.add(p);
|
---|
[13530] | 1428 | }
|
---|
| 1429 | }
|
---|
[15033] | 1430 | return r;
|
---|
[13530] | 1431 | }
|
---|
[15033] | 1432 |
|
---|
| 1433 | static List<String> getProjectionsUnstripped(Object e) {
|
---|
| 1434 | List<String> r = null;
|
---|
[11975] | 1435 | if (e instanceof ImageryInfo) {
|
---|
[15033] | 1436 | r = ((ImageryInfo) e).getServerProjections();
|
---|
[11975] | 1437 | } else {
|
---|
[15033] | 1438 | JsonValue s = ((Map<String, JsonObject>) e).get("properties").get("available_projections");
|
---|
| 1439 | if (s != null) {
|
---|
| 1440 | r = new ArrayList<>();
|
---|
| 1441 | for (JsonValue p : s.asJsonArray()) {
|
---|
| 1442 | r.add(((JsonString) p).getString());
|
---|
[13530] | 1443 | }
|
---|
[11981] | 1444 | }
|
---|
[11975] | 1445 | }
|
---|
[15033] | 1446 | return r != null ? r : Collections.emptyList();
|
---|
[11975] | 1447 | }
|
---|
[15033] | 1448 |
|
---|
[16740] | 1449 | static void addJsonShapes(List<Shape> l, JsonArray a) {
|
---|
| 1450 | if (a.get(0).asJsonArray().get(0) instanceof JsonArray) {
|
---|
| 1451 | for (JsonValue sub: a.asJsonArray()) {
|
---|
| 1452 | addJsonShapes(l, sub.asJsonArray());
|
---|
| 1453 | }
|
---|
| 1454 | } else {
|
---|
| 1455 | Shape s = new Shape();
|
---|
| 1456 | for (JsonValue point: a.asJsonArray()) {
|
---|
| 1457 | JsonArray ar = point.asJsonArray();
|
---|
| 1458 | String lon = ar.getJsonNumber(0).toString();
|
---|
| 1459 | String lat = ar.getJsonNumber(1).toString();
|
---|
| 1460 | s.addPoint(lat, lon);
|
---|
| 1461 | }
|
---|
| 1462 | l.add(s);
|
---|
| 1463 | }
|
---|
| 1464 | }
|
---|
[16750] | 1465 |
|
---|
[11410] | 1466 | static List<Shape> getShapes(Object e) {
|
---|
| 1467 | if (e instanceof ImageryInfo) {
|
---|
[15033] | 1468 | ImageryBounds bounds = ((ImageryInfo) e).getBounds();
|
---|
[15034] | 1469 | if (bounds != null) {
|
---|
[15033] | 1470 | return bounds.getShapes();
|
---|
[11411] | 1471 | }
|
---|
[15033] | 1472 | return Collections.emptyList();
|
---|
[11410] | 1473 | }
|
---|
[15033] | 1474 | JsonValue ex = ((Map<String, JsonValue>) e).get("geometry");
|
---|
| 1475 | if (ex != null && !JsonValue.NULL.equals(ex) && !ex.asJsonObject().isNull("coordinates")) {
|
---|
| 1476 | JsonArray poly = ex.asJsonObject().getJsonArray("coordinates");
|
---|
| 1477 | List<Shape> l = new ArrayList<>();
|
---|
| 1478 | for (JsonValue shapes: poly) {
|
---|
[16740] | 1479 | addJsonShapes(l, shapes.asJsonArray());
|
---|
[11410] | 1480 | }
|
---|
[15033] | 1481 | return l;
|
---|
[11410] | 1482 | }
|
---|
[15033] | 1483 | return Collections.emptyList();
|
---|
[11410] | 1484 | }
|
---|
[15033] | 1485 |
|
---|
[7726] | 1486 | static String getType(Object e) {
|
---|
[15033] | 1487 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getImageryType().getTypeString();
|
---|
| 1488 | return ((Map<String, JsonObject>) e).get("properties").getString("type");
|
---|
[7726] | 1489 | }
|
---|
[15033] | 1490 |
|
---|
[7726] | 1491 | static Integer getMinZoom(Object e) {
|
---|
| 1492 | if (e instanceof ImageryInfo) {
|
---|
[15033] | 1493 | int mz = ((ImageryInfo) e).getMinZoom();
|
---|
| 1494 | return mz == 0 ? null : mz;
|
---|
[7726] | 1495 | } else {
|
---|
[15033] | 1496 | JsonNumber num = ((Map<String, JsonObject>) e).get("properties").getJsonNumber("min_zoom");
|
---|
| 1497 | if (num == null) return null;
|
---|
| 1498 | return num.intValue();
|
---|
[7726] | 1499 | }
|
---|
| 1500 | }
|
---|
[15033] | 1501 |
|
---|
[7726] | 1502 | static Integer getMaxZoom(Object e) {
|
---|
| 1503 | if (e instanceof ImageryInfo) {
|
---|
[15033] | 1504 | int mz = ((ImageryInfo) e).getMaxZoom();
|
---|
| 1505 | return mz == 0 ? null : mz;
|
---|
[7726] | 1506 | } else {
|
---|
[15033] | 1507 | JsonNumber num = ((Map<String, JsonObject>) e).get("properties").getJsonNumber("max_zoom");
|
---|
| 1508 | if (num == null) return null;
|
---|
| 1509 | return num.intValue();
|
---|
[7726] | 1510 | }
|
---|
| 1511 | }
|
---|
[15033] | 1512 |
|
---|
[7726] | 1513 | static String getCountryCode(Object e) {
|
---|
[15033] | 1514 | if (e instanceof ImageryInfo) return "".equals(((ImageryInfo) e).getCountryCode()) ? null : ((ImageryInfo) e).getCountryCode();
|
---|
| 1515 | return ((Map<String, JsonObject>) e).get("properties").getString("country_code", null);
|
---|
[7726] | 1516 | }
|
---|
[15033] | 1517 |
|
---|
[9505] | 1518 | static String getQuality(Object e) {
|
---|
[15033] | 1519 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).isBestMarked() ? "eli-best" : null;
|
---|
| 1520 | return (((Map<String, JsonObject>) e).get("properties").containsKey("best")
|
---|
| 1521 | && ((Map<String, JsonObject>) e).get("properties").getBoolean("best")) ? "eli-best" : null;
|
---|
[9505] | 1522 | }
|
---|
[15033] | 1523 |
|
---|
| 1524 | static boolean getOverlay(Object e) {
|
---|
| 1525 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).isOverlay();
|
---|
| 1526 | return (((Map<String, JsonObject>) e).get("properties").containsKey("overlay")
|
---|
| 1527 | && ((Map<String, JsonObject>) e).get("properties").getBoolean("overlay"));
|
---|
[13536] | 1528 | }
|
---|
[15033] | 1529 |
|
---|
[11420] | 1530 | static String getIcon(Object e) {
|
---|
[15033] | 1531 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getIcon();
|
---|
| 1532 | return ((Map<String, JsonObject>) e).get("properties").getString("icon", null);
|
---|
[11420] | 1533 | }
|
---|
[15033] | 1534 |
|
---|
[11975] | 1535 | static String getAttributionText(Object e) {
|
---|
[15033] | 1536 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getAttributionText(0, null, null);
|
---|
| 1537 | try {
|
---|
| 1538 | return ((Map<String, JsonObject>) e).get("properties").getJsonObject("attribution").getString("text", null);
|
---|
| 1539 | } catch (NullPointerException ex) {
|
---|
| 1540 | return null;
|
---|
| 1541 | }
|
---|
[11975] | 1542 | }
|
---|
[15033] | 1543 |
|
---|
[11975] | 1544 | static String getAttributionUrl(Object e) {
|
---|
[15033] | 1545 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getAttributionLinkURL();
|
---|
| 1546 | try {
|
---|
| 1547 | return ((Map<String, JsonObject>) e).get("properties").getJsonObject("attribution").getString("url", null);
|
---|
| 1548 | } catch (NullPointerException ex) {
|
---|
| 1549 | return null;
|
---|
| 1550 | }
|
---|
[11975] | 1551 | }
|
---|
[15033] | 1552 |
|
---|
[11975] | 1553 | static String getTermsOfUseText(Object e) {
|
---|
[15033] | 1554 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getTermsOfUseText();
|
---|
| 1555 | return null;
|
---|
[11975] | 1556 | }
|
---|
[15033] | 1557 |
|
---|
[11975] | 1558 | static String getTermsOfUseUrl(Object e) {
|
---|
[15033] | 1559 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getTermsOfUseURL();
|
---|
| 1560 | return null;
|
---|
[11975] | 1561 | }
|
---|
[15033] | 1562 |
|
---|
[13792] | 1563 | static String getCategory(Object e) {
|
---|
| 1564 | if (e instanceof ImageryInfo) {
|
---|
[15033] | 1565 | return ((ImageryInfo) e).getImageryCategoryOriginalString();
|
---|
[13792] | 1566 | }
|
---|
[15692] | 1567 | return ((Map<String, JsonObject>) e).get("properties").getString("category", null);
|
---|
[13792] | 1568 | }
|
---|
[15033] | 1569 |
|
---|
[12261] | 1570 | static String getLogoImage(Object e) {
|
---|
[15033] | 1571 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getAttributionImageRaw();
|
---|
| 1572 | return null;
|
---|
[12261] | 1573 | }
|
---|
[15033] | 1574 |
|
---|
[12261] | 1575 | static String getLogoUrl(Object e) {
|
---|
[15033] | 1576 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getAttributionImageURL();
|
---|
| 1577 | return null;
|
---|
[12261] | 1578 | }
|
---|
[15033] | 1579 |
|
---|
[11975] | 1580 | static String getPermissionReferenceUrl(Object e) {
|
---|
[15033] | 1581 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getPermissionReferenceURL();
|
---|
| 1582 | return ((Map<String, JsonObject>) e).get("properties").getString("license_url", null);
|
---|
[11975] | 1583 | }
|
---|
[15033] | 1584 |
|
---|
[16127] | 1585 | static String getPrivacyPolicyUrl(Object e) {
|
---|
| 1586 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getPrivacyPolicyURL();
|
---|
| 1587 | return ((Map<String, JsonObject>) e).get("properties").getString("privacy_policy_url", null);
|
---|
| 1588 | }
|
---|
| 1589 |
|
---|
[15082] | 1590 | static Map<String, Set<String>> getNoTileHeader(Object e) {
|
---|
| 1591 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).getNoTileHeaders();
|
---|
| 1592 | JsonObject nth = ((Map<String, JsonObject>) e).get("properties").getJsonObject("no_tile_header");
|
---|
| 1593 | return nth == null ? null : nth.keySet().stream().collect(Collectors.toMap(
|
---|
| 1594 | Function.identity(),
|
---|
| 1595 | k -> nth.getJsonArray(k).stream().map(x -> ((JsonString) x).getString()).collect(Collectors.toSet())));
|
---|
| 1596 | }
|
---|
| 1597 |
|
---|
[15034] | 1598 | static Map<String, String> getDescriptions(Object e) {
|
---|
[15082] | 1599 | Map<String, String> res = new HashMap<>();
|
---|
[11975] | 1600 | if (e instanceof ImageryInfo) {
|
---|
[15033] | 1601 | String a = ((ImageryInfo) e).getDescription();
|
---|
| 1602 | if (a != null) res.put("en", a);
|
---|
[11975] | 1603 | } else {
|
---|
[15033] | 1604 | String a = ((Map<String, JsonObject>) e).get("properties").getString("description", null);
|
---|
[15034] | 1605 | if (a != null) res.put("en", a.replaceAll("''", "'"));
|
---|
[11975] | 1606 | }
|
---|
[15033] | 1607 | return res;
|
---|
[11975] | 1608 | }
|
---|
[15033] | 1609 |
|
---|
| 1610 | static boolean getValidGeoreference(Object e) {
|
---|
| 1611 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).isGeoreferenceValid();
|
---|
| 1612 | return false;
|
---|
[11975] | 1613 | }
|
---|
[15033] | 1614 |
|
---|
| 1615 | static boolean getDefault(Object e) {
|
---|
| 1616 | if (e instanceof ImageryInfo) return ((ImageryInfo) e).isDefaultEntry();
|
---|
| 1617 | return ((Map<String, JsonObject>) e).get("properties").getBoolean("default", false);
|
---|
[12226] | 1618 | }
|
---|
[15033] | 1619 |
|
---|
[7726] | 1620 | String getDescription(Object o) {
|
---|
[15033] | 1621 | String url = getUrl(o);
|
---|
| 1622 | String cc = getCountryCode(o);
|
---|
[7726] | 1623 | if (cc == null) {
|
---|
[15033] | 1624 | ImageryInfo j = josmUrls.get(url);
|
---|
| 1625 | if (j != null) cc = getCountryCode(j);
|
---|
[7726] | 1626 | if (cc == null) {
|
---|
[15033] | 1627 | JsonObject e = eliUrls.get(url);
|
---|
| 1628 | if (e != null) cc = getCountryCode(e);
|
---|
[7726] | 1629 | }
|
---|
| 1630 | }
|
---|
| 1631 | if (cc == null) {
|
---|
[15033] | 1632 | cc = "";
|
---|
[7726] | 1633 | } else {
|
---|
[15033] | 1634 | cc = "["+cc+"] ";
|
---|
[7726] | 1635 | }
|
---|
[15878] | 1636 | String name = getName(o);
|
---|
| 1637 | String id = getId(o);
|
---|
| 1638 | String d = cc;
|
---|
[18211] | 1639 | if (!Utils.isEmpty(name)) {
|
---|
[15878] | 1640 | d += name;
|
---|
[18211] | 1641 | if (!Utils.isEmpty(id))
|
---|
[15878] | 1642 | d += " ["+id+"]";
|
---|
[18211] | 1643 | } else if (!Utils.isEmpty(url))
|
---|
[15878] | 1644 | d += url;
|
---|
[15033] | 1645 | if (optionShorten) {
|
---|
| 1646 | if (d.length() > MAXLEN) d = d.substring(0, MAXLEN-1) + "...";
|
---|
[7726] | 1647 | }
|
---|
[15033] | 1648 | return d;
|
---|
[7726] | 1649 | }
|
---|
| 1650 | }
|
---|