[postgis-users] raster clipping

Bborie Park bkpark at ucdavis.edu
Fri Jan 27 14:13:32 PST 2012


Hey Steve,

If you don't have ST_Clip on your machine, you may want to update your 
PostGIS to the latest.  ST_Clip with the parameter "trimraster" set to 
TRUE is functionally the equivalent of ST_Intersection.

You may see better performance by doing the ST_Union AFTER 
ST_Clip/ST_Intersection as then you're only unioning the set of 
"intersecting" rasters.

With ST_Intersection, something like the following might work

SELECT
	ST_Union(rast)
FROM (
	SELECT
		ST_Intersection(r.rast, g.geom) AS rast
	FROM myraster r
	JOIN mygeometry g
		ON ST_Intersects(r.rast, g.geom)
	WHERE r.observation_date = '2011-12-01'
) foo
WHERE ST_IsEmpty(rast) = FALSE

-bborie

On 01/27/2012 01:50 PM, Stephen Crawford wrote:
> Hi All,
>
> I'm new to raster queries and i have what should be a simple operation
> but i can't figure it out. I have a tiled raster table for the USA lower
> 48 in a Lambert Conformal Conic (LCC) projection. I would like to clip
> this raster to the USA polygon layer, which is in epsg 4326. Since I
> will want to repeat this process in the future, I went a head and did a
> Union and Transform of the states layer so it is now just one
> multipolygon geometry in the LCC projection. I can't seem to write the
> query to clip the entire raster table and save it into a new table. A
> couple of things to note:
>
> 1)The raster table has a set of tile for each day, so to just see one
> raster for the domain for one day I use:
> SELECT ST_Union(rast) WHERE observation_date = '20111201';
>
> 2) As far as I can tell ST_Clip() is not on my machine; so I was going
> to try it with ST_Intersection
>
> Any help is greatly appreciated.
>
> Thanks,
> Steve
>

-- 
Bborie Park
Programmer
Center for Vectorborne Diseases
UC Davis
530-752-8380
bkpark at ucdavis.edu



More information about the postgis-users mailing list