From: <svn...@os...> - 2012-04-29 09:32:54
|
Author: aaime Date: 2012-04-29 02:32:47 -0700 (Sun, 29 Apr 2012) New Revision: 38693 Added: branches/2.7.x/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/ branches/2.7.x/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.dbf branches/2.7.x/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.prj branches/2.7.x/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.shp branches/2.7.x/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.shx Modified: branches/2.7.x/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/shp/MultiLineHandler.java branches/2.7.x/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreTest.java Log: [GEOT-4090] Features missing when importing shapefile Modified: branches/2.7.x/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/shp/MultiLineHandler.java =================================================================== --- branches/2.7.x/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/shp/MultiLineHandler.java 2012-04-26 16:21:23 UTC (rev 38692) +++ branches/2.7.x/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/shp/MultiLineHandler.java 2012-04-29 09:32:47 UTC (rev 38693) @@ -145,6 +145,7 @@ } length = finish - start; + int xyLength = length; if (length == 1) { length = 2; clonePoint = true; @@ -153,9 +154,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: branches/2.7.x/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreTest.java =================================================================== --- branches/2.7.x/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreTest.java 2012-04-26 16:21:23 UTC (rev 38692) +++ branches/2.7.x/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreTest.java 2012-04-29 09:32:47 UTC (rev 38693) @@ -67,7 +67,9 @@ 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; @@ -85,8 +87,7 @@ final static String DANISH = "shapes/danish_point.shp"; final static String CHINESE = "shapes/chinese_poly.shp"; final static String RUSSIAN = "shapes/rus-windows-1251.shp"; - final static FilterFactory2 ff = CommonFactoryFinder - .getFilterFactory2(null); + final static FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); private ShapefileDataStore store; public ShapefileDataStoreTest(String testName) throws IOException { @@ -936,7 +937,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()); + assertTrue(ls.getStartPoint().equals(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: branches/2.7.x/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.dbf =================================================================== --- branches/2.7.x/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.dbf (rev 0) +++ branches/2.7.x/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.dbf 2012-04-29 09:32:47 UTC (rev 38693) @@ -0,0 +1,2 @@ +_ |