def read_raster(raster_file): """Read raster by GDAL. Args: raster_file: raster file path. Returns: Raster object. """ ds = gdal_Open(raster_file) band = ds.GetRasterBand(1) data = band.ReadAsArray() xsize = band.XSize ysize = band.YSize nodata_value = band.GetNoDataValue() geotrans = ds.GetGeoTransform() dttype = band.DataType srs = osr_SpatialReference() srs.ImportFromWkt(ds.GetProjection()) # print(srs.ExportToProj4()) if nodata_value is None: nodata_value = DEFAULT_NODATA band = None ds = None return Raster(ysize, xsize, data, nodata_value, geotrans, srs, dttype)
def raster_statistics(raster_file): """Get basic statistics of raster data. Args: raster_file: raster file path Returns: min, max, mean, std """ ds = gdal_Open(raster_file) band = ds.GetRasterBand(1) minv, maxv, meanv, std = band.ComputeStatistics(False) return minv, maxv, meanv, std
def raster_statistics(raster_file): """Get basic statistics of raster data. Args: raster_file: raster file path. Returns: min, max, mean, std. """ ds = gdal_Open(raster_file) band = ds.GetRasterBand(1) minv, maxv, meanv, std = band.ComputeStatistics(False) return minv, maxv, meanv, std