postgis/doc/reference_editor.xml
Regina Obe 3dbbf79fb1 oops
git-svn-id: http://svn.osgeo.org/postgis/trunk@6784 b70326c6-7e19-0410-871a-916f4a2858ee
2011-02-06 00:39:03 +00:00

1865 lines
63 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<sect1 id="Geometry_Editors">
<title>Geometry Editors</title>
<refentry id="ST_AddPoint">
<refnamediv>
<refname>ST_AddPoint</refname>
<refpurpose>Adds a point to a LineString before point &lt;position&gt;
(0-based index).</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_AddPoint</function></funcdef>
<paramdef><type>geometry</type> <parameter>linestring</parameter></paramdef>
<paramdef><type>geometry</type> <parameter>point</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_AddPoint</function></funcdef>
<paramdef><type>geometry</type> <parameter>linestring</parameter></paramdef>
<paramdef><type>geometry</type> <parameter>point</parameter></paramdef>
<paramdef><type>integer</type> <parameter>position</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Adds a point to a LineString before point &lt;position&gt;
(0-based index). Third parameter can be omitted or set to -1 for
appending.</para>
<para>Availability: 1.1.0</para>
<para>&Z_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
--guarantee all linestrings in a table are closed
--by adding the start point of each linestring to the end of the line string
--only for those that are not closed
UPDATE sometable
SET the_geom = ST_AddPoint(the_geom, ST_StartPoint(the_geom))
FROM sometable
WHERE ST_IsClosed(the_geom) = false;
--Adding point to a 3-d line
SELECT ST_AsEWKT(ST_AddPoint(ST_GeomFromEWKT('LINESTRING(0 0 1, 1 1 1)'), ST_MakePoint(1, 2, 3)));
--result
st_asewkt
----------
LINESTRING(0 0 1,1 1 1,1 2 3)
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="ST_RemovePoint"/>, <xref linkend="ST_SetPoint" /></para>
</refsection>
</refentry>
<refentry id="ST_Affine">
<refnamediv>
<refname>ST_Affine</refname>
<refpurpose>Applies a 3d affine transformation to the geometry to do things like translate, rotate, scale in one step.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Affine</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
<paramdef><type>float </type> <parameter>a</parameter></paramdef>
<paramdef><type>float </type> <parameter>b</parameter></paramdef>
<paramdef><type>float </type> <parameter>c</parameter></paramdef>
<paramdef><type>float </type> <parameter>d</parameter></paramdef>
<paramdef><type>float </type> <parameter>e</parameter></paramdef>
<paramdef><type>float </type> <parameter>f</parameter></paramdef>
<paramdef><type>float </type> <parameter>g</parameter></paramdef>
<paramdef><type>float </type> <parameter>h</parameter></paramdef>
<paramdef><type>float </type> <parameter>i</parameter></paramdef>
<paramdef><type>float </type> <parameter>xoff</parameter></paramdef>
<paramdef><type>float </type> <parameter>yoff</parameter></paramdef>
<paramdef><type>float </type> <parameter>zoff</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>geometry <function>ST_Affine</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
<paramdef><type>float </type> <parameter>a</parameter></paramdef>
<paramdef><type>float </type> <parameter>b</parameter></paramdef>
<paramdef><type>float </type> <parameter>d</parameter></paramdef>
<paramdef><type>float </type> <parameter>e</parameter></paramdef>
<paramdef><type>float </type> <parameter>xoff</parameter></paramdef>
<paramdef><type>float </type> <parameter>yoff</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Applies a 3d affine transformation to the geometry to do things like translate, rotate, scale in one step.</para>
<para>
Version 1: The
call <programlisting>ST_Affine(geom, a, b, c, d, e, f, g, h, i, xoff, yoff, zoff) </programlisting>
represents the transformation matrix <programlisting>/ a b c xoff \
| d e f yoff |
| g h i zoff |
\ 0 0 0 1 /</programlisting> and the vertices are transformed as
follows: <programlisting>x' = a*x + b*y + c*z + xoff
y' = d*x + e*y + f*z + yoff
z' = g*x + h*y + i*z + zoff</programlisting> All of the translate / scale
functions below are expressed via such an affine
transformation.</para>
<para>Version 2: Applies a 2d affine transformation to the geometry. The
call <programlisting>ST_Affine(geom, a, b, d, e, xoff, yoff)</programlisting>
represents the transformation matrix <programlisting>/ a b 0 xoff \ / a b xoff \
| d e 0 yoff | rsp. | d e yoff |
| 0 0 1 0 | \ 0 0 1 /
\ 0 0 0 1 /</programlisting> and the vertices are transformed as
follows: <programlisting>x' = a*x + b*y + xoff
y' = d*x + e*y + yoff
z' = z </programlisting> This method is a subcase of the 3D method
above.</para>
<para>Enhanced: 2.0.0 support for Polyhedral surfaces, Triangles and TIN was introduced.</para>
<para>Availability: 1.1.2. Name changed from Affine to ST_Affine in 1.2.2</para>
<note><para>Prior to 1.3.4, this function crashes if used with geometries that contain CURVES. This is fixed in 1.3.4+</para></note>
<para>&P_support;</para>
<para>&T_support;</para>
<para>&Z_support;</para>
<para>&curve_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
--Rotate a 3d line 180 degrees about the z axis. Note this is long-hand for doing ST_RotateZ();
SELECT ST_AsEWKT(ST_Affine(the_geom, cos(pi()), -sin(pi()), 0, sin(pi()), cos(pi()), 0, 0, 0, 1, 0, 0, 0)) As using_affine,
ST_AsEWKT(ST_RotateZ(the_geom, pi())) As using_rotatez
FROM (SELECT ST_GeomFromEWKT('LINESTRING(1 2 3, 1 4 3)') As the_geom) As foo;
using_affine | using_rotatez
-----------------------------+-----------------------------
LINESTRING(-1 -2 3,-1 -4 3) | LINESTRING(-1 -2 3,-1 -4 3)
(1 row)
--Rotate a 3d line 180 degrees in both the x and z axis
SELECT ST_AsEWKT(ST_Affine(the_geom, cos(pi()), -sin(pi()), 0, sin(pi()), cos(pi()), -sin(pi()), 0, sin(pi()), cos(pi()), 0, 0, 0))
FROM (SELECT ST_GeomFromEWKT('LINESTRING(1 2 3, 1 4 3)') As the_geom) As foo;
st_asewkt
-------------------------------
LINESTRING(-1 -2 -3,-1 -4 -3)
(1 row)
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_Rotate" />, <xref linkend="ST_Scale" />, <xref linkend="ST_Translate" />, <xref linkend="ST_TransScale" /></para>
</refsection>
</refentry>
<refentry id="ST_Force_2D">
<refnamediv>
<refname>ST_Force_2D</refname>
<refpurpose>Forces the geometries into a "2-dimensional mode" so that
all output representations will only have the X and Y coordinates.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Force_2D</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Forces the geometries into a "2-dimensional mode" so that
all output representations will only have the X and Y coordinates.
This is useful for force OGC-compliant output (since OGC only
specifies 2-D geometries).</para>
<para>Enhanced: 2.0.0 support for Polyhedral surfaces was introduced.</para>
<para>&curve_support;</para>
<para>&P_support;</para>
<para>&Z_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT ST_AsEWKT(ST_Force_2D(ST_GeomFromEWKT('CIRCULARSTRING(1 1 2, 2 3 2, 4 5 2, 6 7 2, 5 6 2)')));
st_asewkt
-------------------------------------
CIRCULARSTRING(1 1,2 3,4 5,6 7,5 6)
SELECT ST_AsEWKT(ST_Force_2D('POLYGON((0 0 2,0 5 2,5 0 2,0 0 2),(1 1 2,3 1 2,1 3 2,1 1 2))'));
st_asewkt
----------------------------------------------
POLYGON((0 0,0 5,5 0,0 0),(1 1,3 1,1 3,1 1))
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_Force_3D"/></para>
</refsection>
</refentry>
<refentry id="ST_Force_3D">
<refnamediv>
<refname>ST_Force_3D</refname>
<refpurpose>Forces the geometries into XYZ mode. This is an alias for ST_Force_3DZ.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Force_3D</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Forces the geometries into XYZ mode. This is an alias for ST_Force_3DZ. If a geometry has no Z component, then a 0 Z coordinate is tacked on.</para>
<para>Enhanced: 2.0.0 support for Polyhedral surfaces was introduced.</para>
<para>&P_support;</para>
<para>&curve_support;</para>
<para>&Z_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
--Nothing happens to an already 3D geometry
SELECT ST_AsEWKT(ST_Force_3D(ST_GeomFromEWKT('CIRCULARSTRING(1 1 2, 2 3 2, 4 5 2, 6 7 2, 5 6 2)')));
st_asewkt
-----------------------------------------------
CIRCULARSTRING(1 1 2,2 3 2,4 5 2,6 7 2,5 6 2)
SELECT ST_AsEWKT(ST_Force_3D('POLYGON((0 0,0 5,5 0,0 0),(1 1,3 1,1 3,1 1))'));
st_asewkt
--------------------------------------------------------------
POLYGON((0 0 0,0 5 0,5 0 0,0 0 0),(1 1 0,3 1 0,1 3 0,1 1 0))
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_AsEWKT"/>, <xref linkend="ST_Force_2D"/>, <xref linkend="ST_Force_3DM"/>, <xref linkend="ST_Force_3DZ"/></para>
</refsection>
</refentry>
<refentry id="ST_Force_3DZ">
<refnamediv>
<refname>ST_Force_3DZ</refname>
<refpurpose>Forces the geometries into XYZ mode. This is a synonym for ST_Force_3D.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Force_3DZ</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Forces the geometries into XYZ mode. This is a synonym for ST_Force_3DZ. If a geometry has no Z component, then a 0 Z coordinate is tacked on.</para>
<para>Enhanced: 2.0.0 support for Polyhedral surfaces was introduced.</para>
<para>&P_support;</para>
<para>&Z_support;</para>
<para>&curve_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
--Nothing happens to an already 3D geometry
SELECT ST_AsEWKT(ST_Force_3DZ(ST_GeomFromEWKT('CIRCULARSTRING(1 1 2, 2 3 2, 4 5 2, 6 7 2, 5 6 2)')));
st_asewkt
-----------------------------------------------
CIRCULARSTRING(1 1 2,2 3 2,4 5 2,6 7 2,5 6 2)
SELECT ST_AsEWKT(ST_Force_3DZ('POLYGON((0 0,0 5,5 0,0 0),(1 1,3 1,1 3,1 1))'));
st_asewkt
--------------------------------------------------------------
POLYGON((0 0 0,0 5 0,5 0 0,0 0 0),(1 1 0,3 1 0,1 3 0,1 1 0))
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_AsEWKT"/>, <xref linkend="ST_Force_2D"/>, <xref linkend="ST_Force_3DM"/>, <xref linkend="ST_Force_3D"/></para>
</refsection>
</refentry>
<refentry id="ST_Force_3DM">
<refnamediv>
<refname>ST_Force_3DM</refname>
<refpurpose>Forces the geometries into XYM mode.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Force_3DM</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Forces the geometries into XYM mode. If a geometry has no M component, then a 0 M coordinate is tacked on. If it has a Z component, then Z is removed</para>
<para>&curve_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
--Nothing happens to an already 3D geometry
SELECT ST_AsEWKT(ST_Force_3DM(ST_GeomFromEWKT('CIRCULARSTRING(1 1 2, 2 3 2, 4 5 2, 6 7 2, 5 6 2)')));
st_asewkt
------------------------------------------------
CIRCULARSTRINGM(1 1 0,2 3 0,4 5 0,6 7 0,5 6 0)
SELECT ST_AsEWKT(ST_Force_3DM('POLYGON((0 0 1,0 5 1,5 0 1,0 0 1),(1 1 1,3 1 1,1 3 1,1 1 1))'));
st_asewkt
---------------------------------------------------------------
POLYGONM((0 0 0,0 5 0,5 0 0,0 0 0),(1 1 0,3 1 0,1 3 0,1 1 0))
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_AsEWKT"/>, <xref linkend="ST_Force_2D"/>, <xref linkend="ST_Force_3DM"/>, <xref linkend="ST_Force_3D"/>, <xref linkend="ST_GeomFromEWKT"/></para>
</refsection>
</refentry>
<refentry id="ST_Force_4D">
<refnamediv>
<refname>ST_Force_4D</refname>
<refpurpose>Forces the geometries into XYZM mode. </refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Force_4D</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Forces the geometries into XYZM mode. 0 is tacked on for missing Z and M dimensions. </para>
<para>&Z_support;</para>
<para>&curve_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
--Nothing happens to an already 3D geometry
SELECT ST_AsEWKT(ST_Force_4D(ST_GeomFromEWKT('CIRCULARSTRING(1 1 2, 2 3 2, 4 5 2, 6 7 2, 5 6 2)')));
st_asewkt
---------------------------------------------------------
CIRCULARSTRING(1 1 2 0,2 3 2 0,4 5 2 0,6 7 2 0,5 6 2 0)
SELECT ST_AsEWKT(ST_Force_4D('MULTILINESTRINGM((0 0 1,0 5 2,5 0 3,0 0 4),(1 1 1,3 1 1,1 3 1,1 1 1))'));
st_asewkt
--------------------------------------------------------------------------------------
MULTILINESTRING((0 0 0 1,0 5 0 2,5 0 0 3,0 0 0 4),(1 1 0 1,3 1 0 1,1 3 0 1,1 1 0 1))
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_AsEWKT"/>, <xref linkend="ST_Force_2D"/>, <xref linkend="ST_Force_3DM"/>, <xref linkend="ST_Force_3D"/></para>
</refsection>
</refentry>
<refentry id="ST_Force_Collection">
<refnamediv>
<refname>ST_Force_Collection</refname>
<refpurpose>Converts the geometry into a GEOMETRYCOLLECTION.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Force_Collection</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Converts the geometry into a GEOMETRYCOLLECTION. This is
useful for simplifying the WKB representation.</para>
<para>Enhanced: 2.0.0 support for Polyhedral surfaces was introduced.</para>
<para>Availability: 1.2.2, prior to 1.3.4 this function will crash with Curves. This is fixed in 1.3.4+</para>
<para>&P_support;</para>
<para>&Z_support;</para>
<para>&curve_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
SELECT ST_AsEWKT(ST_Force_Collection('POLYGON((0 0 1,0 5 1,5 0 1,0 0 1),(1 1 1,3 1 1,1 3 1,1 1 1))'));
st_asewkt
----------------------------------------------------------------------------------
GEOMETRYCOLLECTION(POLYGON((0 0 1,0 5 1,5 0 1,0 0 1),(1 1 1,3 1 1,1 3 1,1 1 1)))
SELECT ST_AsText(ST_Force_Collection('CIRCULARSTRING(220227 150406,2220227 150407,220227 150406)'));
st_astext
--------------------------------------------------------------------------------
GEOMETRYCOLLECTION(CIRCULARSTRING(220227 150406,2220227 150407,220227 150406))
(1 row)
</programlisting>
<programlisting>
-- POLYHEDRAL example --
SELECT ST_AsEWKT(ST_Force_Collection('POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 1,0 1 0,0 0 0)),
((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),
((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)),
((1 1 0,1 1 1,1 0 1,1 0 0,1 1 0)),
((0 1 0,0 1 1,1 1 1,1 1 0,0 1 0)),
((0 0 1,1 0 1,1 1 1,0 1 1,0 0 1)))'))
st_asewkt
----------------------------------------------------------------------------------
GEOMETRYCOLLECTION(
POLYGON((0 0 0,0 0 1,0 1 1,0 1 0,0 0 0)),
POLYGON((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),
POLYGON((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)),
POLYGON((1 1 0,1 1 1,1 0 1,1 0 0,1 1 0)),
POLYGON((0 1 0,0 1 1,1 1 1,1 1 0,0 1 0)),
POLYGON((0 0 1,1 0 1,1 1 1,0 1 1,0 0 1))
)
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_AsEWKT"/>, <xref linkend="ST_Force_2D"/>, <xref linkend="ST_Force_3DM"/>, <xref linkend="ST_Force_3D"/>, <xref linkend="ST_GeomFromEWKT"/></para>
</refsection>
</refentry>
<refentry id="ST_ForceRHR">
<refnamediv>
<refname>ST_ForceRHR</refname>
<refpurpose>Forces the orientation of the vertices in a polygon to follow the
Right-Hand-Rule.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>boolean
<function>ST_ForceRHR</function></funcdef>
<paramdef><type>geometry</type> <parameter>g</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Forces the orientation of the vertices in a polygon to follow the
Right-Hand-Rule. In GIS terminology, this means that the area that is bounded by the
polygon is to the right of the boundary. In particular, the exterior ring is
orientated in a clockwise direction and the interior rings in a counter-clockwise
direction.</para>
<para>Enhanced: 2.0.0 support for Polyhedral surfaces was introduced.</para>
<para>&Z_support;</para>
<para>&P_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT ST_AsEWKT(
ST_ForceRHR(
'POLYGON((0 0 2, 5 0 2, 0 5 2, 0 0 2),(1 1 2, 1 3 2, 3 1 2, 1 1 2))'
)
);
st_asewkt
--------------------------------------------------------------
POLYGON((0 0 2,0 5 2,5 0 2,0 0 2),(1 1 2,3 1 2,1 3 2,1 1 2))
(1 row)</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="ST_BuildArea"/>,
<xref linkend="ST_Polygonize"/>,
<xref linkend="ST_Reverse"/></para>
</refsection>
</refentry>
<refentry id="ST_LineMerge">
<refnamediv>
<refname>ST_LineMerge</refname>
<refpurpose>Returns a (set of) LineString(s) formed by sewing together
a MULTILINESTRING.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_LineMerge</function></funcdef>
<paramdef><type>geometry </type> <parameter>amultilinestring</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns a (set of) LineString(s) formed by sewing together
the constituent line work of a MULTILINESTRING. </para>
<note><para>Only use with MULTILINESTRING/LINESTRINGs. If you feed a polygon or geometry collection into this function, it
will return an empty GEOMETRYCOLLECTION</para></note>
<para>Availability: 1.1.0</para>
<note><para>requires GEOS &gt;= 2.1.0</para></note>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT ST_AsText(ST_LineMerge(
ST_GeomFromText('MULTILINESTRING((-29 -27,-30 -29.7,-36 -31,-45 -33),(-45 -33,-46 -32))')
)
);
st_astext
--------------------------------------------------------------------------------------------------
LINESTRING(-29 -27,-30 -29.7,-36 -31,-45 -33,-46 -32)
(1 row)
--If can't be merged - original MULTILINESTRING is returned
SELECT ST_AsText(ST_LineMerge(
ST_GeomFromText('MULTILINESTRING((-29 -27,-30 -29.7,-36 -31,-45 -33),(-45.2 -33.2,-46 -32))')
)
);
st_astext
----------------
MULTILINESTRING((-45.2 -33.2,-46 -32),(-29 -27,-30 -29.7,-36 -31,-45 -33))
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="ST_Segmentize" />, <xref linkend="ST_Line_Substring" /></para>
</refsection>
</refentry>
<refentry id="ST_CollectionExtract">
<refnamediv>
<refname>ST_CollectionExtract</refname>
<refpurpose>Given a GEOMETRYCOLLECTION, returns a MULTI* geometry consisting only of the specified type. Sub-geometries that are not
the specified type are ignored. If there are no sub-geometries of the right type, an EMPTY collection will be returned. Only
points, lines and polygons are supported. Type numbers are 1 == POINT, 2 == LINESTRING, 3 == POLYGON.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_CollectionExtract</function></funcdef>
<paramdef><type>geometry </type> <parameter>collection</parameter></paramdef>
<paramdef><type>integer </type> <parameter>type</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Given a GEOMETRYCOLLECTION, returns a MULTI* geometry consisting only of the specified type. Sub-geometries that are not
the specified type are ignored. If there are no sub-geometries of the right type, an EMPTY collection will be returned. Only
points, lines and polygons are supported. Type numbers are 1 == POINT, 2 == LINESTRING, 3 == POLYGON.</para>
<para>Availability: 1.5.0</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>-- Constants: 1 == POINT, 2 == LINESTRING, 3 == POLYGON
SELECT ST_AsText(ST_CollectionExtract(ST_GeomFromText('GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT(0 0)))'),1));
st_astext
---------------
MULTIPOINT(0 0)
(1 row)
SELECT ST_AsText(ST_CollectionExtract(ST_GeomFromText('GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(LINESTRING(0 0, 1 1)),LINESTRING(2 2, 3 3))'),2));
st_astext
---------------
MULTILINESTRING((0 0, 1 1), (2 2, 3 3))
(1 row)
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="ST_Multi" /></para>
</refsection>
</refentry>
<refentry id="ST_Multi">
<refnamediv>
<refname>ST_Multi</refname>
<refpurpose>Returns the geometry as a MULTI* geometry. If the geometry
is already a MULTI*, it is returned unchanged.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Multi</function></funcdef>
<paramdef><type>geometry </type> <parameter>g1</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns the geometry as a MULTI* geometry. If the geometry
is already a MULTI*, it is returned unchanged.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT ST_AsText(ST_Multi(ST_GeomFromText('POLYGON((743238 2967416,743238 2967450,
743265 2967450,743265.625 2967416,743238 2967416))')));
st_astext
--------------------------------------------------------------------------------------------------
MULTIPOLYGON(((743238 2967416,743238 2967450,743265 2967450,743265.625 2967416,
743238 2967416)))
(1 row)
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="ST_AsText" /></para>
</refsection>
</refentry>
<refentry id="ST_RemovePoint">
<refnamediv>
<refname>ST_RemovePoint</refname>
<refpurpose>Removes point from a linestring. Offset is 0-based.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_RemovePoint</function></funcdef>
<paramdef><type>geometry</type> <parameter>linestring</parameter></paramdef>
<paramdef><type>integer</type> <parameter>offset</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Removes point from a linestring. Useful for turning a closed ring into an open line string</para>
<para>Availability: 1.1.0</para>
<para>&Z_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
--guarantee no LINESTRINGS are closed
--by removing the end point. The below assumes the_geom is of type LINESTRING
UPDATE sometable
SET the_geom = ST_RemovePoint(the_geom, ST_NPoints(the_geom) - 1)
FROM sometable
WHERE ST_IsClosed(the_geom) = true;
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="ST_AddPoint"/>, <xref linkend="ST_NPoints"/>, <xref linkend="ST_NumPoints"/></para>
</refsection>
</refentry>
<refentry id="ST_Reverse">
<refnamediv>
<refname>ST_Reverse</refname>
<refpurpose>Returns the geometry with vertex order reversed.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Reverse</function></funcdef>
<paramdef><type>geometry </type> <parameter>g1</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Can be used on any geometry and reverses the order of the vertexes.</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
SELECT ST_AsText(the_geom) as line, ST_AsText(ST_Reverse(the_geom)) As reverseline
FROM
(SELECT ST_MakeLine(ST_MakePoint(1,2),
ST_MakePoint(1,10)) As the_geom) as foo;
--result
line | reverseline
---------------------+----------------------
LINESTRING(1 2,1 10) | LINESTRING(1 10,1 2)
</programlisting>
</refsection>
</refentry>
<refentry id="ST_Rotate">
<refnamediv>
<refname>ST_Rotate</refname>
<refpurpose>This is a synonym for ST_RotateZ</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Rotate</function></funcdef>
<paramdef><type>geometry</type> <parameter>geomA</parameter></paramdef>
<paramdef><type>float</type> <parameter>rotZRadians</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>This is a synonym for ST_RotateZ.. Rotates geometry rotZRadians about the Z-axis.</para>
<para>Enhanced: 2.0.0 support for Polyhedral surfaces, Triangles and TIN was introduced.</para>
<para>Availability: 1.1.2. Name changed from Rotate to ST_Rotate in 1.2.2</para>
<para>&Z_support;</para>
<para>&curve_support;</para>
<para>&P_support;</para>
<para>&T_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting></programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_Affine" />, <xref linkend="ST_RotateX" />, <xref linkend="ST_RotateY" />, <xref linkend="ST_RotateZ" /></para>
</refsection>
</refentry>
<refentry id="ST_RotateX">
<refnamediv>
<refname>ST_RotateX</refname>
<refpurpose>Rotate a geometry rotRadians about the X axis.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_RotateX</function></funcdef>
<paramdef><type>geometry</type> <parameter>geomA</parameter></paramdef>
<paramdef><type>float</type> <parameter>rotRadians</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Rotate a geometry geomA - rotRadians about the X axis.</para>
<note><para><code>ST_RotateX(geomA, rotRadians)</code>
is short-hand for <code>ST_Affine(geomA, 1, 0, 0, 0, cos(rotRadians), -sin(rotRadians), 0, sin(rotRadians), cos(rotRadians), 0, 0, 0)</code>.</para></note>
<para>Enhanced: 2.0.0 support for Polyhedral surfaces, Triangles and TIN was introduced.</para>
<para>Availability: 1.1.2. Name changed from RotateX to ST_RotateX in 1.2.2</para>
<para>&P_support;</para>
<para>&Z_support;</para>
<para>&T_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
--Rotate a line 90 degrees along x-axis
SELECT ST_AsEWKT(ST_RotateX(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'), pi()/2));
st_asewkt
---------------------------
LINESTRING(1 -3 2,1 -1 1)
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_Affine" />, <xref linkend="ST_RotateY" />, <xref linkend="ST_RotateZ" /></para>
</refsection>
</refentry>
<refentry id="ST_RotateY">
<refnamediv>
<refname>ST_RotateY</refname>
<refpurpose>Rotate a geometry rotRadians about the Y axis.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_RotateY</function></funcdef>
<paramdef><type>geometry</type> <parameter>geomA</parameter></paramdef>
<paramdef><type>float</type> <parameter>rotRadians</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Rotate a geometry geomA - rotRadians about the y axis.</para>
<note><para><code>ST_RotateY(geomA, rotRadians)</code>
is short-hand for <code>ST_Affine(geomA, cos(rotRadians), 0, sin(rotRadians), 0, 1, 0, -sin(rotRadians), 0, cos(rotRadians), 0, 0, 0)</code>.</para></note>
<para>Availability: 1.1.2. Name changed from RotateY to ST_RotateY in 1.2.2</para>
<para>Enhanced: 2.0.0 support for Polyhedral surfaces, Triangles and TIN was introduced.</para>
<para>&P_support;</para>
<para>&Z_support;</para>
<para>&T_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
--Rotate a line 90 degrees along y-axis
SELECT ST_AsEWKT(ST_RotateY(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'), pi()/2));
st_asewkt
---------------------------
LINESTRING(3 2 -1,1 1 -1)
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_Affine" />, <xref linkend="ST_RotateX" />, <xref linkend="ST_RotateZ" />, <ulink
url="/support/wiki/index.php?plpgsqlfunctions">Rotate around Point, Create Ellipse functions</ulink></para>
</refsection>
</refentry>
<refentry id="ST_RotateZ">
<refnamediv>
<refname>ST_RotateZ</refname>
<refpurpose>Rotate a geometry rotRadians about the Z axis.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_RotateZ</function></funcdef>
<paramdef><type>geometry</type> <parameter>geomA</parameter></paramdef>
<paramdef><type>float</type> <parameter>rotRadians</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Rotate a geometry geomA - rotRadians about the Z axis.</para>
<note><para><code>ST_RotateZ(geomA, rotRadians)</code>
is short-hand for <code>SELECT ST_Affine(geomA, cos(rotRadians), -sin(rotRadians), 0, sin(rotRadians), cos(rotRadians), 0, 0, 0, 1, 0, 0, 0)</code>.</para></note>
<para>Enhanced: 2.0.0 support for Polyhedral surfaces, Triangles and TIN was introduced.</para>
<para>Availability: 1.1.2. Name changed from RotateZ to ST_RotateZ in 1.2.2</para>
<note><para>Prior to 1.3.4, this function crashes if used with geometries that contain CURVES. This is fixed in 1.3.4+</para></note>
<para>&Z_support;</para>
<para>&curve_support;</para>
<para>&P_support;</para>
<para>&T_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
--Rotate a line 90 degrees along z-axis
SELECT ST_AsEWKT(ST_RotateZ(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'), pi()/2));
st_asewkt
---------------------------
LINESTRING(-2 1 3,-1 1 1)
--Rotate a curved circle around z-axis
SELECT ST_AsEWKT(ST_RotateZ(the_geom, pi()/2))
FROM (SELECT ST_LineToCurve(ST_Buffer(ST_GeomFromText('POINT(234 567)'), 3)) As the_geom) As foo;
st_asewkt
----------------------------------------------------------------------------------------------------------------------------
CURVEPOLYGON(CIRCULARSTRING(-567 237,-564.87867965644 236.12132034356,-564 234,-569.12132034356 231.87867965644,-567 237))
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_Affine" />, <xref linkend="ST_RotateX" />, <xref linkend="ST_RotateY" />, <ulink
url="/support/wiki/index.php?plpgsqlfunctions">Rotate around Point, Create Ellipse functions</ulink></para>
</refsection>
</refentry>
<refentry id="ST_Scale">
<refnamediv>
<refname>ST_Scale</refname>
<refpurpose>Scales the geometry to a new size by multiplying the
ordinates with the parameters. Ie: ST_Scale(geom, Xfactor, Yfactor,
Zfactor).
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Scale</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
<paramdef><type>float</type> <parameter>XFactor</parameter></paramdef>
<paramdef><type>float</type> <parameter>YFactor</parameter></paramdef>
<paramdef><type>float</type> <parameter>ZFactor</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>geometry <function>ST_Scale</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
<paramdef><type>float</type> <parameter>XFactor</parameter></paramdef>
<paramdef><type>float</type> <parameter>YFactor</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Scales the geometry to a new size by multiplying the
ordinates with the parameters. Ie: ST_Scale(geom, Xfactor, Yfactor,
Zfactor).</para>
<note><para><code>ST_Scale(geomA, XFactor, YFactor, ZFactor)</code>
is short-hand for <code>ST_Affine(geomA, XFactor, 0, 0, 0, YFactor, 0, 0, 0, ZFactor, 0, 0, 0)</code>.</para></note>
<note><para>Prior to 1.3.4, this function crashes if used with geometries that contain CURVES. This is fixed in 1.3.4+</para></note>
<para>Availability: 1.1.0.</para>
<para>Enhanced: 2.0.0 support for Polyhedral surfaces, Triangles and TIN was introduced.</para>
<para>&P_support;</para>
<para>&Z_support;</para>
<para>&curve_support;</para>
<para>&T_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>--Version 1: scale X, Y, Z
SELECT ST_AsEWKT(ST_Scale(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'), 0.5, 0.75, 0.8));
st_asewkt
--------------------------------------
LINESTRING(0.5 1.5 2.4,0.5 0.75 0.8)
--Version 2: Scale X Y
SELECT ST_AsEWKT(ST_Scale(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'), 0.5, 0.75));
st_asewkt
----------------------------------
LINESTRING(0.5 1.5 3,0.5 0.75 1)
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_Affine" />, <xref linkend="ST_TransScale" /></para>
</refsection>
</refentry>
<refentry id="ST_Segmentize">
<refnamediv>
<refname>ST_Segmentize</refname>
<refpurpose>Return a modified geometry having no segment longer than the
given distance. Distance computation is performed in 2d
only.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Segmentize</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
<paramdef><type>float </type> <parameter>max_length</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns a modified geometry having no segment longer than the
given distance. Distance computation is performed in 2d
only. </para>
<para>Availability: 1.2.2</para>
<note><para>This will only increase segments. It will not lengthen segments shorter than
max length</para></note>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT ST_AsText(ST_Segmentize(
ST_GeomFromText('MULTILINESTRING((-29 -27,-30 -29.7,-36 -31,-45 -33),(-45 -33,-46 -32))')
,5)
);
st_astext
--------------------------------------------------------------------------------------------------
MULTILINESTRING((-29 -27,-30 -29.7,-34.886615700134 -30.758766735029,-36 -31,
-40.8809353009198 -32.0846522890933,-45 -33),
(-45 -33,-46 -32))
(1 row)
SELECT ST_AsText(ST_Segmentize(ST_GeomFromText('POLYGON((-29 28, -30 40, -29 28))'),10));
st_astext
-----------------------
POLYGON((-29 28,-29.8304547985374 37.9654575824488,-30 40,-29.1695452014626 30.0345424175512,-29 28))
(1 row)
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="ST_Line_Substring" /></para>
</refsection>
</refentry>
<refentry id="ST_SetPoint">
<refnamediv>
<refname>ST_SetPoint</refname>
<refpurpose>Replace point N of linestring with given point. Index is
0-based.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_SetPoint</function></funcdef>
<paramdef><type>geometry</type> <parameter>linestring</parameter></paramdef>
<paramdef><type>integer</type> <parameter>zerobasedposition</parameter></paramdef>
<paramdef><type>geometry</type> <parameter>point</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Replace point N of linestring with given point. Index is
0-based.
This is especially useful in triggers when trying to maintain relationship of joints when one vertex moves.</para>
<para>Availability: 1.1.0</para>
<para>&Z_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
--Change first point in line string from -1 3 to -1 1
SELECT ST_AsText(ST_SetPoint('LINESTRING(-1 2,-1 3)', 0, 'POINT(-1 1)'));
st_astext
-----------------------
LINESTRING(-1 1,-1 3)
---Change last point in a line string (lets play with 3d linestring this time)
SELECT ST_AsEWKT(ST_SetPoint(foo.the_geom, ST_NumPoints(foo.the_geom) - 1, ST_GeomFromEWKT('POINT(-1 1 3)')))
FROM (SELECT ST_GeomFromEWKT('LINESTRING(-1 2 3,-1 3 4, 5 6 7)') As the_geom) As foo;
st_asewkt
-----------------------
LINESTRING(-1 2 3,-1 3 4,-1 1 3)
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="ST_AddPoint"/>,<xref linkend="ST_NPoints"/>, <xref linkend="ST_NumPoints"/>, <xref linkend="ST_PointN"/>, <xref linkend="ST_RemovePoint"/></para>
</refsection>
</refentry>
<refentry id="ST_SetSRID">
<refnamediv>
<refname>ST_SetSRID</refname>
<refpurpose>Sets the SRID on a geometry to a particular integer
value.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_SetSRID</function></funcdef>
<paramdef><type>geometry </type>
<parameter>geom</parameter></paramdef>
<paramdef><type>integer </type>
<parameter>srid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Sets the SRID on a geometry to a particular integer value.
Useful in constructing bounding boxes for queries.</para>
<note>
<para>This function does not transform the geometry coordinates in any way -
it simply sets the meta data defining the spatial reference system the geometry is assumed to be in.
Use <xref linkend="ST_Transform"/> if you want to transform the
geometry into a new projection.</para>
</note>
<para>&sfs_compliant;</para>
<para>&curve_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<para>-- Mark a point as WGS 84 long lat --</para>
<programlisting>SELECT ST_SetSRID(ST_Point(-123.365556, 48.428611),4326) As wgs84long_lat;
-- the ewkt representation (wrap with ST_AsEWKT) -
SRID=4326;POINT(-123.365556 48.428611)
</programlisting>
<para>-- Mark a point as WGS 84 long lat and then transform to web mercator (Spherical Mercator) --</para>
<programlisting>SELECT ST_Transform(ST_SetSRID(ST_Point(-123.365556, 48.428611),4326),3785) As spere_merc;
-- the ewkt representation (wrap with ST_AsEWKT) -
SRID=3785;POINT(-13732990.8753491 6178458.96425423)
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="spatial_ref_sys" />, <xref linkend="ST_AsEWKT"/>, <xref linkend="ST_Point" />, <xref linkend="ST_SRID"/>,<xref linkend="ST_Transform"/>, <xref linkend="UpdateGeometrySRID"/></para>
</refsection>
</refentry>
<refentry id="ST_SnapToGrid">
<refnamediv>
<refname>ST_SnapToGrid</refname>
<refpurpose>
Snap all points of the input geometry to a regular grid.
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_SnapToGrid</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
<paramdef><type>float </type> <parameter>originX</parameter></paramdef>
<paramdef><type>float </type> <parameter>originY</parameter></paramdef>
<paramdef><type>float </type> <parameter>sizeX</parameter></paramdef>
<paramdef><type>float </type> <parameter>sizeY</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>geometry <function>ST_SnapToGrid</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
<paramdef><type>float </type> <parameter>sizeX</parameter></paramdef>
<paramdef><type>float </type> <parameter>sizeY</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>geometry <function>ST_SnapToGrid</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
<paramdef><type>float </type> <parameter>size</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>geometry <function>ST_SnapToGrid</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>pointOrigin</parameter></paramdef>
<paramdef><type>float </type> <parameter>sizeX</parameter></paramdef>
<paramdef><type>float </type> <parameter>sizeY</parameter></paramdef>
<paramdef><type>float </type> <parameter>sizeZ</parameter></paramdef>
<paramdef><type>float </type> <parameter>sizeM</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Variant 1,2,3: Snap all points of the input geometry to the grid defined by
its origin and cell size. Remove consecutive points falling on the
same cell, eventually returning NULL if output points are not
enough to define a geometry of the given type. Collapsed
geometries in a collection are stripped from it.
Useful for reducing precision.
</para>
<para>Variant 4: Introduced 1.1.0 - Snap all points of the input geometry to the grid defined by
its origin (the second argument, must be a point) and cell sizes.
Specify 0 as size for any dimension you don't want to snap to a
grid.</para>
<note>
<para>The returned geometry might loose its simplicity (see
<xref linkend="ST_IsSimple" />).</para>
</note>
<note>
<para>Before release 1.1.0 this function always returned a 2d
geometry. Starting at 1.1.0 the returned geometry will have same
dimensionality as the input one with higher dimension values
untouched. Use the version taking a second geometry argument to
define all grid dimensions.</para>
</note>
<para>Availability: 1.0.0RC1</para>
<para>Availability: 1.1.0 - Z and M support</para>
<para>&Z_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
--Snap your geometries to a precision grid of 10^-3
UPDATE mytable
SET the_geom = ST_SnapToGrid(the_geom, 0.001);
SELECT ST_AsText(ST_SnapToGrid(
ST_GeomFromText('LINESTRING(1.1115678 2.123, 4.111111 3.2374897, 4.11112 3.23748667)'),
0.001)
);
st_astext
-------------------------------------
LINESTRING(1.112 2.123,4.111 3.237)
--Snap a 4d geometry
SELECT ST_AsEWKT(ST_SnapToGrid(
ST_GeomFromEWKT('LINESTRING(-1.1115678 2.123 2.3456 1.11111,
4.111111 3.2374897 3.1234 1.1111, -1.11111112 2.123 2.3456 1.1111112)'),
ST_GeomFromEWKT('POINT(1.12 2.22 3.2 4.4444)'),
0.1, 0.1, 0.1, 0.01) );
st_asewkt
------------------------------------------------------------------------------
LINESTRING(-1.08 2.12 2.3 1.1144,4.12 3.22 3.1 1.1144,-1.08 2.12 2.3 1.1144)
--With a 4d geometry - the ST_SnapToGrid(geom,size) only touches x and y coords but keeps m and z the same
SELECT ST_AsEWKT(ST_SnapToGrid(ST_GeomFromEWKT('LINESTRING(-1.1115678 2.123 3 2.3456,
4.111111 3.2374897 3.1234 1.1111)'),
0.01) );
st_asewkt
---------------------------------------------------------
LINESTRING(-1.11 2.12 3 2.3456,4.11 3.24 3.1234 1.1111)
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="ST_Snap" />,
<xref linkend="ST_AsEWKT" />,
<xref linkend="ST_AsText" />,
<xref linkend="ST_GeomFromText" />,
<xref linkend="ST_GeomFromEWKT" />,
<xref linkend="ST_Simplify" />
</para>
</refsection>
</refentry>
<refentry id="ST_Snap">
<refnamediv>
<refname>ST_Snap</refname>
<refpurpose>
Snap segments and vertices of input geometry
to vertices of a reference geometry.
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Snap</function></funcdef>
<paramdef><type>geometry </type> <parameter>input</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>reference</parameter></paramdef>
<paramdef><type>float </type> <parameter>tolerance</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Snaps the vertices and segments of a geometry
another Geometry's vertices.
A snap distance tolerance is used to control where snapping is performed.
</para>
<para>
Snapping one geometry to another can improve
robustness for overlay operations by eliminating
nearly-coincident edges
(which cause problems during noding and intersection calculation).
</para>
<para>
Too much snapping can result in invalid topology
being created, so the number and location of snapped vertices
is decided using heuristics to determine when it
is safe to snap.
This can result in some potential snaps being omitted, however.
</para>
<note>
<para>
The returned geometry might loose its simplicity (see
<xref linkend="ST_IsSimple" />) and validity (see
<xref linkend="ST_IsValid" />).
</para>
</note>
<para>Availability: 2.0.0 requires GEOS &gt;= 3.3.0.</para>
</refsection>
<refsection>
<title>Examples</title>
<informaltable>
<tgroup cols="2">
<colspec colname="column1" />
<colspec colname="column2" />
<spanspec namest="column1" nameend="column2" spanname="span-horiz" align="center" />
<tbody>
<row>
<entry spanname="span-horiz"><informalfigure>
<mediaobject>
<imageobject>
<imagedata fileref="images/st_snap01.png" />
</imageobject>
<caption><para>A multipolygon shown with a linestring (before any snapping)</para></caption>
</mediaobject>
</informalfigure>
</entry>
</row>
<row>
<entry><para><informalfigure>
<mediaobject>
<imageobject>
<imagedata fileref="images/st_snap02.png" />
</imageobject>
<caption><para>A multipolygon snapped to linestring to tolerance: 1.01 of distance.
The new multipolygon is shown with reference linestring</para></caption>
</mediaobject>
</informalfigure>
<programlisting>
SELECT ST_AsText(ST_Snap(poly,line, ST_Distance(poly,line)*1.01)) AS polysnapped
FROM (SELECT
ST_GeomFromText('MULTIPOLYGON(
((26 125, 26 200, 126 200, 126 125, 26 125 ),
( 51 150, 101 150, 76 175, 51 150 )),
(( 151 100, 151 200, 176 175, 151 100 )))') As poly,
ST_GeomFromText('LINESTRING (5 107, 54 84, 101 100)') As line
) As foo;
polysnapped
---------------------------------------------------------------------
MULTIPOLYGON(((26 125,26 200,126 200,126 125,101 100,26 125),
(51 150,101 150,76 175,51 150)),((151 100,151 200,176 175,151 100)))
</programlisting></para>
</entry>
<entry><para><informalfigure>
<mediaobject>
<imageobject>
<imagedata fileref="images/st_snap04.png" />
</imageobject>
<caption><para>A multipolygon snapped to linestring to tolerance: 1.25 of distance.
The new multipolygon is shown with reference linestring</para></caption>
</mediaobject>
</informalfigure>
<programlisting>
SELECT ST_AsText(
ST_Snap(poly,line, ST_Distance(poly,line)*1.25)
) AS polysnapped
FROM (SELECT
ST_GeomFromText('MULTIPOLYGON(
(( 26 125, 26 200, 126 200, 126 125, 26 125 ),
( 51 150, 101 150, 76 175, 51 150 )),
(( 151 100, 151 200, 176 175, 151 100 )))') As poly,
ST_GeomFromText('LINESTRING (5 107, 54 84, 101 100)') As line
) As foo;
polysnapped
---------------------------------------------------------------------
MULTIPOLYGON(((5 107,26 200,126 200,126 125,101 100,54 84,5 107),
(51 150,101 150,76 175,51 150)),((151 100,151 200,176 175,151 100)))
</programlisting></para>
</entry>
</row>
<row>
<entry><para><informalfigure>
<mediaobject>
<imageobject>
<imagedata fileref="images/st_snap03.png" />
</imageobject>
<caption><para>The linestring snapped to the original multipolygon at tolerance 1.01 of distance.
The new linestring is shown with reference multipolygon</para></caption>
</mediaobject>
</informalfigure>
<programlisting>
SELECT ST_AsText(
ST_Snap(line, poly, ST_Distance(poly,line)*1.01)
) AS linesnapped
FROM (SELECT
ST_GeomFromText('MULTIPOLYGON(
((26 125, 26 200, 126 200, 126 125, 26 125),
(51 150, 101 150, 76 175, 51 150 )),
((151 100, 151 200, 176 175, 151 100)))') As poly,
ST_GeomFromText('LINESTRING (5 107, 54 84, 101 100)') As line
) As foo;
linesnapped
----------------------------------------
LINESTRING(5 107,26 125,54 84,101 100)
</programlisting>
</para>
</entry>
<entry><para><informalfigure>
<mediaobject>
<imageobject>
<imagedata fileref="images/st_snap05.png" />
</imageobject>
<caption><para>The linestring snapped to the original multipolygon at tolerance 1.25 of distance.
The new linestring is shown with reference multipolygon</para></caption>
</mediaobject>
</informalfigure>
<programlisting>
SELECT ST_AsText(
ST_Snap(line, poly, ST_Distance(poly,line)*1.25)
) AS linesnapped
FROM (SELECT
ST_GeomFromText('MULTIPOLYGON(
(( 26 125, 26 200, 126 200, 126 125, 26 125 ),
(51 150, 101 150, 76 175, 51 150 )),
((151 100, 151 200, 176 175, 151 100 )))') As poly,
ST_GeomFromText('LINESTRING (5 107, 54 84, 101 100)') As line
) As foo;
linesnapped
---------------------------------------
LINESTRING(26 125,54 84,101 100)
</programlisting></para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para>
<xref linkend="ST_SnapToGrid" />
</para>
</refsection>
</refentry>
<refentry id="ST_Transform">
<refnamediv>
<refname>ST_Transform</refname>
<refpurpose>Returns a new geometry with its coordinates transformed to
the SRID referenced by the integer parameter.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Transform</function></funcdef>
<paramdef><type>geometry </type> <parameter>g1</parameter></paramdef>
<paramdef><type>integer </type> <parameter>srid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns a new geometry with its coordinates transformed to
spatial reference system referenced by the SRID integer parameter. The destination SRID
must exist in the <varname>SPATIAL_REF_SYS</varname> table.</para>
<para>ST_Transform is often confused with ST_SetSRID(). ST_Transform actually changes the coordinates
of a geometry from one spatial reference system to another, while ST_SetSRID() simply changes the SRID identifier of
the geometry</para>
<note>
<para>Requires PostGIS be compiled with Proj support. Use <xref linkend="PostGIS_Full_Version" /> to confirm you have proj support compiled in.</para>
</note>
<note>
<para>If using more than one transformation, it is useful to have a functional index on the commonly used
transformations to take advantage of index usage.</para>
</note>
<note><para>Prior to 1.3.4, this function crashes if used with geometries that contain CURVES. This is fixed in 1.3.4+</para></note>
<para>Enhanced: 2.0.0 support for Polyhedral surfaces was introduced.</para>
<para>&sqlmm_compliant; SQL-MM 3: 5.1.6</para>
<para>&curve_support;</para>
<para>&P_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<para>Change Mass state plane US feet geometry to WGS 84 long lat</para>
<programlisting>
SELECT ST_AsText(ST_Transform(ST_GeomFromText('POLYGON((743238 2967416,743238 2967450,
743265 2967450,743265.625 2967416,743238 2967416))',2249),4326)) As wgs_geom;
wgs_geom
---------------------------
POLYGON((-71.1776848522251 42.3902896512902,-71.1776843766326 42.3903829478009,
-71.1775844305465 42.3903826677917,-71.1775825927231 42.3902893647987,-71.177684
8522251 42.3902896512902));
(1 row)
--3D Circular String example
SELECT ST_AsEWKT(ST_Transform(ST_GeomFromEWKT('SRID=2249;CIRCULARSTRING(743238 2967416 1,743238 2967450 2,743265 2967450 3,743265.625 2967416 3,743238 2967416 4)'),4326));
st_asewkt
--------------------------------------------------------------------------------------
SRID=4326;CIRCULARSTRING(-71.1776848522251 42.3902896512902 1,-71.1776843766326 42.3903829478009 2,
-71.1775844305465 42.3903826677917 3,
-71.1775825927231 42.3902893647987 3,-71.1776848522251 42.3902896512902 4)
</programlisting>
<para>Example of creating a partial functional index. For tables where you are not sure all the geometries
will be filled in, its best to use a partial index that leaves out null geometries which will both conserve space and make your index smaller and more efficient.</para>
<programlisting>
CREATE INDEX idx_the_geom_26986_parcels
ON parcels
USING gist
(ST_Transform(the_geom, 26986))
WHERE the_geom IS NOT NULL;
</programlisting>
</refsection>
<refsection>
<title>Configuring transformation behaviour</title>
<para>Sometimes coordinate transformation involving a grid-shift can fail, for example if PROJ.4 has not been built with grid-shift files or the coordinate does not lie within the range for which the grid shift is defined. By default, PostGIS will throw an error if a grid shift file is not present, but this behaviour can be configured on a per-SRID basis by altering the proj4text value within the spatial_ref_sys table.</para>
<para>For example, the proj4text parameter +datum=NAD87 is a shorthand form for the following +nadgrids parameter:</para>
<programlisting>+nadgrids=@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat</programlisting>
<para>The @ prefix means no error is reported if the files are not present, but if the end of the list is reached with no file having been appropriate (ie. found and overlapping) then an error is issued.</para>
<para>If, conversely, you wanted to ensure that at least the standard files were present, but that if all files were scanned without a hit a null transformation is applied you could use:</para>
<programlisting>+nadgrids=@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat,null</programlisting>
<para>The null grid shift file is a valid grid shift file covering the whole world and applying no shift. So for a complete example, if you wanted to alter PostGIS so that transformations to SRID 4267 that didn't lie within the correct range did not throw an ERROR, you would use the following:</para>
<programlisting>UPDATE spatial_ref_sys SET proj4text = '+proj=longlat +ellps=clrk66 +nadgrids=@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat,null +no_defs' WHERE srid = 4267;</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="PostGIS_Full_Version" />, <xref linkend="ST_AsText" />, <xref linkend="ST_SetSRID" />, <xref linkend="UpdateGeometrySRID"/></para>
</refsection>
</refentry>
<refentry id="ST_Translate">
<refnamediv>
<refname>ST_Translate</refname>
<refpurpose>Translates the geometry to a new location using the numeric
parameters as offsets. Ie: ST_Translate(geom, X, Y) or ST_Translate(geom, X, Y,Z).</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Translate</function></funcdef>
<paramdef><type>geometry </type> <parameter>g1</parameter></paramdef>
<paramdef><type>float </type> <parameter>deltax</parameter></paramdef>
<paramdef><type>float </type> <parameter>deltay</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>geometry <function>ST_Translate</function></funcdef>
<paramdef><type>geometry </type> <parameter>g1</parameter></paramdef>
<paramdef><type>float </type> <parameter>deltax</parameter></paramdef>
<paramdef><type>float </type> <parameter>deltay</parameter></paramdef>
<paramdef><type>float </type> <parameter>deltaz</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Returns a new geometry whose coordinates are translated delta x,delta y,delta z units. Units are
based on the units defined in spatial reference (SRID) for this geometry.</para>
<note><para>Prior to 1.3.4, this function crashes if used with geometries that contain CURVES. This is fixed in 1.3.4+</para></note>
<para>Availability: 1.2.2</para>
<para>&Z_support;</para>
<para>&curve_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<para>Move a point 1 degree longitude</para>
<programlisting>
SELECT ST_AsText(ST_Translate(ST_GeomFromText('POINT(-71.01 42.37)',4326),1,0)) As wgs_transgeomtxt;
wgs_transgeomtxt
---------------------
POINT(-70.01 42.37)
</programlisting>
<para>Move a linestring 1 degree longitude and 1/2 degree latitude</para>
<programlisting>SELECT ST_AsText(ST_Translate(ST_GeomFromText('LINESTRING(-71.01 42.37,-71.11 42.38)',4326),1,0.5)) As wgs_transgeomtxt;
wgs_transgeomtxt
---------------------------------------
LINESTRING(-70.01 42.87,-70.11 42.88)
</programlisting>
<para>Move a 3d point</para>
<programlisting>SELECT ST_AsEWKT(ST_Translate(CAST('POINT(0 0 0)' As geometry), 5, 12,3));
st_asewkt
---------
POINT(5 12 3)
</programlisting>
<para>Move a curve and a point</para>
<programlisting>SELECT ST_AsText(ST_Translate(ST_Collect('CURVEPOLYGON(CIRCULARSTRING(4 3,3.12 0.878,1 0,-1.121 5.1213,6 7, 8 9,4 3))','POINT(1 3)'),1,2));
st_astext
------------------------------------------------------------------------------------------------------------
GEOMETRYCOLLECTION(CURVEPOLYGON(CIRCULARSTRING(5 5,4.12 2.878,2 2,-0.121 7.1213,7 9,9 11,5 5)),POINT(2 5))
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_Affine" />, <xref linkend="ST_AsText" />, <xref linkend="ST_GeomFromText" /></para>
</refsection>
</refentry>
<refentry id="ST_TransScale">
<refnamediv>
<refname>ST_TransScale</refname>
<refpurpose>Translates the geometry using the deltaX and deltaY args,
then scales it using the XFactor, YFactor args, working in 2D only.
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_TransScale</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
<paramdef><type>float</type> <parameter>deltaX</parameter></paramdef>
<paramdef><type>float</type> <parameter>deltaY</parameter></paramdef>
<paramdef><type>float</type> <parameter>XFactor</parameter></paramdef>
<paramdef><type>float</type> <parameter>YFactor</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Translates the geometry using the deltaX and deltaY args,
then scales it using the XFactor, YFactor args, working in 2D only.</para>
<note><para><code>ST_TransScale(geomA, deltaX, deltaY, XFactor, YFactor)</code>
is short-hand for <code>ST_Affine(geomA, XFactor, 0, 0, 0, YFactor, 0,
0, 0, 1, deltaX*XFactor, deltaY*YFactor, 0)</code>.</para></note>
<note><para>Prior to 1.3.4, this function crashes if used with geometries that contain CURVES. This is fixed in 1.3.4+</para></note>
<para>Availability: 1.1.0.</para>
<para>&Z_support;</para>
<para>&curve_support;</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT ST_AsEWKT(ST_TransScale(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'), 0.5, 1, 1, 2));
st_asewkt
-----------------------------
LINESTRING(1.5 6 3,1.5 4 1)
--Buffer a point to get an approximation of a circle, convert to curve and then translate 1,2 and scale it 3,4
SELECT ST_AsText(ST_Transscale(ST_LineToCurve(ST_Buffer('POINT(234 567)', 3)),1,2,3,4));
st_astext
------------------------------------------------------------------------------------------------------------------------------
CURVEPOLYGON(CIRCULARSTRING(714 2276,711.363961030679 2267.51471862576,705 2264,698.636038969321 2284.48528137424,714 2276))
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_Affine" />, <xref linkend="ST_Translate" /></para>
</refsection>
</refentry>
</sect1>