Running the model
parcel_model.py
can be run from the following notebook: 1-run-ms4-pracel-model.ipynb
Set a path (processed_path
) for where unique shapefiles can be exported for each municipality. The following code generates a shapefile for each municipality:
from src.data.make_dataset import munis
from src.features.parcel_model import parcel_ms4_model
processed_path = "path"
for town_name in munis['municipal'].unique():
parcel_ms4_model(town_name, processed_path)
To combine to generate one combined shapefile, set a path to export the final model (model_path), then run the following.
model_path = "path"
filelist = []
# add all shapefiles - takes about 30 minutes for all of MAPC
for root, folder, files in os.walk(processed_path):
for file in files:
for muni in munis['municipal'].unique():
if muni in file:
if file.endswith('.shp'):
fullname = os.path.join(root, file)
filelist.append(fullname)
merged_gdf = gpd.GeoDataFrame(pd.concat([gpd.read_file(i) for i in filelist],
ignore_index=True), crs=gpd.read_file(filelist[0]).crs)
#export
merged_gdf.to_file(model_path + '\\Merged_MS4_Parcels.shp')
Last updated