File name
Commit message
Commit date
import glob
from pyogrio import read_dataframe, write_dataframe
범죄주의구역_list_by_score = glob.glob("DATA/refined/geopackage/범죄주의구역_격자/*.gpkg")
범죄주의구역_list_by_score = sorted(범죄주의구역_list_by_score)
범죄주의구역_list_by_score = 범죄주의구역_list_by_score[-10:]
print(범죄주의구역_list_by_score)
도로실폭_격자_데이터 = read_dataframe("DATA/refined/geopackage/도로명주소/실폭도로_생활안전도로_0등급_dissolve.gpkg")
도로실폭_격자_데이터["road_area"]=도로실폭_격자_데이터["geometry"].area
도로실폭_격자_데이터 = 도로실폭_격자_데이터.set_index("GID")
격자_데이터 = read_dataframe("/home/juni/문서/경상북도_CCTV_설치_분석/DATA/refined/geopackage/100x100/100m격자총인구.gpkg")
격자_데이터 = 격자_데이터.set_index("GID")
격자_데이터 = 격자_데이터.merge(도로실폭_격자_데이터["road_area"], left_index=True, right_index=True, how="left")
for i, criminal in enumerate(범죄주의구역_list_by_score):
crimin_area = read_dataframe(criminal)
crimin_area = crimin_area.set_index("GID")
col_index = f"{i+1}등급영역"
crimin_area[col_index] = crimin_area["geometry"].area
격자_데이터 = 격자_데이터.merge(crimin_area[col_index], left_index=True, right_index=True, how="left")
def score_calc(row):
ret = 0
if row["road_area"] != 0:
for i in range(10):
ret += row[f"{i + 1}등급영역"]
ret = ret * 0.1
ret = ret / row["road_area"]
else:
ret = 0
return ret
격자_데이터 = 격자_데이터.fillna(0)
격자_데이터["범죄취약점수"] = 격자_데이터.apply(lambda row : score_calc(row), axis=1)
격자_데이터 = 격자_데이터.reset_index()
write_dataframe(격자_데이터, "DATA/processed/범죄취약지수/범죄취약등급.gpkg")