Database Reference
In-Depth Information
Warping and resampling rasters
Inthepreviousrecipe,weprocessedaMODISrastertoextractonlythosesubdata-
setsthatareofinterest,inamoresuitableorder.Oncedonewiththeextraction,we
imported the MODIS raster into its own table.
Here,wemakeuseofthewarpingcapabilitiesprovidedinPostGIS.Thisrangesfrom
simply transforming the MODIS raster to a more suitable projection to creating an
overview by resampling the pixel size.
Getting ready
We will use several PostGIS warping functions, specifically
ST_Transform()
and
ST_Rescale()
.The
ST_Transform()
functionreprojectsarastertoanewspatial
referencesystem(forexample,fromWGS84toNAD83).The
ST_Rescale()
func-
tion shrinks or grows the pixel size of a raster.
How to do it...
The first thing we will do is transform our raster since the MODIS rasters have their
ownuniquespatial-referencesystem.Wewillconverttherasterfrom
MODIS Sinus-
oidal projection
to
US National Atlas Equal Area (SRID 2163)
.
Beforewetransformtheraster,wewillcliptheMODISrasterwithourSanFrancisco
boundaries geometry. By clipping our raster before transformation, the operation
takes less time than it does to transform and then clip the raster.
SELECT ST_Transform(ST_Clip(m.rast,
ST_Transform(sf.geom, 96974)), 2163)
FROM modis m
CROSS JOIN sfpoly sf;
The following screenshot shows the clipped MODIS raster with the San Francisco
boundaries on top for comparison: