I'am currently doing a clip then SQL query to select the biggest cities out of Natural Earth data via 2 commands :
ogr2ogr -clipsrc 1 52 7 49 ./tmp.shp ../data/natural_earth_vector/10m_cultural/ne_10m_populated_places.shp
ogr2ogr -sql "SELECT * FROM tmp ORDER BY POP_MAX DESC LIMIT '15'" -dialect SQLITE ./places.shp ./tmp.shp
rm ./tmp.*
I tried to merge them via :
ogr2ogr -clipsrc 1 52 7 49 \
-sql "SELECT * FROM ne_10m_populated_places ORDER BY POP_MAX DESC LIMIT '15'" -dialect SQLITE \
./places.shp ../data/natural_earth_vector/10m_cultural/ne_10m_populated_places.shp
but it fails. I suspect the FROM ne_10m_populated_places
part to fails on the clipped data.
How could I do this in a single command ?
-
Didn't found a way! Maybe it's not possible to chain.Hugolpz– Hugolpz2015年02月16日 01:08:17 +00:00Commented Feb 16, 2015 at 1:08
-
1I undestand that you want to select top populated cities from the clipped area? How about switching -clipsrc to sql's WHERE ST_Intersect?jzol– jzol2015年02月16日 09:08:58 +00:00Commented Feb 16, 2015 at 9:08
-
Yes indeed, i am looking for such way if chaining clip => sql select is not possible.Hugolpz– Hugolpz2015年02月16日 09:10:02 +00:00Commented Feb 16, 2015 at 9:10
1 Answer 1
To select top populated cites in given extent you can use ogr2ogr's option -spat
: spatial query extents.
Only features whose geometry intersects the extents will be selected.
Try:
ogr2ogr -sql "SELECT * FROM ne_10m_populated_places ORDER BY POP_MAX DESC LIMIT '15'" -dialect SQLITE -spat 1 49 7 52 ./places.shp ../data/natural_earth_vector/10m_cultural/ne_10m_populated_places.shp
-
Top populated places from target area? (From my mobile) if so => yes!Hugolpz– Hugolpz2015年02月16日 11:11:46 +00:00Commented Feb 16, 2015 at 11:11
-