Skip to content

Instantly share code, notes, and snippets.

@knutole
Created May 31, 2016 20:19
Show Gist options
  • Save knutole/3b34cc132f15907b13c22f06b56d761a to your computer and use it in GitHub Desktop.
Save knutole/3b34cc132f15907b13c22f06b56d761a to your computer and use it in GitHub Desktop.
The idea here is that there are two different rasters - one large rasterA, and one small rasterB used as a mask. We need to get the values of rasterA which are within the bounds of rasterB.
Additional problem: rasterB has NODATA value of 0, and ONLY the part of the rasterB that is NOT NODATA should be used as a mask.
The example below is wrong, for several reasons. Can you fix it?
select row_to_json(t) from (
SELECT A.rid, B.rid, pvc
FROM rasterA A
JOIN rasterB B
ON ST_Intersects(A.rast, B.rast),
ST_ValueCount(A.rast,1) AS pvc
) as t;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment