コード例 #1
0
def angle_between_views(geotiff_path_1, geotiff_path_2, lon=None, lat=None,
                        z=None, verbose=False):
    """
    Compute the view angle difference between two (stereo) images.

    Args:
        geotiff_path_1 (str): path or url to a GeoTIFF file
        geotiff_path_2 (str): path or url to a GeoTIFF file
        lon, lat, z (floats): longitude, latitude, altitude of the 3D point
            where to compute the angle

    Returns:
        float: angle between the views, in degrees
    """
    rpc1 = rpc_from_geotiff(geotiff_path_1)
    rpc2 = rpc_from_geotiff(geotiff_path_2)

    if lon is None:
        lon = rpc1.lon_offset
    if lat is None:
        lat = rpc1.lat_offset
    if z is None:
        z = srtm4.srtm4(lon, lat)

    a = utils.viewing_direction(*rpc1.incidence_angles(lon, lat, z))
    b = utils.viewing_direction(*rpc2.incidence_angles(lon, lat, z))
    angle = np.degrees(np.arccos(np.dot(a, b)))

    if verbose:
        print('{:.3f}'.format(angle))

    return angle
コード例 #2
0
ファイル: __init__.py プロジェクト: tianjg/rpcm
def localization(img_path, x, y, z, crop_path=None, verbose=False):
    """
    Conversion of image coordinates to geographic coordinates.

    Args:
        img_path (str): path or url to a GeoTIFF image with RPC metadata
        x (float or list): x coordinate(s) of the input points
        y (float or list): y coordinate(s) of the input points
        z (float or list): altitude(s) of the input points
        crop_path (str): path or url to an image crop produced by rpcm.
            Input image coordinates are interpreted wrt this crop.

    Returns:
        float or list: longitude(s) of the localised point(s)
        float or list: latitude(s) of the localised point(s)
    """
    if crop_path:  # load and apply crop transformation matrix
        with rasterio.open(crop_path, 'r') as src:
            tags = src.tags()

        C = list(map(float, tags['CROP_TRANSFORM'].split()))
        C = np.array(C).reshape(3, 3)
        h = np.row_stack((x, y, x**0))  # homogeneous coordinates
        x, y = np.dot(np.linalg.inv(C), h).squeeze()[:2]

    rpc = rpc_from_geotiff(img_path)
    lon, lat = rpc.localization(x, y, z)

    if verbose:
        for p in zip(np.atleast_1d(lon), np.atleast_1d(lat)):
            print('{:.8f} {:.8f}'.format(*p))

    return lon, lat
コード例 #3
0
ファイル: __init__.py プロジェクト: tianjg/rpcm
def projection(img_path,
               lon,
               lat,
               z=None,
               crop_path=None,
               svg_path=None,
               verbose=False):
    """
    Conversion of geographic coordinates to image coordinates.

    Args:
        img_path (str): path or url to a GeoTIFF image with RPC metadata
        lon (float or list): longitude(s) of the input points
        lat (float or list): latitude(s) of the input points
        z (float or list): altitude(s) of the input points
        crop_path (str): path or url to an image crop produced by rpcm.
            Projected image coordinates are computed wrt this crop.
        svg_path (str): path to an svg file where to plot the projected image
            point(s)

    Returns:
        float or list: x pixel coordinate(s) of the projected point(s)
        float or list: y pixel coordinate(s) of the projected point(s)
    """
    rpc = rpc_from_geotiff(img_path)
    if z is None:
        z = srtm4.srtm4(lon, lat)

    x, y = rpc.projection(lon, lat, z)

    if crop_path:  # load and apply crop transformation matrix
        with rasterio.open(crop_path, 'r') as src:
            tags = src.tags()

        C = list(map(float, tags['CROP_TRANSFORM'].split()))
        C = np.array(C).reshape(3, 3)
        h = np.row_stack((x, y, x**0))  # homogeneous coordinates
        x, y = np.dot(C, h).squeeze()[:2]

    if svg_path:  #TODO
        pass

    if verbose:
        for p in zip(np.atleast_1d(x), np.atleast_1d(y)):
            print('{:.4f} {:.4f}'.format(*p))

    return x, y
コード例 #4
0
def crop_aoi(geotiff, aoi, z=0):
    """
    Crop a geographic AOI in a georeferenced image using its RPC functions.

    Args:
        geotiff (string): path or url to the input GeoTIFF image file
        aoi (geojson.Polygon): GeoJSON polygon representing the AOI
        z (float, optional): base altitude with respect to WGS84 ellipsoid (0
            by default)

    Return:
        crop (array): numpy array containing the cropped image
        x, y, w, h (ints): image coordinates of the crop. x, y are the
            coordinates of the top-left corner, while w, h are the dimensions
            of the crop.
    """
    x, y, w, h = bounding_box_of_projected_aoi(
        rpc_model.rpc_from_geotiff(geotiff), aoi, z)
    with rasterio.open(geotiff, 'r') as src:
        crop = src.read(window=((y, y + h), (x, x + w)),
                        boundless=True).squeeze()
    return crop, x, y