Geotools在shapefile路网数据中建立缓冲区,并获取缓冲区内的要素
记录一下如何创建创建缓冲区并获取缓冲区内的要素,便于以后查找使用
- static SimpleFeatureSource featureSource = null;
- static CoordinateReferenceSystem targetCRS;
- static String geometryPropertyName;
- static FilterFactory2 ff;
- public SimpleFeatureCollection grabFeaturesInBoundingBox(double x1, double y1, double x2, double y2)
- throws Exception {
- ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
- ShapefileDataStore sds = (ShapefileDataStore)dataStoreFactory.createDataStore
- (new File("E://Merge_direction.shp").toURI().toURL());
- Charset charset = Charset.forName("GBK");
- sds.setCharset(charset);
- String typeName = sds.getTypeNames()[0];
- featureSource = sds.getFeatureSource (typeName);
- FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
- FeatureType schema = featureSource.getSchema();
- geometryPropertyName = schema.getGeometryDescriptor().getLocalName();
- targetCRS = schema.getGeometryDescriptor().getCoordinateReferenceSystem();
- ReferencedEnvelope bbox = new ReferencedEnvelope(x1, y1, x2, y2, targetCRS);
- Filter filter = ff.bbox(ff.property(geometryPropertyName), bbox);
- return featureSource.getFeatures(filter);
- }
版权声明:本文为help-silence原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。