PDAL / python

PDAL's Python Support
Other
115 stars 34 forks source link

geopackage support/SQL queries in python #151

Closed SjoerdBraaksma closed 11 months ago

SjoerdBraaksma commented 11 months ago

Hi! Loving the package so far. I am currently writing all my old code using command-line pdal and capturing the output, into python-pdal functions.

I was wondering: Is it possible to, when loading a geopackage, use a synonym for the datasource name in the query? Especially when file location names become long, this can be tedious.

For example:

pipeline= pdal.Filter.overlay(
   dimension="dimension",
   datasource= "test/file/in/path/further/down/1234/gpkg",
   as= "testfile",
  query= "select classification from testfile where classification == 11",
  layer="roads"
).pipeline(data)

thanks in advance!

hobu commented 11 months ago

Is it possible to, when loading a geopackage, use a synonym for the datasource name in the query?

Can you show me an example of what you mean? I would think this would have to be supported by OGR, as PDAL's simply passing this down to OGR to select the geometry used for intersection.

SjoerdBraaksma commented 11 months ago

Hi!

yes, the above example shows what I mean. How I do it now:

pipeline= pdal.Filter.overlay(
   dimension="dimension",
   datasource= "test/file/in/path/further/down/1234/gpkg",
  query= "select classification from test/file/in/path/further/down/1234/gpkg where classification == 11",
  layer="roads"
).pipeline(data)

What I mean:

pipeline= pdal.Filter.overlay(
   dimension="dimension",
   datasource= "test/file/in/path/further/down/1234/gpkg",
   as= "testfile",
  query= "select classification from testfile where classification == 11",
  layer="roads"
).pipeline(data)

This would also possibly open the way to more complex SQL queries where you can combine multiple layers/datasets before passing it to overlay.

hobu commented 11 months ago

I would accept a PR to PDAL that implemented this substitution, but do know that the OGR_SQL variant supports table aliasing and a bunch of other stuff. This contribution would belong in the PDAL repository, so please reopen a PR there if you do implement it.

SjoerdBraaksma commented 10 months ago

I thought about it for a while, and I think the easiest and most clear solution is just by constructing an f-string:

pipeline= pdal.Filter.overlay(
   dimension="dimension",
   datasource= datasource,
   as= "testfile",
  query= f"select classification from {os.splitext(datasource)[0]} where classification == 11",
  layer="roads"
).pipeline(data)