Creating a point cloud from arrays

Creating a point cloud from arrays#

This example demonstrates the creation of a point cloud through from_xyz(), from_array() or from_tuples().

import numpy as np
import pyproj

We create a data array as ndarray, and a coordinate reference system (CRS) as pyproj.CRS.

import geoutils as gu

# A random N x 3 array
rng = np.random.default_rng(42)
arr = rng.normal(size=(5, 3))
# A CRS, here geographic (latitude/longitude)
crs = pyproj.CRS.from_epsg(4326)

# Create a point cloud using three 1-d arrays
pc = gu.PointCloud.from_xyz(x=arr[:, 0], y=arr[:, 1], z=arr[:, 2], crs=crs, data_column="z")
pc
PointCloud(
  ds=          z                  geometry
       0  0.750451  POINT (0.30472 -1.03998)
       1 -1.302180  POINT (0.94056 -1.95104)
       2 -0.016801  POINT (0.12784 -0.31624)
       3  0.777792   POINT (-0.85304 0.8794)
       4  0.467509   POINT (0.06603 1.12724)
  crs=EPSG:4326
  bounds=BoundingBox(left=np.float64(-0.85304392757358), bottom=np.float64(-1.9510351886538364), right=np.float64(0.9405647163912139), top=np.float64(1.1272412069680329)))


We can print info on the point cloud.

Filename:           None
Coordinate system:  EPSG:4326
Extent:             [-0.85304392757358, -1.9510351886538364, 0.9405647163912139, 1.1272412069680329]
Number of features: 5
Attributes:         ['z', 'geometry']

Note that we can also use the N x 3 array directly, or also an iterable of 3-tuples

pc = gu.PointCloud.from_array(arr, crs=crs, data_column="z")

The different functionalities of GeoUtils will use data as default as the main data column, including plotting.

pc.plot(cmap="copper")
pc from xyz

Total running time of the script: (0 minutes 0.212 seconds)

Gallery generated by Sphinx-Gallery