当前位置: 首页>>代码示例>>Python>>正文


Python Polygon.simplify方法代码示例

本文整理汇总了Python中shapely.geometry.Polygon.simplify方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.simplify方法的具体用法?Python Polygon.simplify怎么用?Python Polygon.simplify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shapely.geometry.Polygon的用法示例。


在下文中一共展示了Polygon.simplify方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: simplify

# 需要导入模块: from shapely.geometry import Polygon [as 别名]
# 或者: from shapely.geometry.Polygon import simplify [as 别名]
def simplify(points):
    polygon = Polygon(map(lambda x: (x["x"], x["y"]), points))
    polygon = polygon.simplify(0.05)

    return {
        "points": map(lambda x: {"x": x[0], "y": x[1]},
            polygon.exterior.coords),
        "centroid": (polygon.centroid.x, polygon.centroid.y),
        "bounds": polygon.bounds,
        "area": polygon.area
    }
开发者ID:Mondego,项目名称:pyreco,代码行数:13,代码来源:allPythonContent.py

示例2: get_tile_geometry

# 需要导入模块: from shapely.geometry import Polygon [as 别名]
# 或者: from shapely.geometry.Polygon import simplify [as 别名]
def get_tile_geometry(path, origin_espg, tolerance=500):
    """ Calculate the data and tile geometry for sentinel-2 tiles """

    with rasterio.open(path) as src:

        # Get tile geometry
        b = src.bounds
        tile_shape = Polygon([(b[0], b[1]), (b[2], b[1]), (b[2], b[3]), (b[0], b[3]), (b[0], b[1])])
        tile_geojson = mapping(tile_shape)

        # read first band of the image
        image = src.read(1)

        # create a mask of zero values
        mask = image == 0.

        # generate shapes of the mask
        novalue_shape = shapes(image, mask=mask, transform=src.affine)

        # generate polygons using shapely
        novalue_shape = [Polygon(s['coordinates'][0]) for (s, v) in novalue_shape]

        if novalue_shape:

            # Make sure polygons are united
            # also simplify the resulting polygon
            union = cascaded_union(novalue_shape)

            # generates a geojson
            data_shape = tile_shape.difference(union)

            # If there are multipolygons, select the largest one
            if data_shape.geom_type == 'MultiPolygon':
                areas = {p.area: i for i, p in enumerate(data_shape)}
                largest = max(areas.keys())
                data_shape = data_shape[areas[largest]]

            # if the polygon has interior rings, remove them
            if list(data_shape.interiors):
                data_shape = Polygon(data_shape.exterior.coords)

            data_shape = data_shape.simplify(tolerance, preserve_topology=False)
            data_geojson = mapping(data_shape)

        else:
            data_geojson = tile_geojson

        # convert cooridnates to degrees
        return (to_latlon(tile_geojson, origin_espg), to_latlon(data_geojson, origin_espg))
开发者ID:developmentseed,项目名称:sentinel-s3,代码行数:51,代码来源:converter.py

示例3: shape_to_polygons

# 需要导入模块: from shapely.geometry import Polygon [as 别名]
# 或者: from shapely.geometry.Polygon import simplify [as 别名]
def shape_to_polygons(shape):
    def inside(pt):
        return hypot(*pt) <= R
    def adjust(pt):
        x, y = pt
        a = atan2(y, x)
        x = cos(a) * R
        y = sin(a) * R
        return (x, y)
    result = []
    parts = list(shape.parts) + [len(shape.points)]
    for i1, i2 in zip(parts, parts[1:]):
        points = map(tuple, shape.points[i1:i2])
        points = map(laea, points)
        points = filter(None, points)
        p = Polygon(points)
        p = p.buffer(-0.01)
        p = p.buffer(0.01)
        p = p.simplify()
        if p.is_empty:
            continue
        if isinstance(p, Polygon):
            ps = [p]
        else:
            ps = p.geoms
        for p in ps:
            points = list(p.exterior.coords)
            print points
            for a, b in zip(points, points[1:]):
                # if not a[-1] and not b[-1]:
                #     continue
                a = a[:2]
                b = b[:2]
                in1 = inside(a)
                in2 = inside(b)
                if not in1 and not in2:
                    continue
                if in1 and not in2:
                    b = adjust(b)
                if in2 and not in1:
                    a = adjust(a)
                result.append(LineString([a, b]))
    return result
开发者ID:fogleman,项目名称:Carolina,代码行数:45,代码来源:hemi.py


注:本文中的shapely.geometry.Polygon.simplify方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。