开发者

Split or save a subset of a ESRI Shape SHP file to a new file?

I'm working with shape files in GeoDjango. Right now I'm trying to write a test for cod开发者_如何学JAVAe 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜