当前位置: 首页>>代码示例>>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;未经允许,请勿转载。