Opened 4 years ago

Last modified 4 months ago

#2474 new enhancement

[raster]: ST_Union that takes 2 rasters

Reported by: robe Owned by: dustymugs
Priority: medium Milestone: PostGIS Fund Me
Component: raster Version: trunk
Keywords: Cc:

Description

I'm finding myself constantly needing to do a union of just two rasters. So I often end up doing ugly things like

SELECT ST_Union(f.rast)
FROM (SELECT rast
FROM table1 INNER JOIN table2 ON ST_Intersects(table1.rast,1,table2.geom)
WHERE table2.gid =1
UNION ALL 
SELECT ST_AsRaster(somegeom, rast,100)
FROM ST_Intersects(table1.rast,1,table2.geom)
WHERE table2.gid = 1) As f

When all I want to do is this

SELECT ST_Union(rast, ST_AsRaster(somegeom,rast) )
FROM table1 INNER JOIN table2
 ON ST_Intersects(rast,1, table2.geom)
WHERE table2.gid = 1

In theory I could use MapAlgebra? but MapAlgebra? blows my mind with all the permutations of it.

Note geometry has an ST_Union(geom1,geom2) so it would be in line with what we do with geometry already except we'd have an optional expression type

So I'm think the proto would look like

ST_Union(rast1,rast2, expressiontype = 'LAST')

Change History (4)

comment:1 Changed 4 years ago by dustymugs

Based on the ST_Union signature, would the function be unioning all bands of rast1 and rast2?

comment:2 Changed 4 years ago by robe

thinking about this more ST_Union geometry has a ST_Union(geometry[]) array version. http://postgis.net/docs/manual-dev/ST_Union.html

That might be more valuable than ST_Union(rast,rast) if we had a ST_Union(rast[],..)

Because I could do crazy stuff like

ST_Union(ST_Union(ARRAY[rast1,rast2,rast3], 'SUM'), 'MEAN')

Such a case would be useful if I want to convert multiple bands (different themes of same space) to a single band and then group by some division.

comment:3 Changed 2 years ago by robe

Milestone: PostGIS 2.2.0PostGIS Future

comment:4 Changed 4 months ago by robe

Milestone: PostGIS FuturePostGIS Fund Me

Milestone renamed

Note: See TracTickets for help on using tickets.