-
Notifications
You must be signed in to change notification settings - Fork 4
/
create_contours.py
executable file
·362 lines (300 loc) · 19.8 KB
/
create_contours.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import re
import string
import random
import sys
import getopt
def randomString(): # Calculate a random string
length = 6
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for i in range(length))
def smoothTerrain(inputTerrain, gaussianBlur, medianBlur):
inputDEM = inputTerrain
prefix = "tmp_" + randomString()
method = "gaussain"
smooth = 9
if gaussianBlur != '':
smooth = int(gaussianBlur)
method = "gaussain"
if medianBlur != '':
smooth = int(medianBlur)
method = "median"
os.system(f"gdal_translate -ot Float32 -a_nodata -32768 {inputDEM} {prefix}_dem.tif -q")
# Calculate TPI
print("Calculate TPI...")
os.system(f"gdaldem TPI {inputDEM} {prefix}_dem_tpi.tif -q")
# Build VRT for soft smoothed DEM
print("Smooth DEM...")
os.system(f"gdalbuildvrt {prefix}_dem_blur_3x3.vrt {prefix}_dem.tif -q")
file = open(prefix + "_dem_blur_3x3.vrt", "rt")
data = file.read()
data = data.replace("ComplexSource", "KernelFilteredSource")
data = data.replace("<NODATA>-32768</NODATA>", '<NODATA>-32768</NODATA><Kernel normalized="1"><Size>3</Size><Coefs>0.077847 0.123317 0.077847 0.123317 0.195346 0.123317 0.077847 0.123317 0.077847</Coefs></Kernel>')
file.close()
file = open(prefix + "_dem_blur_3x3.vrt", "wt")
file.write(data)
file.close()
# Build VRT for soft smoothed DEM with median filter
os.system(f"gdalbuildvrt {prefix}_dem_median_3x3.vrt {prefix}_dem.tif -q")
file = open(prefix + "_dem_median_3x3.vrt", "rt")
data = file.read()
data = data.replace("ComplexSource", "KernelFilteredSource")
data = data.replace("<NODATA>-32768</NODATA>", '<NODATA>-32768</NODATA><Kernel normalized="1"><Size>3</Size><Coefs>0.11111111 0.11111111 0.11111111 0.11111111 0.11111111 0.11111111 0.11111111 0.11111111 0.11111111</Coefs></Kernel>')
file.close()
file = open(prefix + "_dem_median_3x3.vrt", "wt")
file.write(data)
file.close()
# Build VRT for smoothed DEM
os.system(f"gdalbuildvrt {prefix}_dem_blur_5x5.vrt {prefix}_dem.tif -q")
file = open(prefix + "_dem_blur_5x5.vrt", "rt")
data = file.read()
data = data.replace("ComplexSource", "KernelFilteredSource")
data = data.replace("<NODATA>-32768</NODATA>", '<NODATA>-32768</NODATA><Kernel normalized="1"><Size>5</Size><Coefs>0.003765 0.015019 0.023792 0.015019 0.003765 0.015019 0.059912 0.094907 0.059912 0.015019 0.023792 0.094907 0.150342 0.094907 0.023792 0.015019 0.059912 0.094907 0.059912 0.015019 0.003765 0.015019 0.023792 0.015019 0.003765</Coefs></Kernel>')
file.close()
file = open(prefix + "_dem_blur_5x5.vrt", "wt")
file.write(data)
file.close()
# Build VRT for smoothed DEM (median)
os.system(f"gdalbuildvrt {prefix}_dem_median_5x5.vrt {prefix}_dem.tif -q")
file = open(prefix + "_dem_median_5x5.vrt", "rt")
data = file.read()
data = data.replace("ComplexSource", "KernelFilteredSource")
data = data.replace("<NODATA>-32768</NODATA>", '<NODATA>-32768</NODATA><Kernel normalized="1"><Size>5</Size><Coefs>0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 </Coefs></Kernel>')
file.close()
file = open(prefix + "_dem_median_5x5.vrt", "wt")
file.write(data)
file.close()
# Build VRT for more smoothed DEM
os.system(f"gdalbuildvrt {prefix}_dem_blur_7x7.vrt {prefix}_dem.tif -q")
file = open(prefix + "_dem_blur_7x7.vrt", "rt")
data = file.read()
data = data.replace("ComplexSource", "KernelFilteredSource")
data = data.replace("<NODATA>-32768</NODATA>", '<NODATA>-32768</NODATA><Kernel normalized="1"><Size>7</Size><Coefs>0.000036 0.000363 0.001446 0.002291 0.001446 0.000363 0.000036 0.000363 0.003676 0.014662 0.023226 0.014662 0.003676 0.000363 0.001446 0.014662 0.058488 0.092651 0.058488 0.014662 0.001446 0.002291 0.023226 0.092651 0.146768 0.092651 0.023226 0.002291 0.001446 0.014662 0.058488 0.092651 0.058488 0.014662 0.001446 0.000363 0.003676 0.014662 0.023226 0.014662 0.003676 0.000363 0.000036 0.000363 0.001446 0.002291 0.001446 0.000363 0.000036</Coefs></Kernel>')
file.close()
file = open(prefix + "_dem_blur_7x7.vrt", "wt")
file.write(data)
file.close()
# Build VRT for more smoothed DEM (median)
os.system(f"gdalbuildvrt {prefix}_dem_median_7x7.vrt {prefix}_dem.tif -q")
file = open(prefix + "_dem_median_7x7.vrt", "rt")
data = file.read()
data = data.replace("ComplexSource", "KernelFilteredSource")
data = data.replace("<NODATA>-32768</NODATA>", '<NODATA>-32768</NODATA><Kernel normalized="1"><Size>7</Size><Coefs>0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 </Coefs></Kernel>')
file.close()
file = open(prefix + "_dem_median_7x7.vrt", "wt")
file.write(data)
file.close()
# Build VRT for more stronger smoothed DEM
os.system(f"gdalbuildvrt {prefix}_dem_blur_9x9.vrt {prefix}_dem.tif -q")
file = open(prefix + "_dem_blur_9x9.vrt", "rt")
data = file.read()
data = data.replace("ComplexSource", "KernelFilteredSource")
data = data.replace("<NODATA>-32768</NODATA>", '<NODATA>-32768</NODATA><Kernel normalized="1"><Size>9</Size><Coefs>0 0.000001 0.000014 0.000055 0.000088 0.000055 0.000014 0.000001 0 0.000001 0.000036 0.000362 0.001445 0.002289 0.001445 0.000362 0.000036 0.000001 0.000014 0.000362 0.003672 0.014648 0.023205 0.014648 0.003672 0.000362 0.000014 0.000055 0.001445 0.014648 0.058434 0.092566 0.058434 0.014648 0.001445 0.000055 0.000088 0.002289 0.023205 0.092566 0.146634 0.092566 0.023205 0.002289 0.000088 0.000055 0.001445 0.014648 0.058434 0.092566 0.058434 0.014648 0.001445 0.000055 0.000014 0.000362 0.003672 0.014648 0.023205 0.014648 0.003672 0.000362 0.000014 0.000001 0.000036 0.000362 0.001445 0.002289 0.001445 0.000362 0.000036 0.000001 0 0.000001 0.000014 0.000055 0.000088 0.000055 0.000014 0.000001 0</Coefs></Kernel>')
file.close()
file = open(prefix + "_dem_blur_9x9.vrt", "wt")
file.write(data)
file.close()
# Build VRT for strong smoothed DEM
os.system(f"gdalbuildvrt {prefix}_dem_blur_13x13.vrt {prefix}_dem.tif -q")
file = open(prefix + "_dem_blur_13x13.vrt", "rt")
data = file.read()
data = data.replace("ComplexSource", "KernelFilteredSource")
data = data.replace("<NODATA>-32768</NODATA>", '<NODATA>-32768</NODATA><Kernel normalized="1"><Size>13</Size><Coefs>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.000001 0.000001 0.000001 0 0 0 0 0 0 0 0 0.000001 0.000014 0.000055 0.000088 0.000055 0.000014 0.000001 0 0 0 0 0 0.000001 0.000036 0.000362 0.001445 0.002289 0.001445 0.000362 0.000036 0.000001 0 0 0 0 0.000014 0.000362 0.003672 0.014648 0.023204 0.014648 0.003672 0.000362 0.000014 0 0 0 0.000001 0.000055 0.001445 0.014648 0.058433 0.092564 0.058433 0.014648 0.001445 0.000055 0.000001 0 0 0.000001 0.000088 0.002289 0.023204 0.092564 0.146632 0.092564 0.023204 0.002289 0.000088 0.000001 0 0 0.000001 0.000055 0.001445 0.014648 0.058433 0.092564 0.058433 0.014648 0.001445 0.000055 0.000001 0 0 0 0.000014 0.000362 0.003672 0.014648 0.023204 0.014648 0.003672 0.000362 0.000014 0 0 0 0 0.000001 0.000036 0.000362 0.001445 0.002289 0.001445 0.000362 0.000036 0.000001 0 0 0 0 0 0.000001 0.000014 0.000055 0.000088 0.000055 0.000014 0.000001 0 0 0 0 0 0 0 0 0.000001 0.000001 0.000001 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</Coefs></Kernel>')
file.close()
file = open(prefix + "_dem_blur_13x13.vrt", "wt")
file.write(data)
file.close()
print("Reclassify and smooth TPI...")
# Reclassify TPI
os.system(f"gdal_calc.py -A {prefix}_dem_tpi.tif --outfile={prefix}_tpi_pos.tif --NoDataValue=-32768 --calc=\"((-1)*A*(A<0))+(A*(A>=0))\" --quiet")
# Build VRT for smooth TPI
os.system(f"gdalbuildvrt {prefix}_tpi_blur_3x3.vrt {prefix}_tpi_pos.tif -q")
file = open(prefix + "_tpi_blur_3x3.vrt", "rt")
data = file.read()
data = data.replace("ComplexSource", "KernelFilteredSource")
data = data.replace("<NODATA>-32768</NODATA>", '<NODATA>-32768</NODATA><Kernel normalized="1"><Size>3</Size><Coefs>0.077847 0.123317 0.077847 0.123317 0.195346 0.123317 0.077847 0.123317 0.077847</Coefs></Kernel>')
file.close()
file = open(prefix + "_tpi_blur_3x3.vrt", "wt")
file.write(data)
file.close()
info = os.popen(f"gdalinfo {prefix}_tpi_blur_3x3.vrt -hist").read()
# Normalize smoothed TPI, if no max avaible than just copy file
try:
maxValue = re.findall('[0-9]*\.[0-9]*', re.findall('STATISTICS_MAXIMUM=\d*.\d*', info)[0])[0]
os.system(f"gdal_calc.py -A {prefix}_tpi_blur_3x3.vrt --outfile={prefix}_tpi_norm.tif --NoDataValue=-32768 --calc=\"A / {maxValue}\" --quiet")
except:
os.system(f"gdal_translate {prefix}_tpi_blur_3x3.vrt {prefix}_tpi_norm.tif -q")
# Combine it together
print("Build better DEM for contour lines...")
# use gaussian filter
if (smooth == 13) & (method == "gaussian"):
print(f"Using gaussian smoothing with value {smooth}...")
os.system(f"gdal_calc.py -A {prefix}_tpi_norm.tif -B {prefix}_dem_blur_3x3.vrt -C {prefix}_dem_blur_13x13.vrt --outfile=\"smooth_{inputDEM}\" --overwrite --calc=\"A*B+(1-A)*C\" --quiet")
if (smooth == 9) & (method == "gaussian"):
print(f"Using gaussian smoothing with value {smooth}...")
os.system(f"gdal_calc.py -A {prefix}_tpi_norm.tif -B {prefix}_dem_blur_3x3.vrt -C {prefix}_dem_blur_9x9.vrt --outfile=\"smooth_{inputDEM}\" --overwrite --calc=\"A*B+(1-A)*C\" --quiet")
if (smooth == 7) & (method == "gaussian"):
print(f"Using gaussian smoothing with value {smooth}...")
os.system(f"gdal_calc.py -A {prefix}_tpi_norm.tif -B {prefix}_dem_blur_3x3.vrt -C {prefix}_dem_blur_7x7.vrt --outfile=\"smooth_{inputDEM}\" --overwrite --calc=\"A*B+(1-A)*C\" --quiet")
if (smooth == 5) & (method == "gaussian"):
print(f"Using gaussian smoothing with value {smooth}...")
os.system(f"gdal_calc.py -A {prefix}_tpi_norm.tif -B {prefix}_dem_blur_3x3.vrt -C {prefix}_dem_blur_5x5.vrt --outfile=\"smooth_{inputDEM}\" --overwrite --calc=\"A*B+(1-A)*C\" --quiet")
if (smooth == 3) & (method == "gaussian"):
print(f"Using gaussian smoothing with value {smooth}...")
os.system(f"gdal_calc.py -A {prefix}_tpi_norm.tif -B {prefix}_dem_blur_3x3.vrt -C {prefix}_dem_blur_3x3.vrt --outfile=\"smooth_{inputDEM}\" --overwrite --calc=\"A*B+(1-A)*C\" --quiet")
# use median filter
if (smooth == 7) & (method == "median"):
print(f"Using median smoothing with value {smooth}...")
os.system(f"gdal_calc.py -A {prefix}_tpi_norm.tif -B {prefix}_dem_median_3x3.vrt -C {prefix}_dem_median_7x7.vrt --outfile=\"smooth_{inputDEM}\" --overwrite --calc=\"A*B+(1-A)*C\" --quiet")
if (smooth == 5) & (method == "median"):
print(f"Using median smoothing with value {smooth}...")
os.system(f"gdal_calc.py -A {prefix}_tpi_norm.tif -B {prefix}_dem_median_3x3.vrt -C {prefix}_dem_median_5x5.vrt --outfile=\"smooth_{inputDEM}\" --overwrite --calc=\"A*B+(1-A)*C\" --quiet")
if (smooth == 3) & (method == "median"):
print(f"Using median smoothing with value {smooth}...")
os.system(f"gdal_calc.py -A {prefix}_tpi_norm.tif -B {prefix}_dem_median_3x3.vrt -C {prefix}_dem_median_3x3.vrt --outfile=\"smooth_{inputDEM}\" --overwrite --calc=\"A*B+(1-A)*C\" --quiet")
else:
print(f"Using gaussian smoothing with value 9 ...")
os.system(f"gdal_calc.py -A {prefix}_tpi_norm.tif -B {prefix}_dem_blur_3x3.vrt -C {prefix}_dem_blur_9x9.vrt --outfile=\"smooth_{inputDEM}\" --overwrite --calc=\"A*B+(1-A)*C\" --quiet")
# Clean up
os.remove(prefix + "_dem.tif")
os.remove(prefix + "_dem_tpi.tif")
os.remove(prefix + "_dem_blur_3x3.vrt")
os.remove(prefix + "_dem_blur_5x5.vrt")
os.remove(prefix + "_dem_blur_7x7.vrt")
os.remove(prefix + "_dem_blur_9x9.vrt")
os.remove(prefix + "_dem_blur_13x13.vrt")
os.remove(prefix + "_dem_median_3x3.vrt")
os.remove(prefix + "_dem_median_5x5.vrt")
os.remove(prefix + "_dem_median_7x7.vrt")
os.remove(prefix + "_tpi_pos.tif")
os.remove(prefix + "_tpi_pos.tif.aux.xml")
os.remove(prefix + "_tpi_blur_3x3.vrt")
os.remove(prefix + "_tpi_norm.tif")
return("smooth_" + inputDEM)
def createContours(outputFile, smooth_dem, interval, contourBuffer):
# define variables
buffer = contourBuffer
prefix = randomString()
contoursFile = prefix + "_contour.gpkg"
if contourBuffer != 0:
doubleInterval = float(interval) / 2
else:
doubleInterval = float(interval)
os.system(f"gdal_contour -inodata -a ele {smooth_dem} {contoursFile} -i {doubleInterval} -q ")
# Calculate length of countour lines
print("Calculate lenght of contour lines...")
os.system(f"ogr2ogr {contoursFile} {contoursFile} -update -dialect SQLITE -sql 'ALTER TABLE contour ADD COLUMN line_length float'")
os.system(f"ogr2ogr {contoursFile} {contoursFile} -update -dialect SQLITE -sql 'UPDATE contour SET line_length = ST_Length(geom)'")
# Reverse lines for easier german style labeling
os.system(f"ogr2ogr {contoursFile} {contoursFile} -update -dialect SQLITE -sql 'UPDATE contour SET geom = ST_Reverse(geom)'")
if contourBuffer != 0:
# Calculate additional contour lines for flatter areas
print("Calculate additional contour lines for flatter areas...")
os.system(f"ogr2ogr {contoursFile} {contoursFile} -append -nln 'buffer' -dialect SQLITE -sql 'SELECT id, ele, line_length, ST_Union(ST_Buffer(geom, {buffer} )) as geom FROM contour WHERE (ele % {interval} = 0)'")
os.system(f"ogr2ogr {contoursFile} {contoursFile} -append -nln 'bbox' -dialect SQLITE -sql 'SELECT ST_Envelope(ST_Union(geom)) as geom FROM contour'")
os.system(f"ogr2ogr {contoursFile} {contoursFile} -append -nln 'diff' -dialect SQLITE -sql 'SELECT ST_Difference(bbox.geom, buffer.geom) as geom FROM bbox, buffer'")
os.system(f"ogr2ogr {contoursFile} {contoursFile} -append -nln 'contour_cliped' -nlt PROMOTE_TO_MULTI -dialect SQLITE -sql 'SELECT contour.id, contour.ele, contour.line_length, (ST_intersection(diff.geom, contour.geom)) AS geom FROM diff JOIN contour ON ST_intersects(contour.geom, diff.geom)'")
os.system(f"ogr2ogr {contoursFile} {contoursFile} -update -dialect SQLITE -sql 'UPDATE contour_cliped SET line_length = ST_Length(geom)'")
# Select and merge contours
os.system(f"ogr2ogr {contoursFile} {contoursFile} -append -nln contour_add -nlt PROMOTE_TO_MULTI -dialect SQLITE -sql 'SELECT ID, ele, line_length, geom FROM contour WHERE ele % 20 = 0 UNION ALL SELECT ID, ele, line_length, geom FROM contour_cliped'")
# Remove temp
os.system(f"ogr2ogr {contoursFile} {contoursFile} -update -dialect SQL -sql 'DROP TABLE buffer'")
os.system(f"ogr2ogr {contoursFile} {contoursFile} -update -dialect SQL -sql 'DROP TABLE bbox'")
os.system(f"ogr2ogr {contoursFile} {contoursFile} -update -dialect SQL -sql 'DROP TABLE diff'")
os.system(f"ogr2ogr {contoursFile} {contoursFile} -update -dialect SQL -sql 'DROP TABLE contour_cliped'")
# Convert to output format
os.system(f"ogr2ogr {outputFile} {contoursFile}")
# Clean up
os.remove(contoursFile)
def main(argv):
inputDEM = ''
outputFile = ''
interval = ''
pixelSize = ''
gaussainBlur = ''
medianBlur = ''
contourBuffer = 0
tmp_file = "resample_dem.tif"
overwrite = True
try:
opts, args = getopt.getopt(argv, "", ["help", "inputDEM=", "outputFile=", "interval=", "pixelSize=", "gaussainBlur=", "medianBlur=", "addContoursBuffer="])
except getopt.GetoptError:
print("Please look use create_contours.py --help to get more information how to use the script. ")
sys.exit(2)
for opt, arg in opts:
if opt in ("--help"):
print("Create smooth contours with the help of GDAL. Usage:")
print("")
print("\t python3 create_contours.py --inputDEM=DEMfile.tif --outputFile=contours.gpkg --interval=5 --pixelSize=2")
print("")
print("Algorithm for smooth contours in flat areas after: ")
print("P. Kettunen, C. Koski, and J. Oksanen, 'A design of contour generation for topographic maps with adaptive DEM smoothing' ")
print("International Journal of Cartography, vol. 3, no. 1, pp. 19–30, Jun. 2017.")
print("")
print("Parameters:")
print("\t--inputDEM=(rasterFilename)* put here your DEM in any GDAL readable format.")
print("\t--outputFile=(vectorFilename)* write the name of the outputfile for the contours. The format is guessed form the extention")
print("\t--interval=(float)* interval between the contour lines.")
print("\t--pixelSize=(float)* pixel size of the DEM, or a greater number. Used for reampling and should correspond with the aimed map scale")
print("\t--gaussainBlur={3, 5, 7, 9, 13} kernel size for smoothing flat areas. Default 9.")
print("\t--medianBlur={3, 5, 7} kernel size for smoothing flat areas. Default is gaussianBlur.")
print("\t--addContoursBuffer=(float) create addional contour lines in between and cut them to the buffer. Default 0 for no execution.")
print("\t--help print this hopefully helpfull text.")
print("\t* Necessary for execution!")
print("")
print("Mathias Gröbe 2020")
sys.exit(0)
elif opt in ("--inputDEM"):
inputDEM = arg #dem_file.tif
elif opt in ("--outputFile"):
outputFile = arg #contour.sqlite
elif opt in ("--interval"):
interval = arg #5
elif opt in ("--pixelSize"):
pixelSize = arg #10
elif opt in ("--gaussainBlur"):
gaussainBlur = arg #{3, 5, 7, 9, 13}
elif opt in ("--medianBlur"):
medianBlur = arg #{3, 5, 7}
elif opt in ("--addContoursBuffer"):
contourBuffer = arg #50
if (inputDEM != '') & (outputFile != '') & (interval != '') & (pixelSize != ''):
# Print info
print("")
print("Create smooth contours with the help of GDAL. ")
print("----------------------------------------------")
print("Mathias Gröbe, 2020")
print("Algorithm for smooth contours in flat areas after: ")
print("P. Kettunen, C. Koski, and J. Oksanen, 'A design of contour generation for topographic maps with adaptive DEM smoothing' ")
print("International Journal of Cartography, vol. 3, no. 1, pp. 19–30, Jun. 2017.")
print("----------------------------------------------")
print("")
# Resample
os.system(f"gdal_translate {inputDEM} {tmp_file} -tr {pixelSize} {pixelSize} -r cubic -q")
# Smooth terrain
smooth_dem = smoothTerrain(tmp_file, gaussainBlur, medianBlur)
# Create contour lines file
print("Create contour lines...")
if(overwrite):
try:
os.remove(outputFile)
print("Overwrite old file...")
createContours(outputFile, smooth_dem, interval, contourBuffer)
except:
if os.path.isfile(outputFile):
print("Can not delete old file! Is it open in a GIS?")
else:
print(f"Create {outputFile} ...")
createContours(outputFile, smooth_dem, interval, contourBuffer)
# Clean up
os.remove(tmp_file)
os.remove(smooth_dem)
sys.exit(0)
else:
print("Sorry, missing some information. Please see help.")
print("create_contour.py --help")
sys.exit(2)
if __name__ == "__main__":
main(sys.argv[1:])