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

◆ transform()

Datum transform ( PG_FUNCTION_ARGS  )

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

56{
57 GSERIALIZED* geom;
58 GSERIALIZED* result=NULL;
59 LWGEOM* lwgeom;
60 LWPROJ *pj;
61 int32 srid_to, srid_from;
62
63 srid_to = PG_GETARG_INT32(1);
64 if (srid_to == SRID_UNKNOWN)
65 {
66 elog(ERROR, "ST_Transform: %d is an invalid target SRID", SRID_UNKNOWN);
67 PG_RETURN_NULL();
68 }
69
70 geom = PG_GETARG_GSERIALIZED_P_COPY(0);
71 srid_from = gserialized_get_srid(geom);
72
73 if ( srid_from == SRID_UNKNOWN )
74 {
75 PG_FREE_IF_COPY(geom, 0);
76 elog(ERROR, "ST_Transform: Input geometry has unknown (%d) SRID", SRID_UNKNOWN);
77 PG_RETURN_NULL();
78 }
79
80 /* Input SRID and output SRID are equal, noop */
81 if ( srid_from == srid_to )
82 PG_RETURN_POINTER(geom);
83
84 postgis_initialize_cache();
85 if ( lwproj_lookup(srid_from, srid_to, &pj) == LW_FAILURE )
86 {
87 PG_FREE_IF_COPY(geom, 0);
88 elog(ERROR, "ST_Transform: Failure reading projections from spatial_ref_sys.");
89 PG_RETURN_NULL();
90 }
91
92 /* now we have a geometry, and input/output PJ structs. */
93 lwgeom = lwgeom_from_gserialized(geom);
94 lwgeom_transform(lwgeom, pj);
95 lwgeom->srid = srid_to;
96
97 /* Re-compute bbox if input had one (COMPUTE_BBOX TAINTING) */
98 if ( lwgeom->bbox )
99 {
100 lwgeom_refresh_bbox(lwgeom);
101 }
102
103 result = geometry_serialize(lwgeom);
104 lwgeom_free(lwgeom);
105 PG_FREE_IF_COPY(geom, 0);
106
107 PG_RETURN_POINTER(result); /* new geometry */
108}
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition cu_print.c:267
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:735
#define LW_FAILURE
Definition liblwgeom.h:96
int lwgeom_transform(LWGEOM *geom, LWPROJ *pj)
Transform (reproject) a geometry in-place.
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
#define SRID_UNKNOWN
Unknown SRID value.
Definition liblwgeom.h:215
unsigned int int32
Definition shpopen.c:54
GBOX * bbox
Definition liblwgeom.h:458
int32_t srid
Definition liblwgeom.h:460

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

Here is the call graph for this function: