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

Add PointCloud subclass of Vector #492

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion dev-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies:
- pip

# Optional dependencies
- laspy
- scikit-image

# Test dependencies
Expand Down Expand Up @@ -49,4 +50,4 @@ dependencies:
- typing-extensions

- pip:
- -e ./
- -e ./
8 changes: 5 additions & 3 deletions geoutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
GeoUtils is a Python package for the analysis of geospatial data.
"""

from geoutils import examples, pointcloud, projtools, raster, vector # noqa
from geoutils import examples, projtools # noqa
from geoutils._config import config # noqa
from geoutils.raster import Mask, Raster # noqa
from geoutils.vector import Vector # noqa

from geoutils.raster import Mask, Raster # noqa isort:skip
from geoutils.vector import Vector # noqa isort:skip
from geoutils.pointcloud import PointCloud # noqa isort:skip

try:
from geoutils._version import __version__ as __version__ # noqa
Expand Down
9 changes: 7 additions & 2 deletions geoutils/interface/gridding.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import warnings
from typing import Literal

import affine
import geopandas as gpd
import numpy as np
import rasterio as rio
from scipy.interpolate import griddata

from geoutils._typing import NDArrayNum
Expand All @@ -16,7 +18,7 @@ def _grid_pointcloud(
data_column_name: str = "b1",
resampling: Literal["nearest", "linear", "cubic"] = "linear",
dist_nodata_pixel: float = 1.0,
) -> NDArrayNum:
) -> tuple[NDArrayNum, affine.Affine]:
"""
Grid point cloud (possibly irregular coordinates) to raster (regular grid) using delaunay triangles interpolation.

Expand Down Expand Up @@ -88,4 +90,7 @@ def _grid_pointcloud(
# Flip Y axis of grid
aligned_dem = np.flip(aligned_dem, axis=0)

return aligned_dem
# 3/ Derive output transform from input grid
transform_from_coords = rio.transform.from_origin(min(grid_coords[0]), max(grid_coords[1]), res_x, res_y)

return aligned_dem, transform_from_coords
16 changes: 7 additions & 9 deletions geoutils/interface/raster_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _raster_to_pointcloud(
as_array: bool,
random_state: int | np.random.Generator | None,
force_pixel_offset: Literal["center", "ul", "ur", "ll", "lr"],
) -> NDArrayNum | gu.Vector:
) -> NDArrayNum | gu.PointCloud:
"""
Convert a raster to a point cloud. See Raster.to_pointcloud() for details.
"""
Expand Down Expand Up @@ -227,15 +227,13 @@ def _raster_to_pointcloud(
)

if not as_array:
points = gu.Vector(
gpd.GeoDataFrame(
pixel_data.T,
columns=all_column_names,
geometry=gpd.points_from_xy(x_coords_2, y_coords_2),
crs=source_raster.crs,
)
pc = gpd.GeoDataFrame(
pixel_data.T,
columns=all_column_names,
geometry=gpd.points_from_xy(x_coords_2, y_coords_2),
crs=source_raster.crs,
)
return points
return gu.PointCloud(pc, data_column=data_column_name)
else:
# Merge the coordinates and pixel data an array of N x K
# This has the downside of converting all the data to the same data type
Expand Down
2 changes: 1 addition & 1 deletion geoutils/pointcloud/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from geoutils.pointcloud.pointcloud import * # noqa
from geoutils.pointcloud.pointcloud import PointCloud # noqa
Loading
Loading