[pdal] PDAL Python + Geopandas

James Ford irvine.ford at gmail.com
Wed Jun 26 14:29:16 PDT 2024


Hello,

I am using the PDAL python bindings to read point clouds into geopandas
GeoDataFrames and then write them back to disc.

The approach I have works, but is slow. Is there a faster way of doing this?

The slowest part is converting from a GeoDataFrame back to a structured
numpy array.

Code below.

Thanks,

James

import pdal
import numpy as np
import pandas as pd
import geopandas as gpd

input_point_cloud_filepath = "..."

output_point_cloud_filepath = "..."

crs = "..."

#################### Read PC into Memory and convert to GeoDataFrame
####################

pipeline_stages = [
    pdal.Reader.copc(input_point_cloud_filepath),
    pdal.Filter.hag_nn()
]

pipeline = pdal.Pipeline(pipeline_stages)

_ = pipeline.execute()

pointcloud_dtype = pipeline.arrays[0].dtype

pointcloud_df = pipeline.get_dataframe(0)

pointcloud_gdf = gpd.GeoDataFrame(
    pointcloud_df,
    geometry=gpd.points_from_xy(pointcloud_df["X"], pointcloud_df["Y"],
pointcloud_df["Z"]),
    crs= crs ,
)

_ = pointcloud_gdf.sindex

########################## Manipulate PC via geopandas & numpy
##########################

# Do stuff here


########################### GeoDataFrame -> numpy -> pipeline
###########################

pointcloud_arr = np.array(
    (
        pointcloud_gdf
        .drop(columns=["geometry"])
        .apply(tuple, axis=1)
    ),
    dtype=pointcloud_dtype
)

output_pipeline = pdal.Filter.stats().pipeline(pointcloud_arr)

output_pipeline |= pdal.Writer.copc(
    output_point_cloud_filepath,
    forward="all",
    a_srs=crs,
)

_ = output_pipeline.execute()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/pdal/attachments/20240627/6c687351/attachment.htm>


More information about the pdal mailing list