File name
Commit message
Commit date
from pyogrio import write_dataframe, read_dataframe
import pandas as pd
import geopandas as gpd
import numpy as np
import glob
SIG_CODE = [
["경산", "47290"],
["경주", "47130"],
["구미", "47190"],
["김천", "47150"],
["안동", "47170"],
["영주", "47210"],
["영천", "47230"],
["예천", "47900"],
["칠곡", "47850"],
["포항_남구", "47111"],
["포항_북구", "47113"]
]
# origin = read_dataframe("DATA/refined/geopackage/100x100/100m격자총인구.gpkg")
# print(origin.columns)
boarder = read_dataframe("DATA/refined/geopackage/음영구역_격자/100m격자총인구.gpkg격자_경계.gpkg")
print(boarder.columns)
negative = read_dataframe("DATA/refined/geopackage/음영구역_격자/100m격자_음영구역_CPTED.gpkg")
print(negative.columns)
print("dataframe_loaded!")
for SIG in SIG_CODE:
boarder_SIG = boarder[boarder["EMD_CD"].str.contains(SIG[1])]
negative_SIG = negative[negative["EMD_CD"].str.contains(SIG[1])]
# origin_SIG = origin[origin["EMD_CD"].str.contains(SIG[1])]
boarder_SIG = boarder_SIG.dissolve(by="GID")
negative_SIG = negative_SIG.dissolve(by="GID")
boarder_SIG["boarder_area"] = boarder_SIG["geometry"].area
negative_SIG["negative_area"] = negative_SIG["geometry"].area
boarder_SIG = boarder_SIG.rename(columns={"geometry" : "boarder_geometry"})
negative_SIG = negative_SIG.rename(columns={"geometry": "negative_geometry"})
merged = pd.merge(boarder_SIG, negative_SIG, on="GID").reset_index()
merged["area_ratio"] = merged["negative_area"] / merged["boarder_area"]
merged = merged.set_geometry("negative_geometry")
merged = merged.drop(columns="boarder_geometry")
write_dataframe(merged, f"DATA/refined/geopackage/100x100음영구역_비율/음영구역비율_{SIG[0]}.gpkg")