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


Python geometry.LinearRing方法代码示例

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


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

示例1: svgcircle2shapely

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import LinearRing [as 别名]
def svgcircle2shapely(circle):
    """
    Converts an SVG circle into Shapely geometry.

    :param circle: Circle Element
    :type circle: xml.etree.ElementTree.Element
    :return: Shapely representation of the circle.
    :rtype: shapely.geometry.polygon.LinearRing
    """
    # cx = float(circle.get('cx'))
    # cy = float(circle.get('cy'))
    # r = float(circle.get('r'))
    cx = svgparselength(circle.get('cx'))[0]  # TODO: No units support yet
    cy = svgparselength(circle.get('cy'))[0]  # TODO: No units support yet
    r = svgparselength(circle.get('r'))[0]  # TODO: No units support yet

    # TODO: No resolution specified.
    return Point(cx, cy).buffer(r) 
开发者ID:Denvi,项目名称:FlatCAM,代码行数:20,代码来源:svgparse.py

示例2: svgellipse2shapely

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import LinearRing [as 别名]
def svgellipse2shapely(ellipse, n_points=64):
    """
    Converts an SVG ellipse into Shapely geometry

    :param ellipse: Ellipse Element
    :type ellipse: xml.etree.ElementTree.Element
    :param n_points: Number of discrete points in output.
    :return: Shapely representation of the ellipse.
    :rtype: shapely.geometry.polygon.LinearRing
    """

    cx = svgparselength(ellipse.get('cx'))[0]  # TODO: No units support yet
    cy = svgparselength(ellipse.get('cy'))[0]  # TODO: No units support yet

    rx = svgparselength(ellipse.get('rx'))[0]  # TODO: No units support yet
    ry = svgparselength(ellipse.get('ry'))[0]  # TODO: No units support yet

    t = np.arange(n_points, dtype=float) / n_points
    x = cx + rx * np.cos(2 * np.pi * t)
    y = cy + ry * np.sin(2 * np.pi * t)
    pts = [(x[i], y[i]) for i in range(n_points)]

    return LinearRing(pts) 
开发者ID:Denvi,项目名称:FlatCAM,代码行数:25,代码来源:svgparse.py

示例3: cutpath

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import LinearRing [as 别名]
def cutpath(self):
        selected = self.get_selected()
        tools = selected[1:]
        toolgeo = cascaded_union([shp.geo for shp in tools])

        target = selected[0]
        if type(target.geo) == Polygon:
            for ring in poly2rings(target.geo):
                self.add_shape(DrawToolShape(ring.difference(toolgeo)))
            self.delete_shape(target)
        elif type(target.geo) == LineString or type(target.geo) == LinearRing:
            self.add_shape(DrawToolShape(target.geo.difference(toolgeo)))
            self.delete_shape(target)
        else:
            self.app.log.warning("Not implemented.")

        self.replot() 
开发者ID:Denvi,项目名称:FlatCAM,代码行数:19,代码来源:FlatCAMDraw.py

示例4: cut_ring

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import LinearRing [as 别名]
def cut_ring(ring: LinearRing) -> List[LinearRing]:
    """
    Cuts a Linearring into multiple linearrings. Useful if the ring intersects with itself.
    An 8-ring would be split into it's two circles for example.
    """
    rings = []
    new_ring = []
    # noinspection PyPropertyAccess
    for point in ring.coords:
        try:
            # check if this point is already part of the ring
            index = new_ring.index(point)
        except ValueError:
            # if not, append it
            new_ring.append(point)
            continue

        # if yes, we got a loop, add it to the result and remove it from new_ring.
        if len(new_ring) > 2+index:
            rings.append(LinearRing(new_ring[index:]+[point]))
        new_ring = new_ring[:index+1]

    return rings 
开发者ID:c3nav,项目名称:c3nav,代码行数:25,代码来源:geometry.py

示例5: get_names_rings

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import LinearRing [as 别名]
def get_names_rings(area):
    names = []
    all_rings =[]

    for idx, a in enumerate(area):
        rings = [LinearRing(p) for p in a['polygons']]
        if len(rings) > 1:
            u = cascaded_union(rings)
        else:
            u = rings[0]
        all_rings.append(u.envelope)
        if a.get('name'):
            names.append(a.get('name'))

    names = sorted(names)
    
    return names, all_rings 
开发者ID:DFO-Ocean-Navigator,项目名称:Ocean-Data-Map-Project,代码行数:19,代码来源:stats.py

示例6: fill_polygons

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import LinearRing [as 别名]
def fill_polygons(area):
    area_polys = []
    output = []
    for a in area:
        rings = [LinearRing(p) for p in a['polygons']]
        innerrings = [LinearRing(p) for p in a['innerrings']]

        polygons = []
        for r in rings:
            inners = []
            for ir in innerrings:
                if r.contains(ir):
                    inners.append(ir)

            polygons.append(Polygon(r, inners))

        area_polys.append(MultiPolygon(polygons))

        output.append({
            'name': a.get('name'),
            'variables': [],
        })

    return area_polys, output 
开发者ID:DFO-Ocean-Navigator,项目名称:Ocean-Data-Map-Project,代码行数:26,代码来源:stats.py

示例7: __init__

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import LinearRing [as 别名]
def __init__(self, raster_mask, no_data_value=None, ignore_labels=None):
        if ignore_labels is None:
            ignore_labels = []

        self.geometries = [{'label': int(label),
                            'polygon': Polygon(LinearRing(shp['coordinates'][0]),
                                               [LinearRing(pts) for pts in shp['coordinates'][1:]])}
                           for index, (shp, label) in enumerate(rasterio.features.shapes(raster_mask, mask=None))
                           if (int(label) is not no_data_value) and (int(label) not in ignore_labels)]

        self.areas = np.asarray([entry['polygon'].area for entry in self.geometries])
        self.decomposition = [shapely.ops.triangulate(entry['polygon']) for entry in self.geometries]

        self.label2cc = collections.defaultdict(list)
        for index, entry in enumerate(self.geometries):
            self.label2cc[entry['label']].append(index) 
开发者ID:sentinel-hub,项目名称:eo-learn,代码行数:18,代码来源:sampling.py

示例8: _interp_polygon

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import LinearRing [as 别名]
def _interp_polygon(polygon, dx):
    """Interpolates an irregular polygon to a regular step dx.

    Interior geometries are also interpolated if they are longer then 3*dx,
    otherwise they are ignored.

    Parameters
    ----------
    polygon: The shapely.geometry.Polygon instance to interpolate
    dx : the step (float)

    Returns
    -------
    an interpolated shapely.geometry.Polygon class instance.
    """

    # remove last (duplex) point to build a LineString from the LinearRing
    line = shpg.LineString(np.asarray(polygon.exterior.xy).T)

    e_line = []
    for distance in np.arange(0.0, line.length, dx):
        e_line.append(*line.interpolate(distance).coords)
    e_line = shpg.LinearRing(e_line)

    i_lines = []
    for ipoly in polygon.interiors:
        line = shpg.LineString(np.asarray(ipoly.xy).T)
        if line.length < 3*dx:
            continue
        i_points = []
        for distance in np.arange(0.0, line.length, dx):
            i_points.append(*line.interpolate(distance).coords)
        i_lines.append(shpg.LinearRing(i_points))

    return shpg.Polygon(e_line, i_lines) 
开发者ID:OGGM,项目名称:oggm,代码行数:37,代码来源:gis.py

示例9: GetConusBorder

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import LinearRing [as 别名]
def GetConusBorder(doc):
  for pm in doc.Document.Placemark:
    coordinates = pm.Polygon.outerBoundaryIs.LinearRing.coordinates.text
    coords = coordinates.split(' ')
    if len(coords) > 60000:
      print 'Found CONUS border at %s with length %d' % (pm.name, len(coords))
      latLng = []
      for c in coords:
        if c.strip():
          xy = c.strip().split(',')
          latLng.append([float(xy[0]), float(xy[1])])
      return SLinearRing(latLng) 
开发者ID:Wireless-Innovation-Forum,项目名称:Spectrum-Access-System,代码行数:14,代码来源:protection_zones.py

示例10: test_degenerate_shapes

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import LinearRing [as 别名]
def test_degenerate_shapes(self):
    # Test all degenerate shapes (points, lines) have area zero
    points = sgeo.MultiPoint([(4, 59), (6, 59), (6, 61), (4, 61)])
    line = sgeo.LineString([(4, 59), (6, 59), (6, 61), (4, 61)])
    ring = sgeo.LinearRing([(4, 59), (6, 59), (6, 61), (4, 61)])
    self.assertEqual(utils.GeometryArea(points), 0)
    self.assertEqual(utils.GeometryArea(line), 0)
    self.assertEqual(utils.GeometryArea(ring), 0) 
开发者ID:Wireless-Innovation-Forum,项目名称:Spectrum-Access-System,代码行数:10,代码来源:utils_test.py

示例11: HasCorrectGeoJsonWinding

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import LinearRing [as 别名]
def HasCorrectGeoJsonWinding(geometry):
  """Returns True if a GeoJSON geometry has correct windings.

  A GeoJSON polygon should follow the right-hand rule with respect to the area it
  bounds, ie exterior rings are CCW and holes are CW.

  Args:
    geometry: A dict or string representing a GeoJSON geometry.

  Raises:
    ValueError: If invalid input or GeoJSON geometry type.
  """
  if isinstance(geometry, basestring):
    geometry = json.loads(geometry)
  if not isinstance(geometry, dict) or 'type' not in geometry:
    raise ValueError('Invalid GeoJSON geometry.')

  def _HasSinglePolygonCorrectWinding(coords):
    exterior = coords[0]
    if not sgeo.LinearRing(exterior).is_ccw:
      return False
    for hole in coords[1:]:
      if sgeo.LinearRing(hole).is_ccw:
        return False
    return True

  if geometry['type'] == 'Polygon':
    coords = geometry['coordinates']
    return _HasSinglePolygonCorrectWinding(coords)
  elif geometry['type'] == 'MultiPolygon':
    for coords in geometry['coordinates']:
      if not _HasSinglePolygonCorrectWinding(coords):
        return False
    return True
  elif geometry['type'] == 'GeometryCollection':
    for subgeo in geometry['geometries']:
      if not HasCorrectGeoJsonWinding(subgeo):
        return False
    return True
  else:
    return True 
开发者ID:Wireless-Innovation-Forum,项目名称:Spectrum-Access-System,代码行数:43,代码来源:utils.py

示例12: svgline2shapely

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import LinearRing [as 别名]
def svgline2shapely(line):
    """

    :param line: Line element
    :type line: xml.etree.ElementTree.Element
    :return: Shapely representation on the line.
    :rtype: shapely.geometry.polygon.LinearRing
    """

    x1 = svgparselength(line.get('x1'))[0]
    y1 = svgparselength(line.get('y1'))[0]
    x2 = svgparselength(line.get('x2'))[0]
    y2 = svgparselength(line.get('y2'))[0]

    return LineString([(x1, y1), (x2, y2)]) 
开发者ID:Denvi,项目名称:FlatCAM,代码行数:17,代码来源:svgparse.py

示例13: svgpolygon2shapely

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import LinearRing [as 别名]
def svgpolygon2shapely(polygon):

    ptliststr = polygon.get('points')
    points = parse_svg_point_list(ptliststr)

    return LinearRing(points) 
开发者ID:Denvi,项目名称:FlatCAM,代码行数:8,代码来源:svgparse.py

示例14: make

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import LinearRing [as 别名]
def make(self):
        p1 = self.points[0]
        p2 = self.points[1]
        #self.geometry = LinearRing([p1, (p2[0], p1[1]), p2, (p1[0], p2[1])])
        self.geometry = DrawToolShape(Polygon([p1, (p2[0], p1[1]), p2, (p1[0], p2[1])]))
        self.complete = True 
开发者ID:Denvi,项目名称:FlatCAM,代码行数:8,代码来源:FlatCAMDraw.py

示例15: utility_geometry

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import LinearRing [as 别名]
def utility_geometry(self, data=None):
        if len(self.points) == 1:
            temp_points = [x for x in self.points]
            temp_points.append(data)
            return DrawToolUtilityShape(LineString(temp_points))

        if len(self.points) > 1:
            temp_points = [x for x in self.points]
            temp_points.append(data)
            return DrawToolUtilityShape(LinearRing(temp_points))

        return None 
开发者ID:Denvi,项目名称:FlatCAM,代码行数:14,代码来源:FlatCAMDraw.py


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