<refentry id="RT_ST_Resample">
<refnamediv>
<refname>ST_Resample</refname>
- <refpurpose>Resample a raster using a specified resampling algorithm, new dimensions, an arbitrary grid corner and a set of raster georeferencing attributes defined or borrowed from another raster. New pixel values are computed using the NearestNeighbor (English or American spelling), Bilinear, Cubic, CubicSpline or Lanczos resampling algorithm. Default is NearestNeighbor.</refpurpose>
+ <refpurpose>
+ Resample a raster using a specified resampling algorithm, new dimensions, an arbitrary grid corner and a set of raster georeferencing attributes defined or borrowed from another raster.
+ </refpurpose>
</refnamediv>
<refsynopsisdiv>
<refsection>
<title>Description</title>
- <para>Resample a raster using a specified resampling algorithm, new dimensions (width & height), a grid corner (gridx & gridy) and a set of raster georeferencing attributes (scalex, scaley, skewx & skewy) defined or borrowed from another raster.</para>
+ <para>
+ Resample a raster using a specified resampling algorithm, new dimensions (width & height), a grid corner (gridx & gridy) and a set of raster georeferencing attributes (scalex, scaley, skewx & skewy) defined or borrowed from another raster. If using a reference raster, the two rasters must have the same SRID.
+ </para>
- <para>New pixel values are computed using the NearestNeighbor (English or American spelling), Bilinear, Cubic, CubicSpline or Lanczos resampling algorithm. Default is NearestNeighbor which is the fastest but produce the worst interpolation.</para>
+ <para>
+ New pixel values are computed using the NearestNeighbor (English or American spelling), Bilinear, Cubic, CubicSpline or Lanczos resampling algorithm. Default is NearestNeighbor which is the fastest but produce the worst interpolation.
+ </para>
- <para>A maxerror percent of 0.125 is used if no <varname>maxerr</varname> is specified.</para>
+ <para>
+ A maxerror percent of 0.125 is used if no <varname>maxerr</varname> is specified.
+ </para>
- <note><para>Refer to: <ulink url="http://www.gdal.org/gdalwarp.html">GDAL Warp resampling methods</ulink> for more details.</para></note>
+ <note>
+ <para>
+ Refer to: <ulink url="http://www.gdal.org/gdalwarp.html">GDAL Warp resampling methods</ulink> for more details.
+ </para>
+ </note>
<para>Availability: 2.0.0 Requires GDAL 1.6.1+</para>
- <para>Changed: 2.1.0 Parameter srid removed. Use ST_Transform() to reproject raster. Works on rasters with no SRID.</para>
+ <para>Changed: 2.1.0 Parameter srid removed. Variants with a reference raster no longer applies the reference raster's SRID. Use ST_Transform() to reproject raster. Works on rasters with no SRID.</para>
</refsection>
<refsection>
RETURNS raster
AS $$
DECLARE
- dim_x int;
- dim_y int;
- scale_x double precision;
- scale_y double precision;
- grid_x double precision;
- grid_y double precision;
- skew_x double precision;
- skew_y double precision;
+ rastsrid int;
+
+ _srid int;
+ _dimx int;
+ _dimy int;
+ _scalex double precision;
+ _scaley double precision;
+ _gridx double precision;
+ _gridy double precision;
+ _skewx double precision;
+ _skewy double precision;
BEGIN
- SELECT width, height, scalex, scaley, upperleftx, upperlefty, skewx, skewy INTO dim_x, dim_y, scale_x, scale_y, grid_x, grid_y, skew_x, skew_y FROM st_metadata($2);
+ SELECT srid, width, height, scalex, scaley, upperleftx, upperlefty, skewx, skewy INTO _srid, _dimx, _dimy, _scalex, _scaley, _gridx, _gridy, _skewx, _skewy FROM st_metadata($2);
+
+ rastsrid := ST_SRID($1);
+
+ -- both rasters must have the same SRID
+ IF (rastsrid != _srid) THEN
+ RAISE EXCEPTION 'The raster to be resampled has a different SRID from the reference raster';
+ RETURN NULL;
+ END IF;
IF usescale IS TRUE THEN
- dim_x := NULL;
- dim_y := NULL;
+ _dimx := NULL;
+ _dimy := NULL;
ELSE
- scale_x := NULL;
- scale_y := NULL;
+ _scalex := NULL;
+ _scaley := NULL;
END IF;
- RETURN _st_gdalwarp($1, $3, $4, NULL, scale_x, scale_y, grid_x, grid_y, skew_x, skew_y, dim_x, dim_y);
+ RETURN _st_gdalwarp($1, $3, $4, NULL, _scalex, _scaley, _gridx, _gridy, _skewx, _skewy, _dimx, _dimy);
END;
$$ LANGUAGE 'plpgsql' STABLE STRICT;