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

  1. static SimpleFeatureSource featureSource = null;
  2. static CoordinateReferenceSystem targetCRS;
  3. static String geometryPropertyName;
  4. static FilterFactory2 ff;
  5. public SimpleFeatureCollection grabFeaturesInBoundingBox(double x1, double y1, double x2, double y2)
  6. throws Exception {
  7. ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
  8. ShapefileDataStore sds = (ShapefileDataStore)dataStoreFactory.createDataStore
  9. (new File("E://Merge_direction.shp").toURI().toURL());
  10. Charset charset = Charset.forName("GBK");
  11. sds.setCharset(charset);
  12. String typeName = sds.getTypeNames()[0];
  13. featureSource = sds.getFeatureSource (typeName);
  14. FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
  15. FeatureType schema = featureSource.getSchema();
  16. geometryPropertyName = schema.getGeometryDescriptor().getLocalName();
  17. targetCRS = schema.getGeometryDescriptor().getCoordinateReferenceSystem();
  18. ReferencedEnvelope bbox = new ReferencedEnvelope(x1, y1, x2, y2, targetCRS);
  19. Filter filter = ff.bbox(ff.property(geometryPropertyName), bbox);
  20. return featureSource.getFeatures(filter);
  21. }

 

版权声明:本文为help-silence原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/help-silence/p/11872257.html