Exemplo n.º 1
0
	def execute(self):
		
		try:
			pointFile    = self.pointFileEntry.get()
			centEasting  = self.centEastEntry.get()
			centNorthing = self.centNorthEntry.get()
			
			#
			# ensure valid input
			#
			if pointFile == "":
				if centEasting == "" or centNorthing == "":
					self.update_message_text("Error: Must specify a centroid or input file.\n\n")
					return
			
			if self.pointDirEntry.get() == "" or self.outFileEntry.get() == "":
				self.update_message_text("Error: Must specify input CHM directory and output directory.\n\n")
			   	return
			   	
			if self.radiusBound.get() == 0 and self.boxBound.get() == 0:
				self.update_message_text("Error: Must specify bounding region.\n\n")
			   	return
					
			if self.minEastingEntry.get() == ""  or self.minNorthingEntry.get() == "" or \
			   self.blockSizeEntry.get() == "" or self.htThresholdEntry.get() == "":
			   	
				self.update_message_text("Error: Missing input.\n\n")
			   	return
			
			points = []
		
			if not(pointFile == ""):
			
				pointFile = open(pointFile, "r")
				
				line = pointFile.readline()
				
				while not(line == ""):
					
					self.update_message_text("line:"+line)
					line  = line.strip()
					self.update_message_text("strip:"+line + "\n")
					point = line.split()
					
					if len(point) != 2:
						self.update_message_text("Error: Input centroid points file format error. " + str(len(point)) + "\n\n")
						return
					
					points.append( [ float(point[0]), float(point[1]) ] )
					
					line = pointFile.readline()
		
			else:
				easting  = float(self.centEastEntry.get())
				northing = float(self.centNorthEntry.get())
				
				points.append([easting, northing])
						
			curPoint  = 1
			numPoints = len(points)
			
			self.write_centroid_header(self.outFileEntry.get())
			
			for point in points:
				
				centroidEasting  = point[0]
				centroidNorthing = point[1]
				minEasting 	 = float(self.minEastingEntry.get())
				minNorthing 	 = float(self.minNorthingEntry.get())
				blockSize 	 = int(self.blockSizeEntry.get())
				zThreshold 	 = int(self.htThresholdEntry.get())
				chmDir 		 = self.pointDirEntry.get()
				outFile 	 = self.outFileEntry.get()
				
				self.update_message_text("Point " + str(curPoint) + " of " + str(numPoints))
				self.update_message_text("   (" + str(centroidEasting) + ", " + str(centroidNorthing) + ")\n")
				
				if self.radiusBound.get() == 1:
					
					radius = int(self.radiusEntry.get())
					Bio_module.computeBiometricsAroundCentroid(curPoint, centroidEasting, centroidNorthing, minEasting, minNorthing, radius, blockSize, zThreshold, chmDir, outFile)
	
					
				else:
					
					length = int(self.boxEntry.get())
					Bio_module.computeBiometricsInBoundingBox(curPoint, centroidEasting, centroidNorthing, minEasting, minNorthing, length, blockSize, zThreshold, chmDir, outFile)
				
				curPoint = curPoint + 1
				
			self.update_message_text("Complete.\n\n")
			
		except:
			self.handle_exception(sys.exc_info())
Exemplo n.º 2
0
	def generate_random_points(self):
		
		try:
			if self.numPointsEntry.get() == "":
				self.update_message_text("Error. Must specify the number of points to generate.\n\n")
				return
				
			if self.minEastingRangeEntry.get() == "" or self.maxEastingRangeEntry.get() == "" or\
			   self.minNorthingRangeEntry.get() == "" or self.maxNorthingRangeEntry.get() == "":
				self.update_message_text("Error. Must specify range of the random numbers to generate.\n\n")
				return
				
			numPoints   = int(self.numPointsEntry.get())
			minEasting  = float(self.minEastingRangeEntry.get())
			maxEasting  = float(self.maxEastingRangeEntry.get())
			minNorthing = float(self.minNorthingRangeEntry.get())
			maxNorthing = float(self.maxNorthingRangeEntry.get())
			
			self.update_message_text("Generating " + str(numPoints) + " random points...\n")
			
			eRange = maxEasting - minEasting
			nRange = maxNorthing - minNorthing
			
			randPoints = []
			
			for i in range(numPoints):
				
				x = random.random()
				x = x * eRange
				x = x + minEasting
				y = random.random()
				y = y * nRange
				y = y + minNorthing
				randPoints.append([x,y])
			
			if self.processLater.get() == 1:
				
				f = open(self.randFileEntry.get(), "w")
				
				self.update_message_text("Writing points to " + self.randFileEntry.get() + "...\n")
				
				#write to file
				for point in randPoints:
					f.write(str(point[0]) + ' ' + str(point[1]) + '\n')
				
				f.close()
				
				self.update_message_text("Complete!\n")
					
			else:
				
				#process all the points
				if self.pointDirEntry.get() == "" or self.outFileEntry.get() == "":
					self.update_message_text("Error: Must specify input CHM directory and output directory.\n\n")
					return
				
				if self.minEastingEntry.get() == ""  or self.minNorthingEntry.get() == "" or \
			           self.blockSizeEntry.get() == ""   or self.htThresholdEntry.get() == "":
			           	   self.update_message_text("Error: Missing input.\n\n")
			           	   return
				
				if self.radiusBound.get() == 0 and self.boxBound.get() == 0:
					self.update_message_text("Error: Must specify bounding region.\n\n")
					return
				
				minE = float(self.minEastingEntry.get())
				minN = float(self.minNorthingEntry.get())
				blkS = int(self.blockSizeEntry.get())
				zThr = int(self.htThresholdEntry.get())
				chmD = self.pointDirEntry.get()
				outF = self.outFileEntry.get()
				
				self.write_centroid_header(outF)
				
				pointIdx = 1
				numPoints = len(randPoints)
				
				for point in randPoints:
					
					cntE = point[0]
					cntN = point[1]
					
					self.update_message_text("Point " + str(pointIdx) + " of " + str(numPoints))
					self.update_message_text("   (" + str(cntE) + ", " + str(cntN) + ")\n")
					
					if self.radiusBound.get() == 1:
						
						radius = int(self.radiusEntry.get())
						Bio_module.computeBiometricsAroundCentroid(pointIdx, cntE, cntN, minE, minN, radius, blkS, zThr, chmD, outF)
					else:
						
						length = int(self.boxEntry.get())
						Bio_module.computeBiometricsInBoundingBox(pointIdx, cntE, cntN, minE, minN, length, blkS, zThr, chmD, outF)
					
					pointIdx = pointIdx + 1
				
				self.update_message_text("Complete.\n\n")
		except:
			self.handle_exception(sys.exc_info())