I've seen other answers detailing how one can clip a .shp file with ogr2ogr but this just returns a clipped set of geographic features. I also want to clip the .shx and the .dbf in the same manner. Is this possible?

For instance, if I have all-of-rhode-island{.shp, .shx, .dbf} in my current directory, I could try:

ogr2ogr -clipsrc 41.31 -71.87 41.50 -71.53 smaller-ri all-of-rhode-island

But ogr2ogr can't figure out which driver to use with that input file.

My actual goal is to take a TIGER Census file and reduce its size drastically. I only need a few features, but I do need "matching" .dbf and .shx files.

  • 1
    Are you looking for a specific solution? You mention OGR so I guess you are not using ArcGIS/MapInfo as what you are asking would be trivial in those GIS systems. If you are looking for an open source solution then consider QGIS? – Hornbydd Dec 20 '14 at 0:31
  • I would love something for Linux or the command line or (best of all) python. I will try QGIS Desktop, thanks. I had been stumped looking at QGIS /Browser/, not realizing there was a difference. – Matt Dec 20 '14 at 0:33
  • 1
    The shapefile format spans the three files; it is required that the .shx and .dbf have the same number of records as the .shp (or it's not a valid shapefile). – Vince Dec 20 '14 at 1:41

ogr2ogr is the tool to use for this, I've realized. It will clip .shp, .shx, .dbf and other files if you run it correctly (which I was not doing).

I was using latitude as x and longitude as y, but that is incorrect. This was what I eventually used:

ogr2ogr -clipsrc -71.87 41.31 -71.53 41.50 smaller-ri.shp rhode-island.shp

  • Note: ogr2ogr does have shapefile as a default output format but some other GDAL tools have other defaults, like GML. Your command is correct but myself I give always output format explicitly even for shapefiles by addin -f "ESRI Shapefile". It makes me feel that I am the one who controlls the situation. – user30184 Dec 20 '14 at 10:18

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.