Changeset 28755 in osm
- Timestamp:
- 2012-09-30T12:33:11+02:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/poly/src/poly
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/poly/src/poly/PolyExporter.java
r28573 r28755 9 9 import java.util.ArrayList; 10 10 import java.util.Comparator; 11 import java.util.LinkedHashMap; 11 12 import java.util.List; 12 13 import java.util.Locale; … … 40 41 try { 41 42 DataSet ds = ((OsmDataLayer)layer).data; 42 Map<Way, Boolean> ways = new TreeMap<Way, Boolean>( new AreaComparator());43 Map<Way, Boolean> ways = new TreeMap<Way, Boolean>(); 43 44 String polygonName = file.getName(); 44 45 if( polygonName.indexOf('.') > 0 ) … … 46 47 for( Way w : ds.getWays() ) { 47 48 if( w.isClosed() ) { 48 boolean outer = true; 49 for( OsmPrimitive p : w.getReferrers() ) { 50 if( p instanceof Relation && ((Relation)p).isMultipolygon() ) { 51 for( RelationMember m : ((Relation)p).getMembers() ) { 52 if( m.refersTo(w) && "inner".equals(m.getRole()) ) { 53 outer = false; 54 break; 55 } 56 } 57 } 58 if( !outer ) break; 59 } 49 boolean outer = isOuter(w); 60 50 ways.put(w, outer); 61 51 if( w.hasKey("name") ) … … 63 53 } 64 54 } 55 ways = sortOuterInner(ways); 65 56 66 57 int counter = 1; … … 70 61 if( !ways.get(w) ) 71 62 writer.write('!'); 72 writer.write( w.hasKey("ref") ? w.get("ref") :String.valueOf(counter++));63 writer.write(String.valueOf(counter++)); 73 64 writer.newLine(); 74 65 for( Node n : w.getNodes() ) { 75 writer.write(String.format(Locale.ENGLISH, " % E %E", n.getCoor().lon(), n.getCoor().lat()));66 writer.write(String.format(Locale.ENGLISH, " %f %f", n.getCoor().lon(), n.getCoor().lat())); 76 67 writer.newLine(); 77 68 } … … 87 78 } 88 79 89 private class AreaComparator implements Comparator<Way> { 90 @Override 91 public int compare( Way w1, Way w2 ) { 92 if( w1.hasKey("ref") && !w2.hasKey("ref") ) 93 return -1; 94 else if( !w1.hasKey("ref") && w2.hasKey("ref") ) 95 return 1; 96 else if( w1.hasKey("ref") && w2.hasKey("ref") && !w1.get("ref").equals(w2.get("ref")) ) 97 return w1.get("ref").compareTo(w2.get("ref")); 80 private boolean isOuter( Way w ) { 81 for( OsmPrimitive p : w.getReferrers() ) { 82 if( p instanceof Relation && ((Relation)p).isMultipolygon() ) { 83 for( RelationMember m : ((Relation)p).getMembers() ) { 84 if( m.refersTo(w) && "inner".equals(m.getRole()) ) { 85 return false; 86 } 87 } 88 } 89 } 90 return true; 91 } 92 93 private Map<Way, Boolean> sortOuterInner( Map<Way, Boolean> ways ) { 94 LinkedHashMap<Way, Boolean> result = new LinkedHashMap<Way, Boolean>(ways.size()); 95 List<Way> inner = new ArrayList<Way>(); 96 for( Way w : ways.keySet() ) { 97 Boolean outer = ways.get(w); 98 if( outer ) 99 result.put(w, outer); 98 100 else 99 return w1.compareTo(w2);101 inner.add(w); 100 102 } 103 for( Way w : inner ) 104 result.put(w, Boolean.FALSE); 105 return result; 101 106 } 102 107 } -
applications/editors/josm/plugins/poly/src/poly/PolyImporter.java
r28573 r28755 7 7 import java.util.ArrayList; 8 8 import java.util.List; 9 import javax.swing.JOptionPane; 10 import org.openstreetmap.josm.Main; 9 11 import org.openstreetmap.josm.data.coor.LatLon; 10 12 … … 73 75 Area area = null; 74 76 boolean parsingSection = false; 77 int fixedCoords = 0; 75 78 while(true) { 76 79 String line; … … 117 120 throw new IllegalDataException(tr("A polygon coordinate line must contain exactly 2 numbers")); 118 121 LatLon coord = new LatLon(coords[1], coords[0]); 119 if( !coord.isValid() ) 120 throw new IllegalDataException(tr("Invalid coordinates were found: {0}, {1}", coord.lat(), coord.lon())); 122 if( !coord.isValid() ) { 123 // fix small deviations 124 double lat = coord.lat(); 125 double lon = coord.lon(); 126 if( lon < -180.0 && lon> -185.0 ) lon = -180.0; 127 if( lon > 180.0 && lon < 185.0 ) lon = 180.0; 128 if( lat < -90.0 && lat > -95.0 ) lat = -90.0; 129 if( lat > 90.0 && lat < 95.0 ) lat = 90.0; 130 fixedCoords++; 131 coord = new LatLon(lat, lon); 132 if( !coord.isValid() ) 133 throw new IllegalDataException(tr("Invalid coordinates were found: {0}, {1}", coord.lat(), coord.lon())); 134 } 121 135 area.addNode(coord); 122 136 } 123 137 } 124 138 } 139 if( fixedCoords > 0 ) 140 JOptionPane.showMessageDialog(Main.parent, tr("{0} points were outside world bounds and were moved", fixedCoords), "Import poly", JOptionPane.WARNING_MESSAGE); 125 141 return areas; 126 142 } … … 195 211 } 196 212 way.addNode(way.getNode(0)); 197 way.put("ref", name);198 213 if( polygonName != null ) 199 214 way.put("name", polygonName);
Note:
See TracChangeset
for help on using the changeset viewer.