码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-11-16 17:55:31      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:span   pen   typename   uri   mon   collect   local   strong   tool   

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

     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路网数据中建立缓冲区,并获取缓冲区内的要素

标签:span   pen   typename   uri   mon   collect   local   strong   tool   

原文地址:https://www.cnblogs.com/help-silence/p/11872257.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!