๐ ๊ทผ์ ๋ถ์(proximity analysis)
: ์ง๋ฆฌ ์ ๋ณด ์์คํ (GIS) ๋ฐ ๊ณต๊ฐ ๋ฐ์ดํฐ ๋ถ์์์ ์ฌ์ฉ๋๋ ๊ธฐ์ .
releases = gpd.read_file("../input/geospatial-learn-course-data/toxic_release_pennsylvania/toxic_release_pennsylvania/toxic_release_pennsylvania.shp")
releases.head()
stations = gpd.read_file("../input/geospatial-learn-course-data/PhillyHealth_Air_Monitoring_Stations/PhillyHealth_Air_Monitoring_Stations/PhillyHealth_Air_Monitoring_Stations.shp")
stations.head()
print(stations.crs)
print(releases.crs)
# Select one release incident in particular
recent_release = releases.iloc[360]
# Measure distance from release to each station
distances = stations.geometry.distance(recent_release.geometry)
distances
0 44778.509761
1 51006.456589
2 77744.509207
3 14672.170878
4 43753.554393
5 4711.658655
6 23197.430858
7 12072.823097
8 79081.825506
9 3780.623591
10 27577.474903
11 19818.381002
dtype: float64
print('Mean distance to monitoring stations: {} feet'.format(distances.mean()))
Mean distance to monitoring stations: 33516.28487007786 feet
print('Closest monitoring station ({} feet):'.format(distances.min()))
print(stations.iloc[distances.idxmin()][["ADDRESS", "LATITUDE", "LONGITUDE"]])
Closest monitoring station (3780.623590556444 feet):
ADDRESS 3100 Penrose Ferry Road
LATITUDE 39.91279
LONGITUDE -75.185448
Name: 9, dtype: object
๐ Buffer
: ํน์ ์ , ๋ฉด ์ฃผ์์ ์์ฑ๋ ์ผ์ ํ ๊ฑฐ๋ฆฌ์ ์์ญ
- ํด๋น ์ง์ ์ด๋ ๋ฒํผ ์ฃผ๋ณ์ ์ํฅ๋ ฅ์ ์๊ฐํ ๋ฐ ๋ถ์ํ๋๋ฐ ์ฌ์ฉ
- ๋ง์ปค(Marker)๋ฅผ ์ค์ฌ์ผ๋ก ํ๋ ์ผ์ ๊ฑฐ๋ฆฌ์ ์
- ํ ์ง์ ์์ ํน์ ๊ฑฐ๋ฆฌ ๋งํผ ๋จ์ด์ง ๋ฐ๊ฒฝ๋ค
two_mile_buffer = stations.geometry.buffer(2*5280)
two_mile_buffer.head()
0 POLYGON ((2721944.641 257149.310, 2721893.792 ...
1 POLYGON ((2682494.290 271248.900, 2682443.441 ...
2 POLYGON ((2744886.638 280980.247, 2744835.789 ...
3 POLYGON ((2703638.580 233247.101, 2703587.731 ...
4 POLYGON ((2726959.773 251134.976, 2726908.924 ...
dtype: geometry
folium.GeoJson()
์ผ๋ก ์ง๋์ polygon์ ์๊ฐํํ ์ ์๋ค. # Create map with release incidents and monitoring stations
m = folium.Map(location=[39.9526,-75.1652], zoom_start=11)
HeatMap(data=releases[['LATITUDE', 'LONGITUDE']], radius=15).add_to(m)
for idx, row in stations.iterrows():
Marker([row['LATITUDE'], row['LONGITUDE']]).add_to(m)
# Plot each polygon on the map
GeoJson(two_mile_buffer.to_crs(epsg=4326)).add_to(m)
# Show the map
m
unary_union
์ ํตํด polygon์ MultiPolygon์ผ๋ก ์ถ์ํ ๊ฒฝ์ฐ, ํจ๊ณผ์ ์ผ๋ก ์๊ฐํํ ์ ์๋ค. # Turn group of polygons into single multipolygon
my_union = two_mile_buffer.geometry.unary_union
print('Type:', type(my_union))
# Show the MultiPolygon object
my_union
contains()
๋ก ํ์ธํ ์ ์๋ค# The closest station is less than two miles away
my_union.contains(releases.iloc[360].geometry)