Changeset 13602 in josm for trunk/src


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

see #16129 - projections rework for new ESRI file

Location:
trunk/src/org/openstreetmap/josm/data
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • 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                }
Note: See TracChangeset for help on using the changeset viewer.