PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ transform()

Datum transform ( PG_FUNCTION_ARGS  )

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

49 {
50  GSERIALIZED *geom;
51  GSERIALIZED *result=NULL;
52  LWGEOM *lwgeom;
53  projPJ input_pj, output_pj;
54  int32 output_srid, input_srid;
55 
56  output_srid = PG_GETARG_INT32(1);
57  if (output_srid == SRID_UNKNOWN)
58  {
59  elog(ERROR, "%d is an invalid target SRID", SRID_UNKNOWN);
60  PG_RETURN_NULL();
61  }
62 
63  geom = PG_GETARG_GSERIALIZED_P_COPY(0);
64  input_srid = gserialized_get_srid(geom);
65 
66  if ( input_srid == SRID_UNKNOWN )
67  {
68  PG_FREE_IF_COPY(geom, 0);
69  elog(ERROR, "Input geometry has unknown (%d) SRID", SRID_UNKNOWN);
70  PG_RETURN_NULL();
71  }
72 
73  /* Input SRID and output SRID are equal, noop */
74  if ( input_srid == output_srid )
75  PG_RETURN_POINTER(geom);
76 
77  if ( GetProjectionsUsingFCInfo(fcinfo, input_srid, output_srid, &input_pj, &output_pj) == LW_FAILURE )
78  {
79  PG_FREE_IF_COPY(geom, 0);
80  elog(ERROR, "Failure reading projections from spatial_ref_sys.");
81  PG_RETURN_NULL();
82  }
83 
84  /* now we have a geometry, and input/output PJ structs. */
85  lwgeom = lwgeom_from_gserialized(geom);
86  lwgeom_transform(lwgeom, input_pj, output_pj);
87  lwgeom->srid = output_srid;
88 
89  /* Re-compute bbox if input had one (COMPUTE_BBOX TAINTING) */
90  if ( lwgeom->bbox )
91  {
92  lwgeom_refresh_bbox(lwgeom);
93  }
94 
95  result = geometry_serialize(lwgeom);
96  lwgeom_free(lwgeom);
97  PG_FREE_IF_COPY(geom, 0);
98 
99  PG_RETURN_POINTER(result); /* new geometry */
100 }
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:100
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:698
#define LW_FAILURE
Definition: liblwgeom.h:79
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
int lwgeom_transform(LWGEOM *geom, projPJ inpj, projPJ outpj)
Transform (reproject) a geometry in-place.
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
unsigned int int32
Definition: shpopen.c:273
GBOX * bbox
Definition: liblwgeom.h:401
int32_t srid
Definition: liblwgeom.h:402

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

Here is the call graph for this function: