Changeset 19137 in josm for trunk/scripts


Ignore:
Timestamp:
2024-07-10T16:56:12+02:00 (4 months ago)
Author:
stoecker
Message:

add iD and Rapid to editor sync

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/SyncEditorLayerIndex.java

    r19106 r19137  
    8888    private List<ImageryInfo> josmEntries;
    8989    private JsonArray eliEntries;
     90    private JsonArray idEntries;
     91    private JsonArray rapidEntries;
    9092
    9193    private final Map<String, JsonObject> eliUrls = new HashMap<>();
     94    private final Map<String, JsonObject> idUrls = new HashMap<>();
     95    private final Map<String, JsonObject> rapidUrls = new HashMap<>();
    9296    private final Map<String, ImageryInfo> josmUrls = new HashMap<>();
    9397    private final Map<String, ImageryInfo> josmMirrors = new HashMap<>();
     
    96100
    97101    private static String eliInputFile = "imagery_eli.geojson";
     102    private static String idInputFile = "imagery_id.geojson";
     103    private static String rapidInputFile = "imagery_rapid.geojson";
    98104    private static String josmInputFile = "imagery_josm.imagery.xml";
    99105    private static String ignoreInputFile = "imagery_josm.ignores.txt";
     
    136142        }
    137143        script.loadELIEntries();
     144        script.loadELIUsers();
    138145        if (optionEliXml != null) {
    139146            try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(optionEliXml), UTF_8)) {
     
    162169        "-e,--eli_input <eli_input>         Input file for the editor layer index (geojson). " +
    163170                                            "Default is imagery_eli.geojson (current directory).\n" +
     171        "-d,--id_input <id_input>           Input file for the id index (geojson). " +
     172                                            "Default is imagery_id.geojson (current directory).\n" +
    164173        "-h,--help                          show this help\n" +
    165174        "-i,--ignore_input <ignore_input>   Input file for the ignore list. Default is imagery_josm.ignores.txt (current directory).\n" +
    166175        "-j,--josm_input <josm_input>       Input file for the JOSM imagery list (xml). " +
    167176                                            "Default is imagery_josm.imagery.xml (current directory).\n" +
    168         "-m,--noeli                         don't show output for ELI problems\n" +
     177        "-m,--noeli                         don't show output for ELI, Rapid or iD problems\n" +
    169178        "-n,--noskip                        don't skip known entries\n" +
    170179        "-o,--output <output>               Output file, - prints to stdout (default: -)\n" +
    171180        "-p,--elixml <elixml>               ELI entries for use in JOSM as XML file (incomplete)\n" +
    172181        "-q,--josmxml <josmxml>             JOSM entries reoutput as XML file (incomplete)\n" +
     182        "-r,--rapid_input <rapid_input>     Input file for the rapid index (geojson). " +
     183                                            "Default is imagery_rapid.geojson (current directory).\n" +
    173184        "-s,--shorten                       shorten the output, so it is easier to read in a console window\n" +
    174185        "-x,--xhtmlbody                     create XHTML body for display in a web page\n" +
     
    189200                .addArgumentParameter("eli_input", OptionCount.OPTIONAL, x -> eliInputFile = x)
    190201                .addShortAlias("eli_input", "e")
     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")
    191206                .addArgumentParameter("josm_input", OptionCount.OPTIONAL, x -> josmInputFile = x)
    192207                .addShortAlias("josm_input", "j")
     
    370385        }
    371386        myprintln("*** Loaded "+eliEntries.size()+" entries (ELI). ***");
     387    }
     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). ***");
    372409    }
    373410
     
    450487                stream.write("        <icon>"+cdata(t)+"</icon>\n");
    451488            for (Entry<String, String> d : getDescriptions(e).entrySet()) {
    452                 stream.write("        <description lang=\""+d.getKey()+"\">"+d.getValue()+"</description>\n");
     489                stream.write("        <description lang=\""+d.getKey()+"\">"+cdata(d.getValue(), true)+"</description>\n");
    453490            }
    454491            for (ImageryInfo m : getMirrors(e)) {
     
    597634        if (!le.isEmpty()) {
    598635            for (String l : le) {
    599                 myprintln("-  " + getDescription(eliUrls.get(l)));
     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);
    600644            }
    601645        }
     
    13241368    static String getUrl(Object e) {
    13251369        if (e instanceof ImageryInfo) return ((ImageryInfo) e).getUrl();
    1326         return ((Map<String, JsonObject>) e).get("properties").getString("url");
     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");
    13271375    }
    13281376
Note: See TracChangeset for help on using the changeset viewer.