Conrad Jackisch
2014-01-08 09:29:28 UTC
dear community,
i am struggling with a intersection of a large number of points with a
polygon. i use shapely which helps already but returns only the coordinates
of intersecting points of a MultiPoint object. is there anyone who could
help with a way to simply get the indexes of intersecting points?
- - - 8< snip - - -
import numpy as np
import matplotlib.pyplot as plt
from shapely.geometry import Polygon
from shapely.geometry import asMultiPoint
poly=Polygon(zip([0.0,0.3,0.3,0.2,0.0],[0.2,0.2,0.4,0.5,0.4]))
a = array([[0.1,0.1],[0.2,0.3],[0.15,0.45]])
points = asMultiPoint(a)
#plot example
ax = plt.figure(figsize=(8, 4))
ax = plt.subplot(121)
patch = PolygonPatch(poly)
ax.add_patch(patch)
for p in points:
ax.plot(p.x, p.y, 'o', color='#999999')
pyplot.show()
#intersection
np.asarray(points.intersection(poly))
#this gives me the coordinates of the values - but not the index, which i
need much more.
- - - snap >8 - - -
of cause this example is very small and it was possible to compare the
results with the given points. however, for large sets (about one million
of points) this will slow down everything...
if you have any idea, i was most happy.
thanks,
conrad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20140108/62047500/attachment.htm>
i am struggling with a intersection of a large number of points with a
polygon. i use shapely which helps already but returns only the coordinates
of intersecting points of a MultiPoint object. is there anyone who could
help with a way to simply get the indexes of intersecting points?
- - - 8< snip - - -
import numpy as np
import matplotlib.pyplot as plt
from shapely.geometry import Polygon
from shapely.geometry import asMultiPoint
poly=Polygon(zip([0.0,0.3,0.3,0.2,0.0],[0.2,0.2,0.4,0.5,0.4]))
a = array([[0.1,0.1],[0.2,0.3],[0.15,0.45]])
points = asMultiPoint(a)
#plot example
ax = plt.figure(figsize=(8, 4))
ax = plt.subplot(121)
patch = PolygonPatch(poly)
ax.add_patch(patch)
for p in points:
ax.plot(p.x, p.y, 'o', color='#999999')
pyplot.show()
#intersection
np.asarray(points.intersection(poly))
#this gives me the coordinates of the values - but not the index, which i
need much more.
- - - snap >8 - - -
of cause this example is very small and it was possible to compare the
results with the given points. however, for large sets (about one million
of points) this will slow down everything...
if you have any idea, i was most happy.
thanks,
conrad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20140108/62047500/attachment.htm>