Collection<SimpleFeature> features = new ShapeFileReader().readFileAndInitialize(serviceAreaFile); Collection<Geometry> include = new ArrayList<>(); Collection<Geometry> exclude = new ArrayList<>();
public void readZones(String file, String idHeader) { Collection<SimpleFeature> features = ShapeFileReader.getAllFeatures(file); if (features.size() != zones.size()) { throw new RuntimeException("Features#: " + features.size() + "; zones#: " + zones.size()); } for (SimpleFeature ft : features) { String id = ft.getAttribute(idHeader).toString(); Zone z = zones.get(Id.create(id, Zone.class)); z.setMultiPolygon((MultiPolygon)ft.getDefaultGeometry()); } } }
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); } }
Collection<SimpleFeature> features = new ShapeFileReader().readFileAndInitialize(serviceAreaFile); Collection<Geometry> include = new ArrayList<>(); Collection<Geometry> exclude = new ArrayList<>();
int lCnt = network.getLinks().size(); int ignoreCnt = 0; SimpleFeatureSource fs = ShapeFileReader.readDataFile(this.nwShpFileName); SimpleFeatureIterator fIt = fs.getFeatures().features(); while (fIt.hasNext()) {
public void testNodesShape() { String netFileName = "test/scenarios/equil/network.xml"; String outputFileShp = getOutputDirectory() + "./network.shp"; Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); final Network network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile(netFileName); new Nodes2ESRIShape(network,outputFileShp, "DHDN_GK4").write(); Collection<SimpleFeature> writtenFeatures = ShapeFileReader.getAllFeatures(outputFileShp); Assert.assertEquals(network.getNodes().size(), writtenFeatures.size()); } }
public static final ActivityFacilities createFacilityFromBuildingShapefile(String shapeFileName, String identifierCaption, String numberOfHouseholdsCaption) { ShapeFileReader shapeFileReader = new ShapeFileReader(); Collection<SimpleFeature> features = shapeFileReader.readFileAndInitialize(shapeFileName); ActivityFacilities facilities = FacilitiesUtils.createActivityFacilities("DensitiyFacilities"); ActivityFacilitiesFactory aff = facilities.getFactory(); for (SimpleFeature feature : features) { String featureId = (String) feature.getAttribute(identifierCaption); Integer numberOfHouseholds = Integer.parseInt((String) feature.getAttribute(numberOfHouseholdsCaption)); Geometry geometry = (Geometry) feature.getDefaultGeometry(); Coord coord = CoordUtils.createCoord(geometry.getCentroid().getX(), geometry.getCentroid().getY()); for (int i = 0; i < numberOfHouseholds; i++) { ActivityFacility facility = aff.createActivityFacility(Id.create(featureId + "_" + i, ActivityFacility.class), coord); facilities.addActivityFacility(facility); } } return facilities ; }
SimpleFeatureSource fs = ShapeFileReader.readDataFile(jcShpFileName); SimpleFeatureIterator fIt = fs.getFeatures().features(); while (fIt.hasNext()) {
public void testSelectedPlansActsShape() throws IOException { String outputDir = getOutputDirectory(); String outShp = getOutputDirectory() + "acts.shp"; Scenario scenario = ScenarioUtils.createScenario(super.loadConfig(null)); Network network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).parse(new GZIPInputStream(getClass().getResourceAsStream("/test/scenarios/berlin/network.xml.gz"))); Population population = scenario.getPopulation(); new PopulationReader(scenario).parse(new GZIPInputStream(getClass().getResourceAsStream("/test/scenarios/berlin/plans_hwh_1pct.xml.gz"))); CoordinateReferenceSystem crs = MGC.getCRS("DHDN_GK4"); SelectedPlans2ESRIShape sp = new SelectedPlans2ESRIShape(population, network, crs, outputDir); sp.setOutputSample(0.05); sp.setActBlurFactor(100); sp.setWriteActs(true); sp.setWriteLegs(false); sp.write(); Collection<SimpleFeature> writtenFeatures = ShapeFileReader.getAllFeatures(outShp); Assert.assertEquals(2235, writtenFeatures.size()); }
/** * 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()); } }
public void testSelectedPlansLegsShape() throws IOException { String outputDir = getOutputDirectory(); String outShp = getOutputDirectory() + "legs.shp"; Scenario scenario = ScenarioUtils.createScenario(super.loadConfig(null)); Network network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).parse(new GZIPInputStream(getClass().getResourceAsStream("/test/scenarios/berlin/network.xml.gz"))); Population population = scenario.getPopulation(); new PopulationReader(scenario).parse(new GZIPInputStream(getClass().getResourceAsStream("/test/scenarios/berlin/plans_hwh_1pct.xml.gz"))); CoordinateReferenceSystem crs = MGC.getCRS("DHDN_GK4"); SelectedPlans2ESRIShape sp = new SelectedPlans2ESRIShape(population, network, crs, outputDir); sp.setOutputSample(0.05); sp.setLegBlurFactor(100); sp.setWriteActs(false); sp.setWriteLegs(true); sp.write(); Collection<SimpleFeature> writtenFeatures = ShapeFileReader.getAllFeatures(outShp); Assert.assertEquals(1431, writtenFeatures.size()); }
SimpleFeatureSource s1 = ShapeFileReader.readDataFile(outFile); SimpleFeatureCollection fts1 = s1.getFeatures(); SimpleFeatureIterator it1 = fts1.features();
public void testPolygonCapacityShape() { String netFileName = "test/scenarios/equil/network.xml"; String outputFileP = getOutputDirectory() + "./network.shp"; Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); scenario.getConfig().global().setCoordinateSystem("DHDN_GK4"); final Network network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile(netFileName); FeatureGeneratorBuilderImpl builder = new FeatureGeneratorBuilderImpl(network, "DHDN_GK4"); CoordinateReferenceSystem crs = MGC.getCRS("DHDN_GK4"); builder.setWidthCoefficient(0.001); builder.setFeatureGeneratorPrototype(PolygonFeatureGenerator.class); builder.setWidthCalculatorPrototype(CapacityBasedWidthCalculator.class); builder.setCoordinateReferenceSystem(crs); new Links2ESRIShape(network,outputFileP, builder).write(); Collection<SimpleFeature> writtenFeatures = ShapeFileReader.getAllFeatures(outputFileP); Assert.assertEquals(network.getLinks().size(), writtenFeatures.size()); }
@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); }
public void testPolygonFreespeedShape() { String netFileName = "test/scenarios/equil/network.xml"; String outputFileP = getOutputDirectory() + "./network.shp"; Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); scenario.getConfig().global().setCoordinateSystem("DHDN_GK4"); final Network network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile(netFileName); FeatureGeneratorBuilderImpl builder = new FeatureGeneratorBuilderImpl(network, "DHDN_GK4"); CoordinateReferenceSystem crs = MGC.getCRS("DHDN_GK4"); builder.setWidthCoefficient(1); builder.setFeatureGeneratorPrototype(PolygonFeatureGenerator.class); builder.setWidthCalculatorPrototype(LanesBasedWidthCalculator.class); builder.setCoordinateReferenceSystem(crs); new Links2ESRIShape(network,outputFileP, builder).write(); Collection<SimpleFeature> writtenFeatures = ShapeFileReader.getAllFeatures(outputFileP); Assert.assertEquals(network.getLinks().size(), writtenFeatures.size()); }
@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); }
public void testPolygonLanesShape() { String netFileName = "test/scenarios/equil/network.xml"; String outputFileP = getOutputDirectory() + "./network.shp"; Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); scenario.getConfig().global().setCoordinateSystem("DHDN_GK4"); final Network network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile(netFileName); FeatureGeneratorBuilderImpl builder = new FeatureGeneratorBuilderImpl(network, "DHDN_GK4"); CoordinateReferenceSystem crs = MGC.getCRS("DHDN_GK4"); builder.setWidthCoefficient(1); builder.setFeatureGeneratorPrototype(PolygonFeatureGenerator.class); builder.setWidthCalculatorPrototype(LanesBasedWidthCalculator.class); builder.setCoordinateReferenceSystem(crs); new Links2ESRIShape(network,outputFileP, builder).write(); Collection<SimpleFeature> writtenFeatures = ShapeFileReader.getAllFeatures(outputFileP); Assert.assertEquals(network.getLinks().size(), writtenFeatures.size()); }
@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); }
public void testLineStringShape() { String netFileName = "test/scenarios/equil/network.xml"; String outputFileShp = getOutputDirectory() + "./network.shp"; Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); scenario.getConfig().global().setCoordinateSystem("DHDN_GK4"); final Network network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile(netFileName); FeatureGeneratorBuilderImpl builder = new FeatureGeneratorBuilderImpl(network, "DHDN_GK4"); CoordinateReferenceSystem crs = MGC.getCRS("DHDN_GK4"); builder.setWidthCoefficient(1); builder.setFeatureGeneratorPrototype(LineStringBasedFeatureGenerator.class); builder.setWidthCalculatorPrototype(LanesBasedWidthCalculator.class); builder.setCoordinateReferenceSystem(crs); new Links2ESRIShape(network,outputFileShp, builder).write(); Collection<SimpleFeature> writtenFeatures = ShapeFileReader.getAllFeatures(outputFileShp); Assert.assertEquals(network.getLinks().size(), writtenFeatures.size()); }