49{
54 int32 srid_to, srid_from;
55
56 srid_to = PG_GETARG_INT32(1);
58 {
59 elog(ERROR,
"ST_Transform: %d is an invalid target SRID",
SRID_UNKNOWN);
60 PG_RETURN_NULL();
61 }
62
63 geom = PG_GETARG_GSERIALIZED_P_COPY(0);
65
67 {
68 PG_FREE_IF_COPY(geom, 0);
69 elog(ERROR,
"ST_Transform: Input geometry has unknown (%d) SRID",
SRID_UNKNOWN);
70 PG_RETURN_NULL();
71 }
72
73
74 if ( srid_from == srid_to )
75 PG_RETURN_POINTER(geom);
76
77 if ( GetPJUsingFCInfo(fcinfo, srid_from, srid_to, &pj) ==
LW_FAILURE )
78 {
79 PG_FREE_IF_COPY(geom, 0);
80 elog(ERROR, "ST_Transform: Failure reading projections from spatial_ref_sys.");
81 PG_RETURN_NULL();
82 }
83
84
87 lwgeom->
srid = srid_to;
88
89
91 {
93 }
94
97 PG_FREE_IF_COPY(geom, 0);
98
99 PG_RETURN_POINTER(result);
100}
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
int lwgeom_transform(LWGEOM *geom, LWPROJ *pj)
Transform (reproject) a geometry in-place.
void lwgeom_free(LWGEOM *geom)
#define SRID_UNKNOWN
Unknown SRID value.
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)