On 24/04/2016 at 07:35, xxxxxxxx wrote:
If I want to find all the points of a polygonal object that are within a certain distance from a specific point, I believe the using the Neighbors class is the fastest way, instead of going through all the points in the list.
However, the GetPointPolys only gets me the polygons that are attached the the starting point.
I would have to spread out the search until no polygon center was found that was within the specified distance.
Does this has to be done recursively?
I had this code but it is not working :(
def get_near(p_center,distance,polygons,centers,pli,nbr) :
# p_center = the first point coordinates
# distance = the maximum allowed distance from p_center
# polygons = the list of all polygons of the object
# centers = the list of all polygons centers coordinates
# pli = the first set of neighboring polygons around the first point
# nbr = the neighbor structure
near=[]
changed=False
while changed==False:
changed=False
for poly in pli:
p = polygons[poly]
if poly not in near:
length=(centers[poly]-p_center).GetLength()
if length<=distance:
near.append(poly)
new_pli=nbr.GetPointPolys(p.a)
for new_poly in new_pli:
if new_poly not in near:
if (centers[new_poly]-p_center).GetLength()<=distance:
near.append(new_poly)
changed=True
new_pli=nbr.GetPointPolys(p.b)
for new_poly in new_pli:
if new_poly not in near:
if (centers[new_poly]-p_center).GetLength()<=distance:
near.append(new_poly)
changed=True
new_pli=nbr.GetPointPolys(p.c)
for new_poly in new_pli:
if new_poly not in near:
if (centers[new_poly]-p_center).GetLength()<=distance:
near.append(new_poly)
changed=True
new_pli=nbr.GetPointPolys(p.d)
for new_poly in new_pli:
if new_poly not in near:
if (centers[new_poly]-p_center).GetLength()<=distance:
near.append(new_poly)
changed=True
return near