[OSGeo-Discuss] methods for programatically adding fields toshapefiles

Fawcett, David David.Fawcett at state.mn.us
Thu Oct 30 06:23:43 PDT 2008


Here is a link to some python code that I wrote to read a delimited text
file and write out a shapefile.  It uses the ogr and osr python modules.
The code is not particularly clean or efficient, but it does include the
case of creating a shapefile, creating columns, and populating the


You can email me directly if you have any questions about how it works.


-----Original Message-----
From: discuss-bounces at lists.osgeo.org
[mailto:discuss-bounces at lists.osgeo.org] On Behalf Of Tyler Erickson
Sent: Wednesday, October 29, 2008 4:49 PM
To: discuss at lists.osgeo.org
Subject: [OSGeo-Discuss] methods for programatically adding fields

I am interested in approaches for adding a populated field to a
shapefile (for example, adding a new field named 'source_url' with the
value 'http://somewebsite.com').  I would like to do this for several
thousand files.

At first I thought that I might be able to accomplish it using ogr2org
with a sql clause, such as:

ogr2ogr -sql "select *, 'http://somewebsite.com' as source_url from
infile" outfile.shp infile.shp

but that didn't work since ogr2ogr supports a limited set of SQL,

Any ideas on how to accomplish this? (I would prefer suggestions that
can be scripted with python.)

- Tyler
View this message in context:
Sent from the OSGeo Discuss mailing list archive at Nabble.com.

Discuss mailing list
Discuss at lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/discuss

More information about the Discuss mailing list