-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshp_split.py
executable file
·41 lines (33 loc) · 1.23 KB
/
shp_split.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
#!/usr/bin/python3
"""
@brief:
FIXME
"""
import fiona
from shapely.geometry import LineString, mapping
import shapely.affinity as aff
import sys
from common.arg_command_line import myargparse
from geom.dataset import BlueKenueWrite_i2s
from geom.base import get_attr_value, resampling
parser = myargparse(description=__doc__)
parser.add_argument("inname", help="fichier d'entrée shp")
parser.add_argument("outname", help="fichier de sortie shp")
args = parser.parse_args()
schema = {'geometry': 'LineString', 'properties': {'rien': 'float'}}
with fiona.open(args.inname, 'r') as filein:
with fiona.open(args.outname, 'w', 'ESRI Shapefile', schema) as layer:
def write_linestring(linestring):
elem = {}
elem['geometry'] = mapping(linestring)
elem['properties'] = {'rien': 0.0}
layer.write(elem)
for i, obj in enumerate(filein):
print(i)
obj_type = obj['geometry']['type']
coord = obj['geometry']['coordinates']
if obj_type == 'MultiLineString':
for subcoord in coord:
write_linestring(LineString(subcoord))
elif obj_type == 'LineString':
write_linestring(LineString(coord))