10
10
from vector import meta
11
11
from raster import measurements
12
12
from spatial_functions .calculations import Convert , origin_calc
13
+ from raster import meta as raster_functions
14
+ from shapely .geometry import Polygon
15
+ import shutil
16
+ from PyQt5 .QtWidgets import QHeaderView , QTableWidgetItem
13
17
14
18
anaconda_dir = os .path .join (str (Path .home ()), "anaconda3\\ envs\\ GIS-Helper" )
15
19
print ("Anaconda3 Dir: {}" .format (anaconda_dir ))
@@ -27,6 +31,20 @@ def __init__(self):
27
31
self .setupUi (self )
28
32
self .setFixedSize (self .size ())
29
33
34
+ self .catalogTiffOutputWindow .setColumnCount (5 )
35
+ self .catalogTiffOutputWindow .setHorizontalHeaderLabels (['Filename' ,
36
+ 'ULX' , 'ULY' ,
37
+ 'LRX' , 'LRY' ])
38
+
39
+ self .copyTiffOutputWindow .setColumnCount (2 )
40
+ self .copyTiffOutputWindow .setColumnWidth (0 , 380 )
41
+ self .copyTiffOutputWindow .setColumnWidth (1 , 379 )
42
+ self .copyTiffOutputWindow .setHorizontalHeaderLabels (["Source" ,
43
+ "Destination" ])
44
+
45
+ self .catalogTiffOutputWindow .horizontalHeader ().\
46
+ setSectionResizeMode (0 , QHeaderView .Stretch )
47
+
30
48
self .shape_functions = meta .PolygonFunctions ()
31
49
32
50
# GIS Calculator page
@@ -64,7 +82,7 @@ def browse_for_intersecting_shp(self):
64
82
:return:
65
83
"""
66
84
67
- openfile = QtWidgets .QFileDialog .getOpenFileName (self )
85
+ openfile = QtWidgets .QFileDialog .getOpenFileName (self , "Open Intersecting Shapefile" , None , "shp(*.shp)" )[ 0 ]
68
86
self .intersectingShapefileEdit .setText (openfile )
69
87
70
88
def browse_for_tiff_directory (self ):
@@ -239,36 +257,91 @@ def get_raster_bounds(self):
239
257
240
258
path = self .geoTiffDir1 .text ()
241
259
output_path = self .TiffCatalogOutputEdit .text ()
260
+ fanout = False
261
+
262
+ if self .FanOutByRes .isChecked ():
263
+ fanout = True
264
+ print ("Fanning out by resolution." )
242
265
243
266
raster_count , raster_dictionary = measurements .\
244
- create_catalog (path , output_path )
267
+ create_catalog (path , output_path , fanout )
245
268
246
269
output_text = "Finished processing {0} rasters.\n \n " .\
247
270
format (raster_count )
248
271
output_text += 'Raster paths and bounds (ulX, ulY, lrX, lrY): \n '
249
272
273
+ row = 0
274
+ self .catalogTiffOutputWindow .setRowCount (len (raster_dictionary ))
250
275
for filepath , bounds in raster_dictionary .items ():
251
- output_text += '{0}: {1}\n \n ' .format (filepath , bounds )
252
-
253
- self .catalogTiffOutputWindow .setText (output_text )
276
+ print (f"adding { filepath } to window." )
277
+ print (bounds [1 ])
278
+
279
+ filename = os .path .basename (filepath )
280
+
281
+ self .catalogTiffOutputWindow .setItem (row , 0 ,
282
+ QTableWidgetItem (filename ))
283
+ self .catalogTiffOutputWindow .\
284
+ setItem (row , 1 , QTableWidgetItem (str (bounds [0 ])))
285
+ self .catalogTiffOutputWindow .\
286
+ setItem (row , 2 , QTableWidgetItem (str (bounds [1 ])))
287
+ self .catalogTiffOutputWindow .\
288
+ setItem (row , 3 , QTableWidgetItem (str (bounds [2 ])))
289
+ self .catalogTiffOutputWindow .\
290
+ setItem (row , 4 , QTableWidgetItem (str (bounds [3 ])))
291
+ row += 1
254
292
255
293
return raster_count , raster_dictionary
256
294
257
295
def handle_tiff_copy (self ):
258
296
"""
259
297
Handles code that copies tifs
260
- :return: IO
298
+ :return: None
261
299
"""
300
+ rasters_by_resolution = {}
301
+ resolution = None
262
302
263
303
tiff_directory = self .TiffDirectory .text ()
264
- shapefile_directory = self .intersectingShapefileEdit .text ()
304
+ shapefile_path = self .intersectingShapefileEdit .text ()
265
305
output_directory = self .geoTiffOutputDirEdit .text ()
266
306
267
- payload = (tiff_directory , shapefile_directory , output_directory )
268
-
269
- polygon_functions = meta .PolygonFunctions ()
270
- polygon_functions .get_polygon_vertices (payload )
271
-
307
+ intersecting_rasters = raster_functions .\
308
+ intersect_by_shape (tiff_directory , shapefile_path ,
309
+ output_directory )
310
+ self .copyTiffOutputWindow .clear ()
311
+
312
+ if self .CopyFanoutByResolution .isChecked ():
313
+ for raster_path in intersecting_rasters :
314
+ row_position = self .copyTiffOutputWindow .rowCount ()
315
+ self .copyTiffOutputWindow .insertRow (row_position )
316
+ resolution = measurements .get_resolution (raster_path )
317
+
318
+ # Create resolution directory name
319
+ resolution = f"{ resolution [0 ]} x{ resolution [1 ]} "
320
+ output_basedir = os .path .join (output_directory , resolution )
321
+ if not os .path .exists (output_basedir ):
322
+ os .mkdir (output_basedir )
323
+ output_filename = os .path .basename (raster_path )
324
+ output_raster_path = os .path .join (output_basedir ,
325
+ output_filename )
326
+ shutil .copy (raster_path , output_raster_path )
327
+
328
+ self .copyTiffOutputWindow .setItem (row_position , 0 ,
329
+ QTableWidgetItem (raster_path ))
330
+ self .copyTiffOutputWindow .setItem (row_position , 1 ,
331
+ QTableWidgetItem (output_raster_path ))
332
+ self .copyTiffOutputWindow .resizeRowsToContents ()
333
+ else :
334
+ for raster_path in intersecting_rasters :
335
+ row_position = self .copyTiffOutputWindow .rowCount ()
336
+ self .copyTiffOutputWindow .insertRow (row_position )
337
+ output_path = os .path .join (output_directory ,
338
+ os .path .basename (raster_path ))
339
+ shutil .copy (raster_path , output_path )
340
+ self .copyTiffOutputWindow .setItem (row_position , 0 ,
341
+ QTableWidgetItem (raster_path ))
342
+ self .copyTiffOutputWindow .setItem (row_position , 1 ,
343
+ QTableWidgetItem (output_path ))
344
+ self .copyTiffOutputWindow .resizeRowsToContents ()
272
345
def get_origin (self ):
273
346
"""
274
347
Button function to get origin calculation. Runs the origin_calc()
0 commit comments