Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add min/max resampling as options #703

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 28 additions & 7 deletions doc/reference_raster.xml
Expand Up @@ -6844,10 +6844,19 @@ WHERE rid = 2;
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 one of the following resampling algorithms:</para>

<list type="bullet">
<item>NearestNeighbor (english or american spelling)</item>
<item>Bilinear</item>
<item>Cubic</item>
<item>CubicSpline</item>
<item>Lanczos</item>
<item>Max</item>
<item>Min</item>
</list>

<para>The default is NearestNeighbor which is the fastest but results in the worst interpolation.</para>
<para>
A maxerror percent of 0.125 is used if no <varname>maxerr</varname> is specified.
</para>
Expand All @@ -6858,7 +6867,7 @@ WHERE rid = 2;
</para>
</note>
<para>Availability: 2.0.0 Requires GDAL 1.6.1+</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>
<para>Changed: 3.4.0 max and min resampling options added</para>
</refsection>

<refsection>
Expand Down Expand Up @@ -6899,7 +6908,7 @@ FROM (
<refentry id="RT_ST_Rescale">
<refnamediv>
<refname>ST_Rescale</refname>
<refpurpose>Resample a raster by adjusting only its scale (or pixel size). New pixel values are computed using the NearestNeighbor (english or american spelling), Bilinear, Cubic, CubicSpline or Lanczos resampling algorithm. Default is NearestNeighbor.
<refpurpose>Resample a raster by adjusting only its scale (or pixel size). New pixel values are computed using the NearestNeighbor (english or american spelling), Bilinear, Cubic, CubicSpline, Lanczos, Max or Min resampling algorithm. Default is NearestNeighbor.
</refpurpose>
</refnamediv>

Expand Down Expand Up @@ -6928,7 +6937,19 @@ FROM (
<refsection>
<title>Description</title>

<para>Resample a raster by adjusting only its scale (or pixel size). New pixel values are computed using the NearestNeighbor (english or american spelling), Bilinear, Cubic, CubicSpline or Lanczos resampling algorithm. The default is NearestNeighbor which is the fastest but results in the worst interpolation.</para>
<para>Resample a raster by adjusting only its scale (or pixel size). New pixel values are computed using one of the following resampling algorithms:</para>

<list type="bullet">
<item>NearestNeighbor (english or american spelling)</item>
<item>Bilinear</item>
<item>Cubic</item>
<item>CubicSpline</item>
<item>Lanczos</item>
<item>Max</item>
<item>Min</item>
</list>

<para>The default is NearestNeighbor which is the fastest but results in the worst interpolation.</para>

<para><varname>scalex</varname> and <varname>scaley</varname> define the new pixel size. scaley must often be negative to get well oriented raster.</para>

Expand All @@ -6941,7 +6962,7 @@ FROM (
<note><para>ST_Rescale is different from <xref linkend="RT_ST_SetScale" /> in that ST_SetScale do not resample the raster to match the raster extent. ST_SetScale only changes the metadata (or georeference) of the raster to correct an originally mis-specified scaling. ST_Rescale results in a raster having different width and height computed to fit the geographic extent of the input raster. ST_SetScale do not modify the width, nor the height of the raster.</para></note>

<para>Availability: 2.0.0 Requires GDAL 1.6.1+</para>
<para>Changed: 2.1.0 Works on rasters with no SRID</para>
<para>Changed: 3.4.0 max and min resampling options added</para>
</refsection>

<refsection>
Expand Down
5 changes: 4 additions & 1 deletion raster/rt_core/rt_util.c
Expand Up @@ -106,7 +106,10 @@ rt_util_gdal_resample_alg(const char *algname) {
return GRA_Cubic;
else if (strcmp(algname, "LANCZOS") == 0)
return GRA_Lanczos;

else if (strcmp(algname, "MAX") == 0)
return GRA_Max;
else if (strcmp(algname, "MIN") == 0)
return GRA_Min;
return GRA_NearestNeighbour;
}

Expand Down
30 changes: 29 additions & 1 deletion raster/test/regress/rt_gdalwarp.sql
Expand Up @@ -434,7 +434,23 @@ INSERT INTO raster_gdalwarp_dst (rid, rast) VALUES (
NULL::raster,
FALSE
) FROM raster_gdalwarp_src)
);
), (
1.26, (SELECT ST_Resample(
rast,
500., 500.,
NULL, NULL,
0, 0,
'Max', 0
) FROM raster_gdalwarp_src)
), (
1.27, (SELECT ST_Resample(
rast,
500., 500.,
NULL, NULL,
0, 0,
'Min', 0
) FROM raster_gdalwarp_src)
), ;

-- ST_Transform
INSERT INTO raster_gdalwarp_dst (rid, rast) VALUES (
Expand Down Expand Up @@ -547,6 +563,18 @@ INSERT INTO raster_gdalwarp_dst (rid, rast) VALUES (
150, 125,
'Cubic'
) FROM raster_gdalwarp_src)
), (
3.7, (SELECT ST_Rescale(
rast,
150, 125,
'Max', 0
) FROM raster_gdalwarp_src)
), (
3.8, (SELECT ST_Rescale(
rast,
150, 125,
'Min', 0
) FROM raster_gdalwarp_src)
);

-- ST_Reskew
Expand Down