将 ESRI Shape SHP 文件的子集拆分或保存到新文件中?

8
我正在使用GeoDjango处理shape文件。现在,我正试图编写一段代码的测试,该代码将加载shape文件并将其保存到数据库中。目前,该shape文件具有64,118个要素计数。我想将其减少到一小部分,以便测试可以快速加载它并确认一切是否正确。
由于shape文件不是文本格式,是否有免费的应用程序或库可供我使用,以摘出一些特征并将它们保存到新文件中?
我应该提到,我没有任何ESRI产品线的许可证或访问权限。

这些处理过程能够在文件地理数据库中使用shp文件吗?我的坡度和方位角文件有超过1600万条记录。祝好。 - GeorgeC
也许这类问题也适合在http://gis.stackexchange.com/上提问? - Roman Luštrik
1个回答

14

您有几种选项可以从shapefile中导出记录的子集。

  • Any Open Source desktop GIS will be able to perform this. Some of the more populars are Quantum GIS, gvSIG or openJUMP. The exact steps will vary in each of them, but basically you have to load the shape file, start editing, select the records you want and export them to a new shapefile.

  • The ogr2ogr tool, part of the GDAL package allows you to transform between different geographic vector formats (or within the same format), and you can specify an SQL-like expression to filter the original dataset.

    ogr2ogr -f "ESRI Shapefile" -where "id < 10" new_shapefile.shp huge_shapefile.shp
    
  • If you are using PostGIS and don't want to install any of the previous apps, you can use the pgsql2shp tool to export a subset of your PostGIS table to a shapefile.

    pgsql2shp -f "/path/to/shapefile" -h server -u user -P password postgisdb 
     "SELECT * FROM table WHERE id < 10"
    
编辑:在这三个选项中,您可以执行空间过滤器(即落在边界框内的要素),而不是基于属性的选择。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接