SimpleFeatureSource fs = ShapeFileReader.readDataFile(this.mnShpFileName); SimpleFeatureIterator fIt = fs.getFeatures().features(); while (fIt.hasNext()) {
/** * Reads all Features in the file into the returned Set and initializes the instance of this class. */ public Collection<SimpleFeature> readFileAndInitialize(final String filename) throws UncheckedIOException { try { this.featureSource = ShapeFileReader.readDataFile(filename); this.init(); SimpleFeature ft = null; SimpleFeatureIterator it = this.featureSource.getFeatures().features(); this.featureSet = new ArrayList<SimpleFeature>(); log.info("features to read #" + this.featureSource.getFeatures().size()); Counter cnt = new Counter("features read #"); while (it.hasNext()) { ft = it.next(); this.featureSet.add(ft); cnt.incCounter(); } cnt.printCounter(); it.close(); return this.featureSet; } catch (IOException e) { throw new UncheckedIOException(e); } }
SimpleFeatureSource fs = ShapeFileReader.readDataFile(jcShpFileName); SimpleFeatureIterator fIt = fs.getFeatures().features(); while (fIt.hasNext()) {
int lCnt = network.getLinks().size(); int ignoreCnt = 0; SimpleFeatureSource fs = ShapeFileReader.readDataFile(this.nwShpFileName); SimpleFeatureIterator fIt = fs.getFeatures().features(); while (fIt.hasNext()) {
/** * Based on message on users-mailing list from 20Dec2012) * @throws IOException */ @Test public void testPlusInFilename() throws IOException { String filename = "src/test/resources/" + utils.getInputDirectory() + "test+test.shp"; FeatureSource fs = ShapeFileReader.readDataFile(filename); Assert.assertEquals(3, fs.getFeatures().size()); } }
SimpleFeatureSource s1 = ShapeFileReader.readDataFile(outFile); SimpleFeatureCollection fts1 = s1.getFeatures(); SimpleFeatureIterator it1 = fts1.features();
@Test public void testShapeFileWriter() throws IOException{ String inFile = "src/test/resources/" + utils.getInputDirectory() + "test.shp"; String outFile = utils.getOutputDirectory() + "/test.shp"; SimpleFeatureSource s = ShapeFileReader.readDataFile(inFile); SimpleFeatureCollection fts = s.getFeatures(); SimpleFeatureIterator it = fts.features(); SimpleFeature ft = it.next(); Geometry g = (Geometry) ft.getDefaultGeometry(); List<SimpleFeature> fc = new ArrayList<>(); fc.add(ft); ShapeFileWriter.writeGeometries(fc, outFile); SimpleFeatureSource s1 = ShapeFileReader.readDataFile(outFile); SimpleFeatureCollection fts1 = s1.getFeatures(); SimpleFeatureIterator it1 = fts1.features(); SimpleFeature ft1 = it1.next(); Geometry g1 = (Geometry) ft1.getDefaultGeometry(); Assert.assertEquals(g.getCoordinates().length, g1.getCoordinates().length); }
@Test public void testShapeFileWriterWithSelfCreatedContent_withMatsimFactory_Polyline() throws IOException { String outFile = utils.getOutputDirectory() + "test.shp"; PolylineFeatureFactory ff = new PolylineFeatureFactory.Builder() .setName("EvacuationArea") .setCrs(DefaultGeographicCRS.WGS84) .addAttribute("name", String.class) .create(); Coordinate[] coordinates = new Coordinate[]{new Coordinate(0,0),new Coordinate(0,1),new Coordinate(1,1),new Coordinate(0,0)}; SimpleFeature f = ff.createPolyline(coordinates); Collection<SimpleFeature> features = new ArrayList<SimpleFeature>(); features.add(f); Geometry g0 = (Geometry) f.getDefaultGeometry(); ShapeFileWriter.writeGeometries(features, outFile); SimpleFeatureSource s1 = ShapeFileReader.readDataFile(outFile); SimpleFeatureCollection fts1 = s1.getFeatures(); SimpleFeatureIterator it1 = fts1.features(); SimpleFeature ft1 = it1.next(); Geometry g1 = (Geometry) ft1.getDefaultGeometry(); Assert.assertEquals(g0.getCoordinates().length, g1.getCoordinates().length); }
@Test public void testShapeFileWriterWithSelfCreatedContent_withMatsimFactory_Polygon() throws IOException { String outFile = utils.getOutputDirectory() + "test.shp"; PolygonFeatureFactory ff = new PolygonFeatureFactory.Builder() .setName("EvacuationArea") .setCrs(DefaultGeographicCRS.WGS84) .addAttribute("name", String.class) .create(); Coordinate[] coordinates = new Coordinate[]{new Coordinate(0,0),new Coordinate(0,1),new Coordinate(1,1),new Coordinate(0,0)}; SimpleFeature f = ff.createPolygon(coordinates); Collection<SimpleFeature> features = new ArrayList<SimpleFeature>(); features.add(f); Geometry g0 = (Geometry) f.getDefaultGeometry(); ShapeFileWriter.writeGeometries(features, outFile); SimpleFeatureSource s1 = ShapeFileReader.readDataFile(outFile); SimpleFeatureCollection fts1 = s1.getFeatures(); SimpleFeatureIterator it1 = fts1.features(); SimpleFeature ft1 = it1.next(); Geometry g1 = (Geometry) ft1.getDefaultGeometry(); Assert.assertEquals(g0.getCoordinates().length, g1.getCoordinates().length); }
@Test public void testShapeFileWriterWithSelfCreatedContent_withMatsimFactory_Point() throws IOException { String outFile = utils.getOutputDirectory() + "test.shp"; PointFeatureFactory ff = new PointFeatureFactory.Builder() .setName("EvacuationArea") .setCrs(DefaultGeographicCRS.WGS84) .addAttribute("name", String.class) .create(); SimpleFeature f = ff.createPoint(new Coordinate(10, 20)); Collection<SimpleFeature> features = new ArrayList<SimpleFeature>(); features.add(f); Geometry g0 = (Geometry) f.getDefaultGeometry(); ShapeFileWriter.writeGeometries(features, outFile); SimpleFeatureSource s1 = ShapeFileReader.readDataFile(outFile); SimpleFeatureCollection fts1 = s1.getFeatures(); SimpleFeatureIterator it1 = fts1.features(); SimpleFeature ft1 = it1.next(); Geometry g1 = (Geometry) ft1.getDefaultGeometry(); Assert.assertEquals(g0.getCoordinates().length, g1.getCoordinates().length); } }