I'm writing a function that has a geometry as a parameter that can be in different projections:
CREATE OR REPLACE FUNCTION foo(in geometry) RETURNS boolean AS $$
DECLARE
transformed_geom geometry := in;
BEGIN
IF ST_SRID(transformed_geom) != 32737 THEN
transformed_geom := ST_Transform(transformed_geom, 32737);
END IF;
[ ... ]
END;
$$ language plpgsql;
The function needs the geometry in a specific projection (32737) but I don't want to obligate the caller to make the transformation, I prefer to handle it inside the function.
The question is, instead of check the actual srid, it's safe to always call ST_Transform? Will do anything if the geometry is already in the target projection?
I check with a query like this that it seems to be safe, but it will be awesome if someone can confirm this as I did not see it in the docs.
SELECT ST_AsEWKT(geom), ST_AsEWKT(ST_Transform(geom, 32737)) FROM table_in_32737;
Answer
The function checks for same in and out srid, and returns untouched if so, as the source code shows:
/*
* If input SRID and output SRID are equal, return geometry
* without transform it
*/
if ( input_srid == output_srid )
PG_RETURN_POINTER(PG_GETARG_DATUM(0));
No comments:
Post a Comment