Changeset 13602 in josm


Ignore:
Timestamp:
2018-04-07T20:42:34+02:00 (7 years ago)
Author:
Don-vip
Message:

see #16129 - projections rework for new ESRI file

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/BuildProjectionDefinitions.java

    r13599 r13602  
    1313import java.util.Map;
    1414import java.util.TreeMap;
     15import java.util.regex.Matcher;
     16import java.util.regex.Pattern;
    1517
    1618import org.openstreetmap.josm.data.projection.CustomProjection;
     
    8183        if (list.isEmpty())
    8284            throw new AssertionError("EPSG file seems corrupted");
     85        Pattern badDmsPattern = Pattern.compile("(\\d+(?:\\.\\d+)?d\\d+(?:\\.\\d+)?')(N|S|E|W)");
    8386        for (ProjectionDefinition pd : list) {
    84             map.put(pd.code, pd);
     87            // DMS notation without second causes problems with cs2cs, add 0"
     88            Matcher matcher = badDmsPattern.matcher(pd.definition);
     89            StringBuffer sb = new StringBuffer();
     90            while (matcher.find()) {
     91                matcher.appendReplacement(sb, matcher.group(1) + "0\"" + matcher.group(2));
     92            }
     93            matcher.appendTail(sb);
     94            map.put(pd.code, new ProjectionDefinition(pd.code, pd.name, sb.toString()));
    8595        }
    8696    }
     
    113123                }
    114124            }
    115             out.write("## ESRI-specific projections (source: proj.4):\n");
     125            out.write("## ESRI-specific projections (source: ESRI):\n");
    116126            for (ProjectionDefinition pd : esriProj4.values()) {
    117127                pd = new ProjectionDefinition(pd.code, "ESRI: " + pd.name, pd.definition);
     
    194204            result = false;
    195205            noDeprecated++;
     206        }
     207
     208        // exclude projections failing
     209        if (Arrays.asList("EPSG:53025", "EPSG:54025", "EPSG:65062",
     210                "EPSG:102061", "EPSG:102062", "EPSG:102121", "EPSG:102212", "EPSG:102366", "EPSG:102445",
     211                "EPSG:102491", "EPSG:102591", "EPSG:102631", "EPSG:103232", "EPSG:103235", "EPSG:103238",
     212                "EPSG:103241", "EPSG:103371", "EPSG:103471", "EPSG:103474", "EPSG:103475"
     213                ).contains(pd.code)) {
     214            // 53025/54025: Unsuitable parameters 'lat_1' and 'lat_2' for two point method
     215            // Others: cs2cs errors to investigate
     216            result = false;
    196217        }
    197218
  • trunk/src/org/openstreetmap/josm/data/Bounds.java

    r13173 r13602  
    355355    public String toShortString(DecimalFormat format) {
    356356        return format.format(minLat) + ' '
    357         + format.format(minLon) + " / "
    358         + format.format(maxLat) + ' '
    359         + format.format(maxLon);
     357             + format.format(minLon) + " / "
     358             + format.format(maxLat) + ' '
     359             + format.format(maxLon);
    360360    }
    361361
     
    513513     */
    514514    public double getArea() {
    515         double w = getWidth();
    516         return w * (maxLat - minLat);
     515        return getWidth() * (maxLat - minLat);
    517516    }
    518517
     
    523522     */
    524523    public String encodeAsString(String separator) {
    525         StringBuilder sb = new StringBuilder();
    526         sb.append(minLat).append(separator).append(minLon)
    527         .append(separator).append(maxLat).append(separator)
    528         .append(maxLon);
    529         return sb.toString();
     524        return new StringBuilder()
     525          .append(minLat).append(separator).append(minLon).append(separator)
     526          .append(maxLat).append(separator).append(maxLon).toString();
    530527    }
    531528
     
    574571        Bounds bounds = (Bounds) obj;
    575572        return Double.compare(bounds.minLat, minLat) == 0 &&
    576                 Double.compare(bounds.minLon, minLon) == 0 &&
    577                 Double.compare(bounds.maxLat, maxLat) == 0 &&
    578                 Double.compare(bounds.maxLon, maxLon) == 0;
     573               Double.compare(bounds.minLon, minLon) == 0 &&
     574               Double.compare(bounds.maxLat, maxLat) == 0 &&
     575               Double.compare(bounds.maxLon, maxLon) == 0;
    579576    }
    580577}
  • trunk/src/org/openstreetmap/josm/data/coor/conversion/LatLonParser.java

    r12838 r13602  
    5050    private static final Pattern P_XML = Pattern.compile(
    5151            "lat=[\"']([+|-]?\\d+[.,]\\d+)[\"']\\s+lon=[\"']([+|-]?\\d+[.,]\\d+)[\"']");
     52
     53    private static final String FLOAT = "(\\d+(\\.\\d*)?)";
     54    /** Degree-Minute-Second pattern **/
     55    private static final String DMS = "(?<neg1>-)?"
     56            + "(?=\\d)(?:(?<single>" + FLOAT + ")|"
     57            + "((?<degree>" + FLOAT + ")d)?"
     58            + "((?<minutes>" + FLOAT + ")\')?"
     59            + "((?<seconds>" + FLOAT + ")\")?)"
     60            + "(?:[NE]|(?<neg2>[SW]))?";
     61    private static final Pattern P_DMS = Pattern.compile("^" + DMS + "$");
    5262
    5363    private static class LatLonHolder {
     
    199209     */
    200210    public static double parseCoordinate(String angleStr) {
    201         final String floatPattern = "(\\d+(\\.\\d*)?)";
    202211        // pattern does all error handling.
    203         Matcher in = Pattern.compile("^(?<neg1>-)?"
    204                 + "(?=\\d)(?:(?<single>" + floatPattern + ")|"
    205                 + "((?<degree>" + floatPattern + ")d)?"
    206                 + "((?<minutes>" + floatPattern + ")\')?"
    207                 + "((?<seconds>" + floatPattern + ")\")?)"
    208                 + "(?:[NE]|(?<neg2>[SW]))?$").matcher(angleStr);
     212        Matcher in = P_DMS.matcher(angleStr);
    209213
    210214        if (!in.find()) {
  • trunk/src/org/openstreetmap/josm/data/projection/Projections.java

    r13599 r13602  
    315315        List<ProjectionDefinition> result = new ArrayList<>();
    316316        Pattern epsgPattern = Pattern.compile("<(\\d+)>(.*)<>");
     317        String coor = "(-?\\d+\\.\\d+)";
     318        Pattern areaPattern = Pattern.compile("# area: \\(lat: "+coor+", "+coor+"\\) - \\(lon: "+coor+", "+coor+"\\).*");
    317319        StringBuilder sb = new StringBuilder();
     320        String bounds = null;
    318321        String line;
    319322        while ((line = r.readLine()) != null) {
    320323            line = line.trim();
    321             if (!line.isEmpty()) {
     324            if (!line.isEmpty() && !line.startsWith("##")) {
    322325                if (!line.startsWith("#")) {
    323326                    Matcher m = epsgPattern.matcher(line);
     
    325328                        String code = "EPSG:" + m.group(1);
    326329                        String definition = m.group(2).trim();
     330                        if (!definition.contains("+bounds=") && bounds != null) {
     331                            definition += bounds;
     332                        }
    327333                        result.add(new ProjectionDefinition(code, sb.toString(), definition));
    328334                    } else {
     
    330336                    }
    331337                    sb.setLength(0);
    332                 } else if (!line.startsWith("# area: ")) {
     338                    bounds = null;
     339                } else if (line.startsWith("# area: ")) {
     340                    Matcher m = areaPattern.matcher(line);
     341                    if (m.matches()) {
     342                        bounds = " +bounds=" + String.join(",", m.group(3), m.group(1), m.group(4), m.group(2));
     343                    }
     344                } else {
     345                    String s = line.substring(1).trim();
    333346                    if (sb.length() == 0) {
    334                         sb.append(line.substring(1).trim());
     347                        sb.append(s);
    335348                    } else {
    336                         sb.append('(').append(line.substring(1).trim()).append(')');
     349                        sb.append('(').append(s).append(')');
    337350                    }
    338351                }
  • trunk/test/unit/org/openstreetmap/josm/data/projection/CustomProjectionTest.java

    r11931 r13602  
    6161        assertEquals(1.1 + 3 / 60.0 + 5.2 / 3600.0, CustomProjection.parseAngle("1.1d3'5.2\"", "xxx"), 1e-10);
    6262
     63        assertEquals(1.1, CustomProjection.parseAngle("1.1dN", "xxx"), 1e-10);
     64        assertEquals(-1.1, CustomProjection.parseAngle("1.1dS", "xxx"), 1e-10);
     65        assertEquals(1.1, CustomProjection.parseAngle("1.1dE", "xxx"), 1e-10);
     66        assertEquals(-1.1, CustomProjection.parseAngle("1.1dW", "xxx"), 1e-10);
     67
     68        assertEquals(49.5, CustomProjection.parseAngle("49d30'N", "xxx"), 1e-10);
     69        assertEquals(-120.8333333333, CustomProjection.parseAngle("120.0d50'W", "xxx"), 1e-10);
     70
    6371        // fail
    6472        Stream.of("", "-", "-N", "N", "1.1 ", "x", "1.1d1.1d", "1.1e", "1.1.1", ".1", "1.1d3\"5.2'").forEach(
Note: See TracChangeset for help on using the changeset viewer.