PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum transform ( PG_FUNCTION_ARGS  )

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

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.

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

Here is the call graph for this function: