[gdal-dev] Extract Extent or Bounding Box for a subset of shapes for a shapefile

Matthew Pettis matthew.pettis at gmail.com
Fri Apr 22 09:22:39 EDT 2011


Hi All,

I think this is the right list for the question below, as I cannot find a
different list that matches my question better.

I'm using ogr2ogr and ogrinfo (v1.4), and I want to extract the extent from
the result of a subsetting where argument.  I have a solution here that
works but I'm wondering if I'm missing some more obvious solution.  In a
bash script, I do the following (the core snippet only, as I took out the
shebang and option-getting/setting code:)

---------------------------
rm -rf /tmp/tmpshpfile.*

ogr2ogr -where "$WHERECLAUSE" /tmp/tmpshpfile.shp "$FILE"

ogrinfo -ro -so -al /tmp/tmpshpfile.shp | \
    grep Extent | \
    tr -d '[:alpha:]:() -' | \
    tr ',' ' '

rm -rf /tmp/tmpshpfile.*
---------------------------

I can use it as follows:

---------------------------
$ ./bbox.sh -f /path/to/shp/shp_counties.shp -w "COUNTY_NAME='Yellow
Medicine'"
226206.484375 4934737.000000313007.250000 4979500.500000
---------------------------

Where the argument to '-w' is put into the '$WHERECLAUSE' variable in the
script.

This works.  As I wrote, though, am I missing something obvious in
command-line switches to either of these programs that would simplify this
so I wouldn't have to use this script?  Or is there some other, better way
of doing this?  Also, is there a way to pipe the output of ogr2ogr on stdout
directly to the stdin of ogrinfo?

Thanks,
Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110422/92494b4b/attachment.html


More information about the gdal-dev mailing list