Ejemplo n.º 1
0
def get_nd_val(filename):
    '''Attemps to determine the nodata value used in this raster
    First it reads the value from the header metadata
    If that value is approximately the same as raster min
    the return the exact pixel value
    '''
    dataset = gdal.Open(filename, gdalconst.GA_ReadOnly)
    band = dataset.GetRasterBand(1)

    nd_value = band.GetNoDataValue()

    min = band.GetMinimum()
    if utilities.approx_equal(nd_value, min):
        upper_left_pix = band.ReadAsArray(0, 0, 1, 1, 1, 1)[0][0]
        if utilities.approx_equal(nd_value, upper_left_pix):
            nd_value = band.ReadAsArray(0, 0, 1, 1, 1, 1)[0][0]

    dataset = None
    return nd_value
Ejemplo n.º 2
0
def getNDVal(filename):
    dataset = gdal.Open(filename, gdalconst.GA_ReadOnly)
    band = dataset.GetRasterBand(1)

    NDValue = band.GetNoDataValue()
    band.ComputeStatistics(True)
    min_pixel = band.GetMinimum()

    if utilities.approx_equal(min_pixel, -3.399999999999999961272e38):
        NDValue = min_pixel
        band.SetNoDataValue(float(min_pixel))
        band.ComputeStatistics(True)

    dataset = None
    return NDValue
Ejemplo n.º 3
0
def getNDVal(filename):
    dataset = gdal.Open(filename, gdalconst.GA_ReadOnly)
    band = dataset.GetRasterBand(1)

    NDValue = band.GetNoDataValue()
    band.ComputeStatistics(True)
    min_pixel = band.GetMinimum()

    if utilities.approx_equal(min_pixel, -3.399999999999999961272e+38):
        NDValue = min_pixel
        band.SetNoDataValue(float(min_pixel))
        band.ComputeStatistics(True)



    dataset = None
    return NDValue
Ejemplo n.º 4
0
def extentMatch(raster1, raster2):
    answer = True
    if not utilities.approx_equal(raster1.xScale, raster2.xScale): answer = False
    if not utilities.approx_equal(raster1.yScale, raster2.yScale): answer = False
    if not utilities.approx_equal(raster1.width, raster2.width): answer = False
    if not utilities.approx_equal(raster1.height, raster2.height): answer = False
    if not utilities.approx_equal(raster1.east, raster2.east): answer = False
    if not utilities.approx_equal(raster1.north, raster2.north): answer = False
    if raster2.srs.ExportToProj4() != raster1.srs.ExportToProj4():
        raster1.srs.SetTOWGS84(0, 0, 0, 0)
        raster2.srs.SetTOWGS84(0, 0, 0, 0)
        if raster2.srs.ExportToProj4() != raster1.srs.ExportToProj4():
            answer = False

    return answer
Ejemplo n.º 5
0
def extentMatch(raster1, raster2):
    answer = True
    if not utilities.approx_equal(raster1.xScale, raster2.xScale):
        answer = False
    if not utilities.approx_equal(raster1.yScale, raster2.yScale):
        answer = False
    if not utilities.approx_equal(raster1.width, raster2.width):
        answer = False
    if not utilities.approx_equal(raster1.height, raster2.height):
        answer = False
    if not utilities.approx_equal(raster1.east, raster2.east):
        answer = False
    if not utilities.approx_equal(raster1.north, raster2.north):
        answer = False
    if raster2.srs.ExportToProj4() != raster1.srs.ExportToProj4():
        raster1.srs.SetTOWGS84(0, 0, 0, 0)
        raster2.srs.SetTOWGS84(0, 0, 0, 0)
        if raster2.srs.ExportToProj4() != raster1.srs.ExportToProj4():
            answer = False

    return answer