本文整理汇总了Python中shapely.geometry.Polygon.symmetric_difference方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.symmetric_difference方法的具体用法?Python Polygon.symmetric_difference怎么用?Python Polygon.symmetric_difference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shapely.geometry.Polygon
的用法示例。
在下文中一共展示了Polygon.symmetric_difference方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calcCurveErr
# 需要导入模块: from shapely.geometry import Polygon [as 别名]
# 或者: from shapely.geometry.Polygon import symmetric_difference [as 别名]
def calcCurveErr(workspace,poly,mean,sigma,level):
# see: http://toblerity.org/shapely/manual.html
boundaryestimate = getLevelSet (workspace, mean, level)
# GroundTruth = np.vstack((poly,poly[0]))
GroundTruth=Polygon(GroundTruth)
boundaryestimate=Polygon(boundaryestimate)
mislabeled=boundaryestimate.symmetric_difference(GroundTruth) # mislabeled data ()
boundaryestimate.difference(GroundTruth) #mislabeled as tumor--extra that would be removed
GroundTruth.difference(boundaryestimate) # mislbaled as not-tumor--would be missed and should be cut out
correct=boundaryestimate.intersection(GroundTruth) #correctly labeled as tumor
return correct.area, mislabeled.area
示例2: _shift_polygon
# 需要导入模块: from shapely.geometry import Polygon [as 别名]
# 或者: from shapely.geometry.Polygon import symmetric_difference [as 别名]
def _shift_polygon(self, polygon):
"""
shifts a polygon according to the origin longitude
"""
if self.lon0 == 0.0:
return [polygon] # no need to shift anything
from shapely.geometry import Polygon
# we need to split and join some polygons
poly_coords = []
holes = []
for (lon, lat) in polygon.exterior.coords:
poly_coords.append((lon - self.lon0, lat))
for hole in polygon.interiors:
hole_coords = []
for (lon, lat) in hole.coords:
hole_coords.append((lon - self.lon0, lat))
holes.append(hole_coords)
poly = Polygon(poly_coords, holes)
polygons = []
#print "shifted polygons", (time.time() - start)
#start = time.time()
try:
p_in = poly.intersection(self.bounds)
polygons += hasattr(p_in, 'geoms') and p_in.geoms or [p_in]
except:
pass
#print "computed polygons inside bounds", (time.time() - start)
#start = time.time()
try:
p_out = poly.symmetric_difference(self.bounds)
out_geoms = hasattr(p_out, 'geoms') and p_out.geoms or [p_out]
except:
out_geoms = []
pass
#print "computed polygons outside bounds", (time.time() - start)
#start = time.time()
for polygon in out_geoms:
ext_pts = []
int_pts = []
s = 0 # at first we compute the avg longitude
c = 0
for (lon, lat) in polygon.exterior.coords:
s += lon
c += 1
left = s / float(c) < -180 # and use it to decide where to shift the polygon
for (lon, lat) in polygon.exterior.coords:
ext_pts.append((lon + (-360, 360)[left], lat))
for interior in polygon.interiors:
pts = []
for (lon, lat) in interior.coords:
pts.append((lon + (-360, 360)[left], lat))
int_pts.append(pts)
polygons.append(Polygon(ext_pts, int_pts))
# print "shifted outside polygons to inside", (time.time() - start)
return polygons