PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ transform_geom()

Datum transform_geom ( PG_FUNCTION_ARGS  )

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

117 {
118  GSERIALIZED *gser, *gser_result=NULL;
119  LWGEOM *geom;
120  char *input_srs, *output_srs;
121  int32 result_srid;
122  int rv;
123 
124  /* Take a copy, since we will be altering the coordinates */
125  gser = PG_GETARG_GSERIALIZED_P_COPY(0);
126 
127  /* Convert from text to cstring for libproj */
128  input_srs = text_to_cstring(PG_GETARG_TEXT_P(1));
129  output_srs = text_to_cstring(PG_GETARG_TEXT_P(2));
130  result_srid = PG_GETARG_INT32(3);
131 
132  /* now we have a geometry, and input/output PJ structs. */
133  geom = lwgeom_from_gserialized(gser);
134  rv = lwgeom_transform_from_str(geom, input_srs, output_srs);
135  pfree(input_srs);
136  pfree(output_srs);
137 
138  if (rv == LW_FAILURE)
139  {
140  elog(ERROR, "coordinate transformation failed");
141  PG_RETURN_NULL();
142  }
143 
144  /* Re-compute bbox if input had one (COMPUTE_BBOX TAINTING) */
145  geom->srid = result_srid;
146  if (geom->bbox)
147  lwgeom_refresh_bbox(geom);
148 
149  gser_result = geometry_serialize(geom);
150  lwgeom_free(geom);
151  PG_FREE_IF_COPY(gser, 0);
152 
153  PG_RETURN_POINTER(gser_result); /* new geometry */
154 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:268
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
Definition: lwgeom.c:707
#define LW_FAILURE
Definition: liblwgeom.h:96
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1218
int lwgeom_transform_from_str(LWGEOM *geom, const char *instr, const char *outstr)
unsigned int int32
Definition: shpopen.c:54
GBOX * bbox
Definition: liblwgeom.h:458
int32_t srid
Definition: liblwgeom.h:460

References LWGEOM::bbox, LW_FAILURE, lwgeom_free(), lwgeom_from_gserialized(), lwgeom_refresh_bbox(), lwgeom_transform_from_str(), and LWGEOM::srid.

Here is the call graph for this function: