Skip to content

Commit f63a4e4

Browse files
committed
radius placement
1 parent c662800 commit f63a4e4

File tree

1 file changed

+40
-37
lines changed

1 file changed

+40
-37
lines changed

momepy/intensity.py

+40-37
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,45 @@
88
import geopandas as gpd
99

1010

11+
def radius(gpd_df, cpt, radius):
12+
"""
13+
Get a list of indices of objects within radius.
14+
15+
Parameters
16+
----------
17+
gpd_df : GeoDataFrame
18+
geopandas gdf containing point objects to analyse
19+
cpt : shapely.Point
20+
shapely point representing the center of radius
21+
radius : float
22+
radius
23+
24+
Returns
25+
-------
26+
list
27+
Return only the neighbour indices, sorted by distance in ascending order
28+
29+
Reference
30+
---------
31+
https://stackoverflow.com/questions/44622233/rtree-count-points-in-the-neighbourhoods-within-each-point-of-another-set-of-po
32+
33+
"""
34+
# Spatial index
35+
sindex = gpd_df.sindex
36+
# Bounding box of rtree search (West, South, East, North)
37+
bbox = (cpt.x - radius, cpt.y - radius, cpt.x + radius, cpt.y + radius)
38+
# Potential neighbours
39+
good = []
40+
for n in sindex.intersection(bbox):
41+
dist = cpt.distance(gpd_df['geometry'][n])
42+
if dist < radius:
43+
good.append((dist, n))
44+
# Sort list in ascending order by `dist`, then `n`
45+
good.sort()
46+
# Return only the neighbour indices, sorted by distance in ascending order
47+
return [x[1] for x in good]
48+
49+
1150
def frequency(objects, look_for, column_name, id_column='uID'):
1251
"""
1352
Calculate frequency (count) of objects in a given radius.
@@ -36,43 +75,7 @@ def frequency(objects, look_for, column_name, id_column='uID'):
3675
---------
3776
3877
"""
39-
def radius(gpd_df, cpt, radius):
40-
"""
41-
Get a list of indices of objects within radius.
42-
43-
Parameters
44-
----------
45-
gpd_df : GeoDataFrame
46-
geopandas gdf containing point objects to analyse
47-
cpt : shapely.Point
48-
shapely point representing the center of radius
49-
radius : float
50-
radius
51-
52-
Returns
53-
-------
54-
list
55-
Return only the neighbour indices, sorted by distance in ascending order
56-
57-
Reference
58-
---------
59-
https://stackoverflow.com/questions/44622233/rtree-count-points-in-the-neighbourhoods-within-each-point-of-another-set-of-po
60-
61-
"""
62-
# Spatial index
63-
sindex = gpd_df.sindex
64-
# Bounding box of rtree search (West, South, East, North)
65-
bbox = (cpt.x - radius, cpt.y - radius, cpt.x + radius, cpt.y + radius)
66-
# Potential neighbours
67-
good = []
68-
for n in sindex.intersection(bbox):
69-
dist = cpt.distance(gpd_df['geometry'][n])
70-
if dist < radius:
71-
good.append((dist, n))
72-
# Sort list in ascending order by `dist`, then `n`
73-
good.sort()
74-
# Return only the neighbour indices, sorted by distance in ascending order
75-
return [x[1] for x in good]
78+
7679
# define new column
7780

7881
print('Calculating frequency...')

0 commit comments

Comments
 (0)