En raison du déménagement des baies serveurs, les services gitlab.irstea.fr et mattermost.irstea.fr seront interrompus le samedi 2 octobre 2021 au matin. Ils devraient revenir à la normale dans la journée.

Unverified Commit 90205146 authored by Julien Veyssier's avatar Julien Veyssier
Browse files

make get_raster_bounds much safer


Signed-off-by: default avatarJulien Veyssier <eneiluj@posteo.net>
parent a05bf3a5
......@@ -56,19 +56,18 @@ def cutting_raster(raster,raster_out, xmin_slect, ymax_slect, xmax_slect, ymin_s
ds = None
def get_raster_bounds(layer, xmin_slect, ymax_slect, xmax_slect, ymin_slect):
# this is kind of sketchy and should be done right
ds = gdal.Open(layer)
infoLines = gdal.Info(ds).split('\n')
for l in infoLines:
if 'Upper Left' in l:
xmin_slect = max(xmin_slect, float(l.split(')')[0].split('(')[1].split(',')[0]))
ymax_slect = min(ymax_slect, float(l.split(')')[0].split('(')[1].split(',')[1]))
elif 'Lower Right' in l:
xmax_slect = min(xmax_slect, float(l.split(')')[0].split('(')[1].split(',')[0]))
ymin_slect = max(ymin_slect, float(l.split(')')[0].split('(')[1].split(',')[1]))
ds = None
return xmin_slect, ymax_slect, xmax_slect, ymin_slect
# this is better than sketchy "gdal.Info(ds).split('\n')"
src = gdal.Open(layer)
xmin, xres, xskew, ymax, yskew, yres = src.GetGeoTransform()
xmax = xmin + (src.RasterXSize * xres)
ymin = ymax + (src.RasterYSize * yres)
src = None
return (
max(xmin_slect, xmin),
min(ymax_slect, ymax),
min(xmax_slect, xmax),
max(ymin_slect, ymin)
)
def get_polygon_bounds(shape, xmin_slect, ymax_slect, xmax_slect, ymin_slect):
ds = ogr.Open(shape)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment