[postgis-tickets] [PostGIS] #1048: [raster] Coverage version of stats functions should be aggregates

PostGIS trac at osgeo.org
Sat Dec 14 10:34:53 PST 2013


#1048: [raster] Coverage version of stats functions should be aggregates
-------------------------+--------------------------------------------------
 Reporter:  pracine      |       Owner:  dustymugs     
     Type:  enhancement  |      Status:  assigned      
 Priority:  medium       |   Milestone:  PostGIS Future
Component:  raster       |     Version:  trunk         
 Keywords:               |  
-------------------------+--------------------------------------------------
Changes (by dustymugs):

  * owner:  pracine => dustymugs
  * status:  new => assigned


Comment:

 Another item worth noting. It appears as though the following code and
 query fails...

 {{{
 CREATE OR REPLACE FUNCTION _st_summarystats_finalfn(
         internal,
         OUT count bigint,
         OUT sum double precision,
         OUT mean double precision,
         OUT stddev double precision,
         OUT min double precision,
         OUT max double precision
 )
         AS 'MODULE_PATHNAME', 'RASTER_summaryStats_finalfn'
         LANGUAGE 'c' IMMUTABLE;

 CREATE OR REPLACE FUNCTION _st_summarystats_transfn(
         internal,
         raster, integer,
         boolean, double precision
 )
         RETURNS internal
         AS 'MODULE_PATHNAME', 'RASTER_summaryStats_transfn'
         LANGUAGE 'c' IMMUTABLE;

 CREATE AGGREGATE st_summarystatsagg(raster, integer, boolean, double
 precision) (
         SFUNC = _st_summarystats_transfn,
         STYPE = internal,
         FINALFUNC = _st_summarystats_finalfn
 );
 }}}

 {{{
 SELECT
         (stats).count,
         round((stats).sum::numeric, 3),
         round((stats).mean::numeric, 3),
         round((stats).stddev::numeric, 3),
         round((stats).min::numeric, 3),
         round((stats).max::numeric, 3)
 FROM (
 SELECT
                 ST_SummaryStatsAgg(rast, 1, TRUE) AS stats
 FROM test_summarystats
 ) foo;

 ERROR:  record type has not been registered
 }}}

 The only workaround I've found is to create a type.

 {{{
 CREATE TYPE summarystats AS (
         count bigint,
         sum double precision,
         mean double precision,
         stddev double precision,
         min double precision,
         max double precision
 );

 CREATE OR REPLACE FUNCTION _st_summarystats_finalfn(internal)
         RETURNS summarystats
         AS 'MODULE_PATHNAME', 'RASTER_summaryStats_finalfn'
         LANGUAGE 'c' IMMUTABLE;

 }}}

 With the type...

 {{{
 SELECT
         (stats).count,
         round((stats).sum::numeric, 3),
         round((stats).mean::numeric, 3),
         round((stats).stddev::numeric, 3),
         round((stats).min::numeric, 3),
         round((stats).max::numeric, 3)
 FROM (
 SELECT
                 ST_SummaryStatsAgg(rast, 1, TRUE) AS stats
 FROM test_summarystats
 ) foo;


  count |  round  | round  | round |  round  | round
 -------+---------+--------+-------+---------+-------
     20 | -68.584 | -3.429 | 6.571 | -10.000 | 3.142
 (1 row)

 }}}

-- 
Ticket URL: <http://trac.osgeo.org/postgis/ticket/1048#comment:14>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-tickets mailing list