[OSGeo-Discuss] methods for programatically adding fields to shapefiles
P Kishor
punk.kish at gmail.com
Wed Oct 29 18:32:13 PDT 2008
On 10/29/08, David Bianco <me at davidbianco.net> wrote:
> I have experience using Perl and the DBI module to do work like this. I've
> read from dbf files in the past, but have not written to one. Still, I see
> no reason why it would be a hangup. Let me know if you'd like to go in
> that direction.
Don't need DBI for this. Just Xbase will do the job in seconds (or
less). Keep in mind, there are two Xbases... one is called XBase and
is part of DBD::XBase, while the other is called just Xbase. I have
used XBase (without any of the DBD hangups), and it is lightning fast
in creating dbf files.
>
> Dave
>
>
>
> On Wed, Oct 29, 2008 at 4:56 PM, Alex Mandel <tech_dev at wildintellect.com>
> wrote:
> >
> > Tyler Erickson wrote:
> >
> > > 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,
> described
> > > at:
> > > http://www.gdal.org/ogr/ogr_sql.html
> > >
> > > Any ideas on how to accomplish this? (I would prefer suggestions that
> can be
> > > scripted with python.)
> > >
> > > - Tyler
> > >
> >
> > Open a data connection the dbf with python, add a field to the properties
> of the table and populate the field.
> >
> > There are several ways to connect to a dbf depending on the OS, you could
> use an ODBC connector, or use some other type of dbf driver.
> > I haven't looked closely but there might be a dbf driver in the ogr python
> bindings already.
> >
> > I think my quick fix was to use python windows tools to wrap the dbf com
> object as a python object I could call, but that was a quick a dirty
> solution on windows.
> >
> > The other thing I've done is to create a blank shapefile with the exact
> same scheme + one field. Do an ogr2ogr -f "ESRI Shapefile" -a (append) of
> the blank shapefile and your existing one, and now you have a new field.
> >
> > Alex
> >
> >
> >
> > _______________________________________________
> > Discuss mailing list
> > Discuss at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/discuss
> >
>
>
> _______________________________________________
> Discuss mailing list
> Discuss at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/discuss
>
>
--
Puneet Kishor http://punkish.eidesis.org/
Nelson Institute for Environmental Studies http://www.nelson.wisc.edu/
Open Source Geospatial Foundation (OSGeo) http://www.osgeo.org/
More information about the Discuss
mailing list