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 ?

  • Didn't found a way! Maybe it's not possible to chain. – Hugolpz Feb 16 '15 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? – jzol Feb 16 '15 at 9:08
  • Yes indeed, i am looking for such way if chaining clip => sql select is not possible. – Hugolpz Feb 16 '15 at 9:10
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
  • Top populated places from target area? (From my mobile) if so => yes! – Hugolpz Feb 16 '15 at 11:11
  • Working and adopted!!! – Hugolpz Feb 17 '15 at 1:20

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.