Python Sum Lat/lon Points Within Geographic Radius And Sum To Grid
Basically, my experimental program is trying to find the number of points that fall within a (e.g., 50km) radius of a valid point at a given time. My data is structured (but I can
Solution 1:
You would do something like the following... First, group your (x, y)
coordinates for each group in a single points_x
array:
points_1 = np.column_stack((LAT_1, LON_1))
...
points_n = np.column_stack((LAT_n, LON_n))
It may be a good idea to store them in a list of arrays:
points = [point_1, points_2, ..., points_n]
Now, make a kdTree out of each set of points:
import scipy.spatial as spspkdtrees= [spsp.cKdTree(p) for p in point]
And you are ready to go. If you now run the following code:
r = whatever_your_threshold_value_is
points_within_r = np.zeros((len(kdtrees), len(kdtrees)), dtype=np.int)
for j in xrange(len(kdtrees)):
for k in xrange(j+1, len(kdtrees)):
points_within_r[j, k] = kdtrees[j].count_neighbors(kdtrees[k], r, 2)
points_within_r = points_within_r + points_within_r.T
You should now find that points_within_r[j, k]
holds how many points in points_j
are within radius r
of a point in points_k
.
Keep in mind that distances here are the euclidean distance of the coordinates, disregarding the fact that what they measure are spherical angles.
Post a Comment for "Python Sum Lat/lon Points Within Geographic Radius And Sum To Grid"