2
使用GeoTools庫可以獲得Shapefile的範圍嗎? 我想從SHP讀取TOP,LEFT,BOTTOM,RIGHT座標。使用Geotools讀取Shapefile範圍
好像沒有一種getExtent()方法的...
使用GeoTools庫可以獲得Shapefile的範圍嗎? 我想從SHP讀取TOP,LEFT,BOTTOM,RIGHT座標。使用Geotools讀取Shapefile範圍
好像沒有一種getExtent()方法的...
我還沒有整理了以下,但它應該工作。
File file = new File("example.shp");
Map map = new HashMap();
map.put("url", file.toURL());
DataStore dataStore = DataStoreFinder.getDataStore(map);
SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
SimpleFeatureCollection collection = featureSource.getFeatures();
ReferencedEnvelope env = collection.getBounds();
double left = env.getMinX();
double right = env.getMaxX();
double top = env.getMaxY();
double bottom = env.getMinY();
謝謝,這就是我一直在尋找的!我只需要更改網址圖。這是工作代碼:
File file = new File(shpFilePath);
Map<String, URL> map = new HashMap<String, URL>();
map.put("url", file.toURI().toURL());
DataStore dataStore = DataStoreFinder.getDataStore(map);
// SimpleFeatureSource featureSource = dataStore.getFeatureSource(shpName); this works too
SimpleFeatureSource featureSource = dataStore.getFeatureSource(dataStore.getTypeNames()[0]);
SimpleFeatureCollection collection = featureSource.getFeatures();
ReferencedEnvelope env = collection.getBounds();
double left = env.getMinX();
double right = env.getMaxX();
double top = env.getMaxY();
double bottom = env.getMinY();
你的意思是geotools.org或geotools.com? –
geotools.org,對不起。我已經更新了鏈接。你知道任何解決方案嗎? – manuSO