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

Luca Sigfrido Percich sigfrido at tiscali.it
Fri Apr 22 10:14:46 EDT 2011


Hi Matthew,

Your question is interesting. ogrinfo -where seemed to be the answer,
but...

I tried ogrinfo with the -where "sql where" option with both MapInfo and
PostGIS layers. In your case it should be:

ogrinfo -ro -so -al -where "$WHERECLAUSE" "whole_shapefile.shp"

The returned extent is always the same, regardless of the presence or
composition of the -where clause, so it refers to the whole layer rather
than to the selected features.
(I'm using GDAL 1.9 dev)

Is this the expected behaviour of ogrinfo -where "..."? Or sould -where
affect the returned Extent too?

Thank you all

Sig

Il giorno ven, 22/04/2011 alle 08.22 -0500, Matthew Pettis ha scritto:
> 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
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev



More information about the gdal-dev mailing list