|
6 | 6 | import glob |
7 | 7 | import json |
8 | 8 | from shutil import rmtree |
| 9 | +import rasterio |
| 10 | +import geopandas as gpd |
9 | 11 |
|
10 | 12 | import string |
11 | 13 | import random |
@@ -382,15 +384,27 @@ def get_crs_of_data(file, vector=False): |
382 | 384 |
|
383 | 385 | else: |
384 | 386 | print('clipping with bounding box of vector data') |
385 | | - command_output = subprocess.run(["gdalwarp", "-cutline", clip_file[0], join(data_path, input_dir, data_to_clip_dir, input_file), |
386 | | - join(data_path, output_dir, output_file_name_set)]) |
| 387 | + |
| 388 | + print(join(data_path, input_dir, data_to_clip_dir, input_file)) |
| 389 | + print(join(data_path, output_dir, output_file_name_set) |
| 390 | +) |
| 391 | + # this should work but does not for some reason.... |
| 392 | + #command_output = subprocess.run(["gdalwarp", "-cutline", clip_file[0], join(data_path, input_dir, data_to_clip_dir, input_file), join(data_path, output_dir, output_file_name_set)]) |
| 393 | + # so instead using this.... |
| 394 | + |
| 395 | + # read in shapefile |
| 396 | + t = gpd.read_file(clip_file[0]) |
| 397 | + # get bounding box for shapefile |
| 398 | + bounds = t.geometry.total_bounds |
| 399 | + # run clip |
| 400 | + subprocess.run(["gdalwarp", "-te", str(bounds[0]), str(bounds[1]), str(bounds[2]), str(bounds[3]), join(data_path, input_dir, data_to_clip_dir, input_file), join(data_path, output_dir, output_file_name_set)]) |
387 | 401 |
|
388 | 402 | # check the code returned from GDAL to see if an error occurred or not |
389 | | - if command_output.returncode == 1: |
390 | | - print('Error! Clip did not run. Please check for common errors such as missing projection information.') |
391 | | - logger.info('Error! Clip did not run for %s. Please check for common errors such as missing projection information.' % input_file) |
392 | | - elif command_output.returncode == 0: |
393 | | - logger.info('Clip process ran without an error being returned (%s)' % input_file) |
| 403 | + #if command_output.returncode == 1: |
| 404 | + # print('Error! Clip did not run. Please check for common errors such as missing projection information.') |
| 405 | + # logger.info('Error! Clip did not run for %s. Please check for common errors such as missing projection information.' % input_file) |
| 406 | + #elif command_output.returncode == 0: |
| 407 | + # logger.info('Clip process ran without an error being returned (%s)' % input_file) |
394 | 408 |
|
395 | 409 | # add check to see if file written to directory as expected |
396 | 410 | if isfile(join(data_path, output_dir, output_file_name_set)): |
|
0 commit comments