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

Support for terra rasters #325

Open
KyleLochhead opened this issue Jun 6, 2022 · 3 comments
Open

Support for terra rasters #325

KyleLochhead opened this issue Jun 6, 2022 · 3 comments
Labels
computing related to computing infrastructure in progress working on it!

Comments

@KyleLochhead
Copy link
Collaborator

Start the process of supporting terra

@KyleLochhead KyleLochhead added the computing related to computing infrastructure label Jun 6, 2022
@KyleLochhead
Copy link
Collaborator Author

KyleLochhead commented Jun 9, 2022

Removing pgGetRast()
The use of raster package in clus is predominately found in the dataLoaderCLUS module - which sets up the spatial aspects of data stored in a postgresql database. The main function for connecting postgresql raster objects with R is the rpostgis::pgGetRast() function. However, this function is mostly a wrapper for a DBI::dbGetQuery() call where the postgresql function st_dumpvalues() is used to stream all raster values into a table then into R. The proceeding steps of rpostgis::pgGetRast() build the raster using its metadata and then assign its values from this stream.

Proposed workaround

  1. Run one query to fetch the raster metadata.
    select st_xmax(st_envelope(boo.rast)) as xmx,
    st_xmin(st_envelope(boo.rast)) as xmn,
    st_ymax(st_envelope(boo.rast)) as ymx,
    st_ymin(st_envelope(boo.rast)) as ymn,
    st_width(boo.rast) as cols,
    st_height(rast) as rows from (SELECT st_union(ST_Clip(foo.rast, 1, foo.wkb_geometry, true)) as rast FROM
    (SELECT st_union(rast) as rast, wkb_geometry from rast.bc_ha_slope, tsa_aac_bounds
    WHERE tsa_name = 'Quesnel_TSA' AND ST_Intersects(rast, wkb_geometry) group by wkb_geometry) as foo) boo;

  2. All remaining querys simply stream raster values
    SELECT unnest(st_dumpvalues(st_union(ST_Clip(foo.rast, 1, foo.wkb_geometry, true)), 1)) as vals FROM
    (SELECT st_union(rast) as rast, wkb_geometry from rast.bc_ha_slope, tsa_aac_bounds
    WHERE tsa_name = 'Quesnel_TSA' AND ST_Intersects(rast, wkb_geometry) group by wkb_geometry) as foo

@KyleLochhead KyleLochhead added computing related to computing infrastructure in progress working on it! and removed computing related to computing infrastructure labels Sep 15, 2022
KyleLochhead added a commit that referenced this issue Dec 6, 2022
KyleLochhead added a commit that referenced this issue Dec 6, 2022
KyleLochhead added a commit that referenced this issue Dec 6, 2022
KyleLochhead added a commit that referenced this issue Dec 8, 2022
KyleLochhead added a commit that referenced this issue Dec 8, 2022
KyleLochhead added a commit that referenced this issue Dec 8, 2022
KyleLochhead added a commit that referenced this issue Dec 16, 2022
@KyleLochhead
Copy link
Collaborator Author

mock function for terra built need to test

@ElizabethKleynhans
Copy link
Collaborator

If rpostgis is updated to version 1.5.0 or greater the function RASTER_CLIP2 or any function that relies on pgGetRast will not work. This is because pgGetRast relies on rgeos and rgdal and both have been retired. We need to update the raster_clip functions to work around this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
computing related to computing infrastructure in progress working on it!
Projects
None yet
Development

No branches or pull requests

2 participants