【发布时间】:2017-06-16 08:34:15
【问题描述】:
我正在尝试使用 GeoTools 从 LuciadFusion wfs 服务器检索数据,但在查找有关如何实现我的目标的示例时遇到了麻烦。
我的想法是我正在跟踪移动的东西,并想从我移动的东西正在移动的区域中检索地图数据(特征),然后计算距离(例如到最近的道路、最近的湖滨岸有多远) .
我想获取特征,将它们放入 SpatialIndexFeatureCollection(保存在内存中以便快速访问,因为我正在跟踪多个移动对象),在那里我可以查询我想知道的内容。
到目前为止,我正在使用以下数据查询一些随机 wfs 服务器:http://ogc.bgs.ac.uk/digmap625k_gsml32_insp_gs/wfs?。我能够读取功能,并从构建我的 SpatialIndexFeatureCollection 的类型名称之一:
String url = "http://ogc.bgs.ac.uk/digmap625k_gsml32_insp_gs/wfs?";
Map connectionParameters = new HashMap();
connectionParameters.put("WFSDataStoreFactory:GET_CAPABILITIES_URL", url)
connectionParameters.put(WFSDataStoreFactory.TIMEOUT.key, 100000);
WFSDataStoreFactory dsf = new WFSDataStoreFactory();
try {
WFSDataStore dataStore = dsf.createDataStore(connectionParameters);
for(String s : dataStore.getTypeNames()){
System.out.println(s);
}
SimpleFeatureSource source = dataStore.getFeatureSource("test:uk_625k_mapped_feature");
SimpleFeatureCollection fc = source.getFeatures();
System.out.println(fc.getBounds());
SpatialIndexFeatureCollection index = new SpatialIndexFeatureCollection();
fc.accepts(new FeatureVisitor() {
@Override
public void visit(Feature feature) {
SimpleFeature simpleFeature = (SimpleFeature) feature;
Geometry geom = (MultiPolygon) simpleFeature.getDefaultGeometry();
if(geom != null) {
Envelope env = geom.getEnvelopeInternal();
if(!env.isNull()) {
index.add(simpleFeature);
}
}
}
}, new NullProgressListener());
catch (FactoryException e) {
aLog.error("", e);
}
运行它会打印:
- gsml:MappedFeature
- gsmlgu:GeologicUnit
- 测试:uk_625k_mapped_feature
- 参考信封[-132576.7891571155:743466.624998733, -15669.960592884949:1248847.1762802668]
但是,当我自己的 WFS 服务器设置完成后,它将包含更多类型名称,每个类型名称都描述了一个区域的 fx 道路或湖泊。 并且适用于许多领域。
如何获取与定义区域(边界框 BB)相关的类型名称,或者如果可能的话,甚至仅获取 BB 所涵盖的类型名称中的特征?
其次,从上面的示例中提取数据时,所有特征都位于错误的 CoordinateReferenceSystem 中 - 我如何强制它为 EPSG:4326?
谢谢!
【问题讨论】: