2

so I'm trying to rename PostgreSQL/PostGIS columns when importing from WFS using ogr2ogr.

The post here covers how to achieve this when importing from a Shapefile, using the -sql option like this:

-sql "SELECT col_1 AS BetterName, col_2 AS ImprovedName FROM YourShapefile" 

However, as I'm importing from WFS, I'm trying to do something like this:

ogr2ogr -overwrite -f PostgreSQL PG:"dbname=YourDB host=YourHost user=User password=Password active_schema=Schema" -nlt POLYGON -nln TableName "WFS:[WFS_URL_HERE]" -a_srs EPSG:4230 -sql "SELECT shape.area AS shape_area, shape.len AS shape_len FROM [What goes here?]"

How does the -sql option work in this particular use case? I have tried adding the WFS URL after the FROM clause, but this did not work.

Does anyone have any experience of this, is it even possible?

3

The layername should go there. If you need to know the layername first: You can achieve this by doing an ogrinfo:

 ogrinfo "WFS:[WFS_URL_HERE]"

Now, when you have the correct layername you do:

 ogrinfo -so "WFS:[WFS_URL_HERE]" "[LAYERNAME]"

This will give you the attributes. Finally you can do your full SELECT statement in the -sql parameter which will give you the option to alias.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.