PostGIS  2.5.0beta1dev-r@@SVN_REVISION@@

◆ transform()

Datum transform ( PG_FUNCTION_ARGS  )

Definition at line 48 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(), PG_FUNCTION_INFO_V1(), LWGEOM::srid, SRID_UNKNOWN, and transform_geom().

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 }
void lwgeom_refresh_bbox(LWGEOM *lwgeom)
Drop current bbox and calculate a fresh one.
Definition: lwgeom.c:698
unsigned int int32
Definition: shpopen.c:273
GBOX * bbox
Definition: liblwgeom.h:400
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
int lwgeom_transform(LWGEOM *geom, projPJ inpj, projPJ outpj)
Transform (reproject) a geometry in-place.
int32_t srid
Definition: liblwgeom.h:401
#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: