PDAL / java

Java extension and bindings for PDAL
https://pdal.io/java.html
Other
7 stars 9 forks source link

Pipeline from scala-constructed pointcloud #22

Open kervel opened 4 years ago

kervel commented 4 years ago

Hello,

i couldn't find documentation so far. My problem is that i have a dataset that can be converted to a pointcloud. I do the conversion as follows:

  def toPointCloud(sweeps: Seq[Tuple3[Coordinate, Double, Seq[XZ]]]): PointCloud = {
    // the Double in the tuple3 is the azimuth.
    val points = sweeps.map(gs => projectSweep(gs._3, gs._2, gs._1)).
          reduce((a,b) => DenseMatrix.horzcat(a,b))
    var v = new util.HashMap[String, SizedDimType]()
    v += "X" -> SizedDimType(DimType.X, java.lang.Double.BYTES, 0)
    v += "Y" -> SizedDimType(DimType.Y, java.lang.Double.BYTES, java.lang.Double.BYTES)
    v += "Z" -> SizedDimType(DimType.Z, java.lang.Double.BYTES, 2*java.lang.Double.BYTES)
    val bos = ByteBuffer.allocate(points.cols * points.rows * java.lang.Double.BYTES).order(ByteOrder.nativeOrder());
    val ios = bos.asDoubleBuffer();
    ios.put(points.copy.data)
    return new PointCloud(bos.array(), v)
  }

i verified and the pointcloud seems to be okay (i can get points out of it). I'd like to create a PDAL pipeline now using this pointcloud so that i can reproject/persist/... it.

Is there a way to do this ?

greetings, Frank

pomadchin commented 4 years ago

Hey @kervel, so what is your question? How to use PDAL Pipeline, or how to transform points already loaded into memory?

If the first question, than you can do the following:

val pc: PipelineConstructor = LasRead("/path/to/las") ~ CropFilter() ~ SmthElse() ~ LasWrite("/path/to/new/las")
val pipeline = pc.toPipeline
pipeline.execute()
pipeline.getMetadata() // gets some metadata
val pvi = pipeline.getPointViews() // these are PDAL PointViews, views to get the actual pointclouds
val pc = pv.getPointCloud(0, Array(DimType.X, DimType.Y)) // this one will create a PointCloud object with the point 0 and x & y dims
pipeline.dispose()

In the example above we'll push the Pipeline to PDAL, it would process it, and return already transformed points.

If you want to do smth else with your pointclouds I would be happy to help you to start with https://github.com/geotrellis/geotrellis-pointcloud which exposes PDAL capabilities on Spark.

pomadchin commented 4 years ago

Ah, or you want to create a pointcloud object and to return back to PDAL to process it?

kervel commented 4 years ago

yes. i was hoping to use pdal to rasterize a pointcloud that i constructed using spark scala code (i have seen TinToDem also in geotrellis but for that i wouldn't even have to construct a pointcloud). all the existing pdal examples start by loading an existing pointcloud from disk, and hence never face this problem...

pomadchin commented 4 years ago

yea, so PDAL Pipeline interface only allows to perform transformations on read. So it is a sort of an IO interface in this case that allows to do transofmrations with pointclouds right after reading them from file.

PDAL does not expose an interface to provide some pointclouds represented as some in memory buffer as an input for PDAL Pipeline.

For your purposes for sure it is better to use TinToDem from geotrellis-pointcloud, it uses a nice delaunay triangulation implementation to perform it, so it may work.

I'm happy to help you with it! (if you would decide to touch geotrellis-pointcloud)

abellgithub commented 4 years ago

See https://pdal.io/stages/readers.memoryview.html

pomadchin commented 4 years ago

Nice! Thanks for the pointer @abellgithub, I need to look into it.

pomadchin commented 4 years ago

This probably would be done in terms of a 2.0 release.