2

是否有可能使用GeoTools库获取 Shapefile 的范围?我想从 SHP 读取 TOP、LEFT、BOTTOM、RIGHT 坐标。

似乎没有一种 getExtent() 方法......

4

2 回答 2

3

thank you, that's exactly what I was looking for! I only had to change the url map. this is the working code:

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();
于 2013-06-18T18:32:57.410 回答
2

我还没有编译以下内容,但它应该可以工作。

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();
于 2013-06-18T07:21:34.607 回答