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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

济默   2019-11-16 我要评论

记录一下如何创建创建缓冲区并获取缓冲区内的要素,便于以后查找使用

     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);
    }

 

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们