[gdal-dev] Rename a field with ogr2ogr?

Even Rouault even.rouault at mines-paris.org
Tue May 11 14:09:43 EDT 2010


You cannot rename a field in an existing dataset, but while using ogr2ogr you 
can indeed use -sql to do the renaming during the conversion.

For example : ogr2ogr outdataset indataset -sql "SELECT src_field1 AS 
dst_field1, src_field2 AS dst_field2 FROM sourcelayer"

See http://gdal.org/ogr/ogr_sql.html

(Note that the above OGR SQL is not used when the source dataset is a 
database. In that case, the SQL string is just passed to the server. But for 
your use case, this is standard SQL so it shouldn't matter if it's run by OGR 
or by the server. And if you need the SQL query to be run by OGR, you can 
add "-dialect OGRSQL" to the ogr2ogr command line.)

Le Tuesday 11 May 2010 19:10:15 Aleksey Naumov, vous avez écrit :
> Hi,
> Another question on ogr2ogr: is there a way to rename a field while
> converting a layer? E.g. using ogr2ogr to convert a personal geodatabase
> layer with long field names to a shapefile, I'd like to avoid automatic
> truncation of field names, e.g. from "long_field_name123" to "long_field".
> I know I can use -select switch to pick certain fields, but what about
> renaming (perhaps some trick via the -sql option?)?
> Thank you,
> Aleksey

More information about the gdal-dev mailing list