-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdf_concat.py
25 lines (19 loc) · 866 Bytes
/
gdf_concat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 13 17:40:43 2024
@author: laserglaciers
"""
import geopandas as gpd
import os
glacier_names = ['KUJ','KAN','EQI'] # AVA isn't working for some reason
for name in glacier_names:
shp_file_path = f'/Users/kevin/Documents/GitHub/its_live_tutorial/{name}_polygons/'
os.chdir(shp_file_path)
gdfs_dates = [(gpd.read_file(fn),gpd.pd.to_datetime(fn[:10].replace('_', '-'))) for fn in sorted(os.listdir(shp_file_path)) if fn.endswith('shp')]
gdfs, dates = zip(*gdfs_dates)
rdf = gpd.GeoDataFrame(gpd.pd.concat(gdfs, ignore_index=True), crs=gdfs[0].crs)
rdf['date'] = dates
rdf.reset_index(drop=True, inplace=True)
op = '/Users/kevin/Documents/GitHub/its_live_tutorial/merged_geoms/'
rdf.to_file(f'{op}{name}_merged.gpkg', driver='GPKG', crs="EPSG:3413")