PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ transform()

Datum transform ( PG_FUNCTION_ARGS  )

Definition at line 48 of file postgis/lwgeom_transform.c.

49{
50 GSERIALIZED* geom;
51 GSERIALIZED* result=NULL;
52 LWGEOM* lwgeom;
53 LWPROJ *pj;
54 int32 srid_to, srid_from;
55
56 srid_to = PG_GETARG_INT32(1);
57 if (srid_to == SRID_UNKNOWN)
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);
64 srid_from = gserialized_get_srid(geom);
65
66 if ( srid_from == SRID_UNKNOWN )
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 /* Input SRID and output SRID are equal, noop */
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 /* now we have a geometry, and input/output PJ structs. */
85 lwgeom = lwgeom_from_gserialized(geom);
86 lwgeom_transform(lwgeom, pj);
87 lwgeom->srid = srid_to;
88
89 /* Re-compute bbox if input had one (COMPUTE_BBOX TAINTING) */
90 if ( lwgeom->bbox )
91 {
92 lwgeom_refresh_bbox(lwgeom);
93 }
94
95 result = geometry_serialize(lwgeom);
96 lwgeom_free(lwgeom);
97 PG_FREE_IF_COPY(geom, 0);
98
99 PG_RETURN_POINTER(result); /* new geometry */
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.
Definition lwgeom.c:689
#define LW_FAILURE
Definition liblwgeom.h:110
int lwgeom_transform(LWGEOM *geom, LWPROJ *pj)
Transform (reproject) a geometry in-place.
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1138
#define SRID_UNKNOWN
Unknown SRID value.
Definition liblwgeom.h:229
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
unsigned int int32
Definition shpopen.c:273
GBOX * bbox
Definition liblwgeom.h:444
int32_t srid
Definition liblwgeom.h:446

References LWGEOM::bbox, geometry_serialize(), gserialized_get_srid(), LW_FAILURE, lwgeom_free(), lwgeom_from_gserialized(), lwgeom_refresh_bbox(), lwgeom_transform(), LWGEOM::srid, and SRID_UNKNOWN.

Here is the call graph for this function: