PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ transform_geom()

Datum transform_geom ( PG_FUNCTION_ARGS  )

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

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