1

Is it possible to to export a shape polygon to a file? I want to export the polygons from a country to use them on a different map system,

Bruno
  • 11
  • 1
  • 5
    what do you mean by file? Shapefiles are files. Do you mean a specific format? if so which format? What GIS software are you using? – Devdatta Tengshe Apr 10 '14 at 11:02

2 Answers2

1

The most common spatial file format is a shapefile, which your data is most likely in. The shapefile is actually a composite of 3 mandatory files and (commonly) several ancillary files.

  • .shp includes the feature geometry
  • .shx an index file allowing for speedy referencing
  • .dbf the feature attributes

Ancillary (often generated on-the-fly by GIS software)

  • .sbn indexing
  • .sbx indexing
  • .prj projection
  • .shp.xml spatial metadata

The conversion formats are too numerous to mention and vary widely in their application, although a few common ones are KML, ascii, .csv, spatial databases...

Aaron
  • 51,658
  • 28
  • 154
  • 317
1

If you're comfortable with GDAL/OGR (or willing to level up), you can use ogr2ogr along with OGR SQL to quickly and easily export a single feature from any of the OGR supported vector formats into a stand-alone shapefile. For example..

ogr2ogr -f "ESRI Shapefile" "C:/xGIS/Vector/test/Richland.shp" 
"C:/xGIS/Vector/COUNTIES_SC_WGS84.shp" -nlt GEOMETRY 
-sql "select * from counties_sc_wgs84 where cntyname='Richland'" 

Here's a breakdown of this ogr2ogr statement:

  • -f is the format we're exporting to.

  • Richland.shp is the OUTPUT shapefile.

  • COUNTIES_SC_WGS84.shp is the INPUT shapefile.

  • -nlt GEOMETRY is a special condition I added for flexibility, because you never know when a shapefile of polygons has both single and multi-part polygons.

  • -sql is the OGR SQL sentence that targets the single-feature subset I wanted from my INPUT shapefile.

There are tons of other things you could do additionally, if you wanted, like transform from one projection to another, etc.

Gotchas and Caveats

Note that I applied line-breaks only to aid in seeing the whole ogr2ogr statement at a glance, but that any statement you create should not have line-breaks.

Also beware cutting and pasting these script parts. I've found the terminal doesn't play well with quote and double-quote characters copied from web pages. It's best to build your ogr2ogr statement in notepad or something, then paste it into the terminal when you're ready to execute it.

elrobis
  • 6,456
  • 1
  • 31
  • 53