[gdal-dev] Is it possible to Buffer using ogr2ogr?
Pinner, Luke
Luke.Pinner at environment.gov.au
Thu Apr 23 01:14:33 EDT 2009
Something like the following might get you started (note: limited testing and I'm no programmer :)
#buffer.py
import sys,os
from osgeo import ogr
def buffer(infile,outfile,buffdist):
try:
ds=ogr.Open(infile)
drv=ds.GetDriver()
if os.path.exists(outfile):
drv.DeleteDataSource(outfile)
drv.CopyDataSource(ds,outfile)
ds.Destroy()
ds=ogr.Open(outfile,1)
lyr=ds.GetLayer(0)
for i in range(0,lyr.GetFeatureCount()):
feat=lyr.GetFeature(i)
lyr.DeleteFeature(i)
geom=feat.GetGeometryRef()
feat.SetGeometry(geom.Buffer(float(buffdist)))
lyr.CreateFeature(feat)
ds.Destroy()
except:return False
return True
if __name__=='__main__':
usage='usage: buffer <infile> <outfile> <distance>'
if len(sys.argv) == 4:
if buffer(sys.argv[1],sys.argv[2],sys.argv[3]):
print 'Buffer succeeded!'
sys.exit(0)
else:
print 'Buffer failed!'
sys.exit(1)
else:
print usage
sys.exit(1)
________________________________
From: gdal-dev-bounces at lists.osgeo.org [mailto:gdal-dev-bounces at lists.osgeo.org] On Behalf Of Abhay
Sent: Thursday, 23 April 2009 1:32 PM
To: Roger André
Cc: gdal-dev at lists.osgeo.org
Subject: Re: [gdal-dev] Is it possible to Buffer using ogr2ogr?
--- On Thu, 4/23/09, Roger André <randre at gmail.com> wrote:
> From: Roger André <randre at gmail.com>
> Subject: [gdal-dev] Is it possible to Buffer using ogr2ogr?
> To: "gdal-dev" <gdal-dev at lists.osgeo.org>
> Date: Thursday, April 23, 2009, 4:59 AM
> Hi All,
>
> I'm trying to port some of my existing PostGIS based
> workflow to ogr utilities and shapefiles. Is it possible
> to buffer a feature that I've selected via the ogr2ogr
> "-where" clause? I'd like end up with a
> single, buffered feature in a stand-alone shapefile when
> I'm done.
>
>
> Thanks,
>
> Roger
>
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
_______________________________________________
gdal-dev mailing list
gdal-dev at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Hi Roger,
I donot think there is way around in the ogr2ogr to create buffer that I know of.
Instead you will need to write a code in C++ or python to do the same.
Rgds.
Abhay.
------
If you have received this transmission in error please notify us immediately by return e-mail and delete all copies. If this e-mail or any attachments have been sent to you in error, that error does not constitute waiver of any confidentiality, privilege or copyright in respect of information in the e-mail or attachments.
Please consider the environment before printing this email.
------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20090423/79b4be19/attachment.html
More information about the gdal-dev
mailing list