本文整理匯總了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)
示例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)
示例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()
示例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
示例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
示例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
示例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)
示例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)
示例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)
示例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)
示例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
示例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)])
示例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)
示例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
示例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