Changeset 34966 in osm for applications/editors/josm/plugins
- Timestamp:
- 2019-04-07T07:14:21+02:00 (6 years ago)
- Location:
- applications/editors/josm/plugins/poly
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/poly/src/poly/PolyExporter.java
r34860 r34966 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.BufferedWriter;7 6 import java.io.File; 8 7 import java.io.IOException; 8 import java.io.PrintWriter; 9 9 import java.nio.charset.StandardCharsets; 10 10 import java.nio.file.Files; … … 43 43 throw new IOException(tr("Data contains unclosed ways.")); 44 44 } 45 try ( BufferedWriter writer = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) {45 try (PrintWriter writer = new PrintWriter(Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8))) { 46 46 DataSet ds = ((OsmDataLayer) layer).getDataSet(); 47 47 HashSet<Way> written = new HashSet<>(); … … 56 56 if (rel.isMultipolygon()) { 57 57 if (!firstFile) { 58 writer. newLine();58 writer.println(); 59 59 } 60 60 writeRelation(writer, fileName, rel, written); … … 64 64 65 65 if (firstFile) { 66 writer. write(fileName);66 writer.println(fileName); 67 67 } 68 68 int counter = 1; … … 72 72 } 73 73 } 74 writer.write("END"); 75 writer.newLine(); 74 writer.println("END"); 76 75 } 77 76 } 78 77 } 79 78 80 private static void writeRelation( BufferedWriter writer, String fileName, Relation rel, Set<Way> written) throws IOException{79 private static void writeRelation(PrintWriter writer, String fileName, Relation rel, Set<Way> written) { 81 80 String polygonName = fileName; 82 81 if (rel.getName() != null) 83 82 polygonName = rel.getName(); 84 writer.write(polygonName); 85 writer.newLine(); 83 writer.println(polygonName); 86 84 int counter = 1; 87 85 for (RelationMember rm: rel.getMembers()) { … … 96 94 } 97 95 98 private static int writeWay( BufferedWriter writer, Way w, int counter) throws IOException{96 private static int writeWay(PrintWriter writer, Way w, int counter) { 99 97 String name = w.getName(); 100 98 if (name == null) { 101 99 name = String.valueOf(counter++); 102 100 } 103 writer.write(name); 104 writer.newLine(); 101 writer.println(name); 105 102 106 103 for (Node n : w.getNodes()) { 107 writer.write(String.format(Locale.ENGLISH, " %f %f", n.getCoor().lon(), n.getCoor().lat())); 108 writer.newLine(); 104 writer.println(String.format(Locale.ENGLISH, " %f %f", n.getCoor().lon(), n.getCoor().lat())); 109 105 } 110 writer.write("END"); 111 writer.newLine(); 106 writer.println("END"); 112 107 return counter; 113 108 } -
applications/editors/josm/plugins/poly/test/unit/poly/PolyExporterTest.java
r34860 r34966 32 32 */ 33 33 @Test 34 public void testSimpleExport() throws Exception { 35 DataSet dsIn1 = new PolyImporter().parseDataSet(TestUtils.getTestDataRoot() + "/simple.poly"); 36 assertNotNull(dsIn1); 37 assertEquals(4, dsIn1.getNodes().size()); 38 assertEquals(1, dsIn1.getWays().size()); 39 assertEquals(0, dsIn1.getRelations().size()); 40 41 Path out = Files.createTempFile("simple-out", "poly"); 42 new PolyExporter().exportData(out.toFile(), new OsmDataLayer(dsIn1, null, null)); 43 DataSet dsIn2 = new PolyImporter().parseDataSet(out.toString()); 44 assertNotNull(dsIn2); 45 assertEquals(4, dsIn2.getNodes().size()); 46 assertEquals(1, dsIn2.getWays().size()); 47 assertEquals(0, dsIn2.getRelations().size()); 48 49 Files.delete(out); 50 } 51 52 /** 53 * Import file, export it, import the exported file and compare content 54 * @throws Exception if an error occurs 55 */ 56 @Test 34 57 public void testExport() throws Exception { 35 58 DataSet dsIn1 = new PolyImporter().parseDataSet(TestUtils.getTestDataRoot() + "/holes.poly");
Note:
See TracChangeset
for help on using the changeset viewer.