Cidree / rpostgis

rpostgis: R Interface to a 'PostGIS' Database
http://cidree.github.io/rpostgis/
77 stars 14 forks source link

Running any SQL query that returns a spatial object #7

Closed glaroc closed 7 years ago

glaroc commented 7 years ago

It would be great to have a function in RPostGIS that could be used to run any more complex SQL functions that involves multiple layers. For example, as far as I understand, it is not possible to run a ST_Within() between layers to return a spatial object with pgGetGeom() at the moment. Why not just create a function that sends any SQL statement to PostGIS and returns the result as a spatial data frame? @basille

dnbucklin commented 7 years ago

Hi @glaroc , You're right that this is not possible with the current pgGetGeom (which imports from one table/view only), though it appears it can be easily implemented as a new feature using temporary views. I'll keep you posted on adding this feature to our dev branch, and in the next CRAN release.

dnbucklin commented 7 years ago

This feature is now incorporated in pgGetGeom, see the query argument and details/example.

Now on the dev branch, install using:

devtools::install_github("mablab/rpostgis",ref = "dev")

This and other recent updates will be included in the next CRAN version.

glaroc commented 7 years ago

@dnbucklin Works like a charm. Great job!