2

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 ?

asked Feb 15, 2015 at 1:24
3
  • Didn't found a way! Maybe it's not possible to chain. Commented Feb 16, 2015 at 1:08
  • 1
    I undestand that you want to select top populated cities from the clipped area? How about switching -clipsrc to sql's WHERE ST_Intersect? Commented Feb 16, 2015 at 9:08
  • Yes indeed, i am looking for such way if chaining clip => sql select is not possible. Commented Feb 16, 2015 at 9:10

1 Answer 1

2

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
answered Feb 16, 2015 at 8:29
2
  • Top populated places from target area? (From my mobile) if so => yes! Commented Feb 16, 2015 at 11:11
  • Working and adopted!!! Commented Feb 17, 2015 at 1:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.