1
+ import os , sys
2
+ import yaml
3
+ import warnings
4
+ from loguru import logger
5
+ import tqdm as tqdm
6
+
7
+ import geopandas as gpd
8
+ import pandas as pd
9
+ from rasterstats import zonal_stats
10
+ from shapely .ops import unary_union
11
+ import fiona
12
+ import rasterio
13
+
14
+ sys .path .insert (1 , 'scripts' )
15
+ import functions .fct_misc as fct_misc
16
+
17
+ logger = fct_misc .format_logger (logger )
18
+
19
+ logger .info ('Starting...' )
20
+
21
+ logger .info (f"Using config.yaml as config file." )
22
+ with open ('config/clipIm.yml' ) as fp :
23
+ cfg = yaml .load (fp , Loader = yaml .FullLoader )['clipImScratch' ]
24
+
25
+ logger .info ('Defining constants...' )
26
+
27
+ WORKING_DIR = cfg ['working_directory' ]
28
+ INPUTS = cfg ['inputs' ]
29
+
30
+ ORTHO_DIR = INPUTS ['ortho_directory' ]
31
+ AOI = INPUTS ['aoi' ]
32
+ TILE_DELIMITATION = INPUTS ['tile_delimitation' ]
33
+ OUTPUT_DIR = cfg ['output_directory' ]
34
+
35
+ os .chdir (WORKING_DIR )
36
+ fct_misc .ensure_dir_exists (OUTPUT_DIR )
37
+
38
+ logger .info ('Reading files...' )
39
+
40
+ aoi = gpd .read_file (AOI )
41
+ aoi = aoi .filter (['geometry' ])
42
+ for index , row in aoi .iterrows ():
43
+ row = row .copy ()
44
+ aoi .loc [index , 'geometry' ] = row .geometry .buffer (10 )
45
+
46
+ tiles = gpd .read_file (TILE_DELIMITATION )
47
+
48
+ aoi_clipped = fct_misc .clip_labels (aoi , tiles )
49
+ aoi_clipped = aoi_clipped [~ aoi_clipped .is_empty ]
50
+ aoi_clipped = aoi_clipped .reset_index (drop = True )
51
+
52
+ i = 1
53
+ for idx ,row in aoi_clipped .iterrows ():
54
+ fct_misc .clipIm (ORTHO_DIR , aoi_clipped .iloc [[idx ]], OUTPUT_DIR ,i )
55
+ i = i + 1
0 commit comments