[postgis-devel] [PostGIS] #837: [raster] ST_MapAlgebra -- I think we have a memory leak
PostGIS
trac at osgeo.org
Mon Mar 28 14:29:29 PDT 2011
#837: [raster] ST_MapAlgebra -- I think we have a memory leak
----------------------------+-----------------------------------------------
Reporter: robe | Owner: jorgearevalo
Type: defect | Status: assigned
Priority: blocker | Milestone: PostGIS 2.0.0
Component: postgis raster | Version: trunk
Keywords: |
----------------------------+-----------------------------------------------
Comment(by pracine):
My first attemp at the C implementation of ST_MapAlgebra ever:
{{{
CREATE TYPE geomvalxy AS (
geom geometry,
val double precision,
x int,
y int
);
CREATE OR REPLACE FUNCTION ST_PixelAsPolygons(rast raster, band integer)
RETURNS SETOF geomvalxy AS
$$
DECLARE
rast alias for $1;
w integer;
h integer;
x integer;
y integer;
result geomvalxy;
BEGIN
SELECT st_width(rast), st_height(rast)
INTO w, h;
FOR x IN 1..w LOOP
FOR y IN 1..h LOOP
SELECT ST_PixelAsPolygon(rast, band, x, y),
ST_Value(rast, band, x, y), x, y INTO result;
RETURN NEXT result;
END LOOP;
END LOOP;
RETURN;
END;
$$
LANGUAGE 'plpgsql';
-- This query works
SELECT ST_MapAlgebra(ST_AddBand(ST_MakeEmptyRaster(5, 5, 0, 0, 1, 1, 0, 0,
-1), '8BUI'::text, 0, -1), 'rast + 1')
-- This query crashes (certainly because SPI_finish was not done)
SELECT ST_PixelAsPolygons(ST_MapAlgebra(ST_AddBand(ST_MakeEmptyRaster(5,
5, 0, 0, 1, 1, 0, 0, -1), '8BUI'::text, 0, -1), 'rast + 1'))
}}}
with
{{{
ERROR: SPI_connect failed: SPI_ERROR_CONNECT
CONTEXT: SQL function "st_pixelaspolygons" statement 1
********** Error **********
ERROR: SPI_connect failed: SPI_ERROR_CONNECT
SQL state: XX000
Context: SQL function "st_pixelaspolygons" statement 1
}}}
--
Ticket URL: <http://trac.osgeo.org/postgis/ticket/837#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-devel
mailing list