Search code examples
geojsonogr2ogr

How to use GDAL's ogr2ogr to create bounding box


I'm learning about GeoJSON and following Bostock's Lets Make a Map tutorial. Here he uses Natural Earth data, and converts SHP files to JSON for use in D3. The following takes only GBR and IRL data from the SHP file to create subunits.json, which I load into D3 to draw my map.

> ogr2ogr \
  -f GeoJSON \
  -where "ADM0_A3 IN ('GBR', 'IRL')" \
  subunits.json \
  ne_10m_admin_0_map_subunits.shp

ogr2ogr has many more powerful features...The -clipdst argument, for example, clips the shapefile to a rectangular bounding box, useful for displaying only a small part of certain features.

I'd like to create a bounding box for displaying only a small area such as the area around Birmingham. How do I calculate the xmin ymin etc for this? This is the usage [-clipdst [xmin ymin xmax ymax]|WKT|datasource] but what exactly should it look like?


Solution

  • There's an example of the clipdst syntax at the bottom of the page you shared:

    Example reprojecting from ETRS_1989_LAEA_52N_10E to EPSG:4326 and clipping to a bounding box

    ogr2ogr -wrapdateline -t_srs EPSG:4326 -clipdst -5 40 15 55 france_4326.shp europe_laea.shp
    

    http://www.gdal.org/ogr2ogr.html#ogr2ogr_example