[Gdal-dev] ogr2ogr and field matching

Frank Warmerdam fwarmerdam at gmail.com
Tue Aug 2 15:41:51 EDT 2005


On 8/2/05, Armin Burger <armin.burger at gmx.net> wrote:
> Hello everybody,
> 
> I tried to use ogr2ogr for loading data from shapefiles into PostGIS
> because it gives more flexibility than the shp2pgsql utilitiy.  I tried
> to combine data from different sources that can have differences in the
> field names of the shapefiles. ogr2ogr offers the possibility to specify
> the SQL command for loading. So I tried
> 
> "ogr2ogr -sql "SELECT ARRGCDL0 AS iso
> FROM countries WHERE ARCNTY_ID>100"  -a_srs "EPSG:4326" -append
>  -f PostgreSQL PG:'host=localhost user=postgres dbname=testdb'
> countries.shp"
> 
> But I get the error
> ERROR 1: SQL: Missing comma after column ARRGCDL0 in SELECT statement.
> 
> So there seems to be no possibility to map an existing column in the
> shapefile to an existing in the PG table using the 'AS' statement. When
> the two column names differ, the data from the shapefile field are just
> not loaded into the PG table. Are there any workarounds for that?

Armin, 

You are correct that OGR SQL does not support the "AS" keyword 
to rename a field.  I don't know of a direct way of accomplishing
what you want, but it could be done with a Python script of course.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent




More information about the Gdal-dev mailing list