[postgis-tickets] r15562 - ST_MakeEmptyCoverage (David Zwarg, ainomieli)
Regina Obe
lr at pcorp.us
Sun Aug 20 19:06:41 PDT 2017
Author: robe
Date: 2017-08-20 19:06:40 -0700 (Sun, 20 Aug 2017)
New Revision: 15562
Added:
trunk/raster/test/regress/rt_makeemptycoverage.sql
trunk/raster/test/regress/rt_makeemptycoverage_expected
Modified:
trunk/NEWS
trunk/doc/reference_raster.xml
trunk/raster/rt_pg/rtpostgis.sql.in
trunk/raster/test/regress/Makefile.in
Log:
ST_MakeEmptyCoverage (David Zwarg, ainomieli)
Closes #2249 for PostGIS 2.4.0
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2017-08-20 14:43:36 UTC (rev 15561)
+++ trunk/NEWS 2017-08-21 02:06:40 UTC (rev 15562)
@@ -14,8 +14,9 @@
- #3753, Gist penalty speed improvements for 2d and nd points
(Darafei Praliaskouski)
- #3677, ST_FrechetDistance (Shinichi Sugiyama)
- - Most aggregates (raster and geometry),
+ - Most aggregates (raster and geometry),
and all stable / immutable (raster and geometry) marked as parallel safe
+ - #2249, ST_MakeEmptyCoverage for raster (David Zwarg, ainomieli)
* Enhancements *
Modified: trunk/doc/reference_raster.xml
===================================================================
--- trunk/doc/reference_raster.xml 2017-08-20 14:43:36 UTC (rev 15561)
+++ trunk/doc/reference_raster.xml 2017-08-21 02:06:40 UTC (rev 15562)
@@ -1962,6 +1962,72 @@
</refsection>
</refentry>
+ <refentry id="RT_ST_MakeEmptyCoverage">
+ <refnamediv>
+ <refname>ST_MakeEmptyCoverage</refname>
+ <refpurpose>Cover georeferenced area with a grid of empty raster tiles.</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+ <funcsynopsis>
+ <funcprototype>
+ <funcdef>raster <function>ST_MakeEmptyCoverage</function></funcdef>
+ <paramdef><type>integer </type> <parameter>tilewidth</parameter></paramdef>
+ <paramdef><type>integer </type> <parameter>tileheight</parameter></paramdef>
+ <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>scalex</parameter></paramdef>
+ <paramdef><type>double precision </type> <parameter>scaley</parameter></paramdef>
+ <paramdef><type>double precision </type> <parameter>skewx</parameter></paramdef>
+ <paramdef><type>double precision </type> <parameter>skewy</parameter></paramdef>
+ <paramdef choice="opt"><type>integer </type> <parameter>srid=unknown</parameter></paramdef>
+ </funcprototype>
+ </funcsynopsis>
+ </refsynopsisdiv>
+
+ <refsection>
+ <title>Description</title>
+
+ <para>Create a set of raster tiles with <xref linkend="RT_ST_MakeEmptyRaster" />. Grid dimension is <varname>width</varname> & <varname>height</varname>. Tile dimension is <varname>tilewidth</varname> & <varname>tileheight</varname>. The covered georeferenced area is from upper left corner (<varname>upperleftx</varname>, <varname>upperlefty</varname>) to lower right corner (<varname>upperleftx</varname> <varname>width</varname> * <varname>scalex</varname>, <varname>upperlefty</varname> <varname>height</varname> * <varname>scaley</varname>).</para>
+
+ <para>Availability: 2.4.0 </para>
+ </refsection>
+
+ <refsection>
+ <title>Examples Basic</title>
+ <para>Create 16 tiles in a 4x4 grid to cover the WGS84 area from upper left corner (22, 77) to lower right corner (55, 33).</para>
+ <programlisting><![CDATA[SELECT (ST_MetaData(tile)).* FROM ST_MakeEmptyCoverage(1, 1, 4, 4, 22, 33, (55 - 22)/(4)::float, (33 - 77)/(4)::float, 0., 0., 4326) tile;
+
+ upperleftx | upperlefty | width | height | scalex | scaley | skewx | skewy | srid | numbands
+-------------------------------------------------------------------------------------
+ 22 | 33 | 1 | 1 | 8.25 | -11 | 0 | 0 | 4326 | 0
+ 30.25 | 33 | 1 | 1 | 8.25 | -11 | 0 | 0 | 4326 | 0
+ 38.5 | 33 | 1 | 1 | 8.25 | -11 | 0 | 0 | 4326 | 0
+ 46.75 | 33 | 1 | 1 | 8.25 | -11 | 0 | 0 | 4326 | 0
+ 22 | 22 | 1 | 1 | 8.25 | -11 | 0 | 0 | 4326 | 0
+ 30.25 | 22 | 1 | 1 | 8.25 | -11 | 0 | 0 | 4326 | 0
+ 38.5 | 22 | 1 | 1 | 8.25 | -11 | 0 | 0 | 4326 | 0
+ 46.75 | 22 | 1 | 1 | 8.25 | -11 | 0 | 0 | 4326 | 0
+ 22 | 11 | 1 | 1 | 8.25 | -11 | 0 | 0 | 4326 | 0
+ 30.25 | 11 | 1 | 1 | 8.25 | -11 | 0 | 0 | 4326 | 0
+ 38.5 | 11 | 1 | 1 | 8.25 | -11 | 0 | 0 | 4326 | 0
+ 46.75 | 11 | 1 | 1 | 8.25 | -11 | 0 | 0 | 4326 | 0
+ 22 | 0 | 1 | 1 | 8.25 | -11 | 0 | 0 | 4326 | 0
+ 30.25 | 0 | 1 | 1 | 8.25 | -11 | 0 | 0 | 4326 | 0
+ 38.5 | 0 | 1 | 1 | 8.25 | -11 | 0 | 0 | 4326 | 0
+ 46.75 | 0 | 1 | 1 | 8.25 | -11 | 0 | 0 | 4326 | 0]]></programlisting>
+ </refsection>
+
+ <refsection>
+ <title>See Also</title>
+ <para>
+ <xref linkend="RT_ST_MakeEmptyRaster" />
+ </para>
+ </refsection>
+ </refentry>
+
<refentry id="RT_ST_MakeEmptyRaster">
<refnamediv>
<refname>ST_MakeEmptyRaster</refname>
Modified: trunk/raster/rt_pg/rtpostgis.sql.in
===================================================================
--- trunk/raster/rt_pg/rtpostgis.sql.in 2017-08-20 14:43:36 UTC (rev 15561)
+++ trunk/raster/rt_pg/rtpostgis.sql.in 2017-08-21 02:06:40 UTC (rev 15562)
@@ -8836,6 +8836,61 @@
END;
$$ LANGUAGE 'plpgsql' VOLATILE STRICT;
+
+-- Availability: 2.4.0
+CREATE OR REPLACE FUNCTION st_makeemptycoverage(tilewidth int, tileheight int, width int, height int, upperleftx float8, upperlefty float8, scalex float8, scaley float8, skewx float8, skewy float8, srid int4 DEFAULT 0)
+ RETURNS SETOF RASTER AS $$
+ DECLARE
+ ulx double precision; -- upper left x of raster
+ uly double precision; -- upper left y of raster
+ rw int; -- raster width (may change at edges)
+ rh int; -- raster height (may change at edges)
+ x int; -- x index of coverage
+ y int; -- y index of coverage
+ template raster; -- an empty template raster, where each cell
+ -- represents a tile in the coverage
+ minY double precision;
+ maxX double precision;
+ BEGIN
+ template := @extschema at .ST_MakeEmptyRaster(
+ ceil(width::float8/tilewidth)::int,
+ ceil(height::float8/tileheight)::int,
+ upperleftx,
+ upperlefty,
+ tilewidth * scalex,
+ tileheight * scaley,
+ tileheight * skewx,
+ tilewidth * skewy,
+ srid
+ );
+
+ FOR y IN 1..st_height(template) LOOP
+ maxX := @extschema at .ST_RasterToWorldCoordX(template, 1, y) + width * scalex;
+ FOR x IN 1..st_width(template) LOOP
+ minY := @extschema at .ST_RasterToWorldCoordY(template, x, 1) + height * scaley;
+ uly := @extschema at .ST_RasterToWorldCoordY(template, x, y);
+ IF uly + (tileheight * scaley) < minY THEN
+ --raise notice 'uly, minY: %, %', uly, minY;
+ rh := ceil((minY - uly)/scaleY)::int;
+ ELSE
+ rh := tileheight;
+ END IF;
+
+ ulx := @extschema at .ST_RasterToWorldCoordX(template, x, y);
+ IF ulx + (tilewidth * scalex) > maxX THEN
+ --raise notice 'ulx, maxX: %, %', ulx, maxX;
+ rw := ceil((maxX - ulx)/scaleX)::int;
+ ELSE
+ rw := tilewidth;
+ END IF;
+
+ RETURN NEXT @extschema at .ST_MakeEmptyRaster(rw, rh, ulx, uly, scalex, scaley, skewx, skewy, srid);
+ END LOOP;
+ END LOOP;
+ END;
+ $$ LANGUAGE 'plpgsql' IMMUTABLE _PARALLEL;
+
+
-------------------------------------------------------------------
-- Debugging
-------------------------------------------------------------------
Modified: trunk/raster/test/regress/Makefile.in
===================================================================
--- trunk/raster/test/regress/Makefile.in 2017-08-20 14:43:36 UTC (rev 15561)
+++ trunk/raster/test/regress/Makefile.in 2017-08-21 02:06:40 UTC (rev 15562)
@@ -109,6 +109,7 @@
rt_gdalwarp \
rt_asraster \
rt_dumpvalues \
+ rt_makeemptycoverage \
rt_createoverview
TEST_MAPALGEBRA = \
Added: trunk/raster/test/regress/rt_makeemptycoverage.sql
===================================================================
--- trunk/raster/test/regress/rt_makeemptycoverage.sql (rev 0)
+++ trunk/raster/test/regress/rt_makeemptycoverage.sql 2017-08-21 02:06:40 UTC (rev 15562)
@@ -0,0 +1,10 @@
+-- make an empty coverage with equal tiles (all 5x5)
+select '1', st_metadata(st_makeemptycoverage(5, 5, 10, 10, 0, 0, 1, -1, 0, 0, 0));
+-- make an empty coverage with unequal coverage (4x4, 3x4, 4x3, 3x3)
+select '2', st_metadata(st_makeemptycoverage(4, 4, 7, 7, 0, 0, 1, -1, 0, 0, 0));
+-- make an empty coverage with equal coverage and scaled
+select '3', st_metadata(st_makeemptycoverage(5, 5, 10, 10, 0, 0, 2, -2, 0, 0, 0));
+-- make an empty coverage with unequal coverage and scaled
+select '4', st_metadata(st_makeemptycoverage(6, 6, 10, 10, 0, 0, 3, -3, 0, 0, 0));
+-- make an empty coverage with equal coverage and rotated
+select '5', st_metadata(st_makeemptycoverage(5, 5, 10, 10, 0, 0, 0.707106781186548, -0.707106781186548, -0.707106781186548, -0.707106781186548, 0));
Added: trunk/raster/test/regress/rt_makeemptycoverage_expected
===================================================================
--- trunk/raster/test/regress/rt_makeemptycoverage_expected (rev 0)
+++ trunk/raster/test/regress/rt_makeemptycoverage_expected 2017-08-21 02:06:40 UTC (rev 15562)
@@ -0,0 +1,20 @@
+1|(0,0,5,5,1,-1,0,0,0,0)
+1|(5,0,5,5,1,-1,0,0,0,0)
+1|(0,-5,5,5,1,-1,0,0,0,0)
+1|(5,-5,5,5,1,-1,0,0,0,0)
+2|(0,0,4,4,1,-1,0,0,0,0)
+2|(4,0,3,4,1,-1,0,0,0,0)
+2|(0,-4,4,3,1,-1,0,0,0,0)
+2|(4,-4,3,3,1,-1,0,0,0,0)
+3|(0,0,5,5,2,-2,0,0,0,0)
+3|(10,0,5,5,2,-2,0,0,0,0)
+3|(0,-10,5,5,2,-2,0,0,0,0)
+3|(10,-10,5,5,2,-2,0,0,0,0)
+4|(0,0,6,6,3,-3,0,0,0,0)
+4|(18,0,4,6,3,-3,0,0,0,0)
+4|(0,-18,6,4,3,-3,0,0,0,0)
+4|(18,-18,4,4,3,-3,0,0,0,0)
+5|(0,0,5,5,0.707106781186548,-0.707106781186548,-0.707106781186548,-0.707106781186548,0,0)
+5|(3.53553390593274,-3.53553390593274,5,5,0.707106781186548,-0.707106781186548,-0.707106781186548,-0.707106781186548,0,0)
+5|(-3.53553390593274,-3.53553390593274,5,5,0.707106781186548,-0.707106781186548,-0.707106781186548,-0.707106781186548,0,0)
+5|(0,-7.07106781186548,5,5,0.707106781186548,-0.707106781186548,-0.707106781186548,-0.707106781186548,0,0)
More information about the postgis-tickets
mailing list