I have a shapefile that contains data for both sides of the Greenwich meridian.

According to ogrinfo, this shapefile has the extents of (-9.298157, 35.265607) - (4.327108, 45.046054). I want to copy all data in the bounding box (42.5, -0.5) - (43.5, 1). But using ogr2ogr, I got an empty shapefile (it had just 100 bytes …)! I used the following command:

ogr2ogr -progress -spat 42.5 -0.5 43.5 1 outfile.shp infile.shp

If ogr2ogr does not understand negative coordinates, then how do I get that data out of that shapefile?

  • 1
    Perhaps there really is no data inside this small area even though the extent is greater? Aug 16 at 23:10
  • You probably have your coordinates in the wrong order. ogrinfo says "-9.298157, 35.265607" etc but you pass "42.5, -0.5" etc... Try -spat -0.5 42.5 1 43.5
    – user2856
    Aug 17 at 8:03
  • @user2856 OMG I'm dumb - that did the trick !
    – Programmer
    Aug 17 at 16:14

As pointed out by @user2856, ogr2ogr does understand negative coordinates - I only specified the coordinates in the wrong order. The correct and working command is:

ogr2ogr -progress -spat -0.5 42.5 1 43.5 outfile.shp infile.shp

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.