Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
alavenant committed Oct 18, 2024
1 parent e675205 commit 462ecb8
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions pdaltools/add_points_in_las.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

from pdaltools.las_info import get_writer_parameters_from_reader_metadata


def extract_points_from_geo(input_geo: str):
file = open(input_geo)
df = geopandas.read_file(file)
return df.get_coordinates(ignore_index=True, include_z=True)



def add_points_in_las(input_las: str, input_geo: str, output_las: str, values_dimensions: {}):
points_geo = extract_points_from_geo(input_geo)
pipeline = pdal.Pipeline() | pdal.Reader.las(input_las)
Expand All @@ -22,9 +22,9 @@ def add_points_in_las(input_las: str, input_geo: str, output_las: str, values_di

for i in points_geo.index:
pt_las = np.empty(1, dtype=points_las.dtype)
pt_las[0][dimensions.index('X')] = points_geo["x"][i]
pt_las[0][dimensions.index('Y')] = points_geo["y"][i]
pt_las[0][dimensions.index('Z')] = points_geo["z"][i]
pt_las[0][dimensions.index("X")] = points_geo["x"][i]
pt_las[0][dimensions.index("Y")] = points_geo["y"][i]
pt_las[0][dimensions.index("Z")] = points_geo["z"][i]
for val in values_dimensions:
pt_las[0][dimensions.index(val)] = values_dimensions[val]
points_las = np.append(points_las, pt_las, axis=0)
Expand All @@ -40,32 +40,39 @@ def parse_args():
parser.add_argument("--input_file", "-i", type=str, help="Las/Laz input file")
parser.add_argument("--output_file", "-o", type=str, help="Las/Laz output file.")
parser.add_argument("--input_geo_file", "-g", type=str, help="Geometry input file.")
parser.add_argument("--dimensions", "-d", metavar="KEY=VALUE", nargs='+',
help="Set a number of key-value pairs corresponding to value "
"needed in points added in the output las; key should be included in the input las.")
parser.add_argument(
"--dimensions",
"-d",
metavar="KEY=VALUE",
nargs="+",
help="Set a number of key-value pairs corresponding to value "
"needed in points added in the output las; key should be included in the input las.",
)
return parser.parse_args()


def is_nature(value, nature):
if value is None:
return False
try:
nature(value)
return True
except:
return False
if value is None:
return False
try:
nature(value)
return True
except:
return False


def parse_var(s):
items = s.split('=')
items = s.split("=")
key = items[0].strip()
if len(items) > 1:
value = '='.join(items[1:])
value = "=".join(items[1:])
if is_nature(value, int):
value = int(value)
elif is_nature(value, float):
value = float(value)
return (key, value)


def parse_vars(items):
d = {}
if items:
Expand All @@ -74,6 +81,7 @@ def parse_vars(items):
d[key] = value
return d


if __name__ == "__main__":
args = parse_args()
added_dimensions = parse_vars(args.dimensions)
Expand Down

0 comments on commit 462ecb8

Please sign in to comment.