Newer
Older
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import sys
from shapely.ops import unary_union
from main import ENV_targetProj
from utils import *
def computeData(df):
"""
Specific treatments
"""
# Select only some data
arbreDF = df.copy()
arbreDF = arbreDF[(arbreDF.genre != 'Emplacement libre') & (arbreDF.genre != 'Souche')]
# Buffer on rayoncouronne_m field value
arbreDF['geometry'] = arbreDF.apply(customBuffer, axis=1)
# Regroup
unionGeom = unary_union(arbreDF.geometry)
# Make GDF
dataUnion = {'geometry': unionGeom}
unionDF = gp.GeoDataFrame(dataUnion, crs=ENV_targetProj)
# Clean data & explode
currentGeoSerie = unionDF.loc[:,'geometry']
# allGeoSerie = currentGeoSerie.explode(index_parts=False)
# Simplify
currentGeoSerie = currentGeoSerie.simplify(1)
# Make GDF
currGDF = gp.GeoDataFrame(currentGeoSerie)
currGDF.columns = ['geometry']
return currGDF
def customBuffer(row):
if row.rayoncouro > 0:
return row.geometry.buffer(row.rayoncouro)
# return row.geometry.buffer(row.rayoncouronne_m)
else:
# Default buffer value 1m
return row.geometry.buffer(1)
def wrongArguments():
print(style.RED + '/!\ Subscript error : Please specify a source and result filename as arguments to launch this script \n', style.RESET)
sys.exit(1)
if __name__ == "__main__":
# Init timer
subTimer = startTimerLog('Arbre subscript process')
# Get data with temp filename in argv
argv = sys.argv[1:]
firstArgv = None
secArgv = None
# Argv exist ?
if argv:
if len(sys.argv[1:]) > 0:
firstArgv = sys.argv[1:][0]
else:
wrongArguments()
if len(sys.argv[1:]) > 1:
secArgv = sys.argv[1:][1]
else:
wrongArguments()
# Load file Data (geoJSON)
currentGDF = createGDFfromGeoJSON(firstArgv)
# Log & Launch treatment
currentGDF = computeData(currentGDF)
# Write Result in temp file
currentGDF.to_file(secArgv)
# End timer
endTimerLog(subTimer)
else:
wrongArguments()