Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geopackage support/SQL queries in python #151

Closed
SjoerdBraaksma opened this issue Oct 2, 2023 · 4 comments
Closed

geopackage support/SQL queries in python #151

SjoerdBraaksma opened this issue Oct 2, 2023 · 4 comments

Comments

@SjoerdBraaksma
Copy link

SjoerdBraaksma commented Oct 2, 2023

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
Copy link
Member

hobu commented Oct 2, 2023

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
Copy link
Author

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.

@SjoerdBraaksma SjoerdBraaksma changed the title geopackage support in python geopackage support/SQL queries in python Oct 2, 2023
@hobu
Copy link
Member

hobu commented Oct 2, 2023

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.

@hobu hobu closed this as completed Oct 2, 2023
@SjoerdBraaksma
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants