Skip to content

Commit

Permalink
add transform point and points
Browse files Browse the repository at this point in the history
  • Loading branch information
bjlittle committed Sep 11, 2023
1 parent 5645001 commit 0ed9ec9
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 26 deletions.
15 changes: 7 additions & 8 deletions src/geovista/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
"""
from __future__ import annotations

from typing import Union
import warnings

import numpy as np
from numpy import ma
from numpy.typing import ArrayLike
from pyproj import CRS, Transformer
from pyproj import CRS
import pyvista as pv

from .common import (
Expand All @@ -30,13 +29,13 @@
to_cartesian,
wrap,
)
from .crs import WGS84, to_wkt
from .crs import WGS84, CRSLike, to_wkt
from .transform import transform_points

__all__ = ["Transform"]

# type aliases
Shape = tuple[int]
CRSLike = Union[int, str, dict, CRS]

#: Whether mesh cleaning performed by the bridge.
BRIDGE_CLEAN: bool = False
Expand Down Expand Up @@ -593,8 +592,8 @@ def from_points(
crs = CRS.from_user_input(crs)

if crs != WGS84:
transformer = Transformer.from_crs(crs, WGS84, always_xy=True)
xs, ys = transformer.transform(xs, ys, errcheck=True)
transformed = transform_points(src_crs=crs, tgt_crs=WGS84, xs=xs, ys=ys)
xs, ys = transformed[:, 0], transformed[:, 1]

# ensure longitudes (degrees) are in half-closed interval [-180, 180)
xs = wrap(xs)
Expand Down Expand Up @@ -745,8 +744,8 @@ def from_unstructured(
crs = CRS.from_user_input(crs)

if crs != WGS84:
transformer = Transformer.from_crs(crs, WGS84, always_xy=True)
xs, ys = transformer.transform(xs, ys, errcheck=True)
transformed = transform_points(src_crs=crs, tgt_crs=WGS84, xs=xs, ys=ys)
xs, ys = transformed[:, 0], transformed[:, 1]

# ensure longitudes (degrees) are in half-closed interval [-180, 180)
xs = wrap(xs)
Expand Down
6 changes: 6 additions & 0 deletions src/geovista/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
"""
from __future__ import annotations

from typing import Union

import numpy as np
from pyproj import CRS
import pyvista as pv

from .common import GV_FIELD_CRS

__all__ = [
"CRSLike",
"PlateCarree",
"WGS84",
"from_wkt",
Expand All @@ -23,6 +26,9 @@
"to_wkt",
]

# type aliases
CRSLike = Union[int, str, dict, CRS]

#: EPSG projection parameter for longitude of natural origin/central meridian
EPSG_CENTRAL_MERIDIAN: str = "8802"

Expand Down
2 changes: 1 addition & 1 deletion src/geovista/examples/from_2d__orca_moll.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def main() -> None:
mesh = cast(mesh.threshold())

# transform and extrude the mesh
mesh = transform_mesh(mesh, crs)
mesh = transform_mesh(crs, mesh)
mesh.extrude((0, 0, -1000000), capping=True, inplace=True)

# plot the mesh
Expand Down
9 changes: 3 additions & 6 deletions src/geovista/geoplotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from __future__ import annotations

from functools import lru_cache
from typing import Any, Union
from typing import Any
from warnings import warn

from pyproj import CRS
Expand Down Expand Up @@ -52,9 +52,6 @@

__all__ = ["GeoPlotter"]

# type aliases
CRSLike = Union[int, str, dict, CRS]

#: Proportional multiplier for z-axis levels/offsets of base-layer mesh.
BASE_ZLEVEL_SCALE: int = 1.0e-3

Expand Down Expand Up @@ -216,7 +213,7 @@ def _add_graticule_labels(
to_wkt(mesh, WGS84)
# the point-cloud won't be sliced, however it's important that the
# central-meridian rotation is performed here
mesh = transform_mesh(mesh, self.crs, zlevel=zlevel, inplace=True)
mesh = transform_mesh(self.crs, mesh, zlevel=zlevel, inplace=True)
xyz = mesh.points

if "show_points" in point_labels_args:
Expand Down Expand Up @@ -601,8 +598,8 @@ def add_mesh(self, mesh: Any, **kwargs: Any | None):

if transform_required:
mesh = transform_mesh(
mesh,
tgt_crs,
mesh,
slice_connectivity=False,
rtol=rtol,
atol=atol,
Expand Down
10 changes: 6 additions & 4 deletions src/geovista/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import numpy as np
from numpy.typing import ArrayLike
from pykdtree.kdtree import KDTree as pyKDTree
from pyproj import Transformer
from pyvista import PolyData

from .common import _MixinStrEnum, to_cartesian
from .crs import WGS84, from_wkt
from .transform import transform_points

__all__ = ["KDTree", "Preference", "find_cell_neighbours", "find_nearest_cell"]

Expand Down Expand Up @@ -127,9 +127,11 @@ def __init__(
crs = WGS84

if crs != WGS84:
transformer = Transformer.from_crs(crs, WGS84, always_xy=True)
xs, ys = transformer.transform(xyz[:, 0], xyz[:, 1], errcheck=True)
xyz = to_cartesian(xs, ys)
transformed = transform_points(
src_crs=crs, tgt_crs=WGS84, xs=xyz[:, 0], ys=xyz[:, 1]
)
# TODO: clarify zlevel preservation for non-WGS84 point-clouds
xyz = to_cartesian(transformed[:, 0], transformed[:, 1])

self._n_points = xyz.shape[0]
self._mesh_type = mesh.__class__.__name__
Expand Down

0 comments on commit 0ed9ec9

Please sign in to comment.