本文整理汇总了Python中shapely.geometry.Point.difference方法的典型用法代码示例。如果您正苦于以下问题:Python Point.difference方法的具体用法?Python Point.difference怎么用?Python Point.difference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shapely.geometry.Point
的用法示例。
在下文中一共展示了Point.difference方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ring
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import difference [as 别名]
def ring(lat, lon, R, r, proj, EC=2.5):
"""Creates a ring defined by two circles with radiuses r, R
centered at x, y
Args:
lat, lon: latitude and longitude
R: outer radius of the ring in m
r: inner radius of the ring in m
proj. projection used
EC: correction parameter
"""
if R == r:
return None
# get projected coordinates
(x, y) = proj(lon, lat)
# error adjust rings
error_r = EC * projections.proj_error(proj, [lat, lon], r, 0)
error_R = EC * projections.proj_error(proj, [lat, lon], R, 0)
r -= math.fabs(error_r)
R += math.fabs(error_R)
if R > r:
outer_circle = Point(x, y).buffer(R)
inner_circle = Point(x, y).buffer(r)
else:
outer_circle = Point(x, y).buffer(r)
inner_circle = Point(x, y).buffer(R)
ring = outer_circle.difference(inner_circle)
return ring
示例2: solve
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import difference [as 别名]
def solve(f, R, t, r, g):
# make the circle
outerCircle = Point(0, 0).buffer(R, 1 << 12)
# make the ring
innerCircle = Point(0, 0).buffer(R - t - f, 1 << 12)
# make the bars
bars = []
leftMin = -r - (2 * r + g) * (int(R / (2 * r + g)) + 1)
left = leftMin
while left < R:
bars.append(box(left, -R, left + 2 * r + 2 * f, R))
left += 2 * r + g
bottom = leftMin
while bottom < R:
bars.append(box(-R, bottom, R, bottom + 2 * r + 2 * f))
bottom += 2 * r + g
# get the union
union = outerCircle.difference(innerCircle)
for bar in bars:
union = union.union(bar)
# intersection with prev shape
finalPattern = union.intersection(outerCircle)
# calc area ratio
result = finalPattern.area / outerCircle.area
return '%.6f' % result
示例3: ring
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import difference [as 别名]
def ring(centerx, centery, radius, width):
"""
a circular ring
"""
c_out = Point(centerx, centery).buffer(radius)
c_in = Point(centerx, centery).buffer(radius - width)
return c_out.difference(c_in)
示例4: test_operations
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import difference [as 别名]
def test_operations(self):
point = Point(0.0, 0.0)
# General geometry
self.assertEqual(point.area, 0.0)
self.assertEqual(point.length, 0.0)
self.assertAlmostEqual(point.distance(Point(-1.0, -1.0)),
1.4142135623730951)
# Topology operations
# Envelope
self.assertIsInstance(point.envelope, Point)
# Intersection
self.assertIsInstance(point.intersection(Point(-1, -1)),
GeometryCollection)
# Buffer
self.assertIsInstance(point.buffer(10.0), Polygon)
self.assertIsInstance(point.buffer(10.0, 32), Polygon)
# Simplify
p = loads('POLYGON ((120 120, 121 121, 122 122, 220 120, 180 199, '
'160 200, 140 199, 120 120))')
expected = loads('POLYGON ((120 120, 140 199, 160 200, 180 199, '
'220 120, 120 120))')
s = p.simplify(10.0, preserve_topology=False)
self.assertTrue(s.equals_exact(expected, 0.001))
p = loads('POLYGON ((80 200, 240 200, 240 60, 80 60, 80 200),'
'(120 120, 220 120, 180 199, 160 200, 140 199, 120 120))')
expected = loads(
'POLYGON ((80 200, 240 200, 240 60, 80 60, 80 200),'
'(120 120, 220 120, 180 199, 160 200, 140 199, 120 120))')
s = p.simplify(10.0, preserve_topology=True)
self.assertTrue(s.equals_exact(expected, 0.001))
# Convex Hull
self.assertIsInstance(point.convex_hull, Point)
# Differences
self.assertIsInstance(point.difference(Point(-1, 1)), Point)
self.assertIsInstance(point.symmetric_difference(Point(-1, 1)),
MultiPoint)
# Boundary
self.assertIsInstance(point.boundary, GeometryCollection)
# Union
self.assertIsInstance(point.union(Point(-1, 1)), MultiPoint)
self.assertIsInstance(point.representative_point(), Point)
self.assertIsInstance(point.centroid, Point)
# Relate
self.assertEqual(point.relate(Point(-1, -1)), 'FF0FFF0F2')
示例5: testMerger
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import difference [as 别名]
def testMerger(self):
# build chunks for the polygons
tile_box = box(0, 0, 512, 256) # a box having the same dimension as the tile
circle = Point(600, 360)
circle = circle.buffer(250)
circle_part1 = tile_box.intersection(circle)
circle_part2 = translate(tile_box, xoff=512).intersection(circle)
circle_part3 = translate(tile_box, yoff=256).intersection(circle)
circle_part4 = translate(tile_box, xoff=512, yoff=256).intersection(circle)
circle_part5 = translate(tile_box, yoff=512).intersection(circle)
circle_part6 = translate(tile_box, xoff=512, yoff=512).intersection(circle)
# create topology
fake_image = FakeImage(1024, 768, 3)
fake_builder = FakeTileBuilder()
topology = fake_image.tile_topology(fake_builder, 512, 256)
tile1 = topology.tile(1)
tile2 = topology.tile(2)
tile3 = topology.tile(3)
tile4 = topology.tile(4)
tile5 = topology.tile(5)
tile6 = topology.tile(6)
tiles = [tile1.identifier, tile2.identifier, tile3.identifier, tile4.identifier, tile5.identifier, tile6.identifier]
tile_polygons = [[circle_part1], [circle_part2], [circle_part3], [circle_part4], [circle_part5], [circle_part6]]
polygons = SemanticMerger(5).merge(tiles, tile_polygons, topology)
self.assertEqual(len(polygons), 1, "Number of found polygon")
# use recall and false discovery rate to evaluate the error on the surface
tpr = circle.difference(polygons[0]).area / circle.area
fdr = polygons[0].difference(circle).area / polygons[0].area
self.assertLessEqual(tpr, 0.002, "Recall is low for circle area")
self.assertLessEqual(fdr, 0.002, "False discovery rate is low for circle area")
示例6: Point
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import difference [as 别名]
BLUE = '#6699cc'
GRAY = '#999999'
fig = pyplot.figure(1, figsize=SIZE, dpi=90)
a = Point(1, 1).buffer(1.5)
b = Point(2, 1).buffer(1.5)
# 1
ax = fig.add_subplot(121)
patch1 = PolygonPatch(a, fc=GRAY, ec=GRAY, alpha=0.2, zorder=1)
ax.add_patch(patch1)
patch2 = PolygonPatch(b, fc=GRAY, ec=GRAY, alpha=0.2, zorder=1)
ax.add_patch(patch2)
c = a.difference(b)
patchc = PolygonPatch(c, fc=BLUE, ec=BLUE, alpha=0.5, zorder=2)
ax.add_patch(patchc)
ax.set_title('a.difference(b)')
xrange = [-1, 4]
yrange = [-1, 3]
ax.set_xlim(*xrange)
ax.set_xticks(range(*xrange) + [xrange[-1]])
ax.set_ylim(*yrange)
ax.set_yticks(range(*yrange) + [yrange[-1]])
ax.set_aspect(1)
#2
ax = fig.add_subplot(122)
示例7: MultiLineString
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import difference [as 别名]
# -*- coding: utf-8 -*-
import os
from shapely.geometry import Point, LineString, LinearRing, Polygon, MultiLineString
coords = [((0,0),(1,1)),((-1,0),(1,0))]
lines = MultiLineString(coords)
lines.boundary
print(list(lines.boundary))
lines.boundary.boundary.is_empty
LineString([(0,0),(1,1)]).centroid
LineString([(0,0),(1,1)]).centroid.wkt
a = Point(1,1).buffer(1.5)
b = Point(2,1).buffer(1.5)
a.difference(b)
a.intersection(b)
a.symmetric_difference(b)
a.union(b)
a.union(b).boundary
a.boundary.union(b.boundary)
def Test():
assert True
示例8: plot_poly
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import difference [as 别名]
def plot_poly(poly, pen):
plot_line(LineString(poly.exterior.coords), pen)
for i in poly.interiors:
plot_line(LineString(i.coords), pen)
# Drawing limits: (left 0; bottom 0; right 10300; top 7650)
# = Letter paper on HP-7470A
# draw a nice page box
page = box(0, 0, 10300, 7650)
innerpage = scale(page, xfact=0.99, yfact=0.99, origin='center')
hatching = hatchbox(page, 45, 100)
# construct crescent
circle = Point(5000, 4000).buffer(3000)
pt = Point(3500, 4000)
circle1 = pt.buffer(2000)
crescent = circle.difference(circle1).simplify(10.0)
crescent_hatch = crescent.intersection(hatching)
# construct a box with a hole in it
weebox = box(8000, 5000, 9500, 7000)
weehatch = hatchbox(weebox, -45, 40)
tbox = scale(weebox, xfact=0.95, yfact=0.95, origin='center')
tinybox = scale(weebox, xfact=0.5, yfact=0.5, origin='center')
holey = tbox.difference(tinybox)
# add fine hatching
holey_hatch = holey.intersection(weehatch)
# plot stuff ..
print 'IN;' # cheapo init code
plot_poly(page, 1) # outer page border
plot_poly(innerpage, 2) # inner page border