Commit b10e2c27 authored by Regina Obe's avatar Regina Obe

Another example

parent d3a23521
...@@ -897,46 +897,46 @@ WHERE ...@@ -897,46 +897,46 @@ WHERE
</refentry> </refentry>
<refentry id="ST_SquareGrid"> <refentry id="ST_SquareGrid">
<refnamediv> <refnamediv>
<refname>ST_SquareGrid</refname> <refname>ST_SquareGrid</refname>
<refpurpose>Returns a set of grid squares and cell indices that completely cover the bounds of the geometry argument.</refpurpose> <refpurpose>Returns a set of grid squares and cell indices that completely cover the bounds of the geometry argument.</refpurpose>
</refnamediv> </refnamediv>
<refsynopsisdiv> <refsynopsisdiv>
<funcsynopsis> <funcsynopsis>
<funcprototype> <funcprototype>
<funcdef>setof record <function>ST_SquareGrid</function></funcdef> <funcdef>setof record <function>ST_SquareGrid</function></funcdef>
<paramdef><type>float8</type> <parameter>size</parameter></paramdef> <paramdef><type>float8</type> <parameter>size</parameter></paramdef>
<paramdef><type>geometry</type> <parameter>bounds</parameter></paramdef> <paramdef><type>geometry</type> <parameter>bounds</parameter></paramdef>
</funcprototype> </funcprototype>
</funcsynopsis> </funcsynopsis>
</refsynopsisdiv> </refsynopsisdiv>
<refsection> <refsection>
<title>Description</title> <title>Description</title>
<para>Starts with the concept of a square tiling of the plane. <para>Starts with the concept of a square tiling of the plane.
For a given planar SRS, and a given edge size, starting at the origin of the SRS, For a given planar SRS, and a given edge size, starting at the origin of the SRS,
there is one unique square tiling of the plane, Tiling(SRS, Size). there is one unique square tiling of the plane, Tiling(SRS, Size).
This function answers the question: what grids in a given Tiling(SRS, Size) This function answers the question: what grids in a given Tiling(SRS, Size)
overlap with a given bounds.</para> overlap with a given bounds.</para>
<para>The SRS for the output squares is the SRS provided by the bounds geometry.</para> <para>The SRS for the output squares is the SRS provided by the bounds geometry.</para>
<para>Doubling or edge size of the square generates a new parent tiling that <para>Doubling or edge size of the square generates a new parent tiling that
perfectly fits with the original tiling. Standard web map tilings in mercator perfectly fits with the original tiling. Standard web map tilings in mercator
are just powers-of-two square grids in the mercator plane.</para> are just powers-of-two square grids in the mercator plane.</para>
<para>Availability: 3.1</para> <para>Availability: 3.1</para>
</refsection> </refsection>
<refsection> <refsection>
<title>Example: Counting points in squares</title> <title>Example: Counting points in squares (using single chopped grid)</title>
<para>To do a point summary against a square tiling, generate a square grid using the <para>To do a point summary against a square tiling, generate a square grid using the
extent of the points as the bounds, then spatially join to that grid.</para> extent of the points as the bounds, then spatially join to that grid. Note the estimated extent might be off from actual extent, so be cautious and at very least make sure you've analyzed your table.</para>
<programlisting>SELECT COUNT(*), squares.geom <programlisting>SELECT COUNT(*), squares.geom
FROM FROM
pointtable AS pts pointtable AS pts
INNER JOIN INNER JOIN
ST_SquareGrid( ST_SquareGrid(
...@@ -944,16 +944,31 @@ FROM ...@@ -944,16 +944,31 @@ FROM
ST_SetSRID(ST_EstimatedExtent('pointtable', 'geom'), 3857) ST_SetSRID(ST_EstimatedExtent('pointtable', 'geom'), 3857)
) AS squares ) AS squares
ON ST_Intersects(pts.geom, squares.geom) ON ST_Intersects(pts.geom, squares.geom)
GROUP BY squares.geom</programlisting> GROUP BY squares.geom</programlisting>
</refsection> </refsection>
<refsection> <refsection>
<title>See Also</title> <title>Example: Counting points in squares using set of grid per point</title>
<para><xref linkend="ST_TileEnvelope" />, <xref linkend="ST_HexagonGrid" /> <para>This yields the same result as the first example but will be slower for a large number of points</para>
<programlisting>SELECT COUNT(*), squares.geom
FROM
pointtable AS pts
INNER JOIN
ST_SquareGrid(
1000,
pts.geom
) AS squares
ON ST_Intersects(pts.geom, squares.geom)
GROUP BY squares.geom</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para><xref linkend="ST_TileEnvelope" />, <xref linkend="ST_HexagonGrid" />
, <xref linkend="ST_EstimatedExtent" /> , <xref linkend="ST_EstimatedExtent" />
, <xref linkend="ST_SetSRID" /></para> , <xref linkend="ST_SetSRID" /></para>
</refsection> </refsection>
</refentry> </refentry>
<refentry id="ST_Hexagon"> <refentry id="ST_Hexagon">
<refnamediv> <refnamediv>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment