如果你想要一個python庫的幾何操作,看看shapely
。它使得這個如同someline.intersects(somepolygon)
一樣簡單。
下面是交叉點,緩衝區和剪輯的一個簡單示例(帶有一個不錯的繪圖...我使用descartes
可以將整形多邊形輕鬆轉換爲matplotlib補丁。)。
import numpy as np
import matplotlib.pyplot as plt
import shapely.geometry
import descartes
circle = shapely.geometry.Point(5.0, 0.0).buffer(10.0)
clip_poly = shapely.geometry.Polygon([[-9.5, -2], [2, 2], [3, 4], [-1, 3]])
clipped_shape = circle.difference(clip_poly)
line = shapely.geometry.LineString([[-10, -5], [15, 5]])
line2 = shapely.geometry.LineString([[-10, -5], [-5, 0], [2, 3]])
print 'Blue line intersects clipped shape:', line.intersects(clipped_shape)
print 'Green line intersects clipped shape:', line2.intersects(clipped_shape)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(*np.array(line).T, color='blue', linewidth=3, solid_capstyle='round')
ax.plot(*np.array(line2).T, color='green', linewidth=3, solid_capstyle='round')
ax.add_patch(descartes.PolygonPatch(clipped_shape, fc='blue', alpha=0.5))
ax.axis('equal')
plt.show()
這產生了:
Blue line intersects clipped shape: True
Green line intersects clipped shape: False
那麼,什麼是 「點」 在您的標題? – Jacob 2011-05-18 20:22:13
如果你正在尋找一個幾何庫來做到這一點(和許多其他有用的幾何事物),你可能想看看'shapely':http://trac.gispython.org/lab/wiki/形象它使得它像'someline.intersects(somepoly)一樣簡單'http://gispython.org/shapely/docs/1.0/manual.html#intersects – 2011-05-18 20:26:40
@Joe:這是一個很好的答案。爲什麼不把它貼出來呢? – 2011-05-18 20:44:14