是否有可能使用GeoTools库获取 Shapefile 的范围?我想从 SHP 读取 TOP、LEFT、BOTTOM、RIGHT 坐标。
似乎没有一种 getExtent() 方法......
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();
我还没有编译以下内容,但它应该可以工作。
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();