-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun_centerline.py
48 lines (43 loc) · 1.21 KB
/
run_centerline.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
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
u"""
run_centerline.py
Yara Mohajerani (Last update 07/2020)
read polygonized contours and get centerlines for GLs
"""
import os
import sys
import numpy as np
import shapefile
import geopandas as gpd
from shapely.geometry import Polygon,LineString,Point
from label_centerlines import get_centerline
#-- main function
def main():
#-- Read the system arguments listed after the program
if len(sys.argv) == 1:
sys.exit('No input file given')
else:
input_list = sys.argv[1:]
for INPUT in input_list:
#-- read shapefile
gdf = gpd.read_file(INPUT)
out_gdf = gdf.copy()
#-- remove 'err' from ID
out_gdf['ID'][0] = gdf['ID'][0].replace('err','')
#-- check if this is a pinning point
if gdf['Class'][0] == 'Pinning Contour':
#-- pinning point. Just get perimeter of polygon
out_gdf['Class'][0] = 'Pinning Point'
else:
#-- convert to polygon
p = Polygon(gdf['geometry'][0])
dis = p.length/10
mx = p.length/80
out_gdf['geometry'][0] = get_centerline(p,segmentize_maxlen=dis,max_points=mx)
out_gdf['Class'][0] = 'Grounding Line'
#-- save centerline to file
gl_file = INPUT.replace('_ERR','')
out_gdf.to_file(gl_file)
#-- run main program
if __name__ == '__main__':
main()