Geotools在shapefile路网数据中建立缓冲区,并获取缓冲区内的要素

Posted help-silence

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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);
    }

 

以上是关于Geotools在shapefile路网数据中建立缓冲区,并获取缓冲区内的要素的主要内容,如果未能解决你的问题,请参考以下文章

JAVA用geotools读取shape格式文件

GeoTools快速入门

GeoTools快速入门

Qgis中计算shapefile的面积

java geotools

将包含经纬度点位信息的Excel表格数据导入到ArcMap中并输出成shapefile