postgis/doc/reference_raster.xml

3844 lines
133 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_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>
</sect1>
<sect1 id="Raster_Constructors">
<title>Raster Constructors</title>
<refentry id="RT_ST_MakeEmptyRaster">
<refnamediv>
<refname>ST_MakeEmptyRaster</refname>
<refpurpose>Returns an empty raster of given dimensions, pixel x y, skew and spatial reference system with no bands. 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>ipx</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>ipy</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>ipx</parameter></paramdef>
<paramdef><type>float8 </type> <parameter>ipy</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>double precision </type> <parameter>upperleftx</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>upperlefty</parameter></paramdef>
<paramdef><type>double precision </type> <parameter>scale</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns an empty raster of given dimensions, pixel width in spatial coordinates x (ipx), pixel height y in spatial coordinates (ipy), (scale - uses same size for pixel height (ipy) and width (ipx)), skew and spatial reference system with no bands. If an existing raster is passed in,
it returns a new raster with the same meta data settings (minus number of bands and band types). 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 hmm 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>
</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</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>band_num</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>band_num</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>raster1</parameter></paramdef>
<paramdef><type>integer </type> <parameter>nband1</parameter></paramdef>
<paramdef><type>raster </type> <parameter>raster2</parameter></paramdef>
<paramdef><type>integer </type> <parameter>nband2</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns a raster with a new band added in given position (band number), of given type, of given initial value, and of given nodata value. If no index is specified, the band is added to the end. 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
nband1 from raster1 to raster2 in position nband2.</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 | hasnodatavalue | 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_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>
</funcprototype>
<funcprototype>
<funcdef>record <function>ST_BandMetaData</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 basic meta data about a raster band. Columns returned
pixeltype | hasnodatavalue | 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 | hasnodatavalue | 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>
<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>hasnodata</varname> is set to true, then only non <varname>nodata</varname> pixels are considered. If <varname>hasnodata</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>hasnodata</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>hasnodata</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>hasnodata</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>hasnodata</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>hasnodata</varname> is set to true, then only non <varname>nodata</varname> pixels are considered. If <varname>hasnodata</varname> is set to false, then all pixels are considered.</para>
<para>Enhanced: 2.0.0 hasnodata 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>
</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>
<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="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>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para></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>
</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" /></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><type>text </type> <parameter>nodatavalueexpr</parameter></paramdef>
<paramdef><type>text </type> <parameter>pixeltype</parameter></paramdef>
</funcprototype>
<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><type>text </type> <parameter>nodatavalueexpr</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>nodatavalueexpr</parameter></paramdef>
<paramdef><type>text </type> <parameter>pixeltype</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>
<funcprototype>
<funcdef>raster <function>ST_MapAlgebra</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef><type>text </type> <parameter>expression</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>
</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>Returns <varname>TRUE</varname> 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 hasnodata is omitted, reads from band meta data.</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>hasnodata</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>hasnodata</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>hasnodata</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>hasnodata</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>hasnodata</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>