[kaggle] Proximity Analysis

์ด์ƒํ•ด์”จยท2024๋…„ 1์›” 31์ผ
0

GEO

๋ชฉ๋ก ๋ณด๊ธฐ
12/12

proximity analysis ๊ทผ์ ‘๋ถ„์„

๐Ÿ“Œ ๊ทผ์ ‘๋ถ„์„(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()

Measuring distance

  • ๊ฑฐ๋ฆฌ๋ฅผ ์ธก์ •ํ•˜๊ธฐ ์ „์— CRS๋ฅผ ๋™์ผํ•˜๊ฒŒ ๋งž์ถฐ์ฃผ๋Š” ์ž‘์—…์ด ํ•„์š”ํ•˜๋‹ค
print(stations.crs)
print(releases.crs)
  • GeoPandas์—์„œ ๊ฑฐ๋ฆฌ๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ๊ฒƒ์€ ๋น„๊ต์  ๊ฐ„๋‹จํ•˜๋‹ค.
  • ์•„๋ž˜ ์ฝ”๋“œ ์…€์€ ์ตœ๊ทผ_release์—์„œ ๋น„๊ต์  ์ตœ๊ทผ์— ๋ฐœ์ƒํ•œ ๋ฆด๋ฆฌ์Šค ์‚ฌ๊ณ ์™€ ์Šคํ…Œ์ด์…˜ GeoDataFrame์˜ ๋ชจ๋“  ์Šคํ…Œ์ด์…˜ ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ(ํ”ผํŠธ)๋ฅผ ๊ณ„์‚ฐํ•œ๋‹ค.
# 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

Creatung a buffer

๐Ÿ“Œ 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

  • Multipolygon์— point๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ๋Š” ์ง€ contains()๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค
# The closest station is less than two miles away
my_union.contains(releases.iloc[360].geometry)

์ฐธ๊ณ 

profile
๊ณต๋ถ€์—๋Š” ๋์ด ์—†๋‹ค

0๊ฐœ์˜ ๋Œ“๊ธ€