使用冒号查询属性:介于 ogr2ogr 和 PostGIS 之间
Query attributes with colon : inbetween with ogr2ogr and PostGIS
我是 运行 一个由 osm2pgsql 填充的 PostGIS 数据库。地址键存储为例如
"addr:street"
objective 是将这些几何图形存储为 ogr2ogr 的 GeoPackage。脚本看起来像这样
ogr2ogr -f "GPKG" address_point.gpkg PG:"host=**** dbname=**** user=**** password=****" -sql "select addr:housenumber","addr:housename","addr:flats","addr:conscriptionnumber","addr:street","addr:place","addr:postcode","addr:city","addr:country","addr:full","addr:hamlet","addr:suburb","addr:subdistrict","addr:district","addr:province","addr:state","addr:interpolation","addr:interpolation","addr:inclusion","addr:door","addr:unit","addr:floor","addr:block",way from planet_osm_point"
ogr2ogr returns 一个错误,因为每个属性中都有冒号。
我认为,查询失败是因为“假设要包装 ogr2ogr 的查询。
当我如下使用 ' 时:
ogr2ogr -f "GPKG" address_point.gpkg PG:"host=**** dbname=**** user=**** password=****" -sql "select 'addr:housenumber','addr:housename','addr:flats','addr:conscriptionnumber','addr:street','addr:place','addr:postcode','addr:city','addr:country','addr:full','addr:hamlet','addr:suburb','addr:subdistrict','addr:district','addr:province','addr:state','addr:interpolation','addr:interpolation','addr:inclusion','addr:door','addr:unit','addr:floor','addr:block',way from planet_osm_point"
查询也失败了。
有没有办法解决这个问题?
您需要转义字段名称周围的双引号
ogr2ogr [...] -sql "select \"addr:housenumber\",\"addr:housename\" from planet_osm_point"
或者您可以对整个 SQL 字符串使用单引号
ogr2ogr [...] -sql 'select "addr:housenumber","addr:housename" from planet_osm_point'
我是 运行 一个由 osm2pgsql 填充的 PostGIS 数据库。地址键存储为例如
"addr:street"
objective 是将这些几何图形存储为 ogr2ogr 的 GeoPackage。脚本看起来像这样
ogr2ogr -f "GPKG" address_point.gpkg PG:"host=**** dbname=**** user=**** password=****" -sql "select addr:housenumber","addr:housename","addr:flats","addr:conscriptionnumber","addr:street","addr:place","addr:postcode","addr:city","addr:country","addr:full","addr:hamlet","addr:suburb","addr:subdistrict","addr:district","addr:province","addr:state","addr:interpolation","addr:interpolation","addr:inclusion","addr:door","addr:unit","addr:floor","addr:block",way from planet_osm_point"
ogr2ogr returns 一个错误,因为每个属性中都有冒号。 我认为,查询失败是因为“假设要包装 ogr2ogr 的查询。
当我如下使用 ' 时:
ogr2ogr -f "GPKG" address_point.gpkg PG:"host=**** dbname=**** user=**** password=****" -sql "select 'addr:housenumber','addr:housename','addr:flats','addr:conscriptionnumber','addr:street','addr:place','addr:postcode','addr:city','addr:country','addr:full','addr:hamlet','addr:suburb','addr:subdistrict','addr:district','addr:province','addr:state','addr:interpolation','addr:interpolation','addr:inclusion','addr:door','addr:unit','addr:floor','addr:block',way from planet_osm_point"
查询也失败了。
有没有办法解决这个问题?
您需要转义字段名称周围的双引号
ogr2ogr [...] -sql "select \"addr:housenumber\",\"addr:housename\" from planet_osm_point"
或者您可以对整个 SQL 字符串使用单引号
ogr2ogr [...] -sql 'select "addr:housenumber","addr:housename" from planet_osm_point'