[gdal-dev] copy features in python ogr

Sean Gillies sgillies at frii.com
Thu Jul 10 11:12:14 EDT 2008


Bobby H. Braswell wrote:
> 
> Hi-
> 
> I'm trying to make a script that will read a single-polygon shapefile,
> apply a buffer to the polygon (using shapely) and then write out a new
> file with two polygon features representing the original and the
> buffered region. Rather than creating a new polygon shapefile from
> scratch, I'm wondering if I can just make a copy of the contents of the
> source file (one layer, one feature), add the new feature, then write
> the new contents (one layer, two features) to an output shapefile.
> 
> I'm looking at the "CopyLayer" method of the source file, but can't seem
> to get the inputs right, and anyway I'm not sure if that's the way to
> go. Any suggestions would be appreciated.
> 
> Thanks very much,
> Rob Braswell
> University of New Hampshire

Hi Rob,

Keep in mind that you can also buffer geometries using osgeo.ogr only,
and it's probably more efficient to do so if you've already imported
osgeo.ogr to read and write the shapefiles.

I'm not sure if CopyLayer copies features as well as the layer definition.

Cheers,
Sean


More information about the gdal-dev mailing list