[gdal-dev] Need suggestion on clipping vectors in batch

Antonio Falciano afalciano at yahoo.it
Wed Oct 5 04:37:58 PDT 2016


Il 05/10/2016 11:29, Margherita Di Leo ha scritto:
> Hi,
>
> I need a suggestion on the use of ogr2ogr for clipping vector files
> (points) in batch. For all them I need to reduce the spatial extent of a
> certain quantity DX, DY, so it would be
>
> ymax = ymax_current - DY
> ymin = ymin_current + DY
> xmax = xmax_current - DX
> xmin = xmin_current + DX
>
> I could calculate ymax, ymin, xmax, xmin if I could read the current
> values in a FAST way. Or perhaps is there an option to put directly DX
> and DY in ogr2ogr which I didn't spot?

Ciao Margherita,
the current values can be retrieved using ogrinfo. For instance, a quick
and dirty xmin_current value is:

ogrinfo points.shp -dialect SQLite -sql "SELECT
MbrMinX(ST_Union(geometry)) FROM points" | grep "=" | sed
's/MbrMinX(ST_Union(geometry)) (Real) =//g' | sed 's/^[ \t]*//;s/[ \t]*$//'

...and so on for the other ones. Then you can make the reduction and
finally rebuild the spatial query extents to pass to -spat option in 
ogr2ogr.

Antonio

-- 
Antonio Falciano
http://www.linkedin.com/in/antoniofalciano


More information about the gdal-dev mailing list