@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); }
private void initFeatureType(String outputCRS) { this.polygonFeatureFactory = new PolygonFeatureFactory.Builder(). setCrs(MGC.getCRS(outputCRS)). addAttribute("type", String.class). create(); }
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 initLandUseFeatureType(String landUseType) { // TODO make CRS adjustable this.polygonFeatureFactory = new PolygonFeatureFactory.Builder(). setCrs(MGC.getCRS(TransformationFactory.DHDN_GK4)). //setName("buildings"). setName("land_use"). addAttribute(landUseType, String.class). create(); }