-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_FrictionCoeffs.py
66 lines (50 loc) · 2.03 KB
/
extract_FrictionCoeffs.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#authors: Fergus Mcclean, Chris Iliadis
#host: Newcastle University
import geopandas as gpd
#from citycatio.utils import geoseries_to_string
import os
def geoseries_with_value_to_string(geoseries: gpd.GeoSeries, value, index=False, index_first=True):
"""GeoSeries to CityCAT string representation
Args:
geoseries: Polygons to convert
value: Fraction coefficient value
index: Whether or not to include the index
index_first: Whether or not to place the index before the number of points
Returns:
s (str): String representation readable by CityCAT
"""
assert (geoseries.geom_type == 'Polygon').all(), 'Geometries must be of type Polygon'
s = '{}\n'.format(len(geoseries))
for idx, geometry in geoseries.items():
if not index:
s += '{}'.format(len(geometry.exterior.coords))
elif index_first:
s += '{} {}'.format(idx, len(geometry.exterior.coords))
else:
s += '{} {}'.format(len(geometry.exterior.coords), idx)
s += ' {}'.format(value[idx])
x, y = geometry.exterior.coords.xy
for x_val in x:
s += ' {}'.format(x_val)
for y_val in y:
s += ' {}'.format(y_val)
s += '\n'
return s
class FrictionCoefficents:
"""Areas representing different friction coefficents
Args:
data: Table containing Fraction coefficient polygons
"""
def __init__(self, data: gpd.GeoDataFrame):
assert type(data) == gpd.GeoDataFrame
self.data = data
def write(self, path):
with open(os.path.join(path, 'FrictionCoeffs.txt'), 'w') as f:
f.write(geoseries_with_value_to_string(self.data.geometry,self.data.Value))
input_folder = r'C:\Users\steve\Documents\citycat\FrictionCoeffs/'
name_shp_file = 'FrictionCoeffs-test'
gdf = gpd.read_file(input_folder + name_shp_file + '.shp')
FrictionCoefficents(gdf).write('.')
# Just printing the output of the file to show what's in it
with open('FrictionCoeffs.txt') as f:
print(*f.readlines()[:10])