def test_conversion_file_version(): las = pylas.create(point_format_id=0, file_version='1.4') las2 = pylas.convert(las, file_version='1.2') assert las.points_data.point_format == las2.points_data.point_format for dim_name in las.points_data.point_format.dimension_names: assert np.allclose( las.points_data[dim_name], las2.points_data[dim_name]), "{} not equal".format(dim_name)
def test_conversion_keeps_eb(extrab_las): eb_0 = pylas.convert(extrab_las, point_format_id=0) assert eb_0.points_data.extra_dimensions_names == extrab_las.points_data.extra_dimensions_names for name in eb_0.points_data.extra_dimensions_names: assert np.allclose(eb_0[name], extrab_las[name]) eb_0 = pylas.lib.write_then_read_again(eb_0) assert eb_0.points_data.extra_dimensions_names == extrab_las.points_data.extra_dimensions_names for name in eb_0.points_data.extra_dimensions_names: assert np.allclose(eb_0[name], extrab_las[name])
def convert(input, output, point_format_id, file_version, force): """ Converts INPUT to a file with point_format_id and file_version Writes the result to OUTPUT If no file version or point_format_id is provided this will result in a copy. Examples: 1) Compress a file pylas convert stormwind.las stormwind.laz 2) Convert file to point format 3 pylas convert ironforge.las forgeiron.las --point-format-id 3 """ if (point_format_id is not None and point_format_id not in pylas.supported_point_formats()): click.echo( click.style( "Point format {} is not supported".format(point_format_id), fg="red")) raise click.Abort() if file_version is not None and file_version not in pylas.supported_versions( ): click.echo( click.style("LAS version {} is not supported".format(file_version), fg="red")) raise click.Abort() las = pylas.read(openbin_file(input)) if point_format_id is not None and not force: lost_dimensions = pylas.lost_dimensions( las.points_data.point_format.id, point_format_id) if lost_dimensions: click.echo("Converting will lose: {}".format(lost_dimensions)) click.confirm("Continue ?", abort=True) try: las = pylas.convert(las, point_format_id=point_format_id, file_version=file_version) except pylas.errors.PylasError as e: click.echo( click.style("{}: {}".format(e.__class__.__name__, e), fg="red")) raise click.Abort() except Exception as e: click.echo(click.style(str(e), fg="red")) raise click.Abort() else: las.write(openbin_file(output, mode='w'), do_compress=output.endswith('.laz'))
def test_change_format(las): in_version = las.header.version las = pylas.convert(las, point_format_id=2) las = write_then_read_again(las) assert las.points_data.point_format_id == 2 assert las.header.point_format_id == 2 assert las.header.version == in_version assert dim_does_not_exists(las, "gps_time") las = pylas.convert(las, point_format_id=1) las = write_then_read_again(las) assert las.points_data.point_format_id == 1 assert las.header.point_format_id == 1 assert las.header.version == in_version assert dim_does_not_exists(las, "red") assert dim_does_not_exists(las, "green") assert dim_does_not_exists(las, "blue") las = pylas.convert(las, point_format_id=0) las = write_then_read_again(las) assert las.points_data.point_format_id == 0 assert las.header.point_format_id == 0 assert las.header.version == in_version assert dim_does_not_exists(las, "red") assert dim_does_not_exists(las, "green") assert dim_does_not_exists(las, "blue") assert dim_does_not_exists(las, "gps_time") las = pylas.convert(las, point_format_id=8) las = write_then_read_again(las) assert las.header.version == "1.4" assert las.points_data.point_format_id == 8 assert las.header.point_format_id == 8 assert dim_does_exists(las, "red") assert dim_does_exists(las, "green") assert dim_does_exists(las, "blue") assert dim_does_exists(las, "nir") las = pylas.convert(las, point_format_id=7) las = write_then_read_again(las) assert las.header.version == "1.4" assert las.points_data.point_format_id == 7 assert las.header.point_format_id == 7 assert dim_does_exists(las, "red") assert dim_does_exists(las, "green") assert dim_does_exists(las, "blue") assert dim_does_not_exists(las, "nir") las = pylas.convert(las, point_format_id=6) las = write_then_read_again(las) assert las.header.version == "1.4" assert las.points_data.point_format_id == 6 assert las.header.point_format_id == 6 assert dim_does_not_exists(las, "red") assert dim_does_not_exists(las, "green") assert dim_does_not_exists(las, "blue") assert dim_does_not_exists(las, "nir")
def test_conversion_copies_fields(all_las_but_1_4): las = all_las_but_1_4 for i in (0, 1, 2, 3, 2, 1, 0): old_record = las.points_data las = pylas.convert(las, point_format_id=i) las = write_then_read_again(las) for dim_name in old_record.dimensions_names: try: assert np.allclose( las.points_data[dim_name], old_record[dim_name]), "{} not equal".format(dim_name) except ValueError: pass # dim exists in old_record but not new
def test_point_format_conversion_copies_field_values(file_path, target_point_format_id): original = pylas.read(file_path) converted = pylas.convert(original, point_format_id=target_point_format_id) converted = write_then_read_again(converted) converted_dimension_names = set(converted.point_format.dimension_names) dimension_expected_to_be_kept = [ dim_name for dim_name in original.point_format.dimension_names if dim_name in converted_dimension_names ] for dim_name in dimension_expected_to_be_kept: assert np.allclose(converted[dim_name], original[dim_name]), "{} not equal".format(dim_name)
def test_conversion_keeps_eb(las_file_path_with_extra_bytes): """ Test that converting point format does not lose extra bytes """ original = pylas.read(las_file_path_with_extra_bytes) converted_las = pylas.convert(original, point_format_id=0) assert len(list(original.point_format.extra_dimension_names)) == 5 assert list(converted_las.point_format.extra_dimension_names) == list( original.point_format.extra_dimension_names ) for name in converted_las.point_format.extra_dimension_names: assert np.allclose(converted_las[name], original[name]) converted_las = pylas.lib.write_then_read_again(converted_las) assert list(converted_las.point_format.extra_dimension_names) == list( original.point_format.extra_dimension_names ) for name in converted_las.point_format.extra_dimension_names: assert np.allclose(converted_las[name], original[name])