當前位置: 首頁>>代碼示例>>Python>>正文


Python affinity.affine_transform方法代碼示例

本文整理匯總了Python中shapely.affinity.affine_transform方法的典型用法代碼示例。如果您正苦於以下問題:Python affinity.affine_transform方法的具體用法?Python affinity.affine_transform怎麽用?Python affinity.affine_transform使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在shapely.affinity的用法示例。


在下文中一共展示了affinity.affine_transform方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _upload_annotation

# 需要導入模塊: from shapely import affinity [as 別名]
# 或者: from shapely.affinity import affine_transform [as 別名]
def _upload_annotation(cytomine, img_inst, polygon, label=None, proba=1.0):
    """Upload an annotation and its term (if provided)"""
    image_id = img_inst.id

    # Transform polygon to match cytomine (bottom-left) origin point
    polygon = affine_transform(polygon, [1, 0, 0, -1, 0, img_inst.height])

    annotation = cytomine.add_annotation(polygon.wkt, image_id)
    if label is not None and annotation is not None:
        cytomine.add_annotation_term(annotation.id, label, label, proba, annotation_term_model=AlgoAnnotationTerm) 
開發者ID:cytomine,項目名稱:Cytomine-python-datamining,代碼行數:12,代碼來源:add_and_run_job.py

示例2: normalized_to_map_coordinates

# 需要導入模塊: from shapely import affinity [as 別名]
# 或者: from shapely.affinity import affine_transform [as 別名]
def normalized_to_map_coordinates(coords: np.ndarray,
                                  translation: List[List[float]],
                                  rotation: List[float]) -> np.ndarray:
    """Denormalize trajectory to bring it back to map frame.

    Args:
        coords (numpy array): Array of shape (num_tracks x seq_len x 2) containing normalized coordinates
        translation (list): Translation matrix used in normalizing trajectories
        rotation (list): Rotation angle used in normalizing trajectories 
    Returns:
        _ (numpy array: Array of shape (num_tracks x seq_len x 2) containing coordinates in map frame

    """
    abs_coords = []
    for i in range(coords.shape[0]):
        ls = LineString(coords[i])

        # Rotate
        ls_rotate = rotate(ls, -rotation[i], origin=(0, 0))

        # Translate
        M_inv = [1, 0, 0, 1, -translation[i][4], -translation[i][5]]

        ls_offset = affine_transform(ls_rotate, M_inv).coords[:]
        abs_coords.append(ls_offset)

    return np.array(abs_coords) 
開發者ID:jagjeet-singh,項目名稱:argoverse-forecasting,代碼行數:29,代碼來源:baseline_utils.py

示例3: minimum_rotated_rectangle

# 需要導入模塊: from shapely import affinity [as 別名]
# 或者: from shapely.affinity import affine_transform [as 別名]
def minimum_rotated_rectangle(self):
        """Returns the general minimum bounding rectangle of
        the geometry. Can possibly be rotated. If the convex hull
        of the object is a degenerate (line or point) this same degenerate
        is returned.
        """
        # first compute the convex hull
        hull = self.convex_hull
        try:
            coords = hull.exterior.coords
        except AttributeError:  # may be a Point or a LineString
            return hull
        # generate the edge vectors between the convex hull's coords
        edges = ((pt2[0] - pt1[0], pt2[1] - pt1[1]) for pt1, pt2 in zip(
            coords, islice(coords, 1, None)))

        def _transformed_rects():
            for dx, dy in edges:
                # compute the normalized direction vector of the edge
                # vector.
                length = math.sqrt(dx ** 2 + dy ** 2)
                ux, uy = dx / length, dy / length
                # compute the normalized perpendicular vector
                vx, vy = -uy, ux
                # transform hull from the original coordinate system to
                # the coordinate system defined by the edge and compute
                # the axes-parallel bounding rectangle.
                transf_rect = affine_transform(
                    hull, (ux, uy, vx, vy, 0, 0)).envelope
                # yield the transformed rectangle and a matrix to
                # transform it back to the original coordinate system.
                yield (transf_rect, (ux, vx, uy, vy, 0, 0))

        # check for the minimum area rectangle and return it
        transf_rect, inv_matrix = min(
            _transformed_rects(), key=lambda r: r[0].area)
        return affine_transform(transf_rect, inv_matrix) 
開發者ID:enricofer,項目名稱:go2mapillary,代碼行數:39,代碼來源:base.py

示例4: reproject_geometry

# 需要導入模塊: from shapely import affinity [as 別名]
# 或者: from shapely.affinity import affine_transform [as 別名]
def reproject_geometry(input_geom, input_crs=None, target_crs=None,
                       affine_obj=None):
    """Reproject a geometry or coordinate into a new CRS.

    Arguments
    ---------
    input_geom : `str`, `list`, or `Shapely <https://shapely.readthedocs.io>`_ geometry
        A geometry object to re-project. This can be a 2-member ``list``, in
        which case `input_geom` is assumed to coorespond to ``[x, y]``
        coordinates in `input_crs`. It can also be a Shapely geometry object or
        a wkt string.
    input_crs : int, optional
        The coordinate reference system for `input_geom`'s coordinates, as an
        EPSG :class:`int`. Required unless `affine_transform` is provided.
    target_crs : int, optional
        The target coordinate reference system to re-project the geometry into.
        If not provided, the appropriate UTM zone will be selected by default,
        unless `affine_transform` is provided (and therefore CRSs are ignored.)
    affine_transform : :class:`affine.Affine`, optional
        An :class:`affine.Affine` object (or a ``[a, b, c, d, e, f]`` list to
        convert to that format) to use for transformation. Has no effect unless
        `input_crs` **and** `target_crs` are not provided.

    Returns
    -------
    output_geom : Shapely geometry
        A shapely geometry object:
        - in `target_crs`, if one was provided;
        - in the appropriate UTM zone, if `input_crs` was provided and
          `target_crs` was not;
        - with `affine_transform` applied to it if neither `input_crs` nor
          `target_crs` were provided.
    """
    input_geom = _check_geom(input_geom)

    if input_crs is not None:
        input_crs = _check_crs(input_crs)
        if target_crs is None:
            geom = reproject_geometry(input_geom, input_crs,
                                      target_crs=_check_crs(4326))
            target_crs = latlon_to_utm_epsg(geom.centroid.y, geom.centroid.x)
        target_crs = _check_crs(target_crs)
        gdf = gpd.GeoDataFrame(geometry=[input_geom], crs=input_crs.to_wkt())
        # create a new instance of the same geometry class as above with the
        # new coordinates
        output_geom = gdf.to_crs(target_crs.to_wkt()).iloc[0]['geometry']

    else:
        if affine_obj is None:
            raise ValueError('If an input CRS is not provided, '
                             'affine_transform is required to complete the '
                             'transformation.')
        elif isinstance(affine_obj, Affine):
            affine_obj = affine_to_list(affine_obj)

        output_geom = affine_transform(input_geom, affine_obj)

    return output_geom 
開發者ID:CosmiQ,項目名稱:solaris,代碼行數:60,代碼來源:geo.py


注:本文中的shapely.affinity.affine_transform方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。