Exemplo n.º 1
0
	def run_large(self, inTiff, outfile, r1run, r3min, r3max, r2run, r5min, r5max, r3run, r7min, r7max, r9run, r9min, r9max, r11run, r11min, r11max, smooth_strat):
		
		try:
			partdir = inTiff[:inTiff.rfind(".")] + "_parts"
			
			self.writeMessage("\nPartition Directory:\n\t" + partdir + "\n")
			                                        
			if not os.path.exists(partdir):
				os.mkdir(partdir)
			
			self.writeMessage("Partitioning:\n\t" + inTiff + " ...\n\n")
			
			TCD_module.partitionTiff(inTiff, partdir)
			
			regex   = re.compile('[0-9]+_[0-9]+\.tiff?$')
			dirList = os.listdir(partdir)
			
			for part in dirList:
				if regex.match(part):
					tiff = partdir + "/" + part
					self.writeMessage("\t" + tiff + "\n");
					TCD_module.findTreeTops(tiff, outfile, r1run, r3min, r3max, r2run, r5min, r5max, r3run, r7min, r7max, r9run, r9min, r9max, r11run, r11min, r11max, 1, smooth_strat)
						
		except:
			self.handle_exception(sys.exc_info())
Exemplo n.º 2
0
	def run_file(self, inTiff, outdir, r1run, r3min, r3max, r2run, r5min, r5max, r3run, r7min, r7max, r9run, r9min, r9max, r11run, r11min, r11max, smooth_strat, add_noise):
		
		try:
			#
			# Generate base name for output shape file
			#
			a = inTiff.rfind("/")
			b = inTiff.rfind(".")
			date_time_string = datetime.datetime.now().strftime("_%m_%d_%y_%H_%M_%S")
			outfile = outdir + "/TT_" + inTiff[a+1:b] + date_time_string
			
			
			self.createTreetopLogFile(outfile + ".txt", inTiff, smooth_strat,\
				r1run,  r3min,  r3max,\
				r2run,  r5min,  r5max,\
				r3run,  r7min,  r7max,\
				r9run,  r9min,  r9max,\
				r11run, r11min, r11max,
				add_noise)
			
			#
			# Remove output shape file if it already exists
			#
			postfix = [".shp", ".shx", ".dbf"]
			for pf in postfix:
				file = outfile + pf
				if os.path.exists(file):
					os.remove(file)
			
			self.writeMessage("Input:  " + inTiff + "\n")
			self.writeMessage("Output: " + outfile + "\n")
			
			TCD_module.findTreeTops(inTiff, outfile, r1run, r3min, r3max, r2run, r5min, r5max, r3run, r7min, r7max, r9run, r9min, r9max, r11run, r11min, r11max, 0, smooth_strat, add_noise)
			
			
			#########################################################
			#                 Disable Partitioning                  #
			#########################################################
			#
			#imgsize = TCD_module.getImageSize(inTiff)
			#self.writeMessage("Image Size: " + str(imgsize))
			
			#if(imgsize <= 1000000000):
				
			#	TCD_module.findTreeTops(inTiff, outfile, r1run, r3min, r3max, r2run, r5min, r5max, r3run, r7min, r7max, r9run, r9min, r9max, r11run, r11min, r11max, 0, smooth_strat)
			#else:
			#	self.run_large(inTiff, outfile, r1run, r3min, r3max, r2run, r5min, r5max, r3run, r7min, r7max, r9run, r9min, r9max, r11run, r11min, r11max, smooth_strat)
				
		except:
			self.handle_exception(sys.exc_info())
Exemplo n.º 3
0
	def run_treetop_metrics(self):
			
		tt_dir = self.ttDirEntry.get()
		ttm_dir = self.ttmDirEntry.get()
		ref_file = self.refFileEntry.get()
		
		if tt_dir == "":
			self.writeMessage("Error. Input treetop directory is null.\n")
			return
			
		if ttm_dir == "":
			self.writeMessage("Error. Output treetop metrics directory is null.\n")
			return
			
		if ref_file == "":
			self.writeMessage("Error. Reference file is null.\n")
			return
		
		ttm_file = ttm_dir + "/treetop-metrics.tiff"
		
		#init procedure
		self.writeMessage(ref_file + "\n")
		TCD_module.treetopMetricsInit(ref_file);
		
		for tt_file in os.listdir(tt_dir):
			
			if tt_file.endswith(".shp"):
				tt_path = tt_dir + "/" + tt_file[:tt_file.find(".shp")]
				self.writeMessage(tt_path)
				self.writeMessage("\t" + tt_path + "\n")
				TCD_module.treetopMetricsGrid(tt_path);
			
		#finsih
		self.writeMessage(ttm_file + "\n");
		TCD_module.treetopMetricsFinish(ttm_file);
		self.writeMessage("Done!\n\n")
Exemplo n.º 4
0
	def treeCrownDelineation(self):
		
		try:
			
			if self.checkSmoothing() == 0:
				return
			if self.checkSorting() == 0:
				return
				
			in_shp = self.inputTreetopEntry.get()
			in_tif = self.inTiffEntry.get()
			tc_out = self.outTreeCrownDirEntry.get()
			
			h1_run = int(self.run_tcr1.get())
			h2_run = int(self.run_tcr2.get())
			h3_run = int(self.run_tcr3.get())
			
			h1_min = float(self.h1MinEntry.get())
			h1_max = float(self.h1MaxEntry.get())
			h2_min = float(self.h2MinEntry.get())
			h2_max = float(self.h2MaxEntry.get())
			h3_min = float(self.h3MinEntry.get())
			h3_max = float(self.h3MaxEntry.get())
			
			perc_1 = float(self.h1PercentageEntry.get())
			perc_2 = float(self.h2PercentageEntry.get())
			perc_3 = float(self.h3PercentageEntry.get())
			
			rad_1  = int(self.h1RadiusEntry.get())
			rad_2  = int(self.h2RadiusEntry.get())
			rad_3  = int(self.h3RadiusEntry.get())

			sort_type = 0
			if self.sort_asc.get() == 1:
				sort_type = 1
			elif self.sort_dsc.get() == 1:
				sort_type = 2
			
			shape_crown = self.shape_crown.get()
			
			
			
			#
			# Error checking
			#
			if(self.rangeCheckTC(h1_run, h1_min, h1_max, h2_run, h2_min, h2_max, h3_run, h3_min, h3_max) == 0):
				self.writeMessage("Error. Bad ranges. \n\n")
				return
				
			if(in_shp == "" or in_tif == ""):
				self.writeMessage("Error. Specify input shape and tiff file..\n\n")
				return
				
			if(tc_out == ""):
				self.writeMessage("Error. Must specify output directory.\n\n")
				return
			
			
			#
			# get smoothing strategy
			#
			smooth_type = self.getSmoothingStrategy()
			date_time_string = datetime.datetime.now().strftime("_%m_%d_%y_%H_%M_%S")
			
			in_shp   = in_shp[:in_shp.rfind(".")]
			out_file = tc_out + "/TC_" + in_tif[in_tif.rfind("/")+1:]
			out_shp  = tc_out + "/TC_" + in_tif[in_tif.rfind("/")+1:in_tif.rfind(".")] + date_time_string
			
			self.createTreeCrownLogFile(out_shp + ".txt", in_tif, in_shp, smooth_type,\
				h1_run, h1_min, h1_max,\
				h2_run, h2_min, h2_max,\
				h3_run, h3_min, h3_max,\
				perc_1, perc_2, perc_3, rad_1, rad_2, rad_3,\
				shape_crown, sort_type)
				
			self.writeMessage(in_shp + "\n")
			self.writeMessage(in_tif + "\n")
			self.writeMessage(tc_out + "\n")
			self.writeMessage(out_file + "\n")
			self.writeMessage(out_shp + "\n\n")
			
			TCD_module.treeCrownDelineation(in_shp, out_shp, in_tif, out_file, 
				h1_run, h1_min, h1_max, 
				h2_run, h2_min, h2_max,
				h3_run, h3_min, h3_max,
				perc_1, perc_2, perc_3, rad_1, rad_2, rad_3,
				smooth_type, shape_crown, sort_type)
			
			self.writeMessage("Done!\n\n")
			
				
		except:
			self.handle_exception(sys.exc_info())