Geography Reference
In-Depth Information
point grid cover layer. Key values are the X/Y (2D) coordinates; values are the lists
(array of Z values, elevation difference). The first part of the code sets the threshold
value which identifies the break-line between the tree outline and terrain. Tree class
has two attributes: a raster_dict (Hash-table) and an output_array (List). A .csv file
is used as an input data file and loaded into the Hash-table by a method loadPoints
(filePath). Hash-table is filtered by a method filterOut(). The output string is built
during the iteration over the keys and is saved by a method saveXYZ(filePath) as a
filtered output. This approach is very simple and can be customized or extended.
The source code of the script follows.
THRESHOLD = -5.0
DELIMITER = " "
class Trees():
## ATTRIBUTES
raster_dict = {}
output_array = []
## METHODS
def __init__(self):
print("Object created\n")
def loadPoints(self,filePath="D:\\input.csv"):
f = open(filePath, 'r')
for line in f:
line_ar = line.split(";")
if self.raster_dict.has_key(line_ar[0]) == False:
self.raster_dict[line_ar[0]] = [[],[]]
self.raster_dict[line_ar[0]][0].append(line_ar[1])
self.raster_dict[line_ar[0]][1].append(line_ar[2])
f.close()
def filterOut(self):
c = 0
for key, value in self.raster_dict.iteritems():
for index, ar in enumerate(value):
if index == 1:
print("VERTICAL LINE: "+str(c))
c+=1
i = 0
while i < len(ar)-1:
difference = (float(ar[i+1]) - float(ar[i]))
if difference > abs(THRESHOLD) or difference < THRESHOLD:
pLine =
str(key)+DELIMITER+str(value[0][i])+DELIMITER+str(ar[i]).rstrip("\n")+DELIMITER+str(round(
difference,3))+"\n"
self.output_array.append(pLine)
print pLine
i+=1
def saveXYZ(self,fPath = "D:\\filteredXYZ.xyz"):
f = open(fPath,'w')
f.writelines(self.output_array)
f.close()
Search WWH ::




Custom Search