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

发布于 2024-09-04 18:13:58 字数 236 浏览 9 评论 0原文

我正在 GeoDjango 中处理形状文件。现在我正在尝试编写一个测试代码,该代码加载到形状文件中并将其保存到数据库中。 shape 文件当前的特征数为 64,118。我想将其减少到少数,以便测试可以快速加载它并确认一切正确。

由于形状文件不是文本格式,是否有免费的应用程序或库可以用来提取一些特征并将它们保存到新文件中?

我应该指出,我没有许可证,也没有访问任何 ESRI 产品线的权限。

I'm working with shape files in GeoDjango. Right now I'm trying to write a test for code that loads in a shape file and saves it to a database. The shape file currently has a feature count of 64,118. I'd like to reduce this to a handful so the test can quickly load it and confirm everything is right.

Since shape files aren't in a text format, is there a free application or library I can use to pluck out a handful of features and save them to a new file?

I should mention I don't have a license nor access to any of the ESRI product line.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心病无药医 2024-09-11 18:13:58

您可以使用多种选项从 shapefile 中导出记录子集。

编辑:在这三个选项中的任何一个中,您都可以执行空间过滤器(即落在边界框内的要素),而不是基于属性的选择。

You have several options to export a subset of records from a 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"
    

Edit: In any of the three options you can perform a spatial filter (ie features that fall within a bounding box) rather than a selection based on attributes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文