PostGIS  3.6.1dev-r@@SVN_REVISION@@

◆ transform_geom()

Datum transform_geom ( PG_FUNCTION_ARGS  )

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

120 {
121  GSERIALIZED *gser, *gser_result=NULL;
122  LWGEOM *geom;
123  char *input_srs, *output_srs;
124  int32 result_srid;
125  int rv;
126 
127  /* Take a copy, since we will be altering the coordinates */
128  gser = PG_GETARG_GSERIALIZED_P_COPY(0);
129 
130  /* Convert from text to cstring for libproj */
131  input_srs = text_to_cstring(PG_GETARG_TEXT_P(1));
132  output_srs = text_to_cstring(PG_GETARG_TEXT_P(2));
133  result_srid = PG_GETARG_INT32(3);
134 
135  /* now we have a geometry, and input/output PJ structs. */
136  geom = lwgeom_from_gserialized(gser);
137  rv = lwgeom_transform_from_str(geom, input_srs, output_srs);
138  pfree(input_srs);
139  pfree(output_srs);
140 
141  if (rv == LW_FAILURE)
142  {
143  elog(ERROR, "coordinate transformation failed");
144  PG_RETURN_NULL();
145  }
146 
147  /* Re-compute bbox if input had one (COMPUTE_BBOX TAINTING) */
148  geom->srid = result_srid;
149  if (geom->bbox)
150  lwgeom_refresh_bbox(geom);
151 
152  gser_result = geometry_serialize(geom);
153  lwgeom_free(geom);
154  PG_FREE_IF_COPY(gser, 0);
155 
156  PG_RETURN_POINTER(gser_result); /* new geometry */
157 }
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: