-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_one_shapefile.py
60 lines (40 loc) · 1.39 KB
/
create_one_shapefile.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
import pandas as pd
import geopandas as gpd
import pathlib
def get_file_or_filelist(file_path,
file_type: str = ".shp"):
"""Accepts a directory or single filepath and creates a list of file(s).
Parameters
-------
file_path: str
Either path to file or directory
file_type: str
File type to search for if `file_path` is directory.
Returns
-------
file_list: list
List of file(s).
"""
file_list = []
p = pathlib.Path(file_path)
if p.is_file():
file_list.append(str(p))
else:
for file_p in p.iterdir():
if file_type == file_p.suffix:
file_list.append(str(file_p))
print(file_list)
return file_list
def read_shp_geom(file_path, read_params, *args, **kwargs):
filelist = get_file_or_filelist(file_path, *args, **kwargs)
gdf_list = []
for file_ in filelist:
if pathlib.Path(file_).suffix == ".shp" and "RoadLink" in file_:
gdf_list.append(gpd.read_file(file_,
**read_params, ))
target_gdf = pd.concat(gdf_list)
return target_gdf
params = {"engine":"pyogrio",
"columns": ["nameTOID", "name1", ], }
openroads = read_shp_geom("../data/input/target_geoms/oproad_essh_gb-2/data", params, )
openroads.to_file("../data/input/target_geoms/osopenroads/osopenroads.shp" )