sylva.geo.interpolate¶
sylva.geo.interpolate ¶
Interpolation between point clouds and rasters.
Three directions are covered:
transfer_attributescarries attributes from one cloud to another (for example labels computed on a thinned cloud back to the full cloud);gridinterpolates points onto a~sylva.raster.Rasterby inverse distance weighting, a triangulated irregular network or natural-neighbour interpolation;sample_rasterandsample_rastersread rasters at the points of a cloud.
transfer_attributes ¶
transfer_attributes(source: PointCloud, target: PointCloud, names: str | Iterable[str] | None = None, method: str = 'nearest', k: int = 8, power: float = 2.0, max_distance: float | None = None, fill=None) -> PointCloud
Interpolate attributes of one cloud onto the points of another.
A k-d tree is built on source and every target point is
processed independently and in parallel, so the target can hold hundreds
of millions of points; the source is typically a thinned copy of it.
Distances are 3D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
PointCloud
|
Cloud carrying the attributes. Points with a non-finite coordinate are ignored. |
required |
target
|
PointCloud
|
Cloud that receives them. |
required |
names
|
str | Iterable[str] | None
|
Attribute name or names to transfer; every attribute of |
None
|
method
|
('nearest', 'idw', 'majority')
|
|
"nearest"
|
k
|
int
|
Neighbours considered by |
8
|
power
|
float
|
Inverse-distance exponent for |
2.0
|
max_distance
|
float | None
|
Only source points within this distance (m) of a target point are
used. Target points with none keep no value and get |
None
|
fill
|
Value for target points left without one (beyond |
None
|
Returns:
| Type | Description |
|---|---|
PointCloud
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
For an unknown method or attribute name, |
Examples:
Segment a thinned copy of a cloud, then label every original point:
>>> thin = sylva.filters.voxel_downsample(cloud, 0.05)
>>> thin = thin.with_attrs(tree_id=labels)
>>> full = interpolate.transfer_attributes(thin, cloud, "tree_id",
... method="majority", k=5,
... max_distance=0.1)
grid ¶
grid(cloud: PointCloud, resolution: float, value: str = 'z', method: str = 'idw', bounds=None, power: float = 2.0, k: int = 12, max_distance: float | None = None) -> Raster
Interpolate point values onto a regular grid.
Each cell takes the value interpolated at its centre from the points'
x, y positions. Grid geometry follows sylva.ground.make_dtm:
row 0 is at ymin; without bounds the south-west corner is the
points' minimum snapped down to a multiple of resolution and the
grid extends past their maximum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cloud
|
PointCloud
|
Points to interpolate, e.g. the ground points of a classified cloud. Points with a non-finite x, y or value are ignored, and points that share an x, y are merged into one carrying their mean value. |
required |
resolution
|
float
|
Cell size (m). |
required |
value
|
str
|
|
'z'
|
method
|
('idw', 'tin', 'natural')
|
|
"idw"
|
bounds
|
|
None
|
|
power
|
float
|
Inverse-distance exponent ( |
2.0
|
k
|
int
|
Neighbours per cell ( |
12
|
max_distance
|
float | None
|
Cells whose centre is farther than this (m, in x, y) from every point are NaN, for every method; None means no limit. |
None
|
Returns:
| Type | Description |
|---|---|
Raster
|
Interpolated values, NaN where there is none. |
Raises:
| Type | Description |
|---|---|
ValueError
|
For an unknown method or attribute, a non-positive |
See Also
sylva.ground.make_dtm : a DTM with these methods (method="tin").
Examples:
>>> ground = cloud[sylva.ground.ground_mask(cloud)]
>>> dtm = interpolate.grid(ground, 0.25, method="tin")
>>> intensity = interpolate.grid(cloud, 0.5, value="intensity")
sample_raster ¶
sample_raster(cloud: PointCloud, raster: Raster, name: str, method: str = 'bilinear') -> PointCloud
Add the value of a raster at each point as an attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cloud
|
PointCloud
|
Points in the raster's frame. |
required |
raster
|
Raster
|
Grid to read, e.g. a DTM, CHM or canopy cover map. |
required |
name
|
str
|
Name of the new attribute. |
required |
method
|
('bilinear', 'nearest')
|
|
"bilinear"
|
Returns:
| Type | Description |
|---|---|
PointCloud
|
The cloud with |
Raises:
| Type | Description |
|---|---|
ValueError
|
For an unknown method. |
See Also
sylva.ground.normalize_height : height above a DTM, which extends the DTM's edge values beyond it instead of returning NaN.
sample_rasters ¶
sample_rasters(cloud: PointCloud, rasters: Mapping[str, Raster], method: str = 'bilinear') -> PointCloud
Add the values of several rasters at each point as attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cloud
|
PointCloud
|
Points in the rasters' frame. |
required |
rasters
|
Mapping[str, Raster]
|
Attribute name to raster, e.g. |
required |
method
|
('bilinear', 'nearest')
|
As for |
"bilinear"
|
Returns:
| Type | Description |
|---|---|
PointCloud
|
The cloud with one float64 attribute per raster, NaN outside it. |
Raises:
| Type | Description |
|---|---|
ValueError
|
For an unknown method. |