From: <svn...@os...> - 2012-04-21 23:10:38
|
Author: aaime Date: 2012-04-21 16:10:31 -0700 (Sat, 21 Apr 2012) New Revision: 38684 Added: trunk/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/ trunk/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.dbf trunk/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.prj trunk/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.shp trunk/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.shx Modified: trunk/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/shp/MultiLineHandler.java trunk/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreTest.java Log: [GEOT-4090] Features missing when importing shapefile Modified: trunk/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/shp/MultiLineHandler.java =================================================================== --- trunk/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/shp/MultiLineHandler.java 2012-04-21 22:27:55 UTC (rev 38683) +++ trunk/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/shp/MultiLineHandler.java 2012-04-21 23:10:31 UTC (rev 38684) @@ -146,6 +146,7 @@ } length = finish - start; + int xyLength = length; if (length == 1) { length = 2; clonePoint = true; @@ -154,9 +155,9 @@ } CoordinateSequence cs = geometryFactory.getCoordinateSequenceFactory().create(length, dimensions); - double[] xy = new double[length * 2]; + double[] xy = new double[xyLength * 2]; doubleBuffer.get(xy); - for (int i = 0; i < length; i++) { + for (int i = 0; i < xyLength; i++) { cs.setOrdinate(i, 0, xy[i * 2]); cs.setOrdinate(i, 1, xy[i * 2 + 1]); } Modified: trunk/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreTest.java =================================================================== --- trunk/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreTest.java 2012-04-21 22:27:55 UTC (rev 38683) +++ trunk/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreTest.java 2012-04-21 23:10:31 UTC (rev 38684) @@ -47,7 +47,6 @@ import org.geotools.data.simple.SimpleFeatureCollection; import org.geotools.data.simple.SimpleFeatureIterator; import org.geotools.data.simple.SimpleFeatureSource; -import org.geotools.factory.CommonFactoryFinder; import org.geotools.feature.FeatureCollections; import org.geotools.feature.FeatureTypes; import org.geotools.feature.simple.SimpleFeatureBuilder; @@ -60,14 +59,15 @@ import org.opengis.feature.type.AttributeDescriptor; import org.opengis.feature.type.FeatureType; import org.opengis.filter.Filter; -import org.opengis.filter.FilterFactory2; import org.opengis.referencing.crs.CoordinateReferenceSystem; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryCollection; import com.vividsolutions.jts.geom.GeometryFactory; +import com.vividsolutions.jts.geom.LineString; import com.vividsolutions.jts.geom.LinearRing; +import com.vividsolutions.jts.geom.MultiLineString; import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.geom.Polygon; @@ -930,7 +930,40 @@ doTestReadWriteDate("2000-01-01"); } + public void testLinestringOnePoint() throws Exception { + URL u = TestData.url(TestCaseSupport.class, "lsOnePoint/lsOnePoint.shp"); + File f = DataUtilities.urlToFile(u); + assertTrue(f.exists()); + + store = new ShapefileDataStore(u); + SimpleFeatureSource fs = store.getFeatureSource(store.getTypeNames()[0]); + SimpleFeatureCollection fc = fs.getFeatures(); + assertEquals(3, fc.size()); + + int i = 418; + SimpleFeatureIterator it = fc.features(); + while(it.hasNext()) { + SimpleFeature sf = it.next(); + assertEquals("Activity" + i, sf.getAttribute("Name")); + + if(i == 419) { + assertNotNull(sf.getDefaultGeometry()); + assertTrue(sf.getDefaultGeometry() instanceof MultiLineString); + MultiLineString mls = (MultiLineString) sf.getDefaultGeometry(); + assertEquals(1, mls.getNumGeometries()); + LineString ls = (LineString) mls.getGeometryN(0); + assertEquals(2, ls.getNumPoints()); + assertEquals(ls.getStartPoint(), ls.getEndPoint()); + } + i++; + } + + assertEquals(421, i); + + assertEquals(3, fc.toArray().length); + } + /** * This is useful to dump a UTF16 character to an UT16 escape sequence, * basically the only way to represent the chars we don't have on the Added: trunk/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.dbf =================================================================== --- trunk/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.dbf (rev 0) +++ trunk/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.dbf 2012-04-21 23:10:31 UTC (rev 38684) @@ -0,0 +1,2 @@ +_ |