Can't get ST_MapAlgebra to return fractional values
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I have a 4-band raster dataset that I have imported into a Postgres/PostGIS table using raster2pgsql. I am Using ST_MapAlgebra() with a callback function to perform some band math on the dataset. I have set the return type as double precision. However, I am finding that anytime I return a decimal value (e.g., .25 or -.25) it only returns zero. However, if I return a whole number (e.g., 25 or -15), I can receive the values back from the call. I played around with this, but canâÂÂt figure out why this is occurring. Any help would be appreciated. Here is the syntax of my callback function:
CREATE OR REPLACE FUNCTION urban_veg.ndvi_callback (
value double precision,
pos integer,
VARIADIC userargs text
)
RETURNS double precision AS
$$
DECLARE
r1_val double precision;
r4_val double precision;
result double precision;
BEGIN
r1_val := value[1][1][1]::double precision;
r4_val := value[2][1][1]::double precision;
result := (r4_val-r1_val)/(r4_val+r1_val);
RETURN result;
END;
$$
LANGUAGE 'plpgsql' IMMUTABLE COST 1000;
The call to the function is:
ST_MapAlgebra(
ARRAY[
ROW(rast, 1),
ROW(rast, 4) ]::rastbandarg,
'urban_veg.ndvi_callback(
double precision,integer,text
)'::regprocedure, '16BSI'::text)
postgis raster postgresql
add a comment |Â
up vote
3
down vote
favorite
I have a 4-band raster dataset that I have imported into a Postgres/PostGIS table using raster2pgsql. I am Using ST_MapAlgebra() with a callback function to perform some band math on the dataset. I have set the return type as double precision. However, I am finding that anytime I return a decimal value (e.g., .25 or -.25) it only returns zero. However, if I return a whole number (e.g., 25 or -15), I can receive the values back from the call. I played around with this, but canâÂÂt figure out why this is occurring. Any help would be appreciated. Here is the syntax of my callback function:
CREATE OR REPLACE FUNCTION urban_veg.ndvi_callback (
value double precision,
pos integer,
VARIADIC userargs text
)
RETURNS double precision AS
$$
DECLARE
r1_val double precision;
r4_val double precision;
result double precision;
BEGIN
r1_val := value[1][1][1]::double precision;
r4_val := value[2][1][1]::double precision;
result := (r4_val-r1_val)/(r4_val+r1_val);
RETURN result;
END;
$$
LANGUAGE 'plpgsql' IMMUTABLE COST 1000;
The call to the function is:
ST_MapAlgebra(
ARRAY[
ROW(rast, 1),
ROW(rast, 4) ]::rastbandarg,
'urban_veg.ndvi_callback(
double precision,integer,text
)'::regprocedure, '16BSI'::text)
postgis raster postgresql
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I have a 4-band raster dataset that I have imported into a Postgres/PostGIS table using raster2pgsql. I am Using ST_MapAlgebra() with a callback function to perform some band math on the dataset. I have set the return type as double precision. However, I am finding that anytime I return a decimal value (e.g., .25 or -.25) it only returns zero. However, if I return a whole number (e.g., 25 or -15), I can receive the values back from the call. I played around with this, but canâÂÂt figure out why this is occurring. Any help would be appreciated. Here is the syntax of my callback function:
CREATE OR REPLACE FUNCTION urban_veg.ndvi_callback (
value double precision,
pos integer,
VARIADIC userargs text
)
RETURNS double precision AS
$$
DECLARE
r1_val double precision;
r4_val double precision;
result double precision;
BEGIN
r1_val := value[1][1][1]::double precision;
r4_val := value[2][1][1]::double precision;
result := (r4_val-r1_val)/(r4_val+r1_val);
RETURN result;
END;
$$
LANGUAGE 'plpgsql' IMMUTABLE COST 1000;
The call to the function is:
ST_MapAlgebra(
ARRAY[
ROW(rast, 1),
ROW(rast, 4) ]::rastbandarg,
'urban_veg.ndvi_callback(
double precision,integer,text
)'::regprocedure, '16BSI'::text)
postgis raster postgresql
I have a 4-band raster dataset that I have imported into a Postgres/PostGIS table using raster2pgsql. I am Using ST_MapAlgebra() with a callback function to perform some band math on the dataset. I have set the return type as double precision. However, I am finding that anytime I return a decimal value (e.g., .25 or -.25) it only returns zero. However, if I return a whole number (e.g., 25 or -15), I can receive the values back from the call. I played around with this, but canâÂÂt figure out why this is occurring. Any help would be appreciated. Here is the syntax of my callback function:
CREATE OR REPLACE FUNCTION urban_veg.ndvi_callback (
value double precision,
pos integer,
VARIADIC userargs text
)
RETURNS double precision AS
$$
DECLARE
r1_val double precision;
r4_val double precision;
result double precision;
BEGIN
r1_val := value[1][1][1]::double precision;
r4_val := value[2][1][1]::double precision;
result := (r4_val-r1_val)/(r4_val+r1_val);
RETURN result;
END;
$$
LANGUAGE 'plpgsql' IMMUTABLE COST 1000;
The call to the function is:
ST_MapAlgebra(
ARRAY[
ROW(rast, 1),
ROW(rast, 4) ]::rastbandarg,
'urban_veg.ndvi_callback(
double precision,integer,text
)'::regprocedure, '16BSI'::text)
postgis raster postgresql
postgis raster postgresql
edited 8 hours ago
ahmadhanb
19.4k21746
19.4k21746
asked 8 hours ago
geo derek
180115
180115
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
You specify the return pixeltype to be '16BSI'
(16bit signed integer); given this, ST_MapAlgebra
won't return a float, not even with a gun to it's head...
Try with '32BF'
(32bit float).
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
You specify the return pixeltype to be '16BSI'
(16bit signed integer); given this, ST_MapAlgebra
won't return a float, not even with a gun to it's head...
Try with '32BF'
(32bit float).
add a comment |Â
up vote
4
down vote
You specify the return pixeltype to be '16BSI'
(16bit signed integer); given this, ST_MapAlgebra
won't return a float, not even with a gun to it's head...
Try with '32BF'
(32bit float).
add a comment |Â
up vote
4
down vote
up vote
4
down vote
You specify the return pixeltype to be '16BSI'
(16bit signed integer); given this, ST_MapAlgebra
won't return a float, not even with a gun to it's head...
Try with '32BF'
(32bit float).
You specify the return pixeltype to be '16BSI'
(16bit signed integer); given this, ST_MapAlgebra
won't return a float, not even with a gun to it's head...
Try with '32BF'
(32bit float).
answered 1 hour ago
ThingumaBob
4,8431222
4,8431222
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f299593%2fcant-get-st-mapalgebra-to-return-fractional-values%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password