Ticket #17227: poly.patch
| File poly.patch, 39.6 KB (added by , 7 years ago) |
|---|
-
.classpath
1 <?xml version="1.0" encoding="UTF-8"?> 2 <classpath> 3 <classpathentry kind="src" path="src"/> 4 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> 5 <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/> 6 <classpathentry kind="output" path="bin"/> 7 </classpath> 1 <?xml version="1.0" encoding="UTF-8"?> 2 <classpath> 3 <classpathentry kind="src" path="src"/> 4 <classpathentry kind="src" output="buildtest" path="test/unit"> 5 <attributes> 6 <attribute name="test" value="true"/> 7 </attributes> 8 </classpathentry> 9 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> 10 <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/> 11 <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> 12 <classpathentry kind="output" path="build"/> 13 </classpath> -
.project
3 3 <name>JOSM-Poly</name> 4 4 <comment></comment> 5 5 <projects> 6 <project>josm</project> 6 7 </projects> 7 8 <buildSpec> 8 9 <buildCommand> -
src/poly/PolyExporter.java
1 1 // License: GPL. For details, see LICENSE file. 2 2 package poly; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 4 6 import java.io.BufferedWriter; 5 7 import java.io.File; 6 8 import java.io.FileOutputStream; 7 9 import java.io.IOException; 8 10 import java.io.OutputStreamWriter; 9 import java.util.ArrayList; 10 import java.util.LinkedHashMap; 11 import java.util.List; 11 import java.util.HashSet; 12 12 import java.util.Locale; 13 import java.util.Map; 14 import java.util.TreeMap; 13 import java.util.Set; 15 14 16 15 import org.openstreetmap.josm.data.osm.DataSet; 17 16 import org.openstreetmap.josm.data.osm.Node; 18 import org.openstreetmap.josm.data.osm.OsmPrimitive;19 17 import org.openstreetmap.josm.data.osm.Relation; 20 18 import org.openstreetmap.josm.data.osm.RelationMember; 21 19 import org.openstreetmap.josm.data.osm.Way; … … 37 35 @Override 38 36 public void exportData(File file, Layer layer) throws IOException { 39 37 if (layer instanceof OsmDataLayer) { 38 if (((OsmDataLayer) layer).getDataSet().getWays().stream().anyMatch(w -> !w.isClosed())) { 39 throw new IOException(tr("Data contains unclosed ways.")); 40 } 41 String fileName = file.getName(); 42 if (fileName.indexOf('.') > 0) { 43 fileName = fileName.substring(0, fileName.indexOf('.')); 44 } 45 40 46 try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF8"))) { 41 47 DataSet ds = ((OsmDataLayer) layer).getDataSet(); 42 Map<Way, Boolean> ways = new TreeMap<>(); 43 String polygonName = file.getName(); 44 if (polygonName.indexOf('.') > 0) 45 polygonName = polygonName.substring(0, polygonName.indexOf('.')); 46 for (Way w : ds.getWays()) { 47 if (w.isClosed()) { 48 boolean outer = isOuter(w); 49 ways.put(w, outer); 50 if (w.hasKey("name")) 51 polygonName = w.get("name").replace("\n", " "); 48 HashSet<Way> written = new HashSet<>(); 49 boolean firstFile = true; 50 for (Relation rel : ds.getRelations()) { 51 if (rel.isMultipolygon()) { 52 if (!firstFile) { 53 writer.newLine(); 54 } 55 writeRelation(writer, fileName, rel, written); 56 firstFile = false; 52 57 } 53 58 } 54 ways = sortOuterInner(ways); 55 59 60 if (firstFile) { 61 writer.write(fileName); 62 } 56 63 int counter = 1; 57 writer.write(polygonName); 58 writer.newLine(); 59 for (Way w : ways.keySet()) { 60 if (!ways.get(w)) 61 writer.write('!'); 62 writer.write(String.valueOf(counter++)); 63 writer.newLine(); 64 for (Node n : w.getNodes()) { 65 writer.write(String.format(Locale.ENGLISH, " %f %f", n.getCoor().lon(), n.getCoor().lat())); 66 writer.newLine(); 64 for (Way w : ds.getWays()) { 65 if (!written.contains(w)) { 66 writeWay(writer, w, counter); 67 67 } 68 writer.write("END");69 writer.newLine();70 68 } 71 69 writer.write("END"); 72 70 writer.newLine(); … … 74 72 } 75 73 } 76 74 77 private boolean isOuter(Way w) { 78 for (OsmPrimitive p : w.getReferrers()) { 79 if (p instanceof Relation && ((Relation) p).isMultipolygon()) { 80 for (RelationMember m : ((Relation) p).getMembers()) { 81 if (m.refersTo(w) && "inner".equals(m.getRole())) { 82 return false; 83 } 84 } 75 private static void writeRelation(BufferedWriter writer, String fileName, Relation rel, Set<Way> written) throws IOException { 76 String polygonName = fileName; 77 if (rel.getName() != null) 78 polygonName = rel.getName(); 79 writer.write(polygonName); 80 writer.newLine(); 81 int counter = 1; 82 for (RelationMember rm: rel.getMembers()) { 83 if (rm.isWay()) { 84 if ("inner".equals(rm.getRole())) 85 writer.write('!'); 86 Way w = rm.getWay(); 87 counter = writeWay(writer, w, counter); 88 written.add(w); 85 89 } 86 90 } 87 return true;88 91 } 89 92 90 private Map<Way, Boolean> sortOuterInner(Map<Way, Boolean> ways) { 91 LinkedHashMap<Way, Boolean> result = new LinkedHashMap<>(ways.size()); 92 List<Way> inner = new ArrayList<>(); 93 for (Way w : ways.keySet()) { 94 Boolean outer = ways.get(w); 95 if (outer) 96 result.put(w, outer); 97 else 98 inner.add(w); 93 private static int writeWay(BufferedWriter writer, Way w, int counter) throws IOException { 94 String name = w.getName(); 95 if (name == null) { 96 name = String.valueOf(counter++); 97 } 98 writer.write(name); 99 writer.newLine(); 100 101 for (Node n : w.getNodes()) { 102 writer.write(String.format(Locale.ENGLISH, " %f %f", n.getCoor().lon(), n.getCoor().lat())); 103 writer.newLine(); 99 104 } 100 for (Way w : inner) { 101 result.put(w, Boolean.FALSE); 102 } 103 return result; 105 writer.write("END"); 106 writer.newLine(); 107 return counter; 104 108 } 105 109 } -
src/poly/PolyImporter.java
26 26 import org.openstreetmap.josm.io.CachedFile; 27 27 import org.openstreetmap.josm.io.IllegalDataException; 28 28 import org.openstreetmap.josm.tools.CheckParameterUtil; 29 import org.xml.sax.SAXException;30 29 31 30 /** 32 31 * Imports poly files. … … 38 37 super(PolyType.FILE_FILTER); 39 38 } 40 39 41 protected DataSet parseDataSet(final String source) throws IOException, SAXException, IllegalDataException { 42 return parseDataSet(new CachedFile(source).getInputStream(), NullProgressMonitor.INSTANCE); 40 protected DataSet parseDataSet(final String source) throws IOException, IllegalDataException { 41 try (CachedFile cf = new CachedFile(source)) { 42 return parseDataSet(cf.getInputStream(), NullProgressMonitor.INSTANCE); 43 } 43 44 } 44 45 45 46 @Override … … 48 49 progressMonitor = NullProgressMonitor.INSTANCE; 49 50 CheckParameterUtil.ensureParameterNotNull(in, "in"); 50 51 52 progressMonitor.beginTask(tr("Reading polygon filter file..."), 3); 51 53 try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF8"))) { 52 progressMonitor.beginTask(tr("Reading polygon filter file..."), 2);53 54 progressMonitor.indeterminateSubTask(tr("Reading polygon filter file...")); 54 55 List<Area> areas = loadPolygon(reader); 55 56 progressMonitor.worked(1); … … 65 66 } 66 67 } 67 68 68 private List<Area> loadPolygon(BufferedReader reader) throws IllegalDataException, IOException {69 private static List<Area> loadPolygon(BufferedReader reader) throws IllegalDataException, IOException { 69 70 String name = reader.readLine(); 70 71 if (name == null || name.trim().length() == 0) 71 72 throw new IllegalDataException(tr("The file must begin with a polygon name")); … … 75 76 int fixedCoords = 0; 76 77 while (true) { 77 78 String line; 78 do { 79 line = reader.readLine(); 80 if (line == null) 81 throw new IllegalDataException("File ended prematurely without END record"); 82 line = line.trim(); 83 } while (line.length() == 0); 84 85 if (line.equals("END")) { 86 if (!parsingSection) 87 break; 88 else { 79 line = reader.readLine(); 80 if (line == null) 81 break; 82 line = line.trim(); 83 if (line.isEmpty()) { 84 // empty line is only allowed after a complete file (one or more rings belonging to one polygon) 85 if (parsingSection) 86 throw new IllegalDataException(tr("Empty line in coordinate section")); 87 area = null; 88 parsingSection = false; 89 name = null; 90 } else if (line.equals("END")) { 91 if (!parsingSection) { 92 area = null; 93 } else { 89 94 // an area has been read 90 95 if (area.getNodeCount() < 2) 91 96 throw new IllegalDataException(tr("There are less than 2 points in an area")); 92 97 areas.add(area); 93 if (areas.size() == 1) 94 areas.get(0).setPolygonName(name); 98 area.setPolygonName(name); 95 99 parsingSection = false; 96 100 } 97 } else { 101 } else if (name == null) { 102 name = line; 103 } else if (line.length() > 0) { 98 104 if (!parsingSection) { 105 if (line.indexOf(' ') >= 0) { 106 boolean coordInsteadOfName = false; 107 try { 108 LatLon ll = parseCoordinate(line); 109 if (ll.isValid()) { 110 coordInsteadOfName = true; 111 } 112 } catch (IllegalDataException e) { 113 coordInsteadOfName = false; 114 } 115 if (coordInsteadOfName) { 116 throw new IllegalDataException(tr("Found coordinates ''{0}'' instead of name", line)); 117 } 118 } 99 119 area = new Area(line); 100 120 parsingSection = true; 101 121 } else { 102 // reading area, parse coordinates 103 String[] tokens = line.split("\\s+"); 104 double[] coords = new double[2]; 105 int tokenCount = 0; 106 for (String token : tokens) { 107 if (token.length() > 0) { 108 if (tokenCount > 2) 109 throw new IllegalDataException(tr("A polygon coordinate line must contain exactly 2 numbers")); 110 try { 111 coords[tokenCount++] = Double.parseDouble(token); 112 } catch (NumberFormatException e) { 113 throw new IllegalDataException(tr("Unable to parse {0} as a number", token)); 114 } 115 } 116 } 117 if (tokenCount < 2) 118 throw new IllegalDataException(tr("A polygon coordinate line must contain exactly 2 numbers")); 119 LatLon coord = new LatLon(coords[1], coords[0]); 122 LatLon coord = parseCoordinate(line); 120 123 if (!coord.isValid()) { 121 124 // fix small deviations 122 125 double lat = coord.lat(); … … 125 128 if (lon > 180.0 && lon < 185.0) lon = 180.0; 126 129 if (lat < -90.0 && lat > -95.0) lat = -90.0; 127 130 if (lat > 90.0 && lat < 95.0) lat = 90.0; 131 coord = new LatLon(lat, lon); 128 132 fixedCoords++; 129 coord = new LatLon(lat, lon);130 133 if (!coord.isValid()) 131 134 throw new IllegalDataException(tr("Invalid coordinates were found: {0}, {1}", coord.lat(), coord.lon())); 132 135 } 133 area.addNode( coord);136 area.addNode(parseCoordinate(line)); 134 137 } 135 138 } 136 139 } … … 140 143 return areas; 141 144 } 142 145 143 private DataSet constructDataSet(List<Area> areas) { 146 /** 147 * Parse a line that should contain two double values which describe a latitude/longitude pair. 148 * @param line the line to parse 149 * @return a new LatLon 150 * @throws IllegalDataException in case of error 151 */ 152 private static LatLon parseCoordinate(String line) throws IllegalDataException { 153 String[] tokens = line.split("\\s+"); 154 double[] coords = new double[2]; 155 int tokenCount = 0; 156 for (String token : tokens) { 157 if (token.length() > 0) { 158 if (tokenCount > 2) 159 break; 160 try { 161 coords[tokenCount++] = Double.parseDouble(token); 162 } catch (NumberFormatException e) { 163 throw new IllegalDataException(tr("Unable to parse {0} as a number", token)); 164 } 165 } 166 } 167 if (tokenCount != 2) 168 throw new IllegalDataException(tr("A polygon coordinate line must contain exactly 2 numbers")); 169 return new LatLon(coords[1], coords[0]); 170 } 171 172 private static DataSet constructDataSet(List<Area> areas) { 144 173 DataSet ds = new DataSet(); 145 174 ds.setUploadPolicy(UploadPolicy.DISCOURAGED); 146 175 147 boolean foundInner = false; 176 177 List<Area> curretSet = new ArrayList<>(); 178 148 179 for (Area area : areas) { 149 if (!area.isOuter()) 150 foundInner = true; 151 area.constructWay(ds); 180 if (!curretSet.isEmpty() && !area.polygonName.equals(curretSet.get(0).polygonName)) { 181 constructPrimitive(ds, curretSet); 182 curretSet.clear(); 183 } 184 curretSet.add(area); 152 185 } 186 if (!curretSet.isEmpty()) 187 constructPrimitive(ds, curretSet); 153 188 154 if (foundInner) { 189 return ds; 190 } 191 192 private static void constructPrimitive(DataSet ds, List<Area> areas) { 193 boolean isMultipolygon = areas.size() > 1; 194 for (Area area : areas) { 195 area.constructWay(ds, isMultipolygon); 196 } 197 198 if (isMultipolygon) { 155 199 Relation mp = new Relation(); 156 200 mp.put("type", "multipolygon"); 201 Area outer = areas.get(0); 202 if (outer.polygonName != null) { 203 mp.put("name", outer.polygonName); 204 } 157 205 for (Area area : areas) { 158 206 mp.addMember(new RelationMember(area.isOuter() ? "outer" : "inner", area.getWay())); 159 207 } 160 208 ds.addPrimitive(mp); 161 209 } 162 163 return ds;164 210 } 165 211 166 212 private static class Area { … … 177 223 this.name = this.name.substring(1); 178 224 nodes = new ArrayList<>(); 179 225 way = null; 180 polygonName = null;226 polygonName = ""; 181 227 } 182 228 183 229 public void setPolygonName(String polygonName) { 184 this.polygonName = polygonName; 230 if (polygonName != null) { 231 this.polygonName = polygonName; 232 } 185 233 } 186 234 187 235 public void addNode(LatLon node) { … … 201 249 return way; 202 250 } 203 251 204 public void constructWay(DataSet ds ) {252 public void constructWay(DataSet ds, boolean isMultipolygon) { 205 253 way = new Way(); 206 254 for (LatLon coord : nodes) { 207 255 Node node = new Node(coord); … … 209 257 way.addNode(node); 210 258 } 211 259 way.addNode(way.getNode(0)); 212 if (polygonName != null) 213 way.put("name", polygonName); 260 if (isMultipolygon && name != null) 261 way.put("name", name); 262 else { 263 if (polygonName != null) 264 way.put("name", polygonName); 265 } 214 266 ds.addPrimitive(way); 215 267 } 216 268 } -
test/data/bremen-double-end.poly
1 none 2 1 3 8.509653E+00 5.347469E+01 4 8.505762E+00 5.347047E+01 5 8.491577E+00 5.347200E+01 6 8.491656E+00 5.347549E+01 7 8.501178E+00 5.349139E+01 8 8.504218E+00 5.349441E+01 9 8.511296E+00 5.350007E+01 10 8.520366E+00 5.350472E+01 11 8.551284E+00 5.351639E+01 12 8.546220E+00 5.352130E+01 13 8.558515E+00 5.352774E+01 14 8.560064E+00 5.353183E+01 15 8.559076E+00 5.353636E+01 16 8.493468E+00 5.360245E+01 17 8.493498E+00 5.360351E+01 18 8.523178E+00 5.360744E+01 19 8.525435E+00 5.360457E+01 20 8.527368E+00 5.360641E+01 21 8.533663E+00 5.360514E+01 22 8.535422E+00 5.360772E+01 23 8.581374E+00 5.359864E+01 24 8.592972E+00 5.359386E+01 25 8.601275E+00 5.359622E+01 26 8.612262E+00 5.360352E+01 27 8.623225E+00 5.360602E+01 28 8.639793E+00 5.360518E+01 29 8.643798E+00 5.360448E+01 30 8.643166E+00 5.360603E+01 31 8.644382E+00 5.360731E+01 32 8.641847E+00 5.360889E+01 33 8.642658E+00 5.361052E+01 34 8.651924E+00 5.361063E+01 35 8.654038E+00 5.360895E+01 36 8.658592E+00 5.360983E+01 37 8.660066E+00 5.360779E+01 38 8.657775E+00 5.360268E+01 39 8.653304E+00 5.360224E+01 40 8.640072E+00 5.359466E+01 41 8.641363E+00 5.359292E+01 42 8.627218E+00 5.358420E+01 43 8.620693E+00 5.357695E+01 44 8.620204E+00 5.357422E+01 45 8.625819E+00 5.356784E+01 46 8.631574E+00 5.355619E+01 47 8.635984E+00 5.355430E+01 48 8.647419E+00 5.355588E+01 49 8.645195E+00 5.354940E+01 50 8.646030E+00 5.354024E+01 51 8.642684E+00 5.354082E+01 52 8.642332E+00 5.353640E+01 53 8.639048E+00 5.353445E+01 54 8.639099E+00 5.353337E+01 55 8.640124E+00 5.352569E+01 56 8.644103E+00 5.352311E+01 57 8.646059E+00 5.351939E+01 58 8.649762E+00 5.352007E+01 59 8.652930E+00 5.351626E+01 60 8.649244E+00 5.351386E+01 61 8.651507E+00 5.351032E+01 62 8.640633E+00 5.350679E+01 63 8.637674E+00 5.350512E+01 64 8.638345E+00 5.350340E+01 65 8.636614E+00 5.350220E+01 66 8.629345E+00 5.350097E+01 67 8.628816E+00 5.349916E+01 68 8.630505E+00 5.349675E+01 69 8.629601E+00 5.349504E+01 70 8.627630E+00 5.349518E+01 71 8.626241E+00 5.349289E+01 72 8.624468E+00 5.349323E+01 73 8.619703E+00 5.349000E+01 74 8.610639E+00 5.348680E+01 75 8.604164E+00 5.348648E+01 76 8.603295E+00 5.348379E+01 77 8.597157E+00 5.348506E+01 78 8.591864E+00 5.348421E+01 79 8.584140E+00 5.348616E+01 80 8.578344E+00 5.348486E+01 81 8.575051E+00 5.348586E+01 82 8.573728E+00 5.348781E+01 83 8.539527E+00 5.347957E+01 84 8.528859E+00 5.347938E+01 85 8.517022E+00 5.347260E+01 86 8.514411E+00 5.347464E+01 87 8.509653E+00 5.347469E+01 88 END 89 END 90 2 91 8.615320E+00 5.319451E+01 92 8.611878E+00 5.319620E+01 93 8.613360E+00 5.319747E+01 94 8.617090E+00 5.319582E+01 95 8.616084E+00 5.319474E+01 96 8.621347E+00 5.319577E+01 97 8.621455E+00 5.319779E+01 98 8.628186E+00 5.319891E+01 99 8.631454E+00 5.319637E+01 100 8.634298E+00 5.319689E+01 101 8.640220E+00 5.319466E+01 102 8.638992E+00 5.319207E+01 103 8.643234E+00 5.319003E+01 104 8.654726E+00 5.318801E+01 105 8.656097E+00 5.318630E+01 106 8.653511E+00 5.318502E+01 107 8.658608E+00 5.318215E+01 108 8.659425E+00 5.317822E+01 109 8.662827E+00 5.317888E+01 110 8.665359E+00 5.317716E+01 111 8.669937E+00 5.317788E+01 112 8.671074E+00 5.317964E+01 113 8.674892E+00 5.317946E+01 114 8.676175E+00 5.317598E+01 115 8.678430E+00 5.317658E+01 116 8.677812E+00 5.317772E+01 117 8.679439E+00 5.317872E+01 118 8.687234E+00 5.317970E+01 119 8.691238E+00 5.318203E+01 120 8.696560E+00 5.318333E+01 121 8.699443E+00 5.318614E+01 122 8.703409E+00 5.318151E+01 123 8.701904E+00 5.317965E+01 124 8.702337E+00 5.317844E+01 125 8.705491E+00 5.317667E+01 126 8.709726E+00 5.317874E+01 127 8.709577E+00 5.318065E+01 128 8.712246E+00 5.318135E+01 129 8.714161E+00 5.318396E+01 130 8.729187E+00 5.318128E+01 131 8.732554E+00 5.317501E+01 132 8.737198E+00 5.317394E+01 133 8.739386E+00 5.317163E+01 134 8.743869E+00 5.317217E+01 135 8.744135E+00 5.317095E+01 136 8.741523E+00 5.316645E+01 137 8.741885E+00 5.316467E+01 138 8.748036E+00 5.316664E+01 139 8.755166E+00 5.316418E+01 140 8.761751E+00 5.316588E+01 141 8.771124E+00 5.316009E+01 142 8.775121E+00 5.316210E+01 143 8.782127E+00 5.316414E+01 144 8.786732E+00 5.316372E+01 145 8.790699E+00 5.316394E+01 146 8.792599E+00 5.316377E+01 147 8.797220E+00 5.316430E+01 148 8.798689E+00 5.316347E+01 149 8.814552E+00 5.316465E+01 150 8.821277E+00 5.316418E+01 151 8.829275E+00 5.316490E+01 152 8.830586E+00 5.316307E+01 153 8.831747E+00 5.316024E+01 154 8.840334E+00 5.315818E+01 155 8.845287E+00 5.314806E+01 156 8.853117E+00 5.314419E+01 157 8.858228E+00 5.314054E+01 158 8.861722E+00 5.313843E+01 159 8.862411E+00 5.313726E+01 160 8.863432E+00 5.313216E+01 161 8.874316E+00 5.313412E+01 162 8.886153E+00 5.313363E+01 163 8.897505E+00 5.313471E+01 164 8.903128E+00 5.313923E+01 165 8.907142E+00 5.313793E+01 166 8.909629E+00 5.313346E+01 167 8.912146E+00 5.313328E+01 168 8.916077E+00 5.313719E+01 169 8.915927E+00 5.313985E+01 170 8.921400E+00 5.314221E+01 171 8.920051E+00 5.314412E+01 172 8.920491E+00 5.314503E+01 173 8.930619E+00 5.314832E+01 174 8.936901E+00 5.315175E+01 175 8.939893E+00 5.315291E+01 176 8.945054E+00 5.315276E+01 177 8.956958E+00 5.314777E+01 178 8.960158E+00 5.314312E+01 179 8.971611E+00 5.313416E+01 180 8.979324E+00 5.313148E+01 181 8.983984E+00 5.312562E+01 182 8.978232E+00 5.312289E+01 183 8.966957E+00 5.312127E+01 184 8.962749E+00 5.311908E+01 185 8.948558E+00 5.311619E+01 186 8.958218E+00 5.311157E+01 187 8.961763E+00 5.310648E+01 188 8.963470E+00 5.310114E+01 189 8.969005E+00 5.310134E+01 190 8.978750E+00 5.309913E+01 191 8.982155E+00 5.309708E+01 192 8.989558E+00 5.309878E+01 193 8.991268E+00 5.309666E+01 194 8.984503E+00 5.309262E+01 195 8.965782E+00 5.308906E+01 196 8.962445E+00 5.308526E+01 197 8.966571E+00 5.308284E+01 198 8.964914E+00 5.308017E+01 199 8.965461E+00 5.307661E+01 200 8.964578E+00 5.307212E+01 201 8.965471E+00 5.307145E+01 202 8.964611E+00 5.307028E+01 203 8.966550E+00 5.306254E+01 204 8.964580E+00 5.306036E+01 205 8.966615E+00 5.305825E+01 206 8.970870E+00 5.305670E+01 207 8.973879E+00 5.305194E+01 208 8.976998E+00 5.305204E+01 209 8.980996E+00 5.304654E+01 210 8.971601E+00 5.303863E+01 211 8.966901E+00 5.303607E+01 212 8.963457E+00 5.303639E+01 213 8.952458E+00 5.303282E+01 214 8.951431E+00 5.303079E+01 215 8.946744E+00 5.303012E+01 216 8.945654E+00 5.302762E+01 217 8.947041E+00 5.302597E+01 218 8.946119E+00 5.302427E+01 219 8.938848E+00 5.302414E+01 220 8.935836E+00 5.301299E+01 221 8.929521E+00 5.301324E+01 222 8.928204E+00 5.301220E+01 223 8.922525E+00 5.301383E+01 224 8.921712E+00 5.301149E+01 225 8.917827E+00 5.301243E+01 226 8.915746E+00 5.301034E+01 227 8.896934E+00 5.301222E+01 228 8.892659E+00 5.301356E+01 229 8.883590E+00 5.302295E+01 230 8.866418E+00 5.303223E+01 231 8.865539E+00 5.302817E+01 232 8.869883E+00 5.302480E+01 233 8.867059E+00 5.302117E+01 234 8.855103E+00 5.302045E+01 235 8.852819E+00 5.301913E+01 236 8.850924E+00 5.301616E+01 237 8.848968E+00 5.301588E+01 238 8.847454E+00 5.301602E+01 239 8.846577E+00 5.301778E+01 240 8.849042E+00 5.302341E+01 241 8.844866E+00 5.302301E+01 242 8.844202E+00 5.302154E+01 243 8.840843E+00 5.302033E+01 244 8.838031E+00 5.301747E+01 245 8.830788E+00 5.302052E+01 246 8.822030E+00 5.302016E+01 247 8.817499E+00 5.302183E+01 248 8.815214E+00 5.302582E+01 249 8.810032E+00 5.302825E+01 250 8.808574E+00 5.303036E+01 251 8.785725E+00 5.303773E+01 252 8.782499E+00 5.303719E+01 253 8.777443E+00 5.303883E+01 254 8.775875E+00 5.304264E+01 255 8.772064E+00 5.304466E+01 256 8.770096E+00 5.305205E+01 257 8.762022E+00 5.304996E+01 258 8.764634E+00 5.304670E+01 259 8.758404E+00 5.304314E+01 260 8.756541E+00 5.304336E+01 261 8.756123E+00 5.304252E+01 262 8.757962E+00 5.304095E+01 263 8.756901E+00 5.303846E+01 264 8.751439E+00 5.303726E+01 265 8.743301E+00 5.303993E+01 266 8.741748E+00 5.303869E+01 267 8.740454E+00 5.303905E+01 268 8.737982E+00 5.303663E+01 269 8.733200E+00 5.303650E+01 270 8.735485E+00 5.303505E+01 271 8.734242E+00 5.303297E+01 272 8.729968E+00 5.303335E+01 273 8.709331E+00 5.304517E+01 274 8.706123E+00 5.305247E+01 275 8.709702E+00 5.306855E+01 276 8.709194E+00 5.307210E+01 277 8.705708E+00 5.307561E+01 278 8.701124E+00 5.308043E+01 279 8.686927E+00 5.308522E+01 280 8.674488E+00 5.308554E+01 281 8.665954E+00 5.309124E+01 282 8.664211E+00 5.309584E+01 283 8.669353E+00 5.310219E+01 284 8.653751E+00 5.310839E+01 285 8.652751E+00 5.311112E+01 286 8.654288E+00 5.311552E+01 287 8.651881E+00 5.311567E+01 288 8.649707E+00 5.311733E+01 289 8.650273E+00 5.312153E+01 290 8.647819E+00 5.312468E+01 291 8.634341E+00 5.313348E+01 292 8.630098E+00 5.313799E+01 293 8.625879E+00 5.314537E+01 294 8.622735E+00 5.316278E+01 295 8.619494E+00 5.316638E+01 296 8.611348E+00 5.316970E+01 297 8.582453E+00 5.317270E+01 298 8.556976E+00 5.318067E+01 299 8.533636E+00 5.318623E+01 300 8.522611E+00 5.319183E+01 301 8.515308E+00 5.319723E+01 302 8.512254E+00 5.319624E+01 303 8.505858E+00 5.319947E+01 304 8.500976E+00 5.320528E+01 305 8.495432E+00 5.320903E+01 306 8.490537E+00 5.321665E+01 307 8.482431E+00 5.322288E+01 308 8.480959E+00 5.322676E+01 309 8.488865E+00 5.322891E+01 310 8.490168E+00 5.322740E+01 311 8.503920E+00 5.322966E+01 312 8.506858E+00 5.322843E+01 313 8.517307E+00 5.322909E+01 314 8.518743E+00 5.322673E+01 315 8.521242E+00 5.322672E+01 316 8.521073E+00 5.322349E+01 317 8.523079E+00 5.322355E+01 318 8.523496E+00 5.322194E+01 319 8.526415E+00 5.322205E+01 320 8.530420E+00 5.321658E+01 321 8.537112E+00 5.321534E+01 322 8.541184E+00 5.321616E+01 323 8.543892E+00 5.321398E+01 324 8.547045E+00 5.321377E+01 325 8.554182E+00 5.320877E+01 326 8.566145E+00 5.321435E+01 327 8.572005E+00 5.321167E+01 328 8.578437E+00 5.321813E+01 329 8.599362E+00 5.321342E+01 330 8.600150E+00 5.321098E+01 331 8.597396E+00 5.320713E+01 332 8.582182E+00 5.319914E+01 333 8.585757E+00 5.319609E+01 334 8.581361E+00 5.319330E+01 335 8.581800E+00 5.319125E+01 336 8.584542E+00 5.319106E+01 337 8.584954E+00 5.319017E+01 338 8.589129E+00 5.319038E+01 339 8.593007E+00 5.318786E+01 340 8.592324E+00 5.318661E+01 341 8.593501E+00 5.318500E+01 342 8.608214E+00 5.318922E+01 343 8.608342E+00 5.319322E+01 344 8.615320E+00 5.319451E+01 345 END 346 END -
test/data/holes.poly
1 holes 2 o1 3 2.285156e+00 4.126465e+01 4 2.285156e+00 4.161621e+01 5 1.757813e-01 4.161621e+01 6 1.757813e-01 4.258301e+01 7 -3.515625e-01 4.258301e+01 8 -3.515625e-01 4.267090e+01 9 -1.142578e+00 4.267090e+01 10 -1.142578e+00 4.293457e+01 11 -1.494141e+00 4.293457e+01 12 -1.494141e+00 4.302246e+01 13 -6.328125e+00 4.302246e+01 14 -6.328125e+00 4.521973e+01 15 -6.152344e+00 4.521973e+01 16 -6.152344e+00 4.671387e+01 17 -6.328125e+00 4.671387e+01 18 -6.328125e+00 5.084473e+01 19 -2.724609e+00 5.084473e+01 20 -2.724609e+00 5.075684e+01 21 -7.910156e-01 5.075684e+01 22 -7.910156e-01 5.137207e+01 23 2.988281e+00 5.137207e+01 24 2.988281e+00 5.084473e+01 25 3.251953e+00 5.084473e+01 26 3.251953e+00 5.093262e+01 27 4.394531e+00 5.093262e+01 28 4.394531e+00 5.040527e+01 29 5.449219e+00 5.040527e+01 30 5.449219e+00 4.979004e+01 31 6.591797e+00 4.979004e+01 32 6.591797e+00 4.952637e+01 33 7.382813e+00 4.952637e+01 34 7.382813e+00 4.935059e+01 35 8.349609e+00 4.935059e+01 36 8.349609e+00 4.873535e+01 37 8.437500e+00 4.873535e+01 38 8.437500e+00 4.864746e+01 39 8.085938e+00 4.864746e+01 40 8.085938e+00 4.855957e+01 41 7.998047e+00 4.855957e+01 42 7.998047e+00 4.829590e+01 43 7.822266e+00 4.829590e+01 44 7.822266e+00 4.803223e+01 45 9.843750e+00 4.803223e+01 46 9.843750e+00 4.662598e+01 47 7.382813e+00 4.662598e+01 48 7.382813e+00 4.645020e+01 49 7.207031e+00 4.645020e+01 50 7.207031e+00 4.592285e+01 51 9.843750e+00 4.592285e+01 52 9.843750e+00 4.442871e+01 53 9.404297e+00 4.442871e+01 54 9.404297e+00 4.337402e+01 55 9.843750e+00 4.337402e+01 56 9.843750e+00 4.126465e+01 57 8.261719e+00 4.126465e+01 58 8.261719e+00 4.196777e+01 59 7.910156e+00 4.196777e+01 60 7.910156e+00 4.179199e+01 61 6.064453e+00 4.179199e+01 62 6.064453e+00 4.144043e+01 63 4.833984e+00 4.144043e+01 64 4.833984e+00 4.258301e+01 65 4.570313e+00 4.258301e+01 66 4.570313e+00 4.126465e+01 67 2.285156e+00 4.126465e+01 68 END 69 !inner1 70 4.394531e+00 5.014160e+01 71 4.394531e+00 5.022949e+01 72 4.306641e+00 5.022949e+01 73 4.306641e+00 5.014160e+01 74 4.394531e+00 5.014160e+01 75 END 76 !inner2 77 -4.394531e+00 4.873535e+01 78 -4.394531e+00 4.882324e+01 79 -4.746094e+00 4.882324e+01 80 -4.746094e+00 4.873535e+01 81 -4.394531e+00 4.873535e+01 82 END 83 !inner3 84 -2.021484e+00 4.521973e+01 85 -2.021484e+00 4.601074e+01 86 -2.109375e+00 4.601074e+01 87 -2.109375e+00 4.521973e+01 88 -2.021484e+00 4.521973e+01 89 END 90 END -
test/data/multi-concat.poly
1 first 2 1 3 109.116270 -19.754965 4 134.560899 -8.865515 5 155.225021 -11.445777 6 178.973341 -34.767630 7 178.819131 -47.479347 8 122.378319 -49.422367 9 103.873134 -24.186817 10 109.116270 -19.754965 11 END 12 END 13 14 second 15 1 16 -27.000000 75.000000 17 -32.733610 39.048420 18 -17.137840 31.093990 19 -9.611205 35.985870 20 -5.653329 35.894580 21 -5.393482 35.987210 22 -5.085261 36.046190 23 3.541102 37.759810 24 11.600370 37.778150 25 11.600370 34.000000 26 35.408480 33.992890 27 35.408480 35.627900 28 36.236940 35.806410 29 36.768620 36.195300 30 36.754060 36.570560 31 39.193940 36.611490 32 42.398570 37.054530 33 44.328630 36.914900 34 44.996930 37.199370 35 45.000000 75.000000 36 -27.000000 75.000000 37 END 38 !2 39 9.890545E+00 4.822680E+01 40 9.892534E+00 4.752921E+01 41 1.130254E+01 4.753324E+01 42 1.127072E+01 4.827977E+01 43 9.890545E+00 4.822680E+01 44 END 45 END 46 47 third 48 1 49 -179.915000 -60.347030 50 -23.244010 -61.792990 51 -23.834280 -16.230710 52 -45.475220 10.055700 53 -74.969470 13.604260 54 -80.765080 3.298111 55 -95.342020 3.287621 56 -179.999900 -4.938220 57 -179.999900 -60.347030 58 -179.915000 -60.347030 59 END 60 END -
test/data/name-missing.poly
1 multi-1 2 1 3 109.116270 -19.754965 4 134.560899 -8.865515 5 155.225021 -11.445777 6 178.973341 -34.767630 7 178.819131 -47.479347 8 122.378319 -49.422367 9 103.873134 -24.186817 10 109.116270 -19.754965 11 END 12 -179.915000 -60.347030 13 -23.244010 -61.792990 14 -23.834280 -16.230710 15 -45.475220 10.055700 16 -74.969470 13.604260 17 -80.765080 3.298111 18 -95.342020 3.287621 19 -179.999900 -4.938220 20 -179.999900 -60.347030 21 -179.915000 -60.347030 22 END 23 END -
test/data/simple.poly
1 simple 2 1 3 9.890545E+00 4.822680E+01 4 9.892534E+00 4.752921E+01 5 1.130254E+01 4.753324E+01 6 1.127072E+01 4.827977E+01 7 9.890545E+00 4.822680E+01 8 END 9 END -
test/data/splitter.poly
1 area 2 1 3 7.382813 51.284180 4 7.382813 51.679688 5 6.635742 51.679688 6 6.635742 52.690430 7 6.416016 52.690430 8 6.416016 54.184570 9 8.920898 54.184570 10 8.920898 54.140625 11 10.502930 54.140625 12 10.502930 53.964844 13 11.645508 53.964844 14 11.645508 51.459961 15 10.546875 51.459961 16 10.546875 51.284180 17 7.382813 51.284180 18 END 19 END -
test/data/u.poly
1 second 2 1 3 -27.000000 75.000000 4 -32.733610 39.048420 5 -17.137840 31.093990 6 -9.611205 35.985870 7 -5.653329 35.894580 8 -5.393482 35.987210 9 -5.085261 36.046190 10 3.541102 37.759810 11 11.600370 37.778150 12 11.600370 34.000000 13 35.408480 33.992890 14 35.408480 35.627900 15 36.236940 35.806410 16 36.768620 36.195300 17 36.754060 36.570560 18 39.193940 36.611490 19 42.398570 37.054530 20 44.328630 36.914900 21 44.996930 37.199370 22 45.000000 75.000000 23 -27.000000 75.000000 24 END 25 !2 26 9.890545 48.226800 27 9.892534 47.529210 28 11.302540 47.533240 29 11.270720 48.279770 30 9.890545 48.226800 31 END 32 third 33 -179.915000 -60.347030 34 -23.244010 -61.792990 35 -23.834280 -16.230710 36 -45.475220 10.055700 37 -74.969470 13.604260 38 -80.765080 3.298111 39 -95.342020 3.287621 40 -179.999900 -4.938220 41 -179.999900 -60.347030 42 -179.915000 -60.347030 43 END 44 first 45 109.116270 -19.754965 46 134.560899 -8.865515 47 155.225021 -11.445777 48 178.973341 -34.767630 49 178.819131 -47.479347 50 122.378319 -49.422367 51 103.873134 -24.186817 52 109.116270 -19.754965 53 END 54 END -
test/unit/poly/PolyImporterTest.java
1 // License: GPL. For details, see LICENSE file. 2 package poly; 3 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertNotNull; 6 import static org.junit.Assert.assertNull; 7 8 import org.junit.Rule; 9 import org.junit.Test; 10 import org.openstreetmap.josm.TestUtils; 11 import org.openstreetmap.josm.data.osm.DataSet; 12 import org.openstreetmap.josm.io.IllegalDataException; 13 import org.openstreetmap.josm.testutils.JOSMTestRules; 14 15 /** 16 * Unit tests for {@link O5mImporter}. 17 */ 18 public class PolyImporterTest { 19 20 /** 21 * Setup test. 22 */ 23 @Rule 24 public JOSMTestRules rules = new JOSMTestRules().preferences(); 25 26 /** 27 * @throws Exception if an error occurs 28 */ 29 @Test 30 public void testSimple() throws Exception { 31 DataSet ds = new PolyImporter().parseDataSet(TestUtils.getTestDataRoot() + "/simple.poly"); 32 assertNotNull(ds); 33 assertEquals(4, ds.getNodes().size()); 34 assertEquals(1, ds.getWays().size()); 35 assertEquals(0, ds.getRelations().size()); 36 } 37 38 /** 39 * File with human friendly coordinate format 40 * @throws Exception if an error occurs 41 */ 42 @Test 43 public void testSimple2() throws Exception { 44 DataSet ds = new PolyImporter().parseDataSet(TestUtils.getTestDataRoot() + "/splitter.poly"); 45 assertNotNull(ds); 46 assertEquals(14, ds.getNodes().size()); 47 assertEquals(1, ds.getWays().size()); 48 assertEquals(0, ds.getRelations().size()); 49 } 50 51 /** 52 * @throws Exception if an error occurs 53 */ 54 @Test 55 public void testHoles() throws Exception { 56 DataSet ds = new PolyImporter().parseDataSet(TestUtils.getTestDataRoot() + "/holes.poly"); 57 assertNotNull(ds); 58 assertEquals(76, ds.getNodes().size()); 59 assertEquals(4, ds.getWays().size()); 60 assertEquals(1, ds.getRelations().size()); 61 } 62 63 /** 64 * @throws Exception if an error occurs 65 */ 66 @Test 67 public void testDoubleEnd() throws Exception { 68 DataSet ds = new PolyImporter().parseDataSet(TestUtils.getTestDataRoot() + "/bremen-double-end.poly"); 69 assertNotNull(ds); 70 assertEquals(337, ds.getNodes().size()); 71 assertEquals(2, ds.getWays().size()); 72 assertEquals(1, ds.getRelations().size()); 73 } 74 75 /** 76 * @throws Exception if an error occurs 77 */ 78 @Test 79 public void testMultipleFile() throws Exception { 80 DataSet ds = new PolyImporter().parseDataSet(TestUtils.getTestDataRoot() + "/multi-concat.poly"); 81 assertNotNull(ds); 82 assertEquals(40, ds.getNodes().size()); 83 assertEquals(4, ds.getWays().size()); 84 assertEquals(1, ds.getRelations().size()); 85 } 86 87 /** 88 * Should throw an IllegalDataException 89 * @throws Exception if an error occurs 90 */ 91 @Test (expected = IllegalDataException.class) 92 public void testNameMissing() throws Exception { 93 DataSet ds = new PolyImporter().parseDataSet(TestUtils.getTestDataRoot() + "/name-missing.poly"); 94 assertNull(ds); 95 } 96 97 }
