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

Commit

Permalink
define __copy__ for headers, and use it in create_from_header
Browse files Browse the repository at this point in the history
  • Loading branch information
tmontaigu committed Jun 8, 2018
1 parent fb11032 commit 1f22d0e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ We use the classification field to filter points, but this can work with the oth
las = pylas.read('pylastests/simple.las')
new_file = pylas.create()
new_file = pylas.create(point_format_id=las.header.point_format_id, file_version=las.header.version)
new_file.points = las.points[las.classification == 1]
new_file.write('extracted_points.las')
Expand Down
4 changes: 2 additions & 2 deletions docs/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ the same dimensions plus some additional dimensions:
+----------------------+-----------+--------------+
| Added dimensions | Type | Size (bit) |
+======================+===========+==============+
| gps_time | Floating | 64 |
| gps_time | Floating | 64 |
+----------------------+-----------+--------------+


Expand All @@ -122,7 +122,7 @@ the same dimensions plus some additional dimensions:
+----------------------+-----------+--------------+
| Added dimensions | Type | Size (bit) |
+======================+===========+==============+
| gps_time | Floating | 64 |
| gps_time | Floating | 64 |
+----------------------+-----------+--------------+
| red | unsigned | 16 |
+----------------------+-----------+--------------+
Expand Down
11 changes: 11 additions & 0 deletions pylas/headers/rawheader.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,21 @@ def point_format_id(self):
def point_format_id(self, value):
self._point_data_format_id = value

@property
def point_size(self):
return self.point_data_record_length

@point_size.setter
def point_size(self, value):
self.point_data_record_length = value

@property
def are_points_compressed(self):
return compression.is_point_format_compressed(self._point_data_format_id)

def __copy__(self):
return self.__class__.from_buffer_copy(bytes(self))

def __repr__(self):
return "<LasHeader({})>".format(self.version)

Expand Down
9 changes: 7 additions & 2 deletions pylas/lib.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" 'Entry point' of the library, Contains the various functions meant to be
used directly by a user
"""
import copy

from . import headers
from .lasdatas import las12, las14
Expand Down Expand Up @@ -81,7 +82,10 @@ def mmap_las(filename):


def create_from_header(header):
""" Creates a File from an existing header
""" Creates a File from an existing header,
allocating the array of point according to the provided header.
The input header is copied.
Parameters
----------
Expand All @@ -91,14 +95,15 @@ def create_from_header(header):
-------
pylas.lasdatas.base.LasBase
"""
header = copy.copy(header)
points = record.PackedPointRecord.zeros(header.point_format_id, header.point_count)
if header.version >= "1.4":
return las14.LasData(header=header, points=points)
return las12.LasData(header=header, points=points)


def create_las(*, point_format=0, file_version=None):
""" Function to create a new las data object
""" Function to create a new empty las data object
.. note::
Expand Down
13 changes: 13 additions & 0 deletions pylastests/test_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,16 @@ def test_nb_points_return_1_4():
assert tuple(las.header.number_of_points_by_return) == ((1,) * 14) + (
len(las.points_data) - 14,
)


def test_header_copy():
import copy
las = pylas.read(test_common.simple_las)
header_copy = copy.copy(las.header)

assert header_copy.point_format_id == las.header.point_format_id
assert header_copy.version == las.header.version

header_copy.point_format_id = 0
assert header_copy.point_format_id != las.header.point_format_id
assert header_copy.version == las.header.version
25 changes: 13 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
from setuptools import setup, find_packages

with open('README.rst') as f:
with open("README.rst") as f:
readme = f.read()

setup(
name='pylas',
version='0.1.3',
description='Las/Laz reading and writing in python',
name="pylas",
version="0.1.3",
description="Las/Laz reading and writing in python",
long_description=readme,
url='https://github.com/tmontaigu/pylas',
author='Thomas Montaigu',
author_email='thomas.montaigu@laposte.net',
python_requires='>=3',
install_requires=['numpy'],
license='BSD 3-Clause',
packages=find_packages(exclude=('pylastests',)),
zip_safe=False
url="https://github.com/tmontaigu/pylas",
author="Thomas Montaigu",
author_email="thomas.montaigu@laposte.net",
python_requires=">=3",
keywords="las lidar",
install_requires=["numpy"],
license="BSD 3-Clause",
packages=find_packages(exclude=("pylastests",)),
zip_safe=False,
)

0 comments on commit 1f22d0e

Please sign in to comment.