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