我試圖使用GeoTools從LuciadFusion wfs服務器中檢索數據,但遇到了如何實現我的目標的示例。 這個想法是,我正在跟蹤移動的東西,並且想要從我移動的t is正在移動到的區域中檢索地圖數據(特徵),然後計算距離(如離最近的道路,最近的湖岸沿岸多遠)。 我想獲得的功能,把它們放到一個SpatialIndexFeatureCollection(保存在內存中快速訪問,因爲我跟蹤多個移動對象),在那裏我可以查詢我想知道的東西。使用GeoTools通過WFS回收地圖數據
到目前爲止,我正在查詢一些隨數據發現的隨機wfs服務器:http://ogc.bgs.ac.uk/digmap625k_gsml32_insp_gs/wfs?我能夠讀取能力,並且從typenames的一個建設我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
- ReferencedEnvelope [-132576.7891571155:743466.624998733, -15669.960592884949:1248847.1762802668]
但是,當我自己的WFS服務器已經建立時,它將包含更多的類型名稱,每個類型名稱都描述某個區域的fx道路或湖泊。 對於很多領域。
如何獲取與定義區域(邊界框BB)相關的類型名稱,或者甚至可能只有BB所覆蓋的類型名稱中的功能(如果可能)?
其次,從上面的例子中提取數據時,所有的功能都在一個錯誤的CoordinateReferenceSystem - 我如何強制它是EPSG:4326?
謝謝!
非常感謝你的回答! :-) 我們的WFS服務器可能有些問題,我想要獲得_source_對象,我仍然需要說''SimpleFeatureSource source = dataStore.getFeatureSource(「test:uk_625k_mapped_feature」);'因此知道我想檢查的typeName,對吧? 當我在自己的服務器上執行此操作時,出現'java.io.IOException:Schema'_772ced6e_45_54b5_45_4295_45_bb01_45_a50b9179f1ecWorldType'不存在。' (是的,typename看起來也很隨意)。 ... – Mars
我在原始問題中所述的wfs服務器上沒有看到此架構錯誤。 如果我將瀏覽器指向'http://172.20.6.150:8085/LuciadFusion/wfs?REQUEST=GetFeature&SERVICE=WFS&VERSION=1.1.0&TYPENAME=_772ced6e_45_54b5_45_4295_45_bb01_45_a50b9179f1ecWorldType'我確實收到了一些xml完整的數據。 使用geotools時,我是否需要架構來訪問這些數據?或者我可以讀取數據(如果試圖設置Luciad服務器的人無法弄清楚如何獲取架構)? 再次感謝 - 幫助非常感謝! – Mars
您確實需要知道要獲取的featureCollection的typeName,您可以直接閱讀getCapabilities響應以查看可用的功能。 GeoTools應該自動獲取並找出模式。 –