PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ transform_geom()

Datum transform_geom ( PG_FUNCTION_ARGS  )

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

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

Here is the call graph for this function: