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

Even Rouault even.rouault at spatialys.com
Wed Oct 5 11:53:01 PDT 2016


Le mercredi 05 octobre 2016 11:29:43, Margherita Di Leo a écrit :
> 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?

Tiny Python script with GDAL 2.1 :

from osgeo import gdal
src_ds = gdal.OpenEx('your.shp')
lyr = src_ds.GetLayer(0)
minx, maxx, miny, maxy = lyr.GetExtent()
# Note the different order of bounds between previous and next line
gdal.VectorTranslate("out.shp", src_ds, \
 spatFilter=(minx + DX,miny +DY,maxx-DX, maxy-DX))


> 
> Any hints appreciated
> Thanks

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list