Skip to content
This repository has been archived by the owner on Aug 18, 2022. It is now read-only.

Commit

Permalink
Merge branch 'lasbase-write-pathlibPath'
Browse files Browse the repository at this point in the history
  • Loading branch information
tmontaigu committed Oct 2, 2020
2 parents 561e66f + b2177bd commit c2d4c65
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions pylas/lasdatas/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logging
import pathlib
from typing import Union, Optional

import numpy as np

Expand Down Expand Up @@ -192,7 +194,7 @@ def update_header(self):
self.header.number_of_points_by_return = counts

def write_to(
self, out_stream, do_compress=False, laz_backend=LazBackend.detect_available()
self, out_stream, do_compress=False, laz_backend=LazBackend.detect_available()
):
"""writes the data to a stream
Expand All @@ -206,12 +208,12 @@ def write_to(
By default, pylas detect available backends
"""
with LasWriter(
out_stream,
self.header,
self.vlrs,
do_compress=do_compress,
closefd=False,
laz_backend=laz_backend,
out_stream,
self.header,
self.vlrs,
do_compress=do_compress,
closefd=False,
laz_backend=laz_backend,
) as writer:
writer.write(self.points)

Expand All @@ -224,7 +226,7 @@ def _raise_if_not_expected_pos(stream, expected_pos):
)
)

def write_to_file(self, filename, do_compress=None):
def write_to_file(self, filename: Union[str, pathlib.Path], do_compress: Optional[bool] = None) -> None:
"""Writes the las data into a file
Parameters
Expand All @@ -236,15 +238,15 @@ def write_to_file(self, filename, do_compress=None):
to determine if the data should be compressed
otherwise the do_compress flag indicate if the data should be compressed
"""
is_ext_laz = filename.split(".")[-1].lower() == "laz"
is_ext_laz = pathlib.Path(filename).suffix.lower() == "laz"
if is_ext_laz and do_compress is None:
do_compress = True

with open(filename, mode="wb+") as out:
self.write_to(out, do_compress=do_compress)

def write(
self, destination, do_compress=None, laz_backend=LazBackend.detect_available()
self, destination, do_compress=None, laz_backend=LazBackend.detect_available()
):
"""Writes to a stream or file
Expand Down Expand Up @@ -277,7 +279,7 @@ def write(
laz_backend: optional, the laz backend to use
By default, pylas detect available backends
"""
if isinstance(destination, str):
if isinstance(destination, (str, pathlib.Path)):
self.write_to_file(destination)
else:
if do_compress is None:
Expand Down

0 comments on commit c2d4c65

Please sign in to comment.