postgis/doc/reference_raster.xml

5246 lines
199 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<chapter id="RT_reference">
<title>Raster Reference</title>
<para>The functions given below are the ones which a user of PostGIS Raster is
likely to need and which are currently available in PostGIS Raster. There are other functions which are required support
functions to the raster objects which are not of use to a general
user.</para>
<para><varname>raster</varname> is a new PostGIS type for storing and analyzing raster data. </para>
<para>For more information about Raster, please refer to <ulink url="http://trac.osgeo.org/postgis/wiki/WKTRaster">PostGIS Raster Home Page</ulink>.</para>
<sect1 id="RT_Loading_Rasters">
<title>Loading and Creating Rasters</title>
<para>For most use cases, you will create PostGIS rasters by loading existing raster files using the packaged <varname>raster2pgsql</varname> raster loader.</para>
<para>
The <varname>raster2pgsql.py</varname> is a raster loader python script that utilizes Python, PyGDAL, and NumPy to convert any GDAL supported raster format into sql suitable for loading into a PostGIS raster table.
It is capable of loading folders of raster files as well as creating overviews of rasters. More usage examples can be found at <ulink url="http://trac.osgeo.org/gdal/wiki/frmts_wtkraster.html">GDAL PostGIS Raster Driver Usage</ulink>
</para>
<variablelist>
<varlistentry>
<term>--help, -h</term>
<listitem>
<para>
Display help screen.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>(c|a|d) These are mutually exclusive options:</term>
<listitem>
<para>
<variablelist>
<varlistentry>
<term>-c</term>
<listitem>
<para>
Create new table and populate it with raster(s), <emphasis>this is the default mode</emphasis>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-a</term>
<listitem>
<para>
Append raster(s) to an existing table.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-d</term>
<listitem>
<para>
Drop table, create new one and populate it with raster(s)
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-o OUTPUT, --output=OUTPUT</term>
<listitem><para>Specify output file, otherwise send to stdout.</para></listitem>
</varlistentry>
<varlistentry>
<term>--version</term>
<listitem>
<para>
Shows program version
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Mandatory parameters:</term>
<listitem>
<para>
<variablelist>
<varlistentry>
<term>-r RASTER, --raster=RASTER</term>
<listitem>
<para>
Append raster to list of input files, at least one raster file required. You may use wildcards (?,*) for specifying multiple files.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term> -t TABLE, --table=TABLE</term>
<listitem>
<para>
Raster destination in form of [&lt;schema&gt;.]&lt;table&gt; or base raster table for overview level>1, required
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Raster processing: Optional parameters used to manipulate input raster dataset</term>
<listitem>
<para>
<variablelist>
<varlistentry>
<term>-s &lt;SRID&gt;</term>
<listitem>
<para>
Assign output raster with specified SRID.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-b BAND, --band=BAND</term>
<listitem>
<para>
Specify number of band to be extracted from raster. If not specified all bands are added.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-k BLOCK_SIZE, --block-size=BLOCK_SIZE</term>
<listitem>
<para>Cut raster(s) into tiles to be inserted one by table row.BLOCK_SIZE is expressed as WIDTHxHEIGHT. Incomplete tiles are completed with nodata values.</para>
<para>Each tile is stored as a separate record in the raster table. If no block size is specified, then each raster file is brought in as an individual record.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-R, --register</term>
<listitem>
<para>Register the raster as a filesystem (out-db) raster.</para>
<para>Only the metadata of the raster and path location to the raster is stored in the database (not the pixels).</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-l OVERVIEW_LEVEL, --overview-level=OVERVIEW_LEVEL</term>
<listitem><para> create overview tables named as
o_&lt;LEVEL&gt;_&lt;RASTER_TABLE&gt; and populate with GDAL-provided overviews (regular blocking only)</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Optional parameters used to manipulate database objects</term>
<listitem>
<para>
<variablelist>
<varlistentry>
<term>-f COLUMN, --field=COLUMN</term>
<listitem>
<para>Specify name of destination raster column, default is 'rast'
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-F, --filename</term>
<listitem>
<para>Add a column with the name of the file</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-I</term>
<listitem>
<para>
Create a GiST index on the raster column.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-M, --vacuum</term>
<listitem>
<para>
Vacuum analyze the raster table.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-V, --create-raster-overviews</term>
<listitem>
<para>Create RASTER_OVERVIEWS table used to store overviews metadata.</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-e ENDIAN, --endian=ENDIAN</term>
<listitem><para>Control endianness of generated binary output of raster; specify 0 for XDR and 1 for NDR (default); only NDR output is supported now</para></listitem>
</varlistentry>
<varlistentry>
<term>-v, --verbose</term>
<listitem><para>Specify output file, otherwise send to stdout verbose mode. Useful for debugging</para></listitem>
</varlistentry>
</variablelist>
<para>An example session using the loader to create an input file and uploading it might look like this:</para>
<programlisting>python raster2pgsql.py -s 4269 -I -r *.tif -F myschema.demelevation -o elev.sql
psql -d gisdb -f elev.sql</programlisting>
<para>A conversion and upload can be done all in one step using UNIX pipes:</para>
<programlisting>python raster2pgsql.py -s 4269 -I -r *.tif -F myschema.demelevation | psql -d gisdb</programlisting>
<para>For the examples in this reference we will be using a raster table of dummy rasters - Formed with the following code </para>
<programlisting>CREATE TABLE dummy_rast(rid integer, rast raster);
INSERT INTO dummy_rast(rid, rast)
VALUES (1,
('01' -- little endian (uint8 ndr)
||
'0000' -- version (uint16 0)
||
'0000' -- nBands (uint16 0)
||
'0000000000000040' -- scaleX (float64 2)
||
'0000000000000840' -- scaleY (float64 3)
||
'000000000000E03F' -- ipX (float64 0.5)
||
'000000000000E03F' -- ipY (float64 0.5)
||
'0000000000000000' -- skewX (float64 0)
||
'0000000000000000' -- skewY (float64 0)
||
'00000000' -- SRID (int32 0)
||
'0A00' -- width (uint16 10)
||
'1400' -- height (uint16 20)
)::raster
),
-- Raster: 5 x 5 pixels, 3 bands, PT_8BUI pixel type, NODATA = 0
(2, ('01000003009A9999999999A93F9A9999999999A9BF000000E02B274A' ||
'41000000007719564100000000000000000000000000000000FFFFFFFF050005000400FDFEFDFEFEFDFEFEFDF9FAFEF' ||
'EFCF9FBFDFEFEFDFCFAFEFEFE04004E627AADD16076B4F9FE6370A9F5FE59637AB0E54F58617087040046566487A1506CA2E3FA5A6CAFFBFE4D566DA4CB3E454C5665')::raster);</programlisting>
</sect1>
<sect1 id="Raster_Types">
<title>Raster Support Data types</title>
<sect1info>
<abstract>
<para>This section lists the PostgreSQL data types specifically created to support raster functionality.</para>
</abstract>
</sect1info>
<refentry id="geomval">
<refnamediv>
<refname>geomval</refname>
<refpurpose>A spatial datatype with two fields - geom (holding a geometry object)
and val (holding a double precision pixel value from a raster band)</refpurpose>
</refnamediv>
<refsection>
<title>Description</title>
<para>geomval is a compound data type consisting of a geometry object referenced by the .geom field
and val, a double precision value that represents the pixel value at a particular geometric location in a raster band.
It is used by the ST_DumpAsPolygon and Raster intersection family of functions as an output type to explode a raster band into
geometry polygons.</para>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="PostGIS_Geometry_DumpFunctions" /> </para>
</refsection>
</refentry>
<refentry id="histogram">
<refnamediv>
<refname>histogram</refname>
<refpurpose>A composite type used as record output of the ST_Histogram and ST_ApproxHistogram functions. </refpurpose>
</refnamediv>
<refsection>
<title>Description</title>
<para>A composite type used as record outputs of the <xref linkend="RT_ST_Histogram" /> <varname>ST_ApproxHistogram</varname> functions. Note that depending on <varname>exclude_nodata_value</varname> of function, may or may not contain nodata pixels.</para>
<para>Each histogram record in results corresponds to a bin for a selected raster band.</para>
<variablelist>
<varlistentry>
<term><parameter>min </parameter><type>double precision</type></term>
<listitem><para>minimum pixel value in this bin</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>max </parameter><type>double precision</type></term>
<listitem><para>Maximum pixel value in this bin.</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>count </parameter><type>integer</type></term>
<listitem><para>count of pixels in this bin.</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>percent </parameter><type>double precision</type></term>
<listitem><para>Percent of pixels of the overall population in this bin.</para></listitem>
</varlistentry>
</variablelist>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_Histogram" /></para>
</refsection>
</refentry>
<refentry id="raster">
<refnamediv>
<refname>raster</refname>
<refpurpose>raster spatial data type.</refpurpose>
</refnamediv>
<refsection>
<title>Description</title>
<para>raster is a spatial data type used to represent raster data such as those imported from jpegs, tiffs, pngs, digital elevation models.
Each raster has 1 or more bands each having a set of pixel values. Rasters can be georeferenced.</para>
<note>
<para>Requires PostGIS be compiled with GDAL support. Currently rasters can be implicitly converted to geometry type, but the conversion returns the
<xref linkend="RT_ST_ConvexHull" /> of the raster. This auto casting may be removed in the near future so don't rely on it.</para>
</note>
</refsection>
<refsection>
<title>Casting Behavior</title>
<para>This section lists the automatic as well as explicit casts allowed for this data type</para>
<informaltable rowsep="1" frame="all">
<tgroup cols="2">
<tbody>
<row>
<entry>Cast To</entry>
<entry>Behavior</entry>
</row>
<row>
<entry>geometry</entry>
<entry>automatic</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_reference" /></para>
</refsection>
</refentry>
<refentry id="reclassarg">
<refnamediv>
<refname>reclassarg</refname>
<refpurpose>A composite type used as input into the ST_Reclass function defining the behavior of reclassification.</refpurpose>
</refnamediv>
<refsection>
<title>Description</title>
<para>A composite type used as input into the ST_Reclass function defining the behavior of reclassification.</para>
<variablelist>
<varlistentry>
<term><parameter>nband </parameter><type>integer</type></term>
<listitem><para>The band number of band to reclassify.</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>reclassexpr </parameter><type>text</type></term>
<listitem><para>range expression consisting of comma delimited range:map_range mappings. : to define mapping that defines how to map old band values to new band values. ( means &gt;, ) means less than, ] &lt; or equal, [ means &gt; or equal</para>
<para><programlisting>1. [a-b] = a &lt;= x &lt;= b
2. (a-b] = a &lt; x &lt;= b
3. [a-b) = a &lt;= x &lt; b
4. (a-b) = a &lt; x &lt; b</programlisting></para>
<para>( notation is optional so a-b means the same as (a-b)</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>pixeltype </parameter><type>text</type></term>
<listitem><para>One of defined pixel types as described in <xref linkend="RT_ST_BandPixelType" /></para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>nodataval </parameter><type>double precision</type></term>
<listitem><para>Value to treat as no data. For image outputs that support transparency, these will be blank.</para></listitem>
</varlistentry>
</variablelist>
</refsection>
<refsection>
<title>Example: Reclassify band 2 as an 8BUI where 255 is nodata value</title>
<programlisting>SELECT ROW(2, '0-100:1-10, 101-500:11-150,501 - 10000: 151-254', '8BUI', 255)::reclassarg;</programlisting>
</refsection>
<refsection>
<title>Example: Reclassify band 1 as an 1BB and no nodata value defined</title>
<programlisting>SELECT ROW(1, '0-100]:0, (100-255:1', '1BB', NULL)::reclassarg;</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_Reclass" /></para>
</refsection>
</refentry>
<refentry id="summarystats">
<refnamediv>
<refname>summarystats</refname>
<refpurpose>A composite type used as output of the ST_SummaryStats function.</refpurpose>
</refnamediv>
<refsection>
<title>Description</title>
<para>A composite type used as output the <varname>ST_SummaryStats</varname> function. Note that depending on <varname>exclude_nodata_value</varname> of function, may or may not contain nodata pixels.</para>
<variablelist>
<varlistentry>
<term><parameter>count </parameter><type>bigint</type></term>
<listitem><para>count of pixels in raster band. Depending on arguments may or many not include nodata pixel values.</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>sum </parameter><type>double precision</type></term>
<listitem><para>sum of all pixel values in band</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>mean </parameter><type>double precision</type></term>
<listitem><para>Mean of pixel values</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>stddev </parameter><type>double precision</type></term>
<listitem><para>Standard deviation of pixel values.</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>min </parameter><type>double precision</type></term>
<listitem><para>Minimum pixel value</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>max </parameter><type>double precision</type></term>
<listitem><para>Maximum pixel value</para></listitem>
</varlistentry>
</variablelist>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_SummaryStats" /></para>
</refsection>
</refentry>
</sect1>
<sect1 id="Raster_Management_Functions">
<title>Raster Management Functions</title>
<refentry id="RT_AddRasterColumn">
<refnamediv>
<refname>AddRasterColumn</refname>
<refpurpose>Adds a raster column to an existing table and generates column constraint on the new column to enforce srid.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>AddRasterColumn</function></funcdef>
<paramdef><type>varchar </type>
<parameter>table_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>column_name</parameter></paramdef>
<paramdef><type>integer </type>
<parameter>srid</parameter></paramdef>
<paramdef><type>varchar[] </type>
<parameter>pixel_types</parameter></paramdef>
<paramdef><type>boolean </type>
<parameter>out_db</parameter></paramdef>
<paramdef><type>boolean </type>
<parameter>regular_blocking</parameter></paramdef>
<paramdef><type>double precision[] </type>
<parameter>no_data_values</parameter></paramdef>
<paramdef><type>double precision </type>
<parameter>scale_x</parameter></paramdef>
<paramdef><type>double precision </type>
<parameter>scale_y</parameter></paramdef>
<paramdef><type>integer </type>
<parameter>blocksize_x</parameter></paramdef>
<paramdef><type>integer </type>
<parameter>blocksize_y</parameter></paramdef>
<paramdef><type>geometry </type>
<parameter>envelope</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>AddRasterColumn</function></funcdef>
<paramdef><type>varchar </type>
<parameter>schema_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>table_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>column_name</parameter></paramdef>
<paramdef><type>integer </type>
<parameter>srid</parameter></paramdef>
<paramdef><type>varchar[] </type>
<parameter>pixel_types</parameter></paramdef>
<paramdef><type>boolean </type>
<parameter>out_db</parameter></paramdef>
<paramdef><type>boolean </type>
<parameter>regular_blocking</parameter></paramdef>
<paramdef><type>double precision[] </type>
<parameter>no_data_values</parameter></paramdef>
<paramdef><type>double precision </type>
<parameter>scale_x</parameter></paramdef>
<paramdef><type>double precision </type>
<parameter>scale_y</parameter></paramdef>
<paramdef><type>integer </type>
<parameter>blocksize_x</parameter></paramdef>
<paramdef><type>integer </type>
<parameter>blocksize_y</parameter></paramdef>
<paramdef><type>geometry </type>
<parameter>envelope</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>AddRasterColumn</function></funcdef>
<paramdef><type>varchar </type>
<parameter>catalog_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>schema_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>table_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>column_name</parameter></paramdef>
<paramdef><type>integer </type>
<parameter>srid</parameter></paramdef>
<paramdef><type>varchar[] </type>
<parameter>pixel_types</parameter></paramdef>
<paramdef><type>boolean </type>
<parameter>out_db</parameter></paramdef>
<paramdef><type>boolean </type>
<parameter>regular_blocking</parameter></paramdef>
<paramdef><type>double precision[] </type>
<parameter>no_data_values</parameter></paramdef>
<paramdef><type>double precision </type>
<parameter>scale_x</parameter></paramdef>
<paramdef><type>double precision </type>
<parameter>scale_y</parameter></paramdef>
<paramdef><type>integer </type>
<parameter>blocksize_x</parameter></paramdef>
<paramdef><type>integer </type>
<parameter>blocksize_y</parameter></paramdef>
<paramdef><type>geometry </type>
<parameter>envelope</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Adds a raster column to an existing table and also generates constraints on the new column. Currently only constrains the <varname>SRID</varname>.
The <varname>schema_name</varname> is the name of the table schema (unused
for pre-schema PostgreSQL installations). The <varname>srid</varname>
must be an integer value reference to an entry in the SPATIAL_REF_SYS
table. The <varname>pixel_types</varname> must be an array of pixel types as described in <xref linkend="RT_ST_BandPixelType" />, one for each band.
An error is thrown if the schemaname doesn't exist
(or not visible in the current search_path) or the specified SRID,
pixel types are invalid.</para>
<para><varname>raster2pgsql.py</varname> loader uses this function to register raster tables</para>
<note>
<para>Views and derivatively created spatial tables will need to be registered in raster_columns manually,
since AddRasterColumn also adds a raster column which is not needed when you already have a raster column.
</para>
</note>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT AddRasterColumn('public', 'myrasters', 'rast',4326,
'{8BUI,8BUI,8BUI,8BUI}',
false, true, '{255,255,255,255}', 0.25,-0.25,200,300, null);
public.myrasters.rast
srid:4326 pixel_types:{8BUI,8BUI,8BUI,8BUI}
out_db:false
regular_blocking:true
nodata_values:'{255,255,255,255}'
scale_x:'0.25'
scale_y:'-0.25' blocksize_x:'200' blocksize_y:'300' extent:NULL
--- After loading the data, you can currect the geometry column
UPDATE raster_columns SET extent = (SELECT ST_Union(ST_Envelope(rast)) FROM myrasters)
WHERE r_table_schema = 'public'
AND r_table_name = 'myrasters'
AND r_column = 'rast';
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="AddGeometryColumn"/>, <xref linkend="RT_DropRasterTable"/>, <xref linkend="RT_DropRasterColumn"/>, <xref linkend="RT_ST_BandPixelType" />, <xref linkend="RT_ST_SRID" /></para>
</refsection>
</refentry>
<refentry id="RT_DropRasterColumn">
<refnamediv>
<refname>DropRasterColumn</refname>
<refpurpose>Removes a raster column from a table.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>DropRasterColumn</function></funcdef>
<paramdef><type>varchar </type>
<parameter>table_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>column_name</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>DropRasterColumn</function></funcdef>
<paramdef><type>varchar </type>
<parameter>schema_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>table_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>column_name</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>DropRasterColumn</function></funcdef>
<paramdef><type>varchar </type>
<parameter>catalog_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>schema_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>table_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>column_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Removes a raster column from a table. Note that
schema_name will need to match the r_table_schema field of the table's
row in the raster_columns table.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
SELECT DropRasterColumn ('my_schema','my_raster_table','rast');
----RESULT output ---
my_schema.my_raster_table.rast effectively removed.
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_AddRasterColumn"/>, <xref linkend="RT_DropRasterTable"/></para>
</refsection>
</refentry>
<refentry id="RT_DropRasterTable">
<refnamediv>
<refname>DropRasterTable</refname>
<refpurpose>Drops a table and all its references in
raster_columns.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>DropRasterTable</function></funcdef>
<paramdef><type>varchar </type>
<parameter>table_name</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>DropRasterTable</function></funcdef>
<paramdef><type>varchar </type>
<parameter>schema_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>table_name</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>DropRasterTable</function></funcdef>
<paramdef><type>varchar </type>
<parameter>catalog_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>schema_name</parameter></paramdef>
<paramdef><type>varchar </type>
<parameter>table_name</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Drops a table and all its references in raster_columns. Note:
uses current_schema() on schema-aware pgsql installations if schema is
not provided.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
SELECT DropRasterTable ('my_schema','my_raster_table');
----RESULT output ---
my_schema.my_raster_table dropped.
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_AddRasterColumn"/>, <xref linkend="RT_DropRasterColumn"/></para>
</refsection>
</refentry>
<refentry id="RT_PostGIS_Raster_Lib_Build_Date">
<refnamediv>
<refname>PostGIS_Raster_Lib_Build_Date</refname>
<refpurpose>Reports full raster library build date</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>PostGIS_Raster_Lib_Build_Date</function></funcdef>
<paramdef></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Reports raster build date</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT PostGIS_Raster_Lib_Build_Date();
postgis_raster_lib_build_date
-----------------------------
2010-04-28 21:15:10
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para> <xref linkend="RT_PostGIS_Raster_Lib_Version" /></para>
</refsection>
</refentry>
<refentry id="RT_PostGIS_Raster_Lib_Version">
<refnamediv>
<refname>PostGIS_Raster_Lib_Version</refname>
<refpurpose>Reports full raster version and build configuration
infos.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>PostGIS_Raster_Lib_Version</function></funcdef>
<paramdef></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Reports full raster version and build configuration
infos.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT PostGIS_Raster_Lib_Version();
postgis_raster_lib_version
-----------------------------
0.1.6d
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para> <xref
linkend="PostGIS_Lib_Version" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_GDALDrivers">
<refnamediv>
<refname>ST_GDALDrivers</refname>
<refpurpose>Returns a list of raster formats supported by your lib gdal. These are the formats you can output your raster using ST_AsGDALRaster.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>setof record <function>ST_GDALDrivers</function></funcdef>
<paramdef><type>integer </type> <parameter>OUT idx</parameter></paramdef>
<paramdef><type>text </type> <parameter>OUT short_name</parameter></paramdef>
<paramdef><type>text </type> <parameter>OUT long_name</parameter></paramdef>
<paramdef><type>text </type> <parameter>OUT create_options</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns a list of raster formats short_name,long_name and creator options of each format supported by your lib gdal. Use the short_name as input in the <varname>format</varname> parameter of <xref linkend="RT_ST_AsGDALRaster" />.
Options vary depending on what drivers your libgdal was compiled with. <varname>create_options</varname> returns and xml formatted list of create_options for the specific driver.</para>
<para>Availability: 2.0.0 - requires GDAL &gt;= 1.6.0. </para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT short_name, long_name
FROM st_gdaldrivers()
ORDER BY short_name;
short_name | long_name
----------------+--------------------------------------
AAIGrid | Arc/Info ASCII Grid
DTED | DTED Elevation Raster
EHdr | ESRI .hdr Labelled
FIT | FIT Image
GIF | Graphics Interchange Format (.gif)
GSAG | Golden Software ASCII Grid (.grd)
GSBG | Golden Software Binary Grid (.grd)
GTiff | GeoTIFF
HF2 | HF2/HFZ heightfield raster
HFA | Erdas Imagine Images (.img)
ILWIS | ILWIS Raster Map
INGR | Intergraph Raster
JPEG | JPEG JFIF
KMLSUPEROVERLAY | Kml Super Overlay
NITF | National Imagery Transmission Format
PNG | Portable Network Graphics
R | R Object Data Store
SAGA | SAGA GIS Binary Grid (.sdat)
SRTMHGT | SRTMHGT File Format
USGSDEM | USGS Optional ASCII DEM (and CDED)
VRT | Virtual Raster
XPM | X11 PixMap Format
</programlisting>
<programlisting>-- Output the create options XML column of Geo Tiff as a table --
-- Note you can use these creator options in ST_AsGDALRaster options argument
SELECT unnest(xpath('/CreationOptionList/Option/@name', create_options::xml)) As opt_name,
unnest(xpath('/CreationOptionList/Option/@description', create_options::xml)) As opt_descrip
FROM st_gdaldrivers()
WHERE short_name = 'GTiff';
opt_name | opt_descrip
--------------------+----------------------------------------------------------------------
COMPRESS | Predictor Type
PREDICTOR | JPEG quality 1-100
JPEG_QUALITY | DEFLATE compression level 1-9
ZLEVEL | BITS for sub-byte files (1-7), sub-uint16 (9-15), sub-uint 32 (17-31)
NBITS | Switch to tiled format
INTERLEAVE | Write out world file
TILED | Write out .RPB (RPC) file
TFW | Tile Width
RPB | Tile/Strip Height
BLOCKXSIZE | Can newly created files have missing blocks?
BLOCKYSIZE | Mark first extrasample as being alpha
PHOTOMETRIC | Force creation of BigTIFF file
SPARSE_OK | Force endianness of created file. For DEBUG purpose mostly
ALPHA | Force copy of overviews of source dataset (CreateCopy())
PROFILE | Predictor Type
PIXELTYPE | JPEG quality 1-100
:
:
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_AsGDALRaster" /></para>
</refsection>
</refentry>
</sect1>
<sect1 id="Raster_Constructors">
<title>Raster Constructors</title>
<refentry id="RT_ST_MakeEmptyRaster">
<refnamediv>
<refname>ST_MakeEmptyRaster</refname>
<refpurpose>Returns an empty raster (having no bands) of given dimensions, with upperleft x y, pixel size expressed as scalex, scaley, skewx, skewy and reference system (srid).
If a raster is passed in, returns a new raster with same meta data properties.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>raster <function>ST_MakeEmptyRaster</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_MakeEmptyRaster</function></funcdef>
<paramdef><type>integer </type> <parameter>width</parameter></paramdef>
<paramdef><type>integer </type> <parameter>height</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>upperleftx</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>upperlefty</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>scalex</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>scaley</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>skewx</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>skewy</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_MakeEmptyRaster</function></funcdef>
<paramdef><type>integer </type> <parameter>width</parameter></paramdef>
<paramdef><type>integer </type> <parameter>height</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>upperleftx</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>upperlefty</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>scalex</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>scaley</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>skewx</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>skewy</parameter></paramdef>
<paramdef><type>integer </type> <parameter>srid</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_MakeEmptyRaster</function></funcdef>
<paramdef><type>integer </type> <parameter>width</parameter></paramdef>
<paramdef><type>integer </type> <parameter>height</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>upperleftx</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>upperlefty</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>pixelsize</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns an empty raster (having no band) of given dimensions (width &amp; height) and georeferenced in spatial (or world) coordinates with upper left x (upperleftx), upper left y (upperlefty),
pixel size expressed as scalex, scaley, skewx, skewy and reference system (srid).
The last version use a single parameter to specify the pixel size (pixelsize).
In this case scalex and scaley are set to this parameter and skewx and skewy are set to 0.
If an existing raster is passed in, it returns a new raster with the same meta data settings (without the bands). </para>
<para>If no srid is specified it defaults to -1, though this may change to 0 in future. After you create an empty raster you probably want to add bands to it and maybe edit it. Refer to <xref linkend="RT_ST_AddBand" /> to define bands and <xref linkend="RT_ST_SetValue" /> to set pixel values.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
INSERT INTO dummy_rast(rid,rast)
VALUES(3, ST_MakeEmptyRaster( 100, 100, 0.0005, 0.0005, 1, 1, 0, 0, 4326) );
--use an existing raster as template for new raster
INSERT INTO dummy_rast(rid,rast)
SELECT 4, ST_MakeEmptyRaster(rast)
FROM dummy_rast WHERE rid = 3;
-- output meta data of rasters we just added
SELECT rid, (md).*
FROM (SELECT rid, ST_MetaData(rast) As md
FROM dummy_rast
WHERE rid IN(3,4)) As foo;
-- output --
rid | upperleftx | upperlefty | width | height | scalex | scaley | skewx | skewy | srid | numbands
-----+------------+------------+-------+--------+------------+------------+-------+-------+------+----------
3 | 0.0005 | 0.0005 | 100 | 100 | 1 | 1 | 0 | 0 | 4326 | 0
4 | 0.0005 | 0.0005 | 100 | 100 | 1 | 1 | 0 | 0 | 4326 | 0
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_AddBand" />, <xref linkend="RT_ST_MetaData" />, <xref linkend="RT_ST_ScaleX" />, <xref linkend="RT_ST_ScaleY" />, <xref linkend="RT_ST_SetValue" />, <xref linkend="RT_ST_SkewX" />, , <xref linkend="RT_ST_SkewY" /></para>
</refsection>
</refentry>
</sect1>
<sect1 id="Raster_Accessors">
<title>Raster Accessors</title>
<refentry id="RT_ST_GeoReference">
<refnamediv>
<refname>ST_GeoReference</refname>
<refpurpose>Returns the georeference meta data in GDAL or ESRI format as commonly seen in a world file. Default is GDAL.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>ST_GeoReference</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>ST_GeoReference</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>text </type> <parameter>format</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the georeference meta data including carriage return in GDAL or ESRI format as commonly seen in a <ulink url="http://en.wikipedia.org/wiki/World_file">world file</ulink>. Default is GDAL if no type specified. type is string 'GDAL' or 'ESRI'.
</para>
<para>Difference between format representations is as follows:</para>
<para><varname>GDAL</varname>:
<programlisting>scalex
skewy
skewx
scaley
upperleftx
upperlefty</programlisting></para>
<para><varname>ESRI</varname>:
<programlisting>scalex
skewy
skewx
scaley
upperleftx + scalex*0.5
upperlefty + scaley*0.5</programlisting></para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT ST_GeoReference(rast, 'ESRI') As esri_ref, ST_GeoReference(rast, 'GDAL') As gdal_ref
FROM dummy_rast WHERE rid=1;
esri_ref | gdal_ref
--------------+--------------
2.0000000000 | 2.0000000000
0.0000000000 : 0.0000000000
0.0000000000 : 0.0000000000
3.0000000000 : 3.0000000000
1.5000000000 : 0.5000000000
2.0000000000 : 0.5000000000
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_SetGeoReference" />, <xref linkend="RT_ST_ScaleX" />, <xref linkend="RT_ST_ScaleY" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_Height">
<refnamediv>
<refname>ST_Height</refname>
<refpurpose>Returns the height of the raster in pixels?</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>ST_Height</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the height of the raster.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT rid, ST_Height(rast) As rastheight
FROM dummy_rast;
rid | rastheight
-----+------------
1 | 20
2 | 5
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_Width" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_MetaData">
<refnamediv>
<refname>ST_MetaData</refname>
<refpurpose>Returns basic meta data about a raster object such as skew, rotation, upper,lower left etc.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>record <function>ST_MetaData</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns basic meta data about a raster object such as skew, rotation, upper,lower left etc. Columns returned
upperleftx | upperlefty | width | height | scalex | scaley | skewx | skewy | srid | numbands</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT rid, (foo.md).*
FROM (SELECT rid, ST_MetaData(rast) As md
FROM dummy_rast) As foo;
rid | upperleftx | upperlefty | width | height | scalex | scaley | skewx | skewy | srid | numbands
-----+------------+------------+-------+--------+-----------+-----------+-------+-------+------+----------
1 | 0.5 | 0.5 | 10 | 20 | 2 | 3 | 0 | 0 | 0 | 0
2 | 3427927.75 | 5793244 | 5 | 5 | 0.05 | -0.05 | 0 | 0 | -1 | 3
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_BandMetaData" />, <xref linkend="RT_ST_NumBands" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_NumBands">
<refnamediv>
<refname>ST_NumBands</refname>
<refpurpose>Returns the number of bands in the raster object.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>ST_NumBands</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the number of bands in the raster object.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT rid, ST_NumBands(rast) As numbands
FROM dummy_rast;
rid | numbands
----+----------
1 | 0
2 | 3
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_Value" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_ScaleX">
<refnamediv>
<refname>ST_ScaleX</refname>
<refpurpose>Returns the x size of pixels in units of coordinate reference system?</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>float8 <function>ST_ScaleX</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the x size of pixels in units of coordinate reference system?</para>
<para>Changed: 2.0.0. In WKTRaster versions this was called ST_PixelSizeX.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT rid, ST_ScaleX(rast) As rastpixwidth
FROM dummy_rast;
rid | rastpixwidth
-----+--------------
1 | 2
2 | 0.05
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_Width" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_ScaleY">
<refnamediv>
<refname>ST_ScaleY</refname>
<refpurpose>Returns the y size of pixels in units of coordinate reference system?</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>float8 <function>ST_ScaleY</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the y size of pixels in units of coordinate reference system. May be negative. Refer to <ulink url="http://en.wikipedia.org/wiki/World_file">World File</ulink>
for more details.</para>
<para>Changed: 2.0.0. In WKTRaster versions this was called ST_PixelSizeY.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT rid, ST_ScaleY(rast) As rastpixheight
FROM dummy_rast;
rid | rastpixheight
-----+---------------
1 | 3
2 | -0.05
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_Height" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_Raster2WorldCoordX">
<refnamediv>
<refname>ST_Raster2WorldCoordX</refname>
<refpurpose>Returns the geometric x coordinate upper left of a raster, column and row. Numbering of columns
and rows starts at 1. </refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>float8 <function>ST_Raster2WorldCoordX</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>xcolumn</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>float8 <function>ST_Raster2WorldCoordX</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>xcolumn</parameter></paramdef>
<paramdef><type>integer </type> <parameter>yrow</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the upper left x coordinate of a raster column row in geometric units of the georeferenced raster.
Numbering of columns and rows starts at 1 but if you pass in a negative number or number higher than number of
columns in raster, it will give you
coordinates outside of the raster file to left or right with the assumption that the
skew and pixel sizes are same as selected raster. </para>
<note><para>For non-skewed rasters, providing the x column is sufficient. For skewed rasters,
the georeferenced coordinate is a function of the ST_ScaleX and SkewX and row and column.
An error will be raised if you give just the x column for a skewed raster.</para></note>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- non-skewed raster providing column is sufficient
SELECT rid, ST_Raster2WorldCoordX(rast,1) As x1coord,
ST_Raster2WorldCoordX(rast,2) As x2coord,
ST_ScaleX(rast) As pixelx
FROM dummy_rast;
rid | x1coord | x2coord | pixelx
-----+------------+-----------+--------
1 | 0.5 | 2.5 | 2
2 | 3427927.75 | 3427927.8 | 0.05
</programlisting>
<programlisting>
-- for fun lets skew it
SELECT rid, ST_Raster2WorldCoordX(rast,1,1) As x1coord,
ST_Raster2WorldCoordX(rast,2,3) As x2coord,
ST_ScaleX(rast) As pixelx
FROM (SELECT rid, ST_SetSkew(rast,100.5,0) As rast FROM dummy_rast) As foo;
rid | x1coord | x2coord | pixelx
-----+------------+-----------+--------
1 | 0.5 | 203.5 | 2
2 | 3427927.75 | 3428128.8 | 0.05
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_ScaleX" />, <xref linkend="RT_ST_Raster2WorldCoordY" />, <xref linkend="RT_ST_SetSkew" />, <xref linkend="RT_ST_SkewX" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_Raster2WorldCoordY">
<refnamediv>
<refname>ST_Raster2WorldCoordY</refname>
<refpurpose>Returns the geometric y coordinate upper left corner of a raster, column and row. Numbering of columns
and rows starts at 1. </refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>float8 <function>ST_Raster2WorldCoordY</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>yrow</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>float8 <function>ST_Raster2WorldCoordY</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>xcolumn</parameter></paramdef>
<paramdef><type>integer </type> <parameter>yrow</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the upper left y coordinate of a raster column row in geometric units of the georeferenced raster.
Numbering of columns and rows starts at 1 but if you pass in a negative number or number higher than number of
columns/rows in raster, it will give you
coordinates outside of the raster file to left or right with the assumption that the
skew and pixel sizes are same as selected raster tile. </para>
<note><para>For non-skewed rasters, providing the y column is sufficient. For skewed rasters,
the georeferenced coordinate is a function of the ST_ScaleY and SkewY and row and column.
An error will be raised if you give just the y row for a skewed raster.</para></note>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- non-skewed raster providing row is sufficient
SELECT rid, ST_Raster2WorldCoordY(rast,1) As y1coord,
ST_Raster2WorldCoordY(rast,3) As y2coord,
ST_ScaleY(rast) As pixely
FROM dummy_rast;
rid | y1coord | y2coord | pixely
-----+---------+-----------+--------
1 | 0.5 | 6.5 | 3
2 | 5793244 | 5793243.9 | -0.05
</programlisting>
<programlisting>
-- for fun lets skew it
SELECT rid, ST_Raster2WorldCoordY(rast,1,1) As y1coord,
ST_Raster2WorldCoordY(rast,2,3) As y2coord,
ST_ScaleY(rast) As pixely
FROM (SELECT rid, ST_SetSkew(rast,0,100.5) As rast FROM dummy_rast) As foo;
rid | y1coord | y2coord | pixely
-----+---------+-----------+--------
1 | 0.5 | 107 | 3
2 | 5793244 | 5793344.4 | -0.05
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_ScaleY" />, <xref linkend="RT_ST_Raster2WorldCoordX" />, <xref linkend="RT_ST_SetSkew" />, <xref linkend="RT_ST_SkewY" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_SkewX">
<refnamediv>
<refname>ST_SkewX</refname>
<refpurpose>Returns the georeference X skew (or rotation parameter)</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>float8 <function>ST_SkewX</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the georeference X skew (or rotation parameter). Refer to <ulink url="http://en.wikipedia.org/wiki/World_file">World File</ulink>
for more details.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT rid, ST_SkewX(rast) As skewx, ST_SkewY(rast) As skewy,
ST_GeoReference(rast) as georef
FROM dummy_rast;
rid | skewx | skewy | georef
-----+-------+-------+--------------------
1 | 0 | 0 | 2.0000000000
: 0.0000000000
: 0.0000000000
: 3.0000000000
: 0.5000000000
: 0.5000000000
:
2 | 0 | 0 | 0.0500000000
: 0.0000000000
: 0.0000000000
: -0.0500000000
: 3427927.7500000000
: 5793244.0000000000
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_GeoReference" />, <xref linkend="RT_ST_SkewY" />, <xref linkend="RT_ST_SetSkew" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_SkewY">
<refnamediv>
<refname>ST_SkewY</refname>
<refpurpose>Returns the georeference Y skew (or rotation parameter)</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>float8 <function>ST_SkewY</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the georeference Y skew (or rotation parameter). Refer to <ulink url="http://en.wikipedia.org/wiki/World_file">World File</ulink>
for more details.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT rid, ST_SkewX(rast) As skewx, ST_SkewY(rast) As skewy,
ST_GeoReference(rast) as georef
FROM dummy_rast;
rid | skewx | skewy | georef
-----+-------+-------+--------------------
1 | 0 | 0 | 2.0000000000
: 0.0000000000
: 0.0000000000
: 3.0000000000
: 0.5000000000
: 0.5000000000
:
2 | 0 | 0 | 0.0500000000
: 0.0000000000
: 0.0000000000
: -0.0500000000
: 3427927.7500000000
: 5793244.0000000000
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_GeoReference" />, <xref linkend="RT_ST_SkewX" />, <xref linkend="RT_ST_SetSkew" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_SRID">
<refnamediv>
<refname>ST_SRID</refname>
<refpurpose>Returns the spatial reference identifier of the raster as defined in spatial_ref_sys table.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>ST_SRID</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the spatial reference identifier of the raster object as defined in the spatial_ref_sys table.</para>
<note><para>From PostGIS 2.0+ the srid of a non-georeferenced raster/geometry is 0 instead of the prior -1.</para></note>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT ST_SRID(rast) As srid
FROM dummy_rast WHERE rid=1;
srid
----------------
0
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="spatial_ref_sys" />, <xref linkend="ST_SRID" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_UpperLeftX">
<refnamediv>
<refname>ST_UpperLeftX</refname>
<refpurpose>Returns the upper left x coordinate of raster in projected spatial ref.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>float8 <function>ST_UpperLeftX</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the upper left x coordinate of raster in projected spatial ref.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
SELECt rid, ST_UpperLeftX(rast) As ulx
FROM dummy_rast;
rid | ulx
-----+------------
1 | 0.5
2 | 3427927.75
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_UpperLeftY" />, <xref linkend="RT_ST_GeoReference" />, <xref linkend="RT_Box2D" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_UpperLeftY">
<refnamediv>
<refname>ST_UpperLeftY</refname>
<refpurpose>Returns the upper left y coordinate of raster in projected spatial ref.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>float8 <function>ST_UpperLeftY</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the upper left y coordinate of raster in projected spatial ref.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
SELECT rid, ST_UpperLeftY(rast) As uly
FROM dummy_rast;
rid | uly
-----+---------
1 | 0.5
2 | 5793244
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_UpperLeftX" />, <xref linkend="RT_ST_GeoReference" />, <xref linkend="RT_Box2D" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_Width">
<refnamediv>
<refname>ST_Width</refname>
<refpurpose>Returns the width of the raster in pixels?</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>ST_Width</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the width of the raster.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT ST_Width(rast) As rastwidth
FROM dummy_rast WHERE rid=1;
rastwidth
----------------
10
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_Height" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_World2RasterCoordX">
<refnamediv>
<refname>ST_World2RasterCoordX</refname>
<refpurpose>Returns the column in the raster of the point geometry (pt) or a x y world coordinate (xw, yw) represented
in world spatial reference system of raster.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>ST_World2RasterCoordX</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>pt</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>integer <function>ST_World2RasterCoordX</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>xw</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>integer <function>ST_World2RasterCoordX</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>xw</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>yw</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the column in the raster of the point geometry (pt) or a x y world coordinate (xw, yw). A point, or (both xw and yw world coordinates are required if a raster is skewed). If a raster
is not skewed then xw is sufficient. World coordinates are in the spatial reference coordinate system of the raster.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT rid, ST_World2RasterCoordX(rast,3427927.8) As xcoord,
ST_World2RasterCoordX(rast,3427927.8,20.5) As xcoord_xwyw,
ST_World2RasterCoordX(rast,ST_GeomFromText('POINT(3427927.8 20.5)',ST_SRID(rast))) As ptxcoord
FROM dummy_rast;
rid | xcoord | xcoord_xwyw | ptxcoord
-----+---------+---------+----------
1 | 1713964 | 1713964 | 1713964
2 | 1 | 1 | 1
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_Raster2WorldCoordX" />, <xref linkend="RT_ST_Raster2WorldCoordY" />, <xref linkend="RT_ST_SRID" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_World2RasterCoordY">
<refnamediv>
<refname>ST_World2RasterCoordY</refname>
<refpurpose>Returns the row in the raster of the point geometry (pt) or a x y world coordinate (xw, yw) represented
in world spatial reference system of raster.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>ST_World2RasterCoordY</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>pt</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>integer <function>ST_World2RasterCoordY</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>xw</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>integer <function>ST_World2RasterCoordY</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>xw</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>yw</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the row in the raster of the point geometry (pt) or a x y world coordinate (xw, yw). A point, or (both xw and yw world coordinates are required if a raster is skewed). If a raster
is not skewed then xw is sufficient. World coordinates are in the spatial reference coordinate system of the raster.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT rid, ST_World2RasterCoordY(rast,20.5) As ycoord,
ST_World2RasterCoordY(rast,3427927.8,20.5) As ycoord_xwyw,
ST_World2RasterCoordY(rast,ST_GeomFromText('POINT(3427927.8 20.5)',ST_SRID(rast))) As ptycoord
FROM dummy_rast;
rid | ycoord | ycoord_xwyw | ptycoord
-----+-----------+-------------+-----------
1 | 7 | 7 | 7
2 | 115864471 | 115864471 | 115864471
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_Raster2WorldCoordX" />, <xref linkend="RT_ST_Raster2WorldCoordY" />, <xref linkend="RT_ST_SRID" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_IsEmpty">
<refnamediv>
<refname>ST_IsEmpty</refname>
<refpurpose>Returns true if the raster is empty (width = 0 and height = 0). Otherwise, returns false.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>boolean <function>ST_IsEmpty</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns true if the raster is empty (width = 0 and height = 0). Otherwise, returns false.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT ST_IsEmpty(ST_MakeEmptyRaster(100, 100, 0, 0, 0, 0, 0, 0))
st_isempty |
-----------+
f |
SELECT ST_IsEmpty(ST_MakeEmptyRaster(0, 0, 0, 0, 0, 0, 0, 0))
st_isempty |
-----------+
t |
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_HasNoBand" /></para>
</refsection>
</refentry>
</sect1>
<sect1 id="RasterBand_Accessors">
<title>Raster Band Accessors and Constructors</title>
<refentry id="RT_ST_AddBand">
<refnamediv>
<refname>ST_AddBand</refname>
<refpurpose>Returns a raster with the new band of given type added with given initial value in the given index location. If no index is specified, the band is added to the end.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>raster <function>ST_AddBand</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>text </type> <parameter>pixeltype</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_AddBand</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>text </type> <parameter>pixeltype</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>initialvalue</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_AddBand</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>text </type> <parameter>pixeltype</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>initialvalue</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>nodataval</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_AddBand</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>index</parameter></paramdef>
<paramdef><type>text </type> <parameter>pixeltype</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_AddBand</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>index</parameter></paramdef>
<paramdef><type>text </type> <parameter>pixeltype</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>initialvalue</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_AddBand</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>index</parameter></paramdef>
<paramdef><type>text </type> <parameter>pixeltype</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>initialvalue</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>nodataval</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_AddBand</function></funcdef>
<paramdef><type>raster </type> <parameter>torast</parameter></paramdef>
<paramdef><type>raster </type> <parameter>fromrast</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_AddBand</function></funcdef>
<paramdef><type>raster </type> <parameter>torast</parameter></paramdef>
<paramdef><type>raster </type> <parameter>fromrast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>fromband</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_AddBand</function></funcdef>
<paramdef><type>raster </type> <parameter>torast</parameter></paramdef>
<paramdef><type>raster </type> <parameter>fromrast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>fromband</parameter></paramdef>
<paramdef><type>integer </type> <parameter>torastindex</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns a raster with a new band added in given position (index), of given type, of given initial value, and of given nodata value. If no index is specified, the band is added to the end.
If no <varname>fromband</varname> is specified, band 1 is assumed. Pixel type is a string representation
of one of the pixel types specified in <xref linkend="RT_ST_BandPixelType" />. If an existing index is specified all subsequent bands >= that index are incremented by 1.
If an initial value greater than the max of the pixel type
is specified, then the initial value is set to the highest
value allowed by the pixel type. The last version add the
<varname>fromband</varname> from <varname>fromrast</varname> raster to <varname>torast</varname> in position <varname>torastindex</varname>.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>-- Add another band of type 8 bit unsigned integer with pixels initialized to 200
UPDATE dummy_rast
SET rast = ST_AddBand(rast,'8BUI',200)
WHERE rid = 1;
</programlisting>
<programlisting>-- Create an empty raster 100x100 units, with upper left right at 0, add 2 bands (band 1 is 0/1 boolean bit switch, band2 allows values 0-15)
INSERT INTO dummy_rast(rid,rast)
VALUES(10, ST_AddBand(ST_AddBand(ST_MakeEmptyRaster(100,100,0,0,1,-1,0,0, -1), '1BB'), '4BUI') );
-- output meta data of raster bands to verify all is right --
SELECT (bmd).*
FROM (SELECT ST_BandMetaData(rast,generate_series(1,2)) As bmd
FROM dummy_rast WHERE rid = 10) AS foo;
--result --
pixeltype | hasnodata | nodatavalue | isoutdb | path
-----------+----------------+-------------+---------+------
1BB | f | 0 | f |
4BUI | f | 0 | f |
-- output meta data of raster -
SELECT (rmd).width, (rmd).height, (rmd).numbands
FROM (SELECT ST_MetaData(rast) As rmd
FROM dummy_rast WHERE rid = 10) AS foo;
-- result --
upperleftx | upperlefty | width | height | scalex | scaley | skewx | skewy | srid | numbands
------------+------------+-------+--------+------------+------------+-------+-------+------+----------
0 | 0 | 100 | 100 | 1 | -1 | 0 | 0 | -1 | 2
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_BandMetaData" />, <xref linkend="RT_ST_BandPixelType" />, <xref linkend="RT_ST_MakeEmptyRaster" />, <xref linkend="RT_ST_MetaData" />, <xref linkend="RT_ST_NumBands" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_Band">
<refnamediv>
<refname>ST_Band</refname>
<refpurpose>Returns one or more bands of an existing raster as a new raster. Useful for building new rasters from existing rasters.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcprototype>
<funcdef>raster <function>ST_Band</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef choice='opt'><type>integer[] </type> <parameter>nbands = ARRAY[1]</parameter></paramdef>
</funcprototype>
<funcdef>raster <function>ST_Band</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>text </type> <parameter>nbands</parameter></paramdef>
<paramdef choice='opt'><type>character </type> <parameter>delimiter=,</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_Band</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>nband</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns a single band of an existing raster as a new raster. Useful for building new rasters from existing rasters or export of only selected
bands of a raster. If no band is specified, band 1 is assumed. Used as a helper function in various functons suc as for deleting a band.</para>
<para>Availability: 2.0.0</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>-- Make 2 new rasters: 1 containing band 1 of dummy, second containing band 2 of dummy and then reclassified as a 2BUI
SELECT ST_NumBands(rast1) As numb1, ST_BandPixelType(rast1) As pix1,
ST_NumBands(rast2) As numb2, ST_BandPixelType(rast2) As pix2
FROM (
SELECT ST_Band(rast) As rast1, ST_Reclass(ST_Band(rast,3), '100-200):1, [200-254:2', '2BUI') As rast2
FROM dummy_rast
WHERE rid = 2) As foo;
numb1 | pix1 | numb2 | pix2
-------+------+-------+------
1 | 8BUI | 1 | 2BUI
</programlisting>
<programlisting>-- Return bands 2 and 3. Use text to define bands
SELECT ST_NumBands(ST_Band(rast, '2,3')) As num_bands
FROM dummy_rast WHERE rid=2;
num_bands
----------
2
-- Return bands 2 and 3. Use array to define bands
SELECT ST_NumBands(ST_Band(rast, ARRAY[2,3])) As num_bands
FROM dummy_rast
WHERE rid=2;
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_AddBand" />, <xref linkend="RT_ST_NumBands" />, , <xref linkend="RT_ST_Reclass" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_BandMetaData">
<refnamediv>
<refname>ST_BandMetaData</refname>
<refpurpose>Returns basic meta data for a specific raster band. band num 1 is assumed if none-specified.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>record <function>ST_BandMetaData</function></funcdef>
<paramdef><type>raster </type><parameter>rast</parameter></paramdef>
<paramdef choice='opt'><type>integer </type><parameter>bandnum=1</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns basic meta data about a raster band. Columns returned
pixeltype | hasnodata | nodatavalue | isoutdb | path.
</para>
<note>
<para>
If raster contains no bands then an error is thrown.
</para>
</note>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT rid, (foo.md).*
FROM (SELECT rid, ST_BandMetaData(rast,1) As md
FROM dummy_rast WHERE rid=2) As foo;
rid | pixeltype | hasnodata | nodatavalue | isoutdb | path
-----+-----------+----------------+-------------+---------+------
2 | 8BUI | t | 0 | f |
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_MetaData" />, <xref linkend="RT_ST_BandPixelType" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_BandNoDataValue">
<refnamediv>
<refname>ST_BandNoDataValue</refname>
<refpurpose>Returns the value in a given band that represents no data. If no band num 1 is assumed.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>ST_BandNoDataValue</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>integer <function>ST_BandNoDataValue</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>bandnum</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the value that represents no data for the band</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT ST_BandNoDataValue(rast,1) As bnval1,
ST_BandNoDataValue(rast,2) As bnval2, ST_BandNoDataValue(rast,3) As bnval3
FROM dummy_rast
WHERE rid = 2;
bnval1 | bnval2 | bnval3
--------+--------+--------
0 | 0 | 0
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_NumBands" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_BandIsNoData">
<refnamediv>
<refname>ST_BandIsNoData</refname>
<refpurpose>Returns true if the band is filled with only nodata values.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>boolean <function>ST_BandIsNoData</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>band</parameter></paramdef>
<paramdef><type>boolean </type> <parameter>forceChecking</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>boolean <function>ST_BandIsNoData</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>band</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>boolean <function>ST_BandIsNoData</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>boolean </type> <parameter>forceChecking</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>boolean <function>ST_BandIsNoData</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns true if the band is filled with only nodata
values. Band 1 is assumed if not specified. If the last argument
is TRUE, the entire band is checked pixel by pixel. Otherwise,
the function simply returns the value of the isnodata flag for
the band. The default value for this parameter is FALSE, if not
specified.</para>
<para>Availability: 2.0.0</para>
<note>
<para>If the flag is dirty (this is, the result is different
using TRUE as last parameter and not using it) you should
update the raster to set this flag to true, by using ST_SetBandIsNodata function,
or ST_SetBandNodataValue function with TRUE as last argument. The
loader (raster2pgsql.py) currently can not properly set the
flag while loading raster data. See <xref
linkend="RT_ST_SetBandIsNoData" />.</para>
</note>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- Create dummy table with one raster column
create table dummy_rast (rid integer, rast raster);
-- Add raster with two bands, one pixel/band. In the first band, nodatavalue = pixel value = 3.
-- In the second band, nodatavalue = 13, pixel value = 4
insert into dummy_rast values(1,
(
'01' -- little endian (uint8 ndr)
||
'0000' -- version (uint16 0)
||
'0200' -- nBands (uint16 0)
||
'17263529ED684A3F' -- scaleX (float64 0.000805965234044584)
||
'F9253529ED684ABF' -- scaleY (float64 -0.00080596523404458)
||
'1C9F33CE69E352C0' -- ipX (float64 -75.5533328537098)
||
'718F0E9A27A44840' -- ipY (float64 49.2824585505576)
||
'ED50EB853EC32B3F' -- skewX (float64 0.000211812383858707)
||
'7550EB853EC32B3F' -- skewY (float64 0.000211812383858704)
||
'E6100000' -- SRID (int32 4326)
||
'0100' -- width (uint16 1)
||
'0100' -- height (uint16 1)
||
'6' -- hasnodatavalue and isnodata value set to true.
||
'2' -- first band type (4BUI)
||
'03' -- novalue==3
||
'03' -- pixel(0,0)==3 (same that nodata)
||
'0' -- hasnodatavalue set to false
||
'5' -- second band type (16BSI)
||
'0D00' -- novalue==13
||
'0400' -- pixel(0,0)==4
)::raster
);
select st_bandisnodata(rast, 1) from dummy_rast where rid = 1; -- Expected true
select st_bandisnodata(rast, 2) from dummy_rast where rid = 1; -- Expected false
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_BandNoDataValue" />,<xref
linkend="RT_ST_NumBands" />, <xref
linkend="RT_ST_SetBandNoDataValue" />, <xref
linkend="RT_ST_SetBandIsNoData" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_BandPath">
<refnamediv>
<refname>ST_BandPath</refname>
<refpurpose>Returns system file path to a band stored in file system. If no bandnum specified, 1 is assumed.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>ST_BandPath</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>ST_BandPath</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>bandnum</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns system file path to a band. Throws an error if called with an in db band.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting><!-- TODO: -->
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para></para>
</refsection>
</refentry>
<refentry id="RT_ST_BandPixelType">
<refnamediv>
<refname>ST_BandPixelType</refname>
<refpurpose>Returns the type of pixel for given band. If no bandnum specified, 1 is assumed.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>ST_BandPixelType</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>ST_BandPixelType</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>bandnum</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the value that represents no data for the band</para>
<para>There are 11 pixel types. Pixel Types supported are as follows:
<itemizedlist>
<listitem>
<para>1BB - 1-bit boolean</para>
</listitem>
<listitem>
<para>2BUI - 2-bit unsigned integer</para>
</listitem>
<listitem>
<para>4BUI - 4-bit unsigned integer </para>
</listitem>
<listitem>
<para>8BSI - 8-bit signed integer </para>
</listitem>
<listitem>
<para>8BUI - 8-bit unsigned integer</para>
</listitem>
<listitem>
<para>16BSI - 16-bit signed integer</para>
</listitem>
<listitem>
<para>16BUI - 16-bit unsigned integer</para>
</listitem>
<listitem>
<para>32BSI - 32-bit signed integer</para>
</listitem>
<listitem>
<para>32BUI - 32-bit unsigned integer</para>
</listitem>
<listitem>
<para>32BF - 32-bit float</para>
</listitem>
<listitem>
<para>64BF - 64-bit float</para>
</listitem>
</itemizedlist>
</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT ST_BandPixelType(rast,1) As btype1,
ST_BandPixelType(rast,2) As btype2, ST_BandPixelType(rast,3) As btype3
FROM dummy_rast
WHERE rid = 2;
btype1 | btype2 | btype3
--------+--------+--------
8BUI | 8BUI | 8BUI
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_NumBands" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_HasNoBand">
<refnamediv>
<refname>ST_HasNoBand</refname>
<refpurpose>Returns true if there is no band with given band number. If no band number is specified, then band number 1 is assumed.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>boolean <function>ST_HasNoBand</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>boolean <function>ST_HasNoBand</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>bandnum</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns true if there is no band with given band number. If no band number is specified, then band number 1 is assumed.</para>
<para>Availability: 2.0.0</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT rid, ST_HasNoBand(rast) As hb1, ST_HasNoBand(rast,2) as hb2,
ST_HasNoBand(rast,4) as hb4, ST_NumBands(rast) As numbands
FROM dummy_rast;
rid | hb1 | hb2 | hb4 | numbands
-----+-----+-----+-----+----------
1 | t | t | t | 0
2 | f | f | t | 3
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_NumBands" /></para>
</refsection>
</refentry>
</sect1>
<sect1 id="Raster_Pixel_Accessors">
<title>Raster Pixel Accessors and Settors</title>
<refentry id="RT_ST_PixelAsPolygon">
<refnamediv>
<refname>ST_PixelAsPolygon</refname>
<refpurpose>Returns the geometry that bounds the pixel (for now a rectangle) for a particular band, row, column. If no band
specified band num 1 is assumed.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_PixelAsPolygon</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>columnx</parameter></paramdef>
<paramdef><type>integer </type> <parameter>rowy</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>geometry <function>ST_PixelAsPolygon</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>bandnum</parameter></paramdef>
<paramdef><type>integer </type> <parameter>columnx</parameter></paramdef>
<paramdef><type>integer </type> <parameter>rowy</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the geometry that bounds the pixel (for now a rectangle) for a particular band, row, column. If no band
specified band num 1 is assumed.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- get raster pixel polygon
SELECT i,j, ST_AsText(ST_PixelAsPolygon(foo.rast, i,j)) As b1pgeom
FROM dummy_rast As foo
CROSS JOIN generate_series(1,2) As i
CROSS JOIN generate_series(1,1) As j
WHERE rid=2;
i | j | b1pgeom
---+---+-----------------------------------------------------------------------------
1 | 1 | POLYGON((3427927.75 5793244,3427927.8 5793244,3427927.8 5793243.95,...
2 | 1 | POLYGON((3427927.8 5793244,3427927.85 5793244,3427927.85 5793243.95, ..
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_DumpAsPolygons" />, <xref linkend="RT_ST_Intersection" />,
<xref linkend="ST_AsText" />
</para>
</refsection>
</refentry>
<refentry id="RT_ST_Value">
<refnamediv>
<refname>ST_Value</refname>
<refpurpose>Returns the value of a given band in a given columnx, rowy pixel or at a particular geometric point. Band numbers start at 1 and assumed to be 1 if not specified. If <varname>exclude_nodata_value</varname> is set to false, then all pixels include <varname>nodata</varname> pixels are considered to intersect and return value. If <varname>exclude_nodata_value</varname> is not passed in then reads it from metadata of raster.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>double precision <function>ST_Value</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>pt</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>double precision <function>ST_Value</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>pt</parameter></paramdef>
<paramdef><type>boolean </type> <parameter>exclude_nodata_value</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>double precision <function>ST_Value</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>bandnum</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>pt</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>double precision <function>ST_Value</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>bandnum</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>pt</parameter></paramdef>
<paramdef><type>boolean </type> <parameter>exclude_nodata_value</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>double precision <function>ST_Value</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>columnx</parameter></paramdef>
<paramdef><type>integer </type> <parameter>rowy</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>double precision <function>ST_Value</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>columnx</parameter></paramdef>
<paramdef><type>integer </type> <parameter>rowy</parameter></paramdef>
<paramdef><type>boolean </type> <parameter>exclude_nodata_value</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>double precision <function>ST_Value</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>bandnum</parameter></paramdef>
<paramdef><type>integer </type> <parameter>columnx</parameter></paramdef>
<paramdef><type>integer </type> <parameter>rowy</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>double precision <function>ST_Value</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>bandnum</parameter></paramdef>
<paramdef><type>integer </type> <parameter>columnx</parameter></paramdef>
<paramdef><type>integer </type> <parameter>rowy</parameter></paramdef>
<paramdef><type>boolean </type> <parameter>exclude_nodata_value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the value of a given band in a given columnx, rowy pixel or at a given geometry point. Band numbers start at 1 and band is assumed to be 1 if not specified.
If <varname>exclude_nodata_value</varname> is set to true, then only non <varname>nodata</varname> pixels are considered. If <varname>exclude_nodata_value</varname> is set to false, then all pixels are considered.</para>
<para>Enhanced: 2.0.0 exclude_nodata_value optional argument was added.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- get raster values at particular postgis geometry points
-- the srid of your geometry should be same as for your raster
SELECT rid, ST_Value(rast, foo.pt_geom) As b1pval, ST_Value(rast, 2, foo.pt_geom) As b2pval
FROM dummy_rast CROSS JOIN (SELECT ST_SetSRID(ST_Point(3427927.77,5793243.76),-1) As pt_geom) As foo
WHERE rid=2;
rid | b1pval | b2pval
-----+--------+--------
2 | 252 | 79
-- general fictitious example using a real table
SELECT rid, ST_Value(rast, 3, sometable.geom) As b3pval
FROM sometable
WHERE ST_Intersects(rast,sometable.geom);
</programlisting>
<programlisting>
SELECT rid, ST_Value(rast, 1,1,1) As b1pval,
ST_Value(rast, 2,1,1) As b2pval, ST_Value(rast, 3,1,1) As b3pval
FROM dummy_rast
WHERE rid=2;
rid | b1pval | b2pval | b3pval
-----+--------+--------+--------
2 | 253 | 78 | 70
</programlisting>
<programlisting>
--- Get all values in bands 1,2,3 of each pixel --
SELECT x, y, ST_Value(rast, 1, x, y) As b1val,
ST_Value(rast, 2, x, y) As b2val, ST_Value(rast, 3, x, y) As b3val
FROM dummy_rast CROSS JOIN
generate_series(1,1000) As x CROSS JOIN generate_series(1,1000) As y
WHERE rid = 2 AND x &lt;= ST_Width(rast) AND y &lt;= ST_Height(rast);
x | y | b1val | b2val | b3val
---+---+-------+-------+-------
1 | 1 | 253 | 78 | 70
1 | 2 | 253 | 96 | 80
1 | 3 | 250 | 99 | 90
1 | 4 | 251 | 89 | 77
1 | 5 | 252 | 79 | 62
2 | 1 | 254 | 98 | 86
2 | 2 | 254 | 118 | 108
:
:
</programlisting>
<programlisting>
--- Get all values in bands 1,2,3 of each pixel same as above but returning the upper left point point of each pixel --
SELECT ST_AsText(ST_SetSRID(
ST_Point(ST_UpperLeftX(rast) + ST_ScaleX(rast)*x,
ST_UpperLeftY(rast) + ST_ScaleY(rast)*y),
ST_SRID(rast))) As uplpt
, ST_Value(rast, 1, x, y) As b1val,
ST_Value(rast, 2, x, y) As b2val, ST_Value(rast, 3, x, y) As b3val
FROM dummy_rast CROSS JOIN
generate_series(1,1000) As x CROSS JOIN generate_series(1,1000) As y
WHERE rid = 2 AND x &lt;= ST_Width(rast) AND y &lt;= ST_Height(rast);
uplpt | b1val | b2val | b3val
-----------------------------+-------+-------+-------
POINT(3427929.25 5793245.5) | 253 | 78 | 70
POINT(3427929.25 5793247) | 253 | 96 | 80
POINT(3427929.25 5793248.5) | 250 | 99 | 90
:
</programlisting>
<programlisting>
--- Get a polygon formed by union of all pixels
that fall in a particular value range and intersect particular polygon --
SELECT ST_AsText(ST_Union(pixpolyg)) As shadow
FROM (SELECT ST_Translate(ST_MakeEnvelope(
ST_UpperLeftX(rast), ST_UpperLeftY(rast),
ST_UpperLeftX(rast) + ST_ScaleX(rast),
ST_UpperLeftY(rast) + ST_ScaleY(rast), 0
), ST_ScaleX(rast)*x, ST_ScaleY(rast)*y
) As pixpolyg, ST_Value(rast, 2, x, y) As b2val
FROM dummy_rast CROSS JOIN
generate_series(1,1000) As x CROSS JOIN generate_series(1,1000) As y
WHERE rid = 2
AND x &lt;= ST_Width(rast) AND y &lt;= ST_Height(rast)) As foo
WHERE
ST_Intersects(
pixpolyg,
ST_GeomFromText('POLYGON((3427928 5793244,3427927.75 5793243.75,3427928 5793243.75,3427928 5793244))',0)
) AND b2val != 254;
shadow
------------------------------------------------------------------------------------
MULTIPOLYGON(((3427928 5793243.9,3427928 5793243.85,3427927.95 5793243.85,3427927.95 5793243.9,
3427927.95 5793243.95,3427928 5793243.95,3427928.05 5793243.95,3427928.05 5793243.9,3427928 5793243.9)),((3427927.95 5793243.9,3427927.95 579324
3.85,3427927.9 5793243.85,3427927.85 5793243.85,3427927.85 5793243.9,3427927.9 5793243.9,3427927.9 5793243.95,
3427927.95 5793243.95,3427927.95 5793243.9)),((3427927.85 5793243.75,3427927.85 5793243.7,3427927.8 5793243.7,3427927.8 5793243.75
,3427927.8 5793243.8,3427927.8 5793243.85,3427927.85 5793243.85,3427927.85 5793243.8,3427927.85 5793243.75)),
((3427928.05 5793243.75,3427928.05 5793243.7,3427928 5793243.7,3427927.95 5793243.7,3427927.95 5793243.75,3427927.95 5793243.8,3427
927.95 5793243.85,3427928 5793243.85,3427928 5793243.8,3427928.05 5793243.8,
3427928.05 5793243.75)),((3427927.95 5793243.75,3427927.95 5793243.7,3427927.9 5793243.7,3427927.85 5793243.7,
3427927.85 5793243.75,3427927.85 5793243.8,3427927.85 5793243.85,3427927.9 5793243.85,
3427927.95 5793243.85,3427927.95 5793243.8,3427927.95 5793243.75)))
</programlisting>
<programlisting>
--- Checking all the pixels of a large raster tile can take a long time.
--- You can dramatically improve speed at some lose of precision by orders of magnitude
-- by sampling pixels using the step optional parameter of generate_series.
-- This next example does the same as previous but by checking 1 for every 4 (2x2) pixels and putting in the last checked
-- putting in the checked pixel as the value for subsequent 4
SELECT ST_AsText(ST_Union(pixpolyg)) As shadow
FROM (SELECT ST_Translate(ST_MakeEnvelope(
ST_UpperLeftX(rast), ST_UpperLeftY(rast),
ST_UpperLeftX(rast) + ST_ScaleX(rast)*2,
ST_UpperLeftY(rast) + ST_ScaleY(rast)*2, 0
), ST_ScaleX(rast)*x, ST_ScaleY(rast)*y
) As pixpolyg, ST_Value(rast, 2, x, y) As b2val
FROM dummy_rast CROSS JOIN
generate_series(1,1000,2) As x CROSS JOIN generate_series(1,1000,2) As y
WHERE rid = 2
AND x &lt;= ST_Width(rast) AND y &lt;= ST_Height(rast) ) As foo
WHERE
ST_Intersects(
pixpolyg,
ST_GeomFromText('POLYGON((3427928 5793244,3427927.75 5793243.75,3427928 5793243.75,3427928 5793244))',0)
) AND b2val != 254;
shadow
------------------------------------------------------------------------------------
MULTIPOLYGON(((3427927.9 5793243.85,3427927.8 5793243.85,3427927.8 5793243.95,
3427927.9 5793243.95,3427928 5793243.95,3427928.1 5793243.95,3427928.1 5793243.85,3427928 5793243.85,3427927.9 5793243.85)),
((3427927.9 5793243.65,3427927.8 5793243.65,3427927.8 5793243.75,3427927.8 5793243.85,3427927.9 5793243.85,
3427928 5793243.85,3427928 5793243.75,3427928.1 5793243.75,3427928.1 5793243.65,3427928 5793243.65,3427927.9 5793243.65)))
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_DumpAsPolygons" />, <xref linkend="RT_ST_NumBands" />, <xref linkend="RT_ST_PixelAsPolygon" />, <xref linkend="RT_ST_ScaleX" />,
, <xref linkend="RT_ST_ScaleY" />, <xref linkend="RT_ST_UpperLeftX" />,
<xref linkend="RT_ST_UpperLeftY" />, <xref linkend="RT_ST_SRID" />, <xref linkend="ST_AsText" />,
, <xref linkend="ST_Point" />, <xref linkend="ST_MakeEnvelope" />,
<xref linkend="ST_Intersects" />, <xref linkend="ST_Intersection" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_SetValue">
<refnamediv>
<refname>ST_SetValue</refname>
<refpurpose>Returns modified raster resulting from setting the value of a given band in a given columnx, rowy pixel or at a pixel that intersects a particular geometric point. Band numbers start at 1 and assumed to be 1 if not specified.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>raster <function>ST_SetValue</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>pt</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>newvalue</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_SetValue</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>bandnum</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>pt</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>newvalue</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_SetValue</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>columnx</parameter></paramdef>
<paramdef><type>integer </type> <parameter>rowy</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>newvalue</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_SetValue</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>bandnum</parameter></paramdef>
<paramdef><type>integer </type> <parameter>columnx</parameter></paramdef>
<paramdef><type>integer </type> <parameter>rowy</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>newvalue</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns modified raster resulting from setting the specified pixel value to new value for the designed band given the row column location or a geometric point location.
If no band is specified, then band 1 is assumed.
</para>
<note><para>Setting by geometry currently only works for points.</para></note>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- Geometry example
SELECT (foo.geomval).val, ST_AsText(ST_Union((foo.geomval).geom))
FROM (SELECT ST_DumpAsPolygons(
ST_SetValue(rast,1,
ST_Point(3427927.75, 5793243.95),
50)
) As geomval
FROM dummy_rast
where rid = 2) As foo
WHERE (foo.geomval).val &lt; 250
GROUP BY (foo.geomval).val;
val | st_astext
-----+-------------------------------------------------------------------
50 | POLYGON((3427927.75 5793244,3427927.75 5793243.95,3427927.8 579324 ...
249 | POLYGON((3427927.95 5793243.95,3427927.95 5793243.85,3427928 57932 ...
</programlisting>
<programlisting>
-- Store the changed raster --
UPDATE dummy_rast SET rast = ST_SetValue(rast,1, ST_Point(3427927.75, 5793243.95),100)
WHERE rid = 2 ;
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_Value" />, <xref linkend="RT_ST_DumpAsPolygons" /></para>
</refsection>
</refentry>
</sect1>
<sect1 id="Raster_Editors">
<title>Raster Editors</title>
<refentry id="RT_ST_SetGeoReference">
<refnamediv>
<refname>ST_SetGeoReference</refname>
<refpurpose>Set Georeference 6 georeference parameters in a single call. Numbers should be separated by white space. Accepts inputs in GDAL or ESRI format. Default is GDAL.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>raster <function>ST_SetGeoReference</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>text </type> <parameter>georefcoords</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_SetGeoReference</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>text </type> <parameter>georefcoords</parameter></paramdef>
<paramdef><type>text </type> <parameter>format</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Set Georeference 6 georeference parameters in a single call. Accepts inputs in 'GDAL' or 'ESRI' format. Default is GDAL. If 6 coordinates are not provided will return null.</para>
<para>Difference between format representations is as follows:</para>
<para><varname>GDAL</varname>:
<programlisting>scalex skewy skewx scaley upperleftx upperlefty</programlisting></para>
<para><varname>ESRI</varname>:
<programlisting>scalex skewy skewx scaley upperleftx + scalex*0.5 upperlefty + scaley*0.5</programlisting></para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>UPDATE dummy_rast SET rast = ST_SetGeoReference(rast, '2 0 0 3 0.5 0.5','GDAL')
WHERE rid=1;
-- same coordinates set in 'ESRI' format
UPDATE dummy_rast SET rast = ST_SetGeoReference(rast, '2 0 0 3 1.5 2','ESRI')
WHERE rid=1;
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_GeoReference" />, <xref linkend="RT_ST_ScaleX" />, <xref linkend="RT_ST_ScaleY" />, <xref linkend="RT_ST_UpperLeftX" />, <xref linkend="RT_ST_UpperLeftY" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_SetScale">
<refnamediv>
<refname>ST_SetScale</refname>
<refpurpose>Sets the x and y size of pixels in units of coordinate reference system. Number units/pixel width/height</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>raster <function>ST_SetScale</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>xy</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_SetScale</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>x</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>y</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Sets the x and y size of pixels in units of coordinate reference system. Number units/pixel width/height. If
only one unit passed in, assumed x and y are the same number.</para>
<para>Changed: 2.0.0 In WKTRaster versions this was called ST_SetPixelSize. This was changed in 2.0.0.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>UPDATE dummy_rast
SET rast = ST_SetScale(rast,1.5)
WHERE rid = 2;
SELECT ST_ScaleX(rast) As pixx, ST_ScaleY(rast) As pixy, Box2D(rast) As newbox
FROM dummy_rast
WHERE rid = 2;
pixx | pixy | newbox
------+------+----------------------------------------------
1.5 | 1.5 | BOX(3427927.75 5793244,3427935.25 5793251.5)
</programlisting>
<programlisting>UPDATE dummy_rast
SET rast = ST_SetScale(rast,1.5,0.55)
WHERE rid = 2;
SELECT ST_ScaleX(rast) As pixx, ST_ScaleY(rast) As pixy, Box2D(rast) As newbox
FROM dummy_rast
WHERE rid = 2;
pixx | pixy | newbox
------+------+--------------------------------------------
1.5 | 0.55 | BOX(3427927.75 5793244,3427935.25 5793247)
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_ScaleX" />, <xref linkend="RT_ST_ScaleY" />, <xref linkend="RT_Box2D" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_SetSkew">
<refnamediv>
<refname>ST_SetSkew</refname>
<refpurpose>Sets the georeference X and Y skew (or rotation parameter). If only one is passed in sets x and y to same number.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>raster <function>ST_SetSkew</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>skewxy</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_SetSkew</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>skewx</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>skewy</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Sets the georeference X and Y skew (or rotation parameter). If only one is passed in sets x and y to same number. Refer to <ulink url="http://en.wikipedia.org/wiki/World_file">World File</ulink>
for more details.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- Example 1
UPDATE dummy_rast SET rast = ST_SetSkew(rast,1,2) WHERE rid = 1;
SELECT rid, ST_SkewX(rast) As skewx, ST_SkewY(rast) As skewy,
ST_GeoReference(rast) as georef
FROM dummy_rast WHERE rid = 1;
rid | skewx | skewy | georef
----+-------+-------+--------------
1 | 1 | 2 | 2.0000000000
: 2.0000000000
: 1.0000000000
: 3.0000000000
: 0.5000000000
: 0.5000000000
</programlisting>
<programlisting>
-- Example 2 set both to same number:
UPDATE dummy_rast SET rast = ST_SetSkew(rast,0) WHERE rid = 1;
SELECT rid, ST_SkewX(rast) As skewx, ST_SkewY(rast) As skewy,
ST_GeoReference(rast) as georef
FROM dummy_rast WHERE rid = 1;
rid | skewx | skewy | georef
-----+-------+-------+--------------
1 | 0 | 0 | 2.0000000000
: 0.0000000000
: 0.0000000000
: 3.0000000000
: 0.5000000000
: 0.5000000000
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_GeoReference" />,<xref linkend="RT_ST_SetGeoReference" />, <xref linkend="RT_ST_SkewX" />, <xref linkend="RT_ST_SkewY" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_SetSRID">
<refnamediv>
<refname>ST_SetSRID</refname>
<refpurpose>Sets the SRID of a raster to a particular integer srid defined in the spatial_ref_sys table.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>raster <function>ST_SetSRID</function></funcdef>
<paramdef><type>raster </type>
<parameter>rast</parameter></paramdef>
<paramdef><type>integer </type>
<parameter>srid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Sets the SRID on a raster to a particular integer value.</para>
<note>
<para>This function does not transform the raster in any way -
it simply sets meta data defining the spatial ref of the coordinate reference system that it's currently in.
Useful for transformations later.
</para>
</note>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="spatial_ref_sys" />, <xref linkend="RT_ST_SRID"/></para>
</refsection>
</refentry>
<refentry id="RT_ST_SetUpperLeft">
<refnamediv>
<refname>ST_SetUpperLeft</refname>
<refpurpose>Sets the value of the upper left corner of the pixel to projected x,y coordinates</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>raster <function>ST_SetUpperLeft</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>x</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>y</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Set the value of the uppler left corner of raster to the projected x coordinates</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
SELECT ST_SetUpperLeft(rast,-71.01,42.37)
FROM dummy_rast
WHERE rid = 2;
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_UpperLeftX" />,<xref linkend="RT_ST_UpperLeftY" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_Transform">
<refnamediv>
<refname>ST_Transform</refname>
<refpurpose>Reprojects a raster in a known spatial reference system to another known spatial reference system using specified resampling algorithm.
Uses NearestNeighbor if no algorithm is specified Options: NearestNeighbor, Bilinear, Cubic, CubicSpline, Lanczos.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>raster <function>ST_Transform</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>srid</parameter></paramdef>
<paramdef choice='opt'><type>text </type> <parameter>algorithm=NearestNeighbor</parameter></paramdef>
<paramdef choice='opt'><type>double precision </type> <parameter>maxerr=0.125</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Reprojects a raster in a known spatial reference system to another known spatial reference system using specified pixel warping algorithm.
Uses 'NearestNeighbor' if no algorithm is specified and maxerror percent of 0.125 if no maxerr is specified.</para>
<para>Algorithm options are: 'NearestNeighbor', 'Bilinear', 'Cubic', 'CubicSpline', and 'Lanczos'. Refer to: <ulink url="http://www.gdal.org/gdalwarp.html">GDAL Warp resampling methods</ulink> for more details.</para>
<para>Availability: 2.0.0 Requires GDAL 1.6.1+</para>
<note><para>Currently having issues getting this to work right on some platforms: Windows, some Linux. We are working on resolving these.
Refer to <ulink url="http://trac.osgeo.org/postgis/ticket/925">Raster ST_Transform</ulink> for gorydetails.</para></note>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>-- TO DO --</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="ST_Transform" />, <xref linkend="RT_ST_SetSRID" /></para>
</refsection>
</refentry>
</sect1>
<sect1 id="RasterBand_Editors">
<title>Raster Band Editors</title>
<refentry id="RT_ST_SetBandNoDataValue">
<refnamediv>
<refname>ST_SetBandNoDataValue</refname>
<refpurpose>Sets the value for the given band that represents no data. Band 1 is assumed if no band is specified. To mark a band as having no nodata value, set the nodata value = NULL</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>raster <function>ST_SetBandNoDataValue</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>val</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_SetBandNoDataValue</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>band</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>val</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Sets the value that represents no data for the band. Band 1 is assumed if not specified. This will effect <xref linkend="RT_ST_Polygon" /> and <xref linkend="RT_ST_ConvexHull" /> results.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>-- change just first band no data value
UPDATE dummy_rast
SET rast = ST_SetBandNoDataValue(rast,1, 254)
WHERE rid = 2;
-- change no data band value of bands 1,2,3
UPDATE dummy_rast
SET rast =
ST_SetBandNoDataValue(
ST_SetBandNoDataValue(
ST_SetBandNoDataValue(
rast,1, 254)
,2,99),
3,108)
WHERE rid = 2;
-- wipe out the nodata value this will ensure all pixels are considered for all processing functions
UPDATE dummy_rast
SET rast = ST_SetBandNoDataValue(rast,1, NULL)
WHERE rid = 2;
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_BandNoDataValue" />,<xref linkend="RT_ST_NumBands" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_SetBandIsNoData">
<refnamediv>
<refname>ST_SetBandIsNoData</refname>
<refpurpose>Sets the isnodata flag of the band to TRUE. You may
want to call this function if ST_BandIsNoData(rast, band) !=
ST_BandIsNodata(rast, band, TRUE). This is, if the isnodata flag
is dirty. Band 1 is assumed if no band is specified.
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>integer <function>ST_SetBandIsNoData</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>band</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>integer <function>ST_SetBandIsNoData</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Sets the isnodata flag for the band to true. Band 1 is
assumed if not specified. This function should be called only
when the flag is considered dirty. This is, when the result
calling <xref linkend="RT_ST_BandIsNoData" /> is different using
TRUE as last argument and without using it</para>
<para>Availability: 2.0.0</para>
<note><para>Currently, the loader (raster2pgsql.py) is not able
to set the isnodata flag for bands. So, this is the fastest way
to set it to TRUE, without changing any other band value</para></note>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- Create dummy table with one raster column
create table dummy_rast (rid integer, rast raster);
-- Add raster with two bands, one pixel/band. In the first band, nodatavalue = pixel value = 3.
-- In the second band, nodatavalue = 13, pixel value = 4
insert into dummy_rast values(1,
(
'01' -- little endian (uint8 ndr)
||
'0000' -- version (uint16 0)
||
'0200' -- nBands (uint16 0)
||
'17263529ED684A3F' -- scaleX (float64 0.000805965234044584)
||
'F9253529ED684ABF' -- scaleY (float64 -0.00080596523404458)
||
'1C9F33CE69E352C0' -- ipX (float64 -75.5533328537098)
||
'718F0E9A27A44840' -- ipY (float64 49.2824585505576)
||
'ED50EB853EC32B3F' -- skewX (float64 0.000211812383858707)
||
'7550EB853EC32B3F' -- skewY (float64 0.000211812383858704)
||
'E6100000' -- SRID (int32 4326)
||
'0100' -- width (uint16 1)
||
'0100' -- height (uint16 1)
||
'4' -- hasnodatavalue set to true, isnodata value set to false (when it should be true)
||
'2' -- first band type (4BUI)
||
'03' -- novalue==3
||
'03' -- pixel(0,0)==3 (same that nodata)
||
'0' -- hasnodatavalue set to false
||
'5' -- second band type (16BSI)
||
'0D00' -- novalue==13
||
'0400' -- pixel(0,0)==4
)::raster
);
select st_bandisnodata(rast, 1) from dummy_rast where rid = 1; -- Expected false
select st_bandisnodata(rast, 1, TRUE) from dummy_rast where rid = 1; -- Expected true
-- The isnodata flag is dirty. We are going to set it to true
update dummy_rast set rast = st_setbandisnodata(rast, 1) where rid = 1;
select st_bandisnodata(rast, 1) from dummy_rast where rid = 1; -- Expected true
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_BandNoDataValue" />,<xref
linkend="RT_ST_NumBands" />, <xref
linkend="RT_ST_SetBandNoDataValue"/>, <xref
linkend="RT_ST_BandIsNoData"/></para>
</refsection>
</refentry>
</sect1>
<sect1 id="RasterBand_Stats">
<title>Raster Band Statistics and Analytics</title>
<refentry id="RT_ST_Count">
<refnamediv>
<refname>ST_Count</refname>
<refpurpose>Returns the number of pixels in a given band of a raster or raster coverage. If no band is specified defaults to band 1. If exclude_nodata_value is set to true, will only count pixels that are not equal to the nodata value.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>bigint <function>ST_Count</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>nband=1</parameter></paramdef>
<paramdef choice="opt"><type>boolean </type> <parameter>exclude_nodata_value=true</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>bigint <function>ST_Count</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>boolean </type> <parameter>exclude_nodata_value</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>bigint <function>ST_Count</function></funcdef>
<paramdef><type>text </type> <parameter>rastertable</parameter></paramdef>
<paramdef><type>text </type> <parameter>rastercolumn</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>nband=1</parameter></paramdef>
<paramdef choice="opt"><type>boolean </type> <parameter>exclude_nodata_value=true</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>bigint <function>ST_Count</function></funcdef>
<paramdef><type>text </type> <parameter>rastertable</parameter></paramdef>
<paramdef><type>text </type> <parameter>rastercolumn</parameter></paramdef>
<paramdef><type>boolean </type> <parameter>exclude_nodata_value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the number of pixels in a given band of a raster or raster coverage. If no band is specified <varname>nband</varname> defaults to 1. </para>
<note><para>If <varname>exclude_nodata_value</varname> is set to true, will only count pixels with value not equal to the <varname>nodata</varname> value of the raster. Set <varname>exclude_nodata_value</varname> to false to get count all pixels</para></note>
<para>Availability: 2.0.0 </para>
</refsection>
<refsection>
<title>Examples</title>
<!-- TODO: Fix once we confirm the right behavior -->
<programlisting>
--example will count all pixels not 249 and one will count all pixels. --
SELECT rid, ST_Count(ST_SetBandNoDataValue(rast,249)) As exclude_nodata,
ST_Count(ST_SetBandNoDataValue(rast,249),false) As include_nodata
FROM dummy_rast WHERE rid=2;
rid | exclude_nodata | include_nodata
-----+----------------+----------------
2 | 23 | 25
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_SetBandNoDataValue" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_Histogram">
<refnamediv>
<refname>ST_Histogram</refname>
<refpurpose>Returns a set of histogram summarizing a raster's data distribution separate bin ranges. Number of bins are autocomputed if not specified.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>SETOF histogram <function>ST_Histogram</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>nband=1</parameter></paramdef>
<paramdef choice="opt"><type>boolean </type> <parameter>exclude_nodata_value=true</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>bins=autocomputed</parameter></paramdef>
<paramdef choice="opt"><type>double precision[] </type> <parameter>width=NULL</parameter></paramdef>
<paramdef choice="opt"><type>boolean </type> <parameter>right=false</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>SETOF histogram <function>ST_Histogram</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>nband</parameter></paramdef>
<paramdef><type>integer </type> <parameter>bins</parameter></paramdef>
<paramdef choice="opt"><type>double precision[] </type> <parameter>width=NULL</parameter></paramdef>
<paramdef choice="opt"><type>boolean </type> <parameter>right=false</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>SETOF histogram <function>ST_Histogram</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>nband</parameter></paramdef>
<paramdef><type>boolean </type> <parameter>exclude_nodata_value</parameter></paramdef>
<paramdef><type>integer </type> <parameter>bins</parameter></paramdef>
<paramdef><type>boolean </type> <parameter>right</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>SETOF histogram <function>ST_Histogram</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>nband</parameter></paramdef>
<paramdef><type>integer </type> <parameter>bins</parameter></paramdef>
<paramdef><type>boolean </type> <parameter>right</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns set of <varname>histogram</varname> records consisting of min,max, count, percent for a given raster band for each bin. If no band is specified <varname>nband</varname> defaults to 1. </para>
<note><para>By default only considers pixel values not equal to the <varname>nodata</varname> value . Set <varname>exclude_nodata_value</varname> to false to get count all pixels</para>.</note>
<variablelist>
<varlistentry>
<term><parameter>width </parameter><type>double precision[]</type></term>
<listitem><para>width: an array indicating the width of each category/bin. If the number of bins is greater than the number of widths, the widths are repeated. </para>
<para>Example: 9 bins, widths are [a, b, c] will have the output be [a, b, c, a, b, c, a, b, c]</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>bins </parameter><type>integer</type></term>
<listitem><para>Number of breakouts -- this is the number of records you'll get back from the function if specified. If not specified
then the number of breakouts is autocomputed.</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>right </parameter><type>boolean</type></term>
<listitem><para>compute the histogram from the right rather than from the left (default). This changes the criteria for evaluating a value x from [a, b) to (a, b]</para></listitem>
</varlistentry>
</variablelist>
<para>Availability: 2.0.0 </para>
</refsection>
<refsection>
<title>Example: Single raster tile - compute histograms for bands 1, 2, 3 and autocompute bins</title>
<programlisting>SELECT band, (stats).*
FROM (SELECT rid, band, ST_Histogram(rast, band) As stats
FROM dummy_rast CROSS JOIN generate_series(1,3) As band
WHERE rid=2) As foo;
band | min | max | count | percent
------+-------+-------+-------+---------
1 | 249 | 250 | 2 | 0.08
1 | 250 | 251 | 2 | 0.08
1 | 251 | 252 | 1 | 0.04
1 | 252 | 253 | 2 | 0.08
1 | 253 | 254 | 18 | 0.72
2 | 78 | 113.2 | 11 | 0.44
2 | 113.2 | 148.4 | 4 | 0.16
2 | 148.4 | 183.6 | 4 | 0.16
2 | 183.6 | 218.8 | 1 | 0.04
2 | 218.8 | 254 | 5 | 0.2
3 | 62 | 100.4 | 11 | 0.44
3 | 100.4 | 138.8 | 5 | 0.2
3 | 138.8 | 177.2 | 4 | 0.16
3 | 177.2 | 215.6 | 1 | 0.04
3 | 215.6 | 254 | 4 | 0.16</programlisting>
</refsection>
<refsection>
<title>Example: Just band 2 but for 6 bins</title>
<programlisting>SELECT (stats).*
FROM (SELECT rid, ST_Histogram(rast, 2,6) As stats
FROM dummy_rast
WHERE rid=2) As foo;
min | max | count | percent
------------+------------+-------+---------
78 | 107.333333 | 9 | 0.36
107.333333 | 136.666667 | 6 | 0.24
136.666667 | 166 | 0 | 0
166 | 195.333333 | 4 | 0.16
195.333333 | 224.666667 | 1 | 0.04
224.666667 | 254 | 5 | 0.2
(6 rows)
-- Same as previous but we explicitly control the pixel value range of each bin.
SELECT (stats).*
FROM (SELECT rid, ST_Histogram(rast, 2,6,ARRAY[0.5,1,4,100,5]) As stats
FROM dummy_rast
WHERE rid=2) As foo;
min | max | count | percent
-------+-------+-------+----------
78 | 78.5 | 1 | 0.08
78.5 | 79.5 | 1 | 0.04
79.5 | 83.5 | 0 | 0
83.5 | 183.5 | 17 | 0.0068
183.5 | 188.5 | 0 | 0
188.5 | 254 | 6 | 0.003664
(6 rows)</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="histogram" />, <xref linkend="RT_ST_Count" />, <xref linkend="RT_ST_SummaryStats" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_Quantile">
<refnamediv>
<refname>ST_Quantile</refname>
<refpurpose>Compute quantiles in the context of the sample or population. Thus, a value could be examined to be at the raster's 25%, 50%, 75% percentile.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>SETOF quantile <function>ST_Quantile</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef choice='opt'><type>integer </type> <parameter>nband=1</parameter></paramdef>
<paramdef choice='opt'><type>boolean </type> <parameter>exclude_nodata_value=true</parameter></paramdef>
<paramdef choice='opt'><type>double precision[] </type> <parameter>quantiles=NULL</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>SETOF quantile <function>ST_Quantile</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>double precision[] </type> <parameter>quantiles</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>SETOF quantile <function>ST_Quantile</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>nband</parameter></paramdef>
<paramdef><type>double precision[] </type> <parameter>quantiles</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>double precision <function>ST_Quantile</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>quantile</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>double precision <function>ST_Quantile</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>boolean </type> <parameter>exclude_nodata_value</parameter></paramdef>
<paramdef choice='opt'><type>double precision </type> <parameter>quantile=NULL</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>double precision <function>ST_Quantile</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>nband</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>quantile</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>double precision <function>ST_Quantile</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>nband</parameter></paramdef>
<paramdef><type>boolean </type> <parameter>exclude_nodata_value</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>quantile</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>double precision <function>ST_Quantile</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>nband</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>quantile</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Compute quantiles in the context of the sample or population. Thus, a value could be examined to be at the raster's 25%, 50%, 75% percentile.</para>
<note><para>If <varname>exclude_nodata_value</varname> is set to false, will also count pixels with no data.</para></note>
<para>Availability: 2.0.0 </para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
UPDATE dummy_rast SET rast = ST_SetBandNoDataValue(rast,249) WHERE rid=2;
--Example will consider only pixels of band 1 that are not 249 and in named quantiles --
SELECT (pvq).*
FROM (SELECT ST_Quantile(rast, ARRAY[0.25,0.75]) As pvq
FROM dummy_rast WHERE rid=2) As foo
ORDER BY (pvq).quantile;
quantile | value
----------+-------
0.25 | 253
0.75 | 254
SELECT ST_Quantile(rast, 0.75) As value
FROM dummy_rast WHERE rid=2;
value
------
254
</programlisting>
<programlisting>
--real live example. Quantile of all pixels in band 2 intersecting a geometry
SELECT rid, (ST_Quantile(rast,2)).* As pvc
FROM o_4_boston
WHERE ST_Intersects(rast,
ST_GeomFromText('POLYGON((224486 892151,224486 892200,224706 892200,224706 892151,224486 892151))',26986)
)
ORDER BY value, quantile,rid
;
rid | quantile | value
-----+----------+-------
1 | 0 | 0
2 | 0 | 0
14 | 0 | 1
15 | 0 | 2
14 | 0.25 | 37
1 | 0.25 | 42
15 | 0.25 | 47
2 | 0.25 | 50
14 | 0.5 | 56
1 | 0.5 | 64
15 | 0.5 | 66
2 | 0.5 | 77
14 | 0.75 | 81
15 | 0.75 | 87
1 | 0.75 | 94
2 | 0.75 | 106
14 | 1 | 199
1 | 1 | 244
2 | 1 | 255
15 | 1 | 255
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_Count" />, <xref linkend="RT_ST_SetBandNoDataValue" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_SummaryStats">
<refnamediv>
<refname>ST_SummaryStats</refname>
<refpurpose>Returns summary stats consisting of count,sum,mean,stddev,min,max for a given raster band of a raster or raster coverage.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>summarystats <function>ST_SummaryStats</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>nband=1</parameter></paramdef>
<paramdef choice="opt"><type>boolean </type> <parameter>exclude_nodata_value=true</parameter></paramdef>
<paramdef choice="opt"><type>double precision </type> <parameter>sample_percent=1</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>summarystats <function>ST_SummaryStats</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>boolean </type> <parameter>exclude_nodata_value</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>summarystats <function>ST_SummaryStats</function></funcdef>
<paramdef><type>text </type> <parameter>rastertable</parameter></paramdef>
<paramdef><type>text </type> <parameter>rastercolumn</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>nband=1</parameter></paramdef>
<paramdef choice="opt"><type>boolean </type> <parameter>exclude_nodata_value=true</parameter></paramdef>
<paramdef choice="opt"><type>double precision </type> <parameter>sample_percent=1</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>summarystats <function>ST_SummaryStats</function></funcdef>
<paramdef><type>text </type> <parameter>rastertable</parameter></paramdef>
<paramdef><type>text </type> <parameter>rastercolumn</parameter></paramdef>
<paramdef><type>boolean </type> <parameter>exclude_nodata_value</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns <varname>summarystats</varname> consisting of count, sum, mean, stddev, min, max for a given raster band of a raster or raster coverage.. If no band is specified <varname>nband</varname> defaults to 1. </para>
<note><para>By default only considers pixel values no equal to the <varname>nodata</varname> value . Set <varname>exclude_nodata_value</varname> to false to get count all pixels</para>. By default will sample all pixels. To get faster response, set <varname>sample_percent</varname> to lower than 1</note>
<para>Availability: 2.0.0 </para>
</refsection>
<refsection>
<title>Example: Single raster tile</title>
<programlisting>
SELECT rid, band, (stats).*
FROM (SELECT rid, band, ST_SummaryStats(rast, band) As stats
FROM dummy_rast CROSS JOIN generate_series(1,3) As band
WHERE rid=2) As foo;
rid | band | count | sum | mean | stddev | min | max
-----+------+-------+------+------------+-----------+-----+-----
2 | 1 | 23 | 5821 | 253.086957 | 1.248061 | 250 | 254
2 | 2 | 25 | 3682 | 147.28 | 59.862188 | 78 | 254
2 | 3 | 25 | 3290 | 131.6 | 61.647384 | 62 | 254
</programlisting>
</refsection>
<refsection>
<title>Example: Raster coverage</title>
<programlisting>
-- stats for each band --
SELECT band, (stats).*
FROM (SELECT band, ST_SummaryStats('o_4_boston','rast', band) As stats
FROM generate_series(1,3) As band) As foo;
band | count | sum | mean | stddev | min | max
------+---------+--------+------------------+------------------+-----+-----
1 | 8450000 | 725799 | 82.7064349112426 | 45.6800222638537 | 0 | 255
2 | 8450000 | 700487 | 81.4197705325444 | 44.2161184161765 | 0 | 255
3 | 8450000 | 575943 | 74.682739408284 | 44.2143885481407 | 0 | 255
-- For a table -- will get better speed if set sampling to less than 100%
-- Here we set to 25% and get a much faster answer
SELECT band, (stats).*
FROM (SELECT band, ST_SummaryStats('o_4_boston','rast', band,true,0.25) As stats
FROM generate_series(1,3) As band) As foo;
band | count | sum | mean | stddev | min | max
------+---------+--------+------------------+------------------+-----+-----
1 | 2112500 | 180686 | 82.6890480473373 | 45.6961043857248 | 0 | 255
2 | 2112500 | 174571 | 81.448503668639 | 44.2252623171821 | 0 | 255
3 | 2112500 | 144364 | 74.6765884023669 | 44.2014869384578 | 0 | 255
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_Count" />, <para><xref linkend="summarystats" /></para></para>
</refsection>
</refentry>
<refentry id="RT_ST_ValueCount">
<refnamediv>
<refname>ST_ValueCount</refname>
<refpurpose>Returns a set of records containing a pixel band value and count of the number of pixels in a given band of a raster (or a raster coverage) that have a given set of values. If no band is specified defaults to band 1. By default nodata value pixels are not counted.
and all other values in the pixel are output and pixel band values are rounded to the nearest integer.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>SETOF record <function>ST_ValueCount</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>nband=1</parameter></paramdef>
<paramdef choice="opt"><type>boolean </type> <parameter>exclude_nodata_value=true</parameter></paramdef>
<paramdef choice="opt"><type>double precision[] </type> <parameter>searchvalues=NULL</parameter></paramdef>
<paramdef choice="opt"><type>double precision </type> <parameter>roundto=0</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>OUT value</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>OUT count</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>SETOF record <function>ST_ValueCount</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>nband</parameter></paramdef>
<paramdef><type>double precision[] </type> <parameter>searchvalues</parameter></paramdef>
<paramdef choice="opt"><type>double precision </type> <parameter>roundto=0</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>OUT value</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>OUT count</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>SETOF record <function>ST_ValueCount</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>double precision[] </type> <parameter>searchvalues</parameter></paramdef>
<paramdef choice="opt"><type>double precision </type> <parameter>roundto=0</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>OUT value</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>OUT count</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>integer <function>ST_ValueCount</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>searchvalue</parameter></paramdef>
<paramdef choice="opt"><type>double precision </type> <parameter>roundto=0</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>integer <function>ST_ValueCount</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>nband</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>searchvalue</parameter></paramdef>
<paramdef choice="opt"><type>double precision </type> <parameter>roundto=0</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>SETOF record <function>ST_ValueCount</function></funcdef>
<paramdef><type>text </type> <parameter>rastertable</parameter></paramdef>
<paramdef><type>text </type> <parameter>rastercolumn</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>nband=1</parameter></paramdef>
<paramdef choice="opt"><type>boolean </type> <parameter>exclude_nodata_value=true</parameter></paramdef>
<paramdef choice="opt"><type>double precision[] </type> <parameter>searchvalues=NULL</parameter></paramdef>
<paramdef choice="opt"><type>double precision </type> <parameter>roundto=0</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>OUT value</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>OUT count</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>SETOF record <function>ST_ValueCount</function></funcdef>
<paramdef><type>text </type> <parameter>rastertable</parameter></paramdef>
<paramdef><type>text </type> <parameter>rastercolumn</parameter></paramdef>
<paramdef><type>double precision[] </type> <parameter>searchvalues</parameter></paramdef>
<paramdef choice="opt"><type>double precision </type> <parameter>roundto=0</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>OUT value</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>OUT count</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>bigint <function>ST_ValueCount</function></funcdef>
<paramdef><type>text </type> <parameter>rastertable</parameter></paramdef>
<paramdef><type>text </type> <parameter>rastercolumn</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>searchvalue</parameter></paramdef>
<paramdef choice="opt"><type>double precision </type> <parameter>roundto=0</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>bigint <function>ST_ValueCount</function></funcdef>
<paramdef><type>text </type> <parameter>rastertable</parameter></paramdef>
<paramdef><type>text </type> <parameter>rastercolumn</parameter></paramdef>
<paramdef><type>integer </type> <parameter>nband</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>searchvalue</parameter></paramdef>
<paramdef choice="opt"><type>double precision </type> <parameter>roundto=0</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns a set of records with columns <varname>value</varname> <varname>count</varname> which contain the pixel band value and count of pixels in the raster tile or raster coverage of selected band. </para>
<para>If no band is specified <varname>nband</varname> defaults to 1. If no <varname>searchvalues</varname> are specified, will return all pixel values found in the raster or raster coverage. If one searchvalue is given, will return an integer instead of records denoting the count of pixels having that pixel band value</para>
<note><para>If <varname>exclude_nodata_value</varname> is set to false, will also count pixels with no data.</para></note>
<para>Availability: 2.0.0 </para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
UPDATE dummy_rast SET rast = ST_SetBandNoDataValue(rast,249) WHERE rid=2;
--Example will count only pixels of band 1 that are not 249. --
SELECT (pvc).*
FROM (SELECT ST_ValueCount(rast) As pvc
FROM dummy_rast WHERE rid=2) As foo
ORDER BY (pvc).value;
value | count
-------+-------
250 | 2
251 | 1
252 | 2
253 | 6
254 | 12
-- Example will coount all pixels of band 1 including 249 --
SELECT (pvc).*
FROM (SELECT ST_ValueCount(rast,1,false) As pvc
FROM dummy_rast WHERE rid=2) As foo
ORDER BY (pvc).value;
value | count
-------+-------
249 | 2
250 | 2
251 | 1
252 | 2
253 | 6
254 | 12
-- Example will count only non-nodata value pixels of band 2
SELECT (pvc).*
FROM (SELECT ST_ValueCount(rast,2) As pvc
FROM dummy_rast WHERE rid=2) As foo
ORDER BY (pvc).value;
value | count
-------+-------
78 | 1
79 | 1
88 | 1
89 | 1
96 | 1
97 | 1
98 | 1
99 | 2
112 | 2
:
</programlisting>
<programlisting>
--real live example. Count all the pixels in an aerial raster tile band 2 intersecting a geometry
-- and return only the pixel band values that have a count > 500
SELECT (pvc).value, SUM((pvc).count) As total
FROM (SELECT ST_ValueCount(rast,2) As pvc
FROM o_4_boston
WHERE ST_Intersects(rast,
ST_GeomFromText('POLYGON((224486 892151,224486 892200,224706 892200,224706 892151,224486 892151))',26986)
)
) As foo
GROUP BY (pvc).value
HAVING SUM((pvc).count) > 500
ORDER BY (pvc).value;
value | total
-------+-----
51 | 502
54 | 521
</programlisting>
<programlisting>
-- Just return count of pixels in each raster tile that have value of 100 of tiles that intersect a specific geometry --
SELECT rid, ST_ValueCount(rast,2,100) As count
FROM o_4_boston
WHERE ST_Intersects(rast,
ST_GeomFromText('POLYGON((224486 892151,224486 892200,224706 892200,224706 892151,224486 892151))',26986)
) ;
rid | count
-----+-------
1 | 56
2 | 95
14 | 37
15 | 64
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_Count" />, <xref linkend="RT_ST_SetBandNoDataValue" /></para>
</refsection>
</refentry>
</sect1>
<sect1 id="Raster_Outputs">
<title>Raster Outputs</title>
<refentry id="RT_ST_AsBinary">
<refnamediv>
<refname>ST_AsBinary</refname>
<refpurpose>Return the Well-Known Binary (WKB) representation of the raster without SRID meta data.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>bytea <function>ST_AsBinary</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the Binary representation of the raster. There are 2 variants of the function. The first
variant takes no endian encoding parameter and defaults to little endian. The second variant takes a second argument
denoting the encoding - using little-endian ('NDR') or big-endian ('XDR') encoding.</para>
<para>This is useful in binary cursors to pull data out of the
database without converting it to a string representation.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT ST_AsBinary(rast) As rastbin
FROM dummy_rast WHERE rid=1;
rastbin
---------------------------------------------------------------------------------
\001\000\000\000\000\000\000\000\000\000\000\000@\000\000\000\000\000\000\010@\
000\000\000\000\000\000\340?\000\000\000\000\000\000\340?\000\000\000\000\000\00
0\000\000\000\000\000\000\000\000\000\000\012\000\000\000\012\000\024\000
</programlisting>
</refsection>
</refentry>
<refentry id="RT_ST_AsGDALRaster">
<refnamediv>
<refname>ST_AsGDALRaster</refname>
<refpurpose>Return the raster tile in the designated GDAL Raster format. Raster formats are one of those supported by your compiled library. Use ST_GDALRasters() to get a list of formats supported by your library.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>bytea <function>ST_AsGDALRaster</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>text </type> <parameter>format</parameter></paramdef>
<paramdef choice='opt'><type>text[] </type> <parameter>options=NULL</parameter></paramdef>
<paramdef choice='opt'><type>integer </type> <parameter>srid=sameassource</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the raster tile in the designated format. Arguments are itemized below:</para>
<itemizedlist>
<listitem>
<varname>format</varname> format to output. This is dependent on the drivers compiled in your libgdal library. Generally available are 'JPEG', 'GTIff', 'PNG'. Use <xref linkend="RT_ST_GDALDrivers" /> to get a list of formats supported by your library.
</listitem>
<listitem><varname>options</varname> text array of GDAL options. Valid options are dependent on the format. Refer to <ulink url="http://www.gdal.org/frmt_various.html">GDAL Raster format options</ulink> for more details.</listitem>
<listitem><varname>srs</varname> The proj4text or srtext (from spatial_ref_sys) to embed in the image</listitem>
</itemizedlist>
<para>Availability: 2.0.0 - requires GDAL &gt;= 1.6.0. </para>
</refsection>
<refsection>
<title>JPEG Output Examples</title>
<programlisting>SELECT ST_AsGDALRaster(rast, 'JPEG') As rastjpg
FROM dummy_rast WHERE rid=1;
SELECT ST_AsGDALRaster(rast, 'JPEG', ARRAY!['QUALITY=50']) As rastjpg
FROM dummy_rast WHERE rid=2;
</programlisting>
</refsection>
<refsection>
<title>GTIFF Output Examples</title>
<programlisting>SELECT ST_AsGDALRaster(rast, 'GTiff') As rastjpg
FROM dummy_rast WHERE rid=2;
SELECT ST_AsGDALRaster(rast, 'GTiff',
ARRAY['COMPRESS=JPEG', 'JPEG_QUALITY=90'],
'+proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs') As rasttiff
FROM dummy_rast WHERE rid=2;
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_GDALDrivers" />, <xref linkend="RT_ST_SRID" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_AsPNG">
<refnamediv>
<refname>ST_AsPNG</refname>
<refpurpose>Return the raster tile selected bands as a single portable network graphics (PNG) image (byte array). If no band is specified, then the first 3 bands are used.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>bytea <function>ST_AsPNG</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef choice='opt'><type>text[] </type> <parameter>options=NULL</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>bytea <function>ST_AsPNG</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>nband</parameter></paramdef>
<paramdef><type>integer </type> <parameter>compression</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>bytea <function>ST_AsPNG</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>nband</parameter></paramdef>
<paramdef choice='opt'><type>text[] </type> <parameter>options=NULL</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>bytea <function>ST_AsPNG</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer[] </type> <parameter>nbands</parameter></paramdef>
<paramdef><type>integer </type> <parameter>compression</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>bytea <function>ST_AsPNG</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer[] </type> <parameter>nbands</parameter></paramdef>
<paramdef choice='opt'><type>text[] </type> <parameter>options=NULL</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the selected bands of the raster as a single Portable Network Graphics Image (PNG). Use <xref linkend="RT_ST_AsGDALRaster" /> if you need to export as less common raster types. If no band is specified, then the first 3 bands are exported. There are many variants of the function with many options. If no <varname>srid</varname> is specified then then srid of the raster is used. These are itemized below:</para>
<itemizedlist>
<listitem>
<varname>nband</varname> is for single band exports.
</listitem>
<listitem>
<varname>nbands</varname> is an array of bands to export (note that max is 3 for PNG) and the order of the bands is RGB. e.g ARRAY[3,2,1] means map band 3 to Red, band 2 to green and band 1 to blue
</listitem>
<listitem><varname>compression</varname> number from 1 to 9. The higher the number the greater the compression.</listitem>
<listitem><varname>options</varname> text Array of GDAL options as defined for PNG (look at create_options for PNG of <xref linkend="RT_ST_GDALDrivers" />). For PNG valid one is only ZLEVEL (amount of time to spend on compression -- default 6) e.g. ARRAY['ZLEVEL=9'].
WORLDFILE is not allowed since the function would have to output two outputs. Refer to <ulink url="http://www.gdal.org/frmt_various.html">GDAL Raster format options</ulink> for more details.
</listitem>
</itemizedlist>
<para>Availability: 2.0.0 - requires GDAL &gt;= 1.6.0. </para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT ST_AsPNG(rast) As rastpng
FROM dummy_rast WHERE rid=2;
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_GDALDrivers" />, <xref linkend="RT_ST_AsGDALRaster" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_AsTIFF">
<refnamediv>
<refname>ST_AsTIFF</refname>
<refpurpose>Return the raster tile selected bands as a single TIFF image (byte array). If no band is specified, then will try to use all bands?.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>bytea <function>ST_AsTIFF</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef choice="opt"><type>text[] </type> <parameter>options=''</parameter></paramdef>
<paramdef><type>integer </type> <parameter>srid=sameassource</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>bytea <function>ST_AsTIFF</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef choice="opt"><type>text </type> <parameter>compression=''</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>srid=sameassource</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>bytea <function>ST_AsTIFF</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer[] </type> <parameter>nbands</parameter></paramdef>
<paramdef choice="opt"><type>text </type> <parameter>compression=''</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>srid=sameassource</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>bytea <function>ST_AsTIFF</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer[] </type> <parameter>nbands</parameter></paramdef>
<paramdef><type>text[] </type> <parameter>options</parameter></paramdef>
<paramdef><type>integer </type> <parameter>srid=sameassource</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the selected bands of the raster as a single Tagged Image File Format (TIFF). If no band is specified, will try to use all bands. This is a wrapper around <xref linkend="RT_ST_AsGDALRaster" />. Use <xref linkend="RT_ST_AsGDALRaster" /> if you need to export as less common raster types. There are many variants of the function with many options. If no spatial reference SRS text is present, the spatial reference of the raster is used. These are itemized below:</para>
<itemizedlist>
<listitem>
<varname>nbands</varname> is an array of bands to export (note that max is 3 for PNG) and the order of the bands is RGB. e.g ARRAY[3,2,1] means map band 3 to Red, band 2 to green and band 1 to blue
</listitem>
<listitem><varname>compression</varname> Compression expression -- JPEG90 (or someother percent), LZMA, JPEG, DEFALTE9. </listitem>
<listitem><varname>options</varname> text Array of GDAL create options as defined for GTiff (look at create_options for GTiff of <xref linkend="RT_ST_GDALDrivers" />). or refer to <ulink url="http://www.gdal.org/frmt_various.html">GDAL Raster format options</ulink> for more details. </listitem>
<listitem><varname>srid</varname> srid of spatial_ref_sys of the raster. This is used to populate the georeference information </listitem>
</itemizedlist>
<para>Availability: 2.0.0 - requires GDAL &gt;= 1.6.0. </para>
</refsection>
<refsection>
<title>Examples: Use jpeg compression 90%</title>
<programlisting>SELECT ST_AsTIFF(rast, 'JPEG90') As rasttiff
FROM dummy_rast WHERE rid=2;
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_GDALDrivers" />, <xref linkend="RT_ST_AsGDALRaster" />, <xref linkend="RT_ST_SRID" /></para>
</refsection>
</refentry>
</sect1>
<sect1 id="Raster_Processing">
<title>Raster Processing Functions</title>
<refentry id="RT_Box2D">
<refnamediv>
<refname>Box2D</refname>
<refpurpose>Returns the box 2d representation of the enclosing box of the raster</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>box2d <function>Box2D</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the box representing the extent of the raster.</para>
<para>The polygon is defined by the corner points of the bounding box
((<varname>MINX</varname>, <varname>MINY</varname>),
(<varname>MAXX</varname>, <varname>MAXY</varname>))</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT rid, Box2D(rast) As rastbox
FROM dummy_rast;
rid | rastbox
----+-------------------------------------------------
1 | BOX(0.5 0.5,20.5 60.5)
2 | BOX(3427927.75 5793243.5,3427928 5793244)
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_Envelope" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_ConvexHull">
<refnamediv>
<refname>ST_ConvexHull</refname>
<refpurpose>Return the convex hull geometry of the raster including pixel values equal to BandNoDataValue.
For regular shaped and non-skewed
rasters, this gives the same answer as ST_Envelope so only useful for irregularly shaped or skewed rasters.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_ConvexHull</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Return the convex hull geometry of the raster including the NoDataBandValue band pixels. For regular shaped and non-skewed
rasters, this gives more or less the same answer as ST_Envelope
so only useful for irregularly shaped or skewed rasters.</para>
<note><para>ST_Envelope floors the coordinates and hence add a little buffer around the raster so the answer is subtly
different from ST_ConvexHull which does not floor.</para>
</note>
</refsection>
<refsection>
<title>Examples</title>
<para>Refer to <ulink url="http://trac.osgeo.org/postgis/wiki/WKTRaster/SpecificationWorking01">PostGIS Raster Specification</ulink>
for a diagram of this.</para>
<informaltable>
<tgroup cols="1">
<tbody>
<row>
<entry>
<para> <!-- TODO: Put in pictures -->
<programlisting>-- Note envelope and convexhull are more or less the same
SELECT ST_AsText(ST_ConvexHull(rast)) As convhull,
ST_AsText(ST_Envelope(rast)) As env
FROM dummy_rast WHERE rid=1;
convhull | env
--------------------------------------------------------+-----------------------
POLYGON((0.5 0.5,20.5 0.5,20.5 60.5,0.5 60.5,0.5 0.5)) | POLYGON((0 0,20 0,20 60,0 60,0 0))
</programlisting>
</para>
</entry>
</row>
<row>
<entry>
<para> <!-- TODO: Put in pictures -->
<programlisting>
-- now we skew the raster
-- note how the convex hull and envelope are now different
SELECT ST_AsText(ST_ConvexHull(rast)) As convhull,
ST_AsText(ST_Envelope(rast)) As env
FROM (SELECT ST_SetRotation(rast,0.1,0.1) As rast
FROM dummy_rast WHERE rid=1) As foo;
convhull | env
--------------------------------------------------------+------------------------------------
POLYGON((0.5 0.5,20.5 1.5,22.5 61.5,2.5 60.5,0.5 0.5)) | POLYGON((0 0,22 0,22 61,0 61,0 0))
</programlisting>
</para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_Envelope" />, <xref linkend="ST_ConvexHull" />, <xref linkend="ST_AsText" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_DumpAsPolygons">
<refnamediv>
<refname>ST_DumpAsPolygons</refname>
<refpurpose>Returns a set of geomval (geom,val) rows, from a given raster band. If no band number is specified, band num defaults to 1.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>setof geomval <function>ST_DumpAsPolygons</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>setof geomval <function>ST_DumpAsPolygons</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>band_num</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>This is a set-returning function (SRF). It returns a set of
geomval rows, formed by a geometry (geom) and a pixel band value (val).
Each polygon is the union of all pixels for that band that have the same pixel value denoted by val.</para>
<para>ST_DumpAsPolygon is useful for polygonizing rasters. It is the
reverse of a GROUP BY in that it creates new rows. For example it
can be used to expand a single raster into multiple POLYGONS/MULTIPOLYGONS.</para>
<para>Availability: Requires GDAL 1.7 or higher.</para>
<note><para>If there is a no data value set for a band, pixels with that value will not be returned.</para></note>
<note><para>If you only care about count of pixels with a given value in a raster, it is faster to use <xref linkend="RT_ST_ValueCount" />.</para></note>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT val, ST_AsText(geom) As geomwkt
FROM (
SELECT (ST_DumpAsPolygons(rast)).*
FROM dummy_rast
WHERE rid = 2
) As foo
WHERE val BETWEEN 249 and 251
ORDER BY val;
val | geomwkt
-----+--------------------------------------------------------------------------
249 | POLYGON((3427927.95 5793243.95,3427927.95 5793243.85,3427928 5793243.85,
3427928 5793243.95,3427927.95 5793243.95))
250 | POLYGON((3427927.75 5793243.9,3427927.75 5793243.85,3427927.8 5793243.85,
3427927.8 5793243.9,3427927.75 5793243.9))
250 | POLYGON((3427927.8 5793243.8,3427927.8 5793243.75,3427927.85 5793243.75,
3427927.85 5793243.8, 3427927.8 5793243.8))
251 | POLYGON((3427927.75 5793243.85,3427927.75 5793243.8,3427927.8 5793243.8,
3427927.8 5793243.85,3427927.75 5793243.85))
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="geomval" />,<xref linkend="RT_ST_Value" />, <xref linkend="RT_ST_Polygon" />, <xref linkend="RT_ST_ValueCount" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_Envelope">
<refnamediv>
<refname>ST_Envelope</refname>
<refpurpose>Returns the polygon representation of the extent of the raster.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Envelope</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the polygon representation of the extent of the raster in spatial coordinate units defined by srid. It is a float8 minimum bounding box represented as a polygon. </para>
<para>The polygon is defined by the corner points of the bounding box
((<varname>MINX</varname>, <varname>MINY</varname>),
(<varname>MINX</varname>, <varname>MAXY</varname>),
(<varname>MAXX</varname>, <varname>MAXY</varname>),
(<varname>MAXX</varname>, <varname>MINY</varname>),
(<varname>MINX</varname>, <varname>MINY</varname>))</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT rid, ST_AsText(ST_Envelope(rast)) As envgeomwkt
FROM dummy_rast;
rid | envgeomwkt
-----+--------------------------------------------------------------------
1 | POLYGON((0 0,20 0,20 60,0 60,0 0))
2 | POLYGON((3427927 5793243,3427928 5793243,
3427928 5793244,3427927 5793244, 3427927 5793243))
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="ST_Envelope" />, <xref linkend="ST_AsText" />, <xref linkend="RT_ST_SRID" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_Intersection">
<refnamediv>
<refname>ST_Intersection</refname>
<refpurpose>Returns a set of geometry-pixelvalue pairs resulting from intersection of a raster band with a geometry. If
no band number is specified, band 1 is assumed.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>setof geomval <function>ST_Intersection</function></funcdef>
<paramdef><type>geometry </type> <parameter>geom</parameter></paramdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>setof geomval <function>ST_Intersection</function></funcdef>
<paramdef><type>geometry </type> <parameter>geom</parameter></paramdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>band_num</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>setof geomval <function>ST_Intersection</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>geom</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>setof geomval <function>ST_Intersection</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>band_num</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>geom</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Return the intersections of the geometry with the vectorized parts of
the raster and the values associated with those parts, if really their intersection is not empty. If no band number is specified
band 1 is assumed.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT foo.rid, foo.gid,
ST_AsText((foo.geomval).geom) As geomwkt, (foo.geomval).val
FROM
(
SELECT A.rid, g.gid , ST_Intersection(A.rast, g.geom) As geomval
FROM dummy_rast AS A CROSS JOIN
(VALUES (1, ST_Point(3427928, 5793243.85) ) ,
(2, ST_GeomFromText('LINESTRING(3427927.85 5793243.75,3427927.8 5793243.75,3427927.8 5793243.8)') ),
(3, ST_GeomFromText('LINESTRING(1 2, 3 4)') )
) As g(gid,geom)
WHERE A.rid =2 ) As foo;
rid | gid | geomwkt | val
-----+-----+---------------------------------------------------------------------------------------------
2 | 1 | POINT(3427928 5793243.85) | 249
2 | 1 | POINT(3427928 5793243.85) | 253
2 | 2 | POINT(3427927.85 5793243.75) | 254
2 | 2 | POINT(3427927.8 5793243.8) | 251
2 | 2 | POINT(3427927.8 5793243.8) | 253
2 | 2 | LINESTRING(3427927.8 5793243.75,3427927.8 5793243.8) | 252
2 | 2 | MULTILINESTRING((3427927.8 5793243.8,3427927.8 5793243.75),...) | 250
2 | 3 | GEOMETRYCOLLECTION EMPTY
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="geomval" />, <xref linkend="RT_ST_Intersects" />, <xref linkend="ST_AsText" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_MapAlgebra">
<refnamediv>
<refname>ST_MapAlgebra</refname>
<refpurpose>Creates a new one band raster formed by applying a valid PostgreSQL algebraic operation on the input raster band and of pixeltype provided. band 1 is assumed if no band is specified.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>raster <function>ST_MapAlgebra</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>band</parameter></paramdef>
<paramdef><type>text </type> <parameter>expression</parameter></paramdef>
<paramdef choice='opt'><type>text </type> <parameter>nodatavalueexpr=NULL</parameter></paramdef>
<paramdef choice='opt'><type>text </type> <parameter>pixeltype=same_as_source</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_MapAlgebra</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>text </type> <parameter>expression</parameter></paramdef>
<paramdef choice='opt'><type>text </type> <parameter>nodatavalueexpr=NULL</parameter></paramdef>
<paramdef choice='opt'><type>text </type> <parameter>pixeltype=same_as_source</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_MapAlgebra</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>text </type> <parameter>expression</parameter></paramdef>
<paramdef><type>text </type> <parameter>pixeltype</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Creates a new one band raster formed by applying a valid PostgreSQL algebraic operation defined by the <varname>expression</varname> on the input raster (<varname>rast</varname>). If no <varname>band</varname> is specified
band 1 is assumed. The new raster will have the same georeference, width, and height as the original raster but will only have one band.</para>
<para>If <varname>pixeltype</varname> is passed in, then the new raster will have a band of that pixeltype. If no pixeltype is passed in, then the new raster band will have the same pixeltype as the input <varname>rast</varname> band.</para>
<para>Use the term <varname>rast</varname> to refer to the pixel value of the original band.</para>
<para>Availability: 2.0.0 </para>
</refsection>
<refsection>
<title>Examples</title>
<para>Create a new 1 band raster from our original that is a function of modulo 2 of the original raster band.</para>
<programlisting>ALTER TABLE dummy_rast ADD COLUMN map_rast raster;
UPDATE dummy_rast SET map_rast = ST_MapAlgebra(rast,'mod(rast,2)') WHERE rid = 2;
SELECT ST_Value(rast,1,i,j) As origval, ST_Value(map_rast, 1, i, j) As mapval
FROM dummy_rast CROSS JOIN generate_series(1, 3) AS i CROSS JOIN generate_series(1,3) AS j
WHERE rid = 2;
origval | mapval
---------+--------
253 | 1
254 | 0
253 | 1
253 | 1
254 | 0
254 | 0
250 | 0
254 | 0
254 | 0
</programlisting>
<para>Create a new 1 band raster of pixel-type 2BUI from our original that is reclassified.</para>
<programlisting>ALTER TABLE dummy_rast ADD COLUMN map_rast2 raster;
UPDATE dummy_rast SET map_rast2 = ST_MapAlgebra(rast,'CASE WHEN rast BETWEEN 100 and 250 THEN 1
WHEN rast = 252 THEN 2
WHEN rast BETWEEN 253 and 254 THEN 3 ELSE 0 END', '2BUI') WHERE rid = 2;
SELECT DISTINCT ST_Value(rast,1,i,j) As origval, ST_Value(map_rast2, 1, i, j) As mapval
FROM dummy_rast CROSS JOIN generate_series(1, 5) AS i CROSS JOIN generate_series(1,5) AS j
WHERE rid = 2;
origval | mapval
---------+--------
249 | 1
250 | 1
251 |
252 | 2
253 | 3
254 | 3
SELECT ST_BandPixelType(map_rast2) As b1pixtyp
FROM dummy_rast WHERE rid = 2;
b1pixtyp
----------
2BUI</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_BandPixelType" />, <xref linkend="RT_ST_GeoReference" />, <xref linkend="RT_ST_Value" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_Polygon">
<refnamediv>
<refname>ST_Polygon</refname>
<refpurpose>Returns a polygon geometry formed by the union of pixels that have a pixel value that is not no data value. If no band number is specified, band num defaults to 1.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Polygon</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>geometry <function>ST_Polygon</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>band_num</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Availability: Requires GDAL 1.7 or higher.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
-- by default no data band value is 0 or not set, so polygon will return a square polygon
SELECT ST_AsText(ST_Polygon(rast)) As geomwkt
FROM dummy_rast
WHERE rid = 2;
geomwkt
--------------------------------------------
POLYGON((3427927.8 5793243.75,3427927.75 5793243.75,3427927.75 5793243.8,3427927.75 5793243.85,3427927.75 5793243.9,
3427927.75 5793244,3427927.8 5793244,3427927.85 5793244,3427927.9 5793244,3427928 5793244,3427928 5793243.95,
3427928 5793243.85,3427928 5793243.8,3427928 5793243.75,3427927.85 5793243.75,3427927.8 5793243.75))
-- now we change the no data value of first band
UPDATE dummy_rast SET rast = ST_SetBandNoDataValue(rast,1,254)
WHERE rid = 2;
SELECt rid, ST_BandNoDataValue(rast)
from dummy_rast where rid = 2;
-- ST_Polygon excludes the pixel value 254 and returns a multipolygon
SELECT ST_AsText(ST_Polygon(rast)) As geomwkt
FROM dummy_rast
WHERE rid = 2;
geomwkt
---------------------------------------------------------
MULTIPOLYGON(((3427927.9 5793243.95,3427927.85 5793243.95,3427927.85 5793244,3427927.9 5793244,3427927.9 5793243.95)),
((3427928 5793243.85,3427928 5793243.8,3427927.95 5793243.8,3427927.95 5793243.85,3427927.9 5793243.85,3427927.9 5793243.9,3427927.9 5793243.95,3427927.95 5793243.95,3427928 5793243.95,3427928 5793243.85)),
((3427927.8 5793243.75,3427927.75 5793243.75,3427927.75 5793243.8,3427927.75 5793243.85,3427927.75 5793243.9,3427927.75 5793244,3427927.8 5793244,
3427927.8 5793243.9,3427927.8 5793243.85,3427927.85 5793243.85,3427927.85 5793243.8,3427927.85 5793243.75,3427927.8 5793243.75)))
-- Or if you want the no data value different for just one time
SELECT ST_AsText(
ST_Polygon(
ST_SetBandNoDataValue(rast,1,252)
)
) As geomwkt
FROM dummy_rast
WHERE rid =2;
geomwkt
---------------------------------
POLYGON((3427928 5793243.85,3427928 5793243.8,3427928 5793243.75,3427927.85 5793243.75,3427927.8 5793243.75,3427927.8 5793243.8,3427927.75 5793243.8,3427927.75 5793243.85,3427927.75 5793243.9,3427927.75 5793244,3427927.8 5793244,3427927.85 5793244,3427927.9 5793244,3427928 5793244,3427928 5793243.95,3427928 5793243.85),
(3427927.9 5793243.9,3427927.9 5793243.85,3427927.95 5793243.85,3427927.95 5793243.9,3427927.9 5793243.9))
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_Value" />, <xref linkend="RT_ST_DumpAsPolygons" /></para>
</refsection>
</refentry>
<refentry id="RT_ST_Reclass">
<refnamediv>
<refname>ST_Reclass</refname>
<refpurpose>Creates a new raster composed of band types reclassified from original. The nband is the band to be changed. If nband is not specified assumed to be 1. All other bands are returned unchanged.
Use case: convert a 16BUI band to a 8 8BUI and so forth for simpler rendering as viewable formats.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>raster <function>ST_Reclass</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>integer </type> <parameter>nband</parameter></paramdef>
<paramdef><type>text </type> <parameter>reclassexpr</parameter></paramdef>
<paramdef><type>text </type> <parameter>pixeltype</parameter></paramdef>
<paramdef choice='opt'><type>double precision </type> <parameter>nodataval=NULL</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_Reclass</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>reclassarg[] </type> <parameter>VARIADIC reclassargset</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>raster <function>ST_Reclass</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>text </type> <parameter>reclassexpr</parameter></paramdef>
<paramdef><type>text </type> <parameter>pixeltype</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Creates a new raster formed by applying a valid PostgreSQL algebraic operation defined by the <varname>reclassexpr</varname> on the input raster (<varname>rast</varname>). If no <varname>band</varname> is specified
band 1 is assumed. The new raster will have the same georeference, width, and height as the original raster. Bands not designated will come back unchanged.
Refer to <xref linkend="reclassarg" /> for description of valid reclassification expressions.</para>
<para>The bands of the new raster will have pixel type of <varname>pixeltype</varname>. If <varname>reclassargset</varname> is passed in then each reclassarg defines behavior of each band generated.</para>
<para>Availability: 2.0.0 </para>
</refsection>
<refsection>
<title>Examples Basic</title>
<para>Create a new raster from the original where band 2 is converted from 8BUI to 4BUI and all values from 101-254 are set to nodata value.</para>
<programlisting>ALTER TABLE dummy_rast ADD COLUMN reclass_rast raster;
UPDATE dummy_rast SET reclass_rast = ST_Reclass(rast,2,'0-87:1-10, 88-100:11-15, 101-254:0-0', '4BUI',0) WHERE rid = 2;
SELECT i as col, j as row, ST_Value(rast,2,i,j) As origval,
ST_Value(reclass_rast, 2, i, j) As reclassval,
ST_Value(reclass_rast, 2, i, j, false) As reclassval_include_nodata
FROM dummy_rast CROSS JOIN generate_series(1, 3) AS i CROSS JOIN generate_series(1,3) AS j
WHERE rid = 2;
col | row | origval | reclassval | reclassval_include_nodata
-----+-----+---------+------------+---------------------------
1 | 1 | 78 | 9 | 9
2 | 1 | 98 | 14 | 14
3 | 1 | 122 | | 0
1 | 2 | 96 | 14 | 14
2 | 2 | 118 | | 0
3 | 2 | 180 | | 0
1 | 3 | 99 | 15 | 15
2 | 3 | 112 | | 0
3 | 3 | 169 | | 0</programlisting>
</refsection>
<refsection>
<title>Example: Advanced using multiple reclassargs</title>
<para>Create a new raster from the original where band 1,2,3 is converted to 1BB,4BUI, 4BUI respectively and reclassified.
Note this uses the variadic <varname>reclassarg</varname> argument which can take as input an indefinite number of reclassargs (theoretically as many bands as you have) </para>
<programlisting>UPDATE dummy_rast SET reclass_rast =
ST_Reclass(rast,
ROW(2,'0-87]:1-10, (87-100]:11-15, (101-254]:0-0', '4BUI',NULL)::reclassarg,
ROW(1,'0-253]:1, 254:0', '1BB', NULL)::reclassarg,
ROW(3,'0-70]:1, (70-86:2, [86-150):3, [150-255:4', '4BUI', NULL)::reclassarg
) WHERE rid = 2;
SELECT i as col, j as row,ST_Value(rast,1,i,j) As ov1, ST_Value(reclass_rast, 1, i, j) As rv1,
ST_Value(rast,2,i,j) As ov2, ST_Value(reclass_rast, 2, i, j) As rv2,
ST_Value(rast,3,i,j) As ov3, ST_Value(reclass_rast, 3, i, j) As rv3
FROM dummy_rast CROSS JOIN generate_series(1, 3) AS i CROSS JOIN generate_series(1,3) AS j
WHERE rid = 2;
col | row | ov1 | rv1 | ov2 | rv2 | ov3 | rv3
----+-----+-----+-----+-----+-----+-----+-----
1 | 1 | 253 | 1 | 78 | 9 | 70 | 1
2 | 1 | 254 | 0 | 98 | 14 | 86 | 3
3 | 1 | 253 | 1 | 122 | 0 | 100 | 3
1 | 2 | 253 | 1 | 96 | 14 | 80 | 2
2 | 2 | 254 | 0 | 118 | 0 | 108 | 3
3 | 2 | 254 | 0 | 180 | 0 | 162 | 4
1 | 3 | 250 | 1 | 99 | 15 | 90 | 3
2 | 3 | 254 | 0 | 112 | 0 | 108 | 3
3 | 3 | 254 | 0 | 169 | 0 | 175 | 4</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_Band" />, <xref linkend="RT_ST_BandPixelType" />, <xref linkend="reclassarg" />, <xref linkend="RT_ST_Value" /></para>
</refsection>
</refentry>
</sect1>
<sect1 id="RT_Operators">
<title>Raster Operators</title>
<refentry id="RT_Raster_Overlap">
<refnamediv>
<refname>&amp;&amp;</refname>
<refpurpose>Returns <varname>TRUE</varname> if A's bounding box overlaps B's.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>boolean <function>&amp;&amp;</function></funcdef>
<paramdef>
<type>raster </type>
<parameter>A</parameter>
</paramdef>
<paramdef>
<type>raster </type>
<parameter>B</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>The <varname>&amp;&amp;</varname> operator returns <varname>TRUE</varname> if the bounding box of raster A overlaps the bounding box of raster B.</para>
<note><para>This operand will make use of any indexes that may be available on the
rasters.</para></note>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT A.rid As a_rid, B.rid As b_rid, A.rast &amp;&amp; B.rast As overlap
FROM dummy_rast AS A CROSS JOIN dummy_rast AS B LIMIT 3;
a_rid | b_rid | overlap
-------+-------+---------
2 | 2 | t
2 | 3 | f
2 | 1 | f
</programlisting>
</refsection>
</refentry>
<refentry id="RT_Raster_OverLeft">
<refnamediv>
<refname>&amp;&lt;</refname>
<refpurpose>Returns <varname>TRUE</varname> if A's bounding box is to the left of B's.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>boolean <function>&amp;&lt;</function></funcdef>
<paramdef>
<type>raster </type>
<parameter>A</parameter>
</paramdef>
<paramdef>
<type>raster </type>
<parameter>B</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>The <varname>&amp;&lt;</varname> operator returns <varname>TRUE</varname> if the bounding box of raster A
overlaps or is to the left of the bounding box of raster B, or more accurately, overlaps or is NOT to the right
of the bounding box of raster B.</para>
<note><para>This operand will make use of any indexes that may be available on the
geometries.</para></note>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT A.rid As a_rid, B.rid As b_rid, A.rast &amp;&lt; B.rast As overleft
FROM dummy_rast AS A CROSS JOIN dummy_rast AS B;
a_rid | b_rid | overleft
------+-------+----------
2 | 2 | t
2 | 3 | f
2 | 1 | f
3 | 2 | t
3 | 3 | t
3 | 1 | f
1 | 2 | t
1 | 3 | t
1 | 1 | t
</programlisting>
</refsection>
</refentry>
<refentry id="RT_Raster_OverRight">
<refnamediv>
<refname>&amp;&gt;</refname>
<refpurpose>Returns <varname>TRUE</varname> if A's bounding box is to the right of B's.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>boolean <function>&amp;&gt;</function></funcdef>
<paramdef>
<type>raster </type>
<parameter>A</parameter>
</paramdef>
<paramdef>
<type>raster </type>
<parameter>B</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>The <varname>&amp;&gt;</varname> operator returns <varname>TRUE</varname> if the bounding box of raster A
overlaps or is to the right of the bounding box of raster B, or more accurately, overlaps or is NOT to the left
of the bounding box of raster B.</para>
<note><para>This operand will make use of any indexes that may be available on the
geometries.</para></note>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT A.rid As a_rid, B.rid As b_rid, A.rast &amp;&gt; B.rast As overright
FROM dummy_rast AS A CROSS JOIN dummy_rast AS B;
a_rid | b_rid | overright
-------+-------+----------
2 | 2 | t
2 | 3 | t
2 | 1 | t
3 | 2 | f
3 | 3 | t
3 | 1 | f
1 | 2 | f
1 | 3 | t
1 | 1 | t
</programlisting>
</refsection>
</refentry>
</sect1>
<sect1 id="Raster_Relationships">
<title>Raster and Raster Band Spatial Relationships</title>
<refentry id="RT_ST_Intersects">
<refnamediv>
<refname>ST_Intersects</refname>
<refpurpose>If exclude_nodata_value is omitted returns <varname>TRUE</varname> only if rast pixel in a band with non-nodata band value intersects
with a geometry/raster. If band is not specified it defaults to 1. If <varname>exclude_nodata_value</varname> is set to false then <varname>nodata</varname> band values that intersect also return true.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>boolean <function>ST_Intersects</function></funcdef>
<paramdef>
<type>raster </type>
<parameter>rast</parameter>
</paramdef>
<paramdef>
<type>geometry </type>
<parameter>geommin</parameter>
</paramdef>
</funcprototype>
<funcprototype>
<funcdef>boolean <function>ST_Intersects</function></funcdef>
<paramdef>
<type>raster </type>
<parameter>rast</parameter>
</paramdef>
<paramdef>
<type>integer </type>
<parameter>band</parameter>
</paramdef>
<paramdef>
<type>geometry </type>
<parameter>geommin</parameter>
</paramdef>
</funcprototype>
<funcprototype>
<funcdef>boolean <function>ST_Intersects</function></funcdef>
<paramdef>
<type>geometry </type>
<parameter>geomA</parameter>
</paramdef>
<paramdef>
<type>raster </type>
<parameter>rast</parameter>
</paramdef>
</funcprototype>
<funcprototype>
<funcdef>boolean <function>ST_Intersects</function></funcdef>
<paramdef>
<type>geometry </type>
<parameter>geommin</parameter>
</paramdef>
<paramdef>
<type>raster </type>
<parameter>rast</parameter>
</paramdef>
<paramdef>
<type>integer </type>
<parameter>band</parameter>
</paramdef>
</funcprototype>
<funcprototype>
<funcdef>boolean <function>ST_Intersects</function></funcdef>
<paramdef>
<type>raster </type>
<parameter>rast</parameter>
</paramdef>
<paramdef>
<type>boolean </type>
<parameter>exclude_nodata_value</parameter>
</paramdef>
<paramdef>
<type>geometry </type>
<parameter>geommin</parameter>
</paramdef>
</funcprototype>
<funcprototype>
<funcdef>boolean <function>ST_Intersects</function></funcdef>
<paramdef>
<type>geometry </type>
<parameter>geommin</parameter>
</paramdef>
<paramdef>
<type>raster </type>
<parameter>rast</parameter>
</paramdef>
<paramdef>
<type>boolean </type>
<parameter>exclude_nodata_value</parameter>
</paramdef>
</funcprototype>
<funcprototype>
<funcdef>boolean <function>ST_Intersects</function></funcdef>
<paramdef>
<type>geometry </type>
<parameter>geommin</parameter>
</paramdef>
<paramdef>
<type>raster </type>
<parameter>rast</parameter>
</paramdef>
<paramdef>
<type>integer </type>
<parameter>band</parameter>
</paramdef>
<paramdef>
<type>boolean </type>
<parameter>exclude_nodata_value</parameter>
</paramdef>
</funcprototype>
<funcprototype>
<funcdef>boolean <function>ST_Intersects</function></funcdef>
<paramdef>
<type>raster </type>
<parameter>rast</parameter>
</paramdef>
<paramdef>
<type>integer </type>
<parameter>band</parameter>
</paramdef>
<paramdef>
<type>boolean </type>
<parameter>exclude_nodata_value</parameter>
</paramdef>
<paramdef>
<type>geometry </type>
<parameter>geommin</parameter>
</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns true if the geometry intersects with the raster. Nodata values are taken into account so that if the geometry intersects only with nodata values, the function returns false.
<varname>exclude_nodata_value</varname> may modify this behavior: if set to false, nodata value are not taken into account and the function returns true as soon as the geometry intersects with the convex hull of the raster.</para>
<note><para>This operand will make use of any indexes that may be available on the
geometries / rasters.</para></note>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT A.rid, g.gid , ST_Intersects(A.rast, g.geom) As inter
FROM dummy_rast AS A CROSS JOIN
(VALUES (1, ST_Point(3427928, 5793243.85) ) ,
(2, ST_GeomFromText('LINESTRING(3427927.85 5793243.75,3427927.8 5793243.75,3427927.8 5793243.8)') ),
(3, ST_GeomFromText('LINESTRING(1 2, 3 4)') )
) As g(gid,geom)
WHERE A.rid =2 ;
rid | gid | inter
-----+-----+-------
2 | 1 | t
2 | 2 | t
2 | 3 | f
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="RT_ST_Intersection" /></para>
</refsection>
</refentry>
</sect1>
</chapter>