Geotools在shapefile路网数据中建立缓冲区,并获取缓冲区内的要素
2024-08-30 05:56:39
记录一下如何创建创建缓冲区并获取缓冲区内的要素,便于以后查找使用
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);
}
最新文章
- Double Checked Locking 模式
- 面试题目——《CC150》递归与动态规划
- Linux下rz命令使用的实例详解
- GCD学习之dispatch_barrier_async
- android - startActivity浅谈
- wpf 如何设置滚动条在超出范围的时候才显示?(转)
- 服务启动错误1053,一例解决方案(给用户添加NetworkService权限)
- 程序员如何巧用Excel提高工作效率
- Django12-ModelForm中创建局部钩子和全局钩子
- redis安装以及安全配置
- ArcPy批量计算Mean Center的两个实例
- Leetcode 1021. 最佳观光组合
- SQL创建删除索引
- TimeZone 时区 (JS .NET JSON MYSQL) + work week 闰年
- Java面试题整理1
- 【bzoj2006】【NOI2015】超级钢琴
- Git添加本地项目出现fatal: unable to get credential storage lock: File exists
- Spark性能优化的10大问题及其解决方案
- python学习之路 一 :编程语言介绍
- Openshift部署Zookeeper和Kafka