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 $$
    transformed_geom geometry := in;
    IF ST_SRID(transformed_geom) != 32737 THEN
        transformed_geom := ST_Transform(transformed_geom, 32737);
    END IF;
    [ ... ]
$$ 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;

1 Answer 1


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 )
  • Thanks for link the source code. That's the unique source of truth. Jul 29, 2017 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.