Ignore:
Timestamp:
2017-04-21T11:54:35+02:00 (7 years ago)
Author:
stoecker
Message:

add maps sanitity check (will cause new red entries) for double points in bounds, first part for proper formatted XML output in sync script to make copying data easier

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/SyncEditorLayerIndex.groovy

    r11951 r11964  
    5353        script.start()
    5454        script.loadJosmEntries()
     55        if(options.josmxml) {
     56            def file = new FileWriter(options.josmxml)
     57            def stream = new BufferedWriter(file)
     58            script.printentries(script.josmEntries, stream)
     59        }
    5560        script.loadELIEntries()
     61        if(options.elixml) {
     62            def file = new FileWriter(options.elixml)
     63            def stream = new BufferedWriter(file)
     64            script.printentries(script.eliEntries, stream)
     65        }
    5666        script.checkInOneButNotTheOther()
    5767        script.checkCommonEntries()
     
    7888        cli.x(longOpt:'xhtmlbody', argName:"xhtmlbody", "create XHTML body for display in a web page")
    7989        cli.X(longOpt:'xhtml', argName:"xhtml", "create XHTML for display in a web page")
     90        cli.p(longOpt:'elixml', args:1, argName:"elixml", "ELI entries for use in JOSM as XML file (incomplete)")
     91        cli.q(longOpt:'josmxml', args:1, argName:"josmxml", "JOSM entries reoutput as XML file (incomplete)")
    8092        cli.m(longOpt:'nomissingeli', argName:"nomissingeli", "don't show missing editor layer index entries")
    8193        cli.h(longOpt:'help', "show this help")
     
    120132    void myprintlnfinal(String s) {
    121133        if(outputStream != null) {
    122             outputStream.write(s);
    123             outputStream.newLine();
     134            outputStream.write(s)
     135            outputStream.newLine()
    124136        } else {
    125             println s;
     137            println s
    126138        }
    127139    }
     
    135147            }
    136148            if (!options.noskip) {
    137                 return;
     149                return
    138150            }
    139151        } else if(options.xhtmlbody || options.xhtml) {
     
    179191        }
    180192        myprintln "*** Loaded ${eliEntries.size()} entries (ELI). ***"
     193    }
     194
     195    void printentries(def entries, def stream) {
     196        stream.write "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
     197        stream.write "<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n"
     198        for (def e : entries) {
     199            def best = "eli-best".equals(getQuality(e))
     200            stream.write "    <entry"+(best ? " eli-best=\"true\"" : "" )+">\n"
     201            stream.write "        <name>${getName(e)}</name>\n"
     202            stream.write "        <id>${getId(e)}</id>\n"
     203            def minlat = 1000
     204            def minlon = 1000
     205            def maxlat = -1000
     206            def maxlon = -1000
     207            def shapes = ""
     208            def sep = "\n            "
     209            for(def s: getShapes(e)) {
     210                shapes += "            <shape>"
     211                def i = 0
     212                for(def p: s.getPoints()) {
     213                    def lat = p.getLat()
     214                    def lon = p.getLon()
     215                    if(lat > maxlat) maxlat = lat
     216                    if(lon > maxlon) maxlon = lon
     217                    if(lat < minlat) minlat = lat
     218                    if(lon < minlon) minlon = lon
     219                    if(!(i++%3)) {
     220                        shapes += sep + "    "
     221                    }
     222                    shapes += "<point lat='${String.format(Locale.ROOT, "%.7f",lat)}' lon='${String.format(Locale.ROOT, "%.7f",lon)}'/>"
     223                }
     224                shapes += sep + "</shape>\n"
     225            }
     226            if(shapes) {
     227                stream.write "        <bounds min-lat='${minlat}' min-lon='${minlon}' max-lat='${maxlat}' max-lon='${maxlon}'>\n"
     228                stream.write shapes + "        </bounds>\n"
     229                stream.write "    </entry>\n"
     230            }
     231        }
     232        stream.write "</imagery>\n"
     233        stream.close()
    181234    }
    182235
     
    313366            def jd = getDate(j)
    314367            // The forms 2015;- or -;2015 or 2015;2015 are handled equal to 2015
    315             String ef = ed.replaceAll("\\A-;","").replaceAll(";-\\z","").replaceAll("\\A([0-9-]+);\\1\\z","\$1");
     368            String ef = ed.replaceAll("\\A-;","").replaceAll(";-\\z","").replaceAll("\\A([0-9-]+);\\1\\z","\$1")
    316369            // ELI has a strange and inconsistent used end_date definition, so we try again with subtraction by one
    317             String ed2 = ed;
     370            String ed2 = ed
    318371            def reg = (ed =~ /^(.*;)(\d\d\d\d)(-(\d\d)(-(\d\d))?)?$/)
    319372            if(reg != null && reg.count == 1) {
    320                 Calendar cal = Calendar.getInstance();
     373                Calendar cal = Calendar.getInstance()
    321374                cal.set(reg[0][2] as Integer, reg[0][4] == null ? 0 : (reg[0][4] as Integer)-1, reg[0][6] == null ? 1 : reg[0][6] as Integer)
    322375                cal.add(Calendar.DAY_OF_MONTH, -1)
     
    327380                    ed2 += "-" + String.format("%02d", cal.get(Calendar.DAY_OF_MONTH))
    328381            }
    329             String ef2 = ed2.replaceAll("\\A-;","").replaceAll(";-\\z","").replaceAll("\\A([0-9-]+);\\1\\z","\$1");
     382            String ef2 = ed2.replaceAll("\\A-;","").replaceAll(";-\\z","").replaceAll("\\A([0-9-]+);\\1\\z","\$1")
    330383            if (!ed.equals(jd) && !ef.equals(jd) && !ed2.equals(jd) && !ef2.equals(jd)) {
    331                 String t = "'${ed}'";
     384                String t = "'${ed}'"
    332385                if (!ed.equals(ef)) {
    333                     t += " or '${ef}'";
     386                    t += " or '${ef}'"
    334387                }
    335388                if (jd.isEmpty()) {
     
    350403                if(!p[0].equals(p[p.size()-1])) {
    351404                    myprintln "+++ JOSM shape $num unclosed: ${getDescription(j)}"
     405                }
     406                for (def nump = 1; nump < p.size(); ++nump) {
     407                    if (p[nump-1] == p[nump]) {
     408                        myprintln "+++ JOSM shape $num double point at ${nump-1}: ${getDescription(j)}"
     409                    }
    352410                }
    353411                ++num
     
    362420                if(!p[0].equals(p[p.size()-1]) && !options.nomissingeli) {
    363421                    myprintln "+++ ELI shape $num unclosed: ${getDescription(e)}"
     422                }
     423                for (def nump = 1; nump < p.size(); ++nump) {
     424                    if (p[nump-1] == p[nump]) {
     425                        myprintln "+++ ELI shape $num double point at ${nump-1}: ${getDescription(e)}"
     426                    }
    364427                }
    365428                ++num
     
    426489            def id = getId(j)
    427490            if(josmMirrors.containsKey(url)) {
    428                 continue;
     491                continue
    429492            }
    430493            if(id == null) {
     
    433496                myprintln "* JOSM-ID ${id} not unique: ${getDescription(j)}"
    434497            } else {
    435                 josmIds.put(id, j);
     498                josmIds.put(id, j)
    436499            }
    437500            def d = getDate(j)
     
    442505                } else {
    443506                    try {
    444                         def first = verifyDate(reg[0][2],reg[0][4],reg[0][6]);
    445                         def second = verifyDate(reg[0][9],reg[0][11],reg[0][13]);
     507                        def first = verifyDate(reg[0][2],reg[0][4],reg[0][6])
     508                        def second = verifyDate(reg[0][9],reg[0][11],reg[0][13])
    446509                        if(second.compareTo(first) < 0) {
    447510                            myprintln "* JOSM-Date '${d}' is strange (second earlier than first): ${getDescription(j)}"
     
    455518            def js = getShapes(j)
    456519            if(js.size()) {
    457                 def minlat = 1000;
    458                 def minlon = 1000;
    459                 def maxlat = -1000;
    460                 def maxlon = -1000;
     520                def minlat = 1000
     521                def minlon = 1000
     522                def maxlat = -1000
     523                def maxlon = -1000
    461524                for(def s: js) {
    462525                    for(def p: s.getPoints()) {
    463                         def lat = p.getLat();
    464                         def lon = p.getLon();
    465                         if(lat > maxlat) maxlat = lat;
    466                         if(lon > maxlon) maxlon = lon;
    467                         if(lat < minlat) minlat = lat;
    468                         if(lon < minlon) minlon = lon;
    469                     }
    470                 }
    471                 def b = j.getBounds();
     526                        def lat = p.getLat()
     527                        def lon = p.getLon()
     528                        if(lat > maxlat) maxlat = lat
     529                        if(lon > maxlon) maxlon = lon
     530                        if(lat < minlat) minlat = lat
     531                        if(lon < minlon) minlon = lon
     532                    }
     533                }
     534                def b = j.getBounds()
    472535                if(b.getMinLat() != minlat || b.getMinLon() != minlon || b.getMaxLat() != maxlat || b.getMaxLon() != maxlon) {
    473536                    myprintln "* Bounds do not match shape (is ${b.getMinLat()},${b.getMinLon()},${b.getMaxLat()},${b.getMaxLon()}, calculated <bounds min-lat='${minlat}' min-lon='${minlon}' max-lat='${maxlat}' max-lon='${maxlon}'>): ${getDescription(j)}"
     
    495558        else if(!end.isEmpty())
    496559            return "-;"+end
    497         return "";
     560        return ""
    498561    }
    499562    static Date verifyDate(String year, String month, String day) {
     
    518581    static List<Shape> getShapes(Object e) {
    519582        if (e instanceof ImageryInfo) {
    520             def bounds = e.getBounds();
     583            def bounds = e.getBounds()
    521584            if(bounds != null) {
    522                 return bounds.getShapes();
     585                return bounds.getShapes()
    523586            }
    524587            return []
Note: See TracChangeset for help on using the changeset viewer.