[gdal-dev] How to replace an osm key?

Rahkonen Jukka (MML) jukka.rahkonen at maanmittauslaitos.fi
Mon Nov 14 07:44:12 PST 2016


Hi,

If your version and environment requires escaping, then you need to do

"select geometry, \"building\" as bldg,\"building:levels\" as bldg_levels,\”height\” as height from multipolygons ... "
It may work also without escaping as
"select geometry, "building" as bldg,"building:levels" as bldg_levels,height as height from multipolygons ... "

If you plan to follow the SQL route I really recommend you to read some SQL tutorials and exercise at home. I am sure that you will learn the basics soon and tutorials are always in the web while I am not. SQL is so close to English and that you can think that you are making a (comma separated) shopping list
“SELECT milk,bread,juice FROM Wal-Mart”.

-Jukka-




Lähettäjä: Djordje Spasic [mailto:issworld2000 at yahoo.com]
Lähetetty: 14. marraskuuta 2016 17:21
Vastaanottaja: Rahkonen Jukka (MML) <jukka.rahkonen at maanmittauslaitos.fi<mailto:jukka.rahkonen at maanmittauslaitos.fi>>; gdal-dev at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org>
Aihe: Re: VS: [gdal-dev] How to replace an osm key?

Thank you Jukka,

How should I edit the command you gave me:
"C:\gdal\ogr2ogr.exe" --config OSM_USE_CUSTOM_INDEXING NO -skipfailures -f "ESRI Shapefile" -dialect sqlite -sql "select geometry, \"building\" as bldg from multipolygons where \"building\" is not null limit 1" "C:\output_shp_files" "C:\input.osm"
so that "building", "building:levels", and "height" fields are included, not only the "building" field?

On Monday, November 14, 2016 2:10 PM, Rahkonen Jukka (MML) <jukka.rahkonen at maanmittauslaitos.fi<mailto:jukka.rahkonen at maanmittauslaitos.fi>> wrote:

Hi,

If you enclose something between single quotes in SQL it becomes a string.
SELECT ’building’  -> selects literally the given *string* –building—
However,

SELECT "building" -> selects the *value* of *field* –building-- (or “identifier” as is it called in SQL)

See for example https://www.sqlite.org/lang_keywords.html

I tested on Windows with trunk version of GDAL that this syntax works:

ogrinfo -dialect sqlite -sql "select geometry, "building" as bldg
from multipolygons where "building" is not null limit 1" hamburg-latest.osm.pbf

By reading this old thread http://osgeo-org.1560.x6.nabble.com/gdal-dev-OGR-SQL-Excecuting-select-where-column-name-contains-quot-quot-td5006377.html some older GDAL versions may need some more tweaking and inner double quotes must be escaped by back slash as \”

ogrinfo -dialect sqlite -sql "select geometry, \"building\" as bldg
from multipolygons where \"building\" is not null limit 1" hamburg-latest.osm.pbf


-Jukka Rahkonen-

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20161114/931f84f8/attachment-0001.html>


More information about the gdal-dev mailing list