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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

add transform point and points #409

Merged
merged 9 commits into from
Sep 16, 2023
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
5 changes: 1 addition & 4 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
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