[GIS] How to export Extent as shapefile from multiple shapefiles using OGR

ogr2ogrshapefile

I want to export EXTENT as Rectangular shp file from multiple shape using OGR2OGR?

Best Answer

For this special purpose you can use the ogrtindex tool http://gdal.org/ogrtindex.html. The tool is made for creating footprints of vector datasets to be used as a tileindex file with MapServer http://www.mapserver.org/optimization/tileindex.html. Nonetheless, the tool makes exactly what you want even without MapServer.

Another, more general option would be to use ogr2ogr, query the extent of each shapefile with SQL one by one, and append results to the final index file:

Command for testing the system with ogrinfo follows. You can add more attributes into SELECT for getting some metadata into the result but this show the most simple query.

ogrinfo -dialect sqlite -sql "select extent(geometry) from
 FPS_buildings" FPS_buildings.shp
INFO: Open of `FPS_buildings.shp'
      using driver `ESRI Shapefile' successful.

Layer name: SELECT
Geometry: Unknown (any)
Feature Count: 1
Extent: (-121.792995, 38.533776) - (-121.790750, 38.535221)
Layer SRS WKT:
(unknown)
Geometry Column = extent(geometry)
OGRFeature(SELECT):0
  POLYGON ((-121.79299546166366 38.533776179540084,-121.79075036793149 38.533776
179540084,-121.79075036793149 38.535220665903672,-121.79299546166366 38.53522066
5903672,-121.79299546166366 38.533776179540084))

When you see that the command works you can create the index shape as

ogr2ogr -update -append -dialect sqlite -sql "select extent(geometry) from FPS_buildings" index.shp fps_buildings.shp

ogr2ogr -update -append ... [command for the next shape]
.....