public void writeAbsoluteSHPTravelTimes(String file, CoordinateReferenceSystem crs, boolean ignoreExitLinks) { try { Collection<SimpleFeature> ft = generateSHPFileData(crs, this.network, true, ignoreExitLinks); ShapeFileWriter.writeGeometries(ft, file); } catch (Exception e) { throw new RuntimeException(e); } }
public void writeRelativeSHPTravelTimes(String file, CoordinateReferenceSystem crs, boolean ignoreExitLinks) { try { Collection<SimpleFeature> ft = generateSHPFileData(crs, this.network, false, ignoreExitLinks); ShapeFileWriter.writeGeometries(ft, file); } catch (Exception e) { throw new RuntimeException(e); } }
public void write() { log.info("creating features..."); Collection<SimpleFeature> features = new ArrayList<SimpleFeature>(); for (Link link : NetworkUtils.getSortedLinks(this.network)) { features.add(this.featureGenerator.getFeature(link)); } log.info("writing features to shape file... " + this.filename); ShapeFileWriter.writeGeometries(features, this.filename); log.info("done writing shape file."); }
public void write() { Collection<SimpleFeature> features = new ArrayList<SimpleFeature>(); for (Node node : NetworkUtils.getSortedNodes(this.network)) { features.add(getFeature(node)); } ShapeFileWriter.writeGeometries(features, this.filename); }
public static void main(String[] args) { GeometryFactory geometryFactory = new GeometryFactory(); Collection<Coordinate> sites = new ArrayList<>(); sites.add(new Coordinate(70, 70)); sites.add(new Coordinate(50, 150)); sites.add(new Coordinate(150, 50)); sites.add(new Coordinate(150, 150)); sites.add(new Coordinate(250, 50)); sites.add(new Coordinate(250, 150)); sites.add(new Coordinate(350, 50)); sites.add(new Coordinate(370, 170)); VoronoiDiagramBuilder voronoiDiagramBuilder = new VoronoiDiagramBuilder(); voronoiDiagramBuilder.setSites(sites); List<Polygon> polygons = voronoiDiagramBuilder.getSubdivision().getVoronoiCellPolygons(geometryFactory); BoundingBox boundingBox = BoundingBox.createBoundingBox(0, 0, 400, 200); Polygon boundingPolygon = VoronoiGeometryUtils.createBoundingPolygon(boundingBox); Collection<Geometry> cutGeometries = VoronoiGeometryUtils.cutPolygonsByBoundary(polygons, boundingPolygon); Collection<SimpleFeature> features = VoronoiGeometryUtils.createFeaturesFromPolygons(cutGeometries); ShapeFileWriter.writeGeometries(features, "/Users/dominik/voronoi_test.shp"); } }
private void writeActs() throws IOException { String outputFile = this.outputDir + "/acts.shp"; ArrayList<SimpleFeature> fts = new ArrayList<SimpleFeature>(); for (Plan plan : this.outputSamplePlans) { String id = plan.getPerson().getId().toString(); for (PlanElement pe : plan.getPlanElements()) { if (pe instanceof Activity) { Activity act = (Activity) pe; fts.add(getActFeature(id, act)); } } } ShapeFileWriter.writeGeometries(fts, outputFile); }
@Override public void finish() { GeometryFactory geometryFactory = new GeometryFactory(); SimpleFeatureTypeBuilder featureTypeBuilder = createFeatureTypeBuilder(); SimpleFeatureType featureType = featureTypeBuilder.buildFeatureType(); DefaultFeatureCollection featureCollection = createFeatureCollection(geometryFactory, featureType); if (outputDirectory != null) { File file = new File(outputDirectory); file.mkdirs(); } if (createQGisOutput) { ShapeFileWriter.writeGeometries(featureCollection, outputDirectory + "/result.shp"); } if (pushing2Geoserver) { updateOnGeoserver(featureType, featureCollection); } }
public void write(String vrpOutDir) { new File(vrpOutDir).mkdir(); String file = vrpOutDir + "\\route_"; for (Vehicle v : vehicles) { Stream<DriveTask> drives = Schedules.driveTasks(v.getSchedule()); Collection<SimpleFeature> features = new ArrayList<>(); drives.forEach(drive -> { Coordinate[] coords = createLineString(drive); if (coords != null) { features.add(this.factory.createPolyline(coords, new Object[] { v.getId(), v.getId(), drive.getTaskIdx() }, null)); } }); if (!features.isEmpty()) { ShapeFileWriter.writeGeometries(features, file + v.getId() + ".shp"); } } }
public void write(String shpFile) { CoordinateReferenceSystem crs = MGC.getCRS(coordinateSystem); PolygonFeatureFactory factory = new PolygonFeatureFactory.Builder().addAttribute(ID_HEADER, String.class) .setCrs(crs).setName("zone").create(); List<SimpleFeature> features = new ArrayList<>(); for (Zone z : zones.values()) { String id = z.getId() + ""; features.add(factory.createPolygon(z.getMultiPolygon(), new Object[] { id }, id)); } ShapeFileWriter.writeGeometries(features, shpFile); } }
private void writeLegs() throws IOException { String outputFile = this.outputDir + "/legs.shp"; ArrayList<SimpleFeature> fts = new ArrayList<SimpleFeature>(); for (Plan plan : this.outputSamplePlans) { String id = plan.getPerson().getId().toString(); for (PlanElement pe : plan.getPlanElements()) { if (pe instanceof Leg) { Leg leg = (Leg) pe; if (leg.getRoute() instanceof NetworkRoute) { if (RouteUtils.calcDistanceExcludingStartEndLink((NetworkRoute) leg.getRoute(), this.network) > 0) { fts.add(getLegFeature(leg, id)); } } else if (leg.getRoute().getDistance() > 0) { fts.add(getLegFeature(leg, id)); } } } } ShapeFileWriter.writeGeometries(fts, outputFile); }
ShapeFileWriter.writeGeometries(features, outFile);
@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_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_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); } }
@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); }