【问题标题】:Read Shapefile extent with Geotools使用 Geotools 读取 Shapefile 范围
【发布时间】:2013-06-02 23:50:50
【问题描述】:

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

好像没有一种 getExtent() 方法...

【问题讨论】:

  • 你指的是 geotools.org 还是 geotools.com?
  • geotools.org,对不起。我已经更新了链接。你知道有什么解决办法吗?

标签: java shapefile geotools


【解决方案1】:

谢谢,这正是我想要的!我只需要更改 url 映射。这是工作代码:

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();

【讨论】:

    【解决方案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();
    

    【讨论】:

      猜你喜欢
      • 2014-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-22
      相关资源
      最近更新 更多