Пример #1
0
def get_image_location_value(imagepath, x, y, xy_srs, bandindex):
    """
    get the image value of given location(x,y) in bandindex
    Args:
        imagepath:the image path which the information query
        x:x value
        y:y value
        xy_srs:the coordinate system of (x,y), the value is :pixel ,prj or lon_lat_wgs84
        bandindex:the bandindex of image want to query

    Returns:the certain value (float) of given location

    """
    coordinate = ''
    if xy_srs == 'pixel':
        coordinate = ' '
    elif xy_srs == 'prj':
        coordinate = ' -geoloc '
    elif xy_srs == 'lon_lat_wgs84':
        coordinate = ' -wgs84 '
    else:
        basic.outputlogMessage('input error: %s is not right' % xy_srs)
        assert False


    command_str = 'gdallocationinfo  -valonly ' + ' -b ' +str(bandindex) + coordinate \
    + '  '+imagepath + ' ' + str(x) +' '+ str(y)
    result = basic.exec_command_string_output_string(command_str)
    try:
        result = float(result)
    except ValueError:
        basic.outputlogMessage(str(ValueError))
        assert False
    return result
Пример #2
0
def get_image_proj_extent(imagepath):
    """
    get the extent of a image
    Args:
        imagepath:image path

    Returns:(ulx:Upper Left X,uly: Upper Left Y,lrx: Lower Right X,lry: Lower Right Y)

    """
    ulx = False
    uly = False
    lrx = False
    lry = False
    CommandString = 'gdalinfo -json ' + imagepath
    imginfo = basic.exec_command_string_output_string(CommandString)
    if imginfo is False:
        return False
    imginfo_obj = json.loads(imginfo)
    # print imginfo_obj
    # print type(imginfo_obj)
    # print imginfo_obj.keys()
    try:
        cornerCoordinates = imginfo_obj['cornerCoordinates']
        upperLeft_value = cornerCoordinates['upperLeft']
        lowerRight_value = cornerCoordinates['lowerRight']
        ulx = upperLeft_value[0]
        uly = upperLeft_value[1]
        lrx = lowerRight_value[0]
        lry = lowerRight_value[1]
    except KeyError:
        basic.outputlogMessage(str(KeyError))
        pass

    return (ulx, uly, lrx, lry)
Пример #3
0
def get_image_max_min_value(imagepath):
    """
    get image first band max vlaue and min value
    Args:
        imagepath: image path

    Returns:(max value list, min value list) if successful, (False,False) otherwise

    """
    max_value = []
    min_value = []
    CommandString = 'gdalinfo -json  -stats ' + imagepath
    imginfo = basic.exec_command_string_output_string(CommandString)
    if imginfo is False:
        return False
    imginfo_obj = json.loads(imginfo)
    try:
        bands_info = imginfo_obj['bands']
        for band_info in bands_info:
            max_value.append(band_info['maximum'])
            min_value.append(band_info['minimum'])
        return (max_value, min_value)
    except KeyError:
        basic.outputlogMessage(str(KeyError))
        pass
    return (False, False)
Пример #4
0
def get_raster_or_vector_srs_info(spatial_data, format):
    """
    get SRS(Spatial Reference System) information from raster or vector data
    Args:
        spatial_data: the path of raster or vector data
        format: Any of the usual GDAL/OGR forms(complete WKT, PROJ.4, EPSG:n or a file containing the SRS)

    Returns:the string of srs info in special format, False otherwise

    """
    if io_function.is_file_exist(spatial_data) is False:
        return False
    CommandString = 'gdalsrsinfo -o  ' + format + ' ' + spatial_data
    result = basic.exec_command_string_output_string(CommandString)
    if result.find('ERROR') >= 0:
        return False
    return result