Opened 6 years ago

Closed 6 years ago

#2384 closed defect (fixed)

[raster] Problem in ST_Neighborhood(raster, integer, geometry, integer, integer, boolean)

Reported by: jawj Owned by: Bborie Park
Priority: medium Milestone: PostGIS 2.1.0
Component: raster Version: 2.1.x
Keywords: history Cc:

Description

I've just been trying to get to grips with st_neighborhood, and I think there's a problem in the variant that accepts a point (alternatively, if I've misunderstood what's going on here, then please accept my apologies).

In a certain query I'm getting the following error:

ERROR: invalid input syntax for integer: "-0.6465376" CONTEXT: PL/pgSQL function "st_neighborhood" line 15 at assignment

The problem is that the function seems to expect the x and y coordinates of the provided point geometry to be integers. (The PL/pgSQL source of the function is reproduced below for convenience).

Firstly, I don't think there's any reason to suppose that the x and y coordinates of the point argument will be integers.

Secondly, they're simply used as inputs to st_worldtorastercoordx/y, and those functions expect double precision input in any case.

CREATE OR REPLACE FUNCTION public.st_neighborhood(rast raster, band integer, pt geometry, distancex integer, distancey integer, exclude_nodata_value boolean DEFAULT true)
 RETURNS double precision[]
 LANGUAGE plpgsql
 IMMUTABLE STRICT
AS $function$
        DECLARE
                wx int;
                wy int;
                rtn double precision[][];
        BEGIN
                IF (st_geometrytype($3) != 'ST_Point') THEN
                        RAISE EXCEPTION 'Attempting to get the neighbor of a pixel with a non-point geometry';
                END IF;

                IF ST_SRID(rast) != ST_SRID(pt) THEN
                        RAISE EXCEPTION 'Raster and geometry do not have the same SRID';
                END IF;

                wx := st_x($3);
                wy := st_y($3);

                SELECT _st_neighborhood(
                        $1, $2,
                        st_worldtorastercoordx(rast, wx, wy),
                        st_worldtorastercoordy(rast, wx, wy),
                        $4, $5,
                        $6
                ) INTO rtn;
                RETURN rtn;
        END;
        $function$

Change History (4)

comment:1 Changed 6 years ago by robe

Component: postgisraster
Owner: changed from pramsey to Bborie Park

I haven't tried this on my version of PostGIS. Can you please state output of:

SELECT version() || ' ' || postgis_full_version();

comment:2 Changed 6 years ago by jawj

I'm not in front of the relevant computer at the moment, but if it helps:

comment:3 Changed 6 years ago by Bborie Park

Status: newassigned

comment:4 Changed 6 years ago by Bborie Park

Keywords: history added
Resolution: fixed
Status: assignedclosed

Fixed for -trunk on r11692. Fixed for 2.1 on r11693

Note: See TracTickets for help on using tickets.