Opened 5 years ago

# [raster]: ST_Union that takes 2 rasters

Reported by: Owned by: robe Bborie Park medium PostGIS Fund Me raster trunk

### 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')
```

### comment:1 Changed 5 years ago by Bborie Park

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

### comment:2 Changed 5 years ago by robe

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 3 years ago by robe

Milestone: PostGIS 2.2.0 → PostGIS Future

### comment:4 Changed 18 months ago by robe

Milestone: PostGIS Future → PostGIS Fund Me

Milestone renamed

Note: See TracTickets for help on using tickets.