Changeset 13602 in josm
- Timestamp:
- 2018-04-07T20:42:34+02:00 (6 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/scripts/BuildProjectionDefinitions.java
r13599 r13602 13 13 import java.util.Map; 14 14 import java.util.TreeMap; 15 import java.util.regex.Matcher; 16 import java.util.regex.Pattern; 15 17 16 18 import org.openstreetmap.josm.data.projection.CustomProjection; … … 81 83 if (list.isEmpty()) 82 84 throw new AssertionError("EPSG file seems corrupted"); 85 Pattern badDmsPattern = Pattern.compile("(\\d+(?:\\.\\d+)?d\\d+(?:\\.\\d+)?')(N|S|E|W)"); 83 86 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())); 85 95 } 86 96 } … … 113 123 } 114 124 } 115 out.write("## ESRI-specific projections (source: proj.4):\n");125 out.write("## ESRI-specific projections (source: ESRI):\n"); 116 126 for (ProjectionDefinition pd : esriProj4.values()) { 117 127 pd = new ProjectionDefinition(pd.code, "ESRI: " + pd.name, pd.definition); … … 194 204 result = false; 195 205 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; 196 217 } 197 218 -
trunk/src/org/openstreetmap/josm/data/Bounds.java
r13173 r13602 355 355 public String toShortString(DecimalFormat format) { 356 356 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); 360 360 } 361 361 … … 513 513 */ 514 514 public double getArea() { 515 double w = getWidth(); 516 return w * (maxLat - minLat); 515 return getWidth() * (maxLat - minLat); 517 516 } 518 517 … … 523 522 */ 524 523 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(); 530 527 } 531 528 … … 574 571 Bounds bounds = (Bounds) obj; 575 572 return Double.compare(bounds.minLat, minLat) == 0 && 576 577 578 573 Double.compare(bounds.minLon, minLon) == 0 && 574 Double.compare(bounds.maxLat, maxLat) == 0 && 575 Double.compare(bounds.maxLon, maxLon) == 0; 579 576 } 580 577 } -
trunk/src/org/openstreetmap/josm/data/coor/conversion/LatLonParser.java
r12838 r13602 50 50 private static final Pattern P_XML = Pattern.compile( 51 51 "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 + "$"); 52 62 53 63 private static class LatLonHolder { … … 199 209 */ 200 210 public static double parseCoordinate(String angleStr) { 201 final String floatPattern = "(\\d+(\\.\\d*)?)";202 211 // 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); 209 213 210 214 if (!in.find()) { -
trunk/src/org/openstreetmap/josm/data/projection/Projections.java
r13599 r13602 315 315 List<ProjectionDefinition> result = new ArrayList<>(); 316 316 Pattern epsgPattern = Pattern.compile("<(\\d+)>(.*)<>"); 317 String coor = "(-?\\d+\\.\\d+)"; 318 Pattern areaPattern = Pattern.compile("# area: \\(lat: "+coor+", "+coor+"\\) - \\(lon: "+coor+", "+coor+"\\).*"); 317 319 StringBuilder sb = new StringBuilder(); 320 String bounds = null; 318 321 String line; 319 322 while ((line = r.readLine()) != null) { 320 323 line = line.trim(); 321 if (!line.isEmpty() ) {324 if (!line.isEmpty() && !line.startsWith("##")) { 322 325 if (!line.startsWith("#")) { 323 326 Matcher m = epsgPattern.matcher(line); … … 325 328 String code = "EPSG:" + m.group(1); 326 329 String definition = m.group(2).trim(); 330 if (!definition.contains("+bounds=") && bounds != null) { 331 definition += bounds; 332 } 327 333 result.add(new ProjectionDefinition(code, sb.toString(), definition)); 328 334 } else { … … 330 336 } 331 337 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(); 333 346 if (sb.length() == 0) { 334 sb.append( line.substring(1).trim());347 sb.append(s); 335 348 } else { 336 sb.append('(').append( line.substring(1).trim()).append(')');349 sb.append('(').append(s).append(')'); 337 350 } 338 351 } -
trunk/test/unit/org/openstreetmap/josm/data/projection/CustomProjectionTest.java
r11931 r13602 61 61 assertEquals(1.1 + 3 / 60.0 + 5.2 / 3600.0, CustomProjection.parseAngle("1.1d3'5.2\"", "xxx"), 1e-10); 62 62 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 63 71 // fail 64 72 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.