Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    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