Geographic Information Systems Asked on February 21, 2021
I have a text file, each line in the text file has X,Y and Z coordinates eg:
551124.5841823021 470778.1953796738 318.1167521614109
I want to read the data and export it to LAS format, by using laspy.
The code I use, inspired from :
header = laspy.header.Header()
with open(input_file, "r") as file:
lines = list(line for line in (l.strip() for l in file) if line)
output_X = []
output_Y = []
output_Z = []
for line in lines:
splited = line.split()
output_X.append(float((splited[0])))
output_Y.append(float((splited[1])))
output_Z.append(float((splited[2])))
output_file = input_file.rsplit(".", 1)[0]+"_changed.las"
outfile = laspy.file.File(r"{}".format(output_file),
mode="w", header=header)
outfile.X = numpy.array(output_X)
outfile.Y = numpy.array(output_Y)
outfile.Z = numpy.array(output_Z)
outfile.close()
The values I expect to find should be of the same type as those from txt file, however, if I read the file I get:
[((551124, 470778, 318, 0, 0, 0, 0, 0, 0),)
((551124, 470779, 318, 0, 0, 0, 0, 0, 0),)
((551124, 470780, 318, 0, 0, 0, 0, 0, 0),) …
((551438, 470707, 315, 0, 0, 0, 0, 0, 0),)
((551438, 470708, 315, 0, 0, 0, 0, 0, 0),)
((551438, 470709, 315, 0, 0, 0, 0, 0, 0),)]
I want the entries to be of type float, with decimal. I know it should be possible, since I have LAS files received from a third party, that have decimals.
Should I be setting the scale for the LAS file on export?
Also, if I open the output file in a software that reads LAS files, ArcGIS, points are not represented.
What am I doing wrong?
You should be using lower-case letters for the dimensions when accessing them as floats, e.g. outfile.x
instead of outfile.X
.
The capitalized version is used to access the "un-scaled" dimension, which are the integers that are stored internally. Lower case should apply the scaling for you when accessing them. In your case, you're actually assigning floats to the integer fields, which is immediately truncating them.
From the tutorial in the docs:
Laspy can actually scale the x, y, and z dimensions for you. Upper case dimensions (las_file.X, las_file.Y, las_file.Z) give the raw integer dimensions, while lower case dimensions (las_file.x, las_file.y, las_file.z) give the scaled value. Both methods support assignment as well, although due to rounding error assignment using the scaled dimensions is not reccomended.
Correct answer by mikewatt on February 21, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP