-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_swath_polys.py
35 lines (29 loc) · 1.17 KB
/
add_swath_polys.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
26
27
28
29
30
31
32
33
34
35
import geopandas as gpd
import pandas as pd
from cloudpathlib import S3Client
# explicitly instantiate a client that always uses the local cache
client = S3Client(no_sign_request=True)
def get_swath_poly(metadata_link):
path = client.CloudPath('s3://prd-tnm/'+metadata_link.split('prefix=')[1])
shapefiles = list(path.rglob('spatial_metadata/USGS/**/*.shp'))
try:
swath_poly_key = next(str(x) for x in shapefiles if "swath" in str(x).lower())
return swath_poly_key
except StopIteration:
print(metadata_link)
return None
# very slow... but only need to run once hopefully...
#df['swath_poly'] = df['metadata_link'].apply(get_swath_poly)
# Just load results from previous run and save to GeoJSON and GeoParquet
df = pd.read_csv('results.csv')
gf = gpd.read_file('WESM-chulls.geojson')
gf['swath_poly'] = df.swath_poly
gf.to_file('WESM-chulls.geojson')
gf = gpd.read_parquet('WESM-chulls.geoparquet')
# Indexed by FID starting at 1!
# change to swathpolygon_links to match other styles?
gf['swath_poly'] = df.swath_poly.values
gf.to_parquet('WESM-chulls.geoparquet',
schema_version='1.1.0',
write_covering_bbox=True,
)