Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch crs84Extent to a 4-point-polygon #809

Merged
merged 1 commit into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ _When adding new entries to the changelog, please include issue/PR numbers where
## 0.12.3 (UNRELEASED)

- Fix the issue where re-importing the same shapefile with `--replace-existing` would show spurious schema changes (and therefore row changes). [#791](https://github.com/koordinates/kart/issues/791)

- Added support for committing new layers to a kart repository with `add-dataset` and the table name. [#249](https://github.com/koordinates/kart/issues/249)
- Switched the crs84Extent field for point-cloud tiles to store a 4-point-polygons (instead of an axis-aligned envelope).

## 0.12.2

Expand Down
7 changes: 5 additions & 2 deletions kart/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,13 +705,16 @@ def geom_envelope(gpkg_geom, only_2d=False, calculate_if_missing=False):
return envelope


def ring_as_wkt(*points, repeat_first_point=True):
def ring_as_wkt(*points, repeat_first_point=True, dp=None):
if repeat_first_point:
points_iter = itertools.chain(points, [points[0]])
else:
points_iter = points

return "(" + ",".join(f"{x} {y}" for x, y in points_iter) + ")"
if dp is None:
return "(" + ",".join(f"{p[0]} {p[1]}" for p in points_iter) + ")"
else:
return "(" + ",".join(f"{p[0]:.{dp}f} {p[1]:.{dp}f}" for p in points_iter) + ")"


def bbox_as_wkt_polygon(min_x, max_x, min_y, max_y):
Expand Down
19 changes: 8 additions & 11 deletions kart/point_cloud/metadata_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
InvalidOperation,
INVALID_FILE_FORMAT,
)
from kart.geometry import ring_as_wkt
from kart.point_cloud import pdal_execute_pipeline
from kart.point_cloud.schema_util import (
get_schema_from_pdrf,
Expand Down Expand Up @@ -237,20 +238,16 @@ def _calc_crs84_extent(src_extent, src_crs):
dest_srs.SetWellKnownGeogCS("CRS84")

transform = osr.CoordinateTransformation(src_srs, dest_srs)
(ax, ay, az), (bx, by, bz) = transform.TransformPoints(
min_x, max_x, min_y, max_y, min_z, max_z = src_extent
result = transform.TransformPoints(
[
src_extent[0::2],
src_extent[1::2],
(min_x, min_y),
(min_x, max_y),
(max_x, max_y),
(max_x, min_y),
]
)
return (
min(ax, bx),
max(ax, bx),
min(ay, by),
max(ay, by),
min(az, bz),
max(az, bz),
)
return "POLYGON(" + ring_as_wkt(*result, dp=7) + ")"


def is_copc(tile_format):
Expand Down
1 change: 0 additions & 1 deletion kart/raster/metadata_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def extract_raster_tile_metadata(raster_tile_path):


def format_polygon(*points):
# TODO - should we just store the axis-aligned extent?
return "POLYGON(" + ring_as_wkt(*points) + ")"


Expand Down
Binary file modified tests/data/point-cloud/auckland-bare.git.tgz
Binary file not shown.
Binary file modified tests/data/point-cloud/auckland.tgz
Binary file not shown.
Binary file modified tests/data/point-cloud/conflicts.tgz
Binary file not shown.
59 changes: 0 additions & 59 deletions tests/point_cloud/__init__.py
Original file line number Diff line number Diff line change
@@ -1,59 +0,0 @@
import re


def assert_lines_almost_equal(a, b, places=10):
"""Asserts that two lists of strings strings are the same but allows for some floating point innacuracy."""
a, b = fix_almost_equal_lines(a, b, places=places)
assert a == b


def fix_almost_equal_lines(orig_a_lines, orig_b_lines, places=10):
if (
orig_a_lines is None
or orig_b_lines is None
or len(orig_a_lines) != len(orig_b_lines)
):
return orig_a_lines, orig_b_lines

a_lines = []
b_lines = []
for a_line, b_line in zip(orig_a_lines, orig_b_lines):
a_line, b_line = fix_almost_equal_strings(a_line, b_line, places=places)
a_lines.append(a_line)
b_lines.append(b_line)
return a_lines, b_lines


def fix_almost_equal_strings(orig_a_str, orig_b_str, places=10):
if orig_a_str is None or orig_b_str is None or orig_a_str == orig_b_str:
return orig_a_str, orig_b_str

float_pattern = r"\d+\.\d+"
a_floats = re.findall(float_pattern, orig_a_str)
b_floats = re.findall(float_pattern, orig_b_str)

if len(a_floats) != len(b_floats):
return orig_a_str, orig_b_str

shortened_pattern = r"\d+\.\d{1,%d}" % places
common_floats = []
for a_float, b_float in zip(a_floats, b_floats):
if a_float == b_float:
common_floats.append(a_float)
continue
# If the floats are the same for {places} decimal places, then truncate them both to that.
a_shorter = re.search(shortened_pattern, a_float).group(0)
b_shorter = re.search(shortened_pattern, b_float).group(0)
if a_shorter == b_shorter:
common_floats.append(a_shorter)
else:
break

if len(common_floats) != len(a_floats):
return orig_a_str, orig_b_str

it = iter(common_floats)
modifed_a = re.sub(float_pattern, lambda x: next(it), orig_a_str)
it = iter(common_floats)
modified_b = re.sub(float_pattern, lambda x: next(it), orig_b_str)
return modifed_a, modified_b
6 changes: 3 additions & 3 deletions tests/point_cloud/test_bare.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def test_show(cli_runner, data_archive):
"",
"+++ auckland:tile:auckland_0_0",
"+ name = auckland_0_0.copc.laz",
"+ crs84Extent = 174.73844833207193,174.74945404214898,-36.85123712200056,-36.84206322341377,-1.66,99.83",
"+ crs84Extent = POLYGON((174.7384483 -36.8512371,174.7382443 -36.8422277,174.7494540 -36.8420632,174.7496594 -36.8510726,174.7384483 -36.8512371))",
"+ format = laz-1.4/copc-1.0",
"+ nativeExtent = 1754987.85,1755987.77,5920219.76,5921219.64,-1.66,99.83",
"+ pointCount = 4231",
"+ sourceOid = sha256:6b980ce4d7f4978afd3b01e39670e2071a792fba441aca45be69be81cb48b08c",
"+ oid = sha256:a1862450841dede2759af665825403e458dfa551c095d9a65ea6e6765aeae0f7",
"+ size = 69590",
"+ oid = sha256:adbc1dc7fc99c88fcb627b9c40cdb56c211b791fe9cf83fe066b1a9932c12569",
"+ size = 54396",
]
Loading