Ticket #13843: patch_13843.diff
| File patch_13843.diff, 9.9 KB (added by , 7 years ago) |
|---|
-
src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpReader.java
diff --git a/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpReader.java b/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpReader.java index 5b7c3d4..6f472f5 100644
a b public class ShpReader extends GeographicReader { 115 115 } 116 116 } 117 117 118 OsmPrimitive primitive = null; 119 120 if (geometry.getValue() instanceof Point) { 121 primitive = createOrGetEmptyNode((Point) geometry.getValue()); 122 123 } else if (geometry.getValue() instanceof GeometryCollection) { // Deals with both MultiLineString and MultiPolygon 124 GeometryCollection gc = (GeometryCollection) geometry.getValue(); 125 int nGeometries = gc.getNumGeometries(); 126 if (nGeometries < 1) { 127 Logging.error("empty geometry collection found"); 128 } else { 129 Relation r = null; 130 Way w = null; 131 132 for (int i = 0; i < nGeometries; i++) { 133 Geometry g = gc.getGeometryN(i); 134 if (g instanceof Polygon) { 135 Polygon p = (Polygon) g; 136 // Do not create relation if there's only one polygon without interior ring 137 // except if handler prefers it 138 if (r == null && (nGeometries > 1 || p.getNumInteriorRing() > 0 || 139 (handler != null && handler.preferMultipolygonToSimpleWay()))) { 140 r = createMultipolygon(); 141 } 142 w = createOrGetWay(p.getExteriorRing()); 143 if (r != null) { 144 addWayToMp(r, "outer", w); 145 for (int j = 0; j < p.getNumInteriorRing(); j++) { 146 addWayToMp(r, "inner", createOrGetWay(p.getInteriorRingN(j))); 147 } 148 } 149 } else if (g instanceof LineString) { 150 w = createOrGetWay((LineString) g); 151 } else if (g instanceof Point) { 152 // Some belgian data sets hold points into collections ?! 153 readNonGeometricAttributes(feature, createOrGetNode((Point) g)); 154 } else { 155 Logging.error("unsupported geometry : "+g); 156 } 157 } 158 primitive = r != null ? r : w; 118 Object geomObject = geometry.getValue(); 119 if (geomObject instanceof Point) { // TODO: Support LineString and Polygon. 120 // Sure you could have a Set of 1 object and join these 2 branches of 121 // code, but I feel there would be a performance hit. 122 OsmPrimitive primitive = createOrGetEmptyNode((Point) geomObject); 123 readNonGeometricAttributes(feature, primitive); 124 } else if (geomObject instanceof GeometryCollection) { // Deals with both MultiLineString and MultiPolygon 125 Set<OsmPrimitive> primitives = processGeometryCollection((GeometryCollection) geomObject); 126 for (OsmPrimitive prim : primitives) { 127 readNonGeometricAttributes(feature, prim); 159 128 } 160 129 } else { 161 130 // Debug unknown geometry … … public class ShpReader extends GeographicReader { 163 132 Logging.debug("\tbounds: "+geometry.getBounds()); 164 133 Logging.debug("\tdescriptor: "+desc); 165 134 Logging.debug("\tname: "+geometry.getName()); 166 Logging.debug("\tvalue: "+geom etry.getValue());135 Logging.debug("\tvalue: "+geomObject); 167 136 Logging.debug("\tid: "+geometry.getIdentifier()); 168 137 Logging.debug("-------------------------------------------------------------"); 169 138 } 139 } 140 } 170 141 171 if (primitive != null) { 172 // Read primitive non geometric attributes 173 readNonGeometricAttributes(feature, primitive); 142 protected Set<OsmPrimitive> processGeometryCollection(GeometryCollection gc) throws TransformException { 143 // A feture may be a collection. This set holds the items of the collection. 144 Set<OsmPrimitive> primitives = new HashSet<>(); 145 int nGeometries = gc.getNumGeometries(); 146 if (nGeometries < 1) { 147 Logging.error("empty geometry collection found"); 148 } else { 149 // Create the primitive "op" and add it to the set of primitives. 150 for (int i = 0; i < nGeometries; i++) { 151 OsmPrimitive op = null; 152 Geometry g = gc.getGeometryN(i); 153 if (g instanceof Polygon) { 154 Relation r = (Relation) op; 155 Polygon p = (Polygon) g; 156 // Do not create relation if there's only one polygon without interior ring 157 // except if handler prefers it 158 if (r == null && (nGeometries > 1 || p.getNumInteriorRing() > 0 || 159 (handler != null && handler.preferMultipolygonToSimpleWay()))) { 160 r = createMultipolygon(); 161 } 162 if (r != null) { 163 addWayToMp(r, "outer", createOrGetWay(p.getExteriorRing())); 164 for (int j = 0; j < p.getNumInteriorRing(); j++) { 165 addWayToMp(r, "inner", createOrGetWay(p.getInteriorRingN(j))); 166 } 167 } 168 } else if (g instanceof LineString) { 169 op = createOrGetWay((LineString) g); 170 } else if (g instanceof Point) { 171 op = createOrGetNode((Point) g); 172 } else { 173 Logging.error("unsupported geometry : "+g); 174 } 175 primitives.add(op); 174 176 } 175 177 } 178 return primitives; 176 179 } 177 180 178 181 public DataSet parse(File file, ProgressMonitor instance) throws IOException { -
new file test/data/regress/12843/test.prj
diff --git a/test/data/regress/12843/test.dbf b/test/data/regress/12843/test.dbf new file mode 100644 index 0000000..a5a7a46 Binary files /dev/null and b/test/data/regress/12843/test.dbf differ diff --git a/test/data/regress/12843/test.prj b/test/data/regress/12843/test.prj new file mode 100644 index 0000000..a30c00a
- + 1 GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]] 2 No newline at end of file -
new file test/data/regress/12843/test.qpj
diff --git a/test/data/regress/12843/test.qpj b/test/data/regress/12843/test.qpj new file mode 100644 index 0000000..5fbc831
- + 1 GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]] -
test/unit/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpReaderTest.java
diff --git a/test/data/regress/12843/test.shp b/test/data/regress/12843/test.shp new file mode 100644 index 0000000..9f22c28 Binary files /dev/null and b/test/data/regress/12843/test.shp differ diff --git a/test/data/regress/12843/test.shx b/test/data/regress/12843/test.shx new file mode 100644 index 0000000..09fb172 Binary files /dev/null and b/test/data/regress/12843/test.shx differ diff --git a/test/unit/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpReaderTest.java b/test/unit/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpReaderTest.java index cb7fa02..2e89c05 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.opendata.core.io.geographic; 3 3 4 import static org.junit.Assert.assertEquals; 4 5 import static org.junit.Assert.assertFalse; 5 6 import static org.junit.Assert.assertNotNull; 6 7 import static org.junit.Assert.assertTrue; … … import static org.junit.Assert.assertTrue; 8 9 import java.io.File; 9 10 import java.io.FileInputStream; 10 11 import java.io.InputStream; 12 import java.util.Collection; 11 13 12 14 import org.junit.Ignore; 13 15 import org.junit.Rule; … … import org.junit.Test; 15 17 import org.openstreetmap.josm.TestUtils; 16 18 import org.openstreetmap.josm.data.coor.LatLon; 17 19 import org.openstreetmap.josm.data.osm.Node; 20 import org.openstreetmap.josm.data.osm.Way; 18 21 import org.openstreetmap.josm.plugins.opendata.core.io.NonRegFunctionalTests; 19 22 import org.openstreetmap.josm.testutils.JOSMTestRules; 20 23 … … public class ShpReaderTest { 84 87 NonRegFunctionalTests.testGeneric("#8309", ShpReader.parseDataSet(is, file, null, null)); 85 88 } 86 89 } 90 91 /** 92 * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/12843">#12843</a> 93 * @throws Exception if an error occurs during reading 94 */ 95 @Test 96 public void testTicket12843() throws Exception { 97 File file = new File(TestUtils.getRegressionDataFile(12843, "test.shp")); 98 try (InputStream is = new FileInputStream(file)) { 99 Collection<Way> ways = ShpReader.parseDataSet(is, file, null, null).getWays(); 100 assertFalse(ways.isEmpty()); 101 for (Way way : ways) { 102 assertEquals("Test", way.get("name")); 103 } 104 } 105 } 87 106 }
