28 #include "utils/builtins.h"
30 #include "../postgis_config.h"
32 #include "lwgeom_transform.h"
53 projPJ input_pj, output_pj;
54 int32 output_srid, input_srid;
56 output_srid = PG_GETARG_INT32(1);
59 elog(ERROR,
"%d is an invalid target SRID",
SRID_UNKNOWN);
63 geom = PG_GETARG_GSERIALIZED_P_COPY(0);
68 PG_FREE_IF_COPY(geom, 0);
69 elog(ERROR,
"Input geometry has unknown (%d) SRID",
SRID_UNKNOWN);
74 if ( input_srid == output_srid )
75 PG_RETURN_POINTER(geom);
77 if ( GetProjectionsUsingFCInfo(fcinfo, input_srid, output_srid, &input_pj, &output_pj) ==
LW_FAILURE )
79 PG_FREE_IF_COPY(geom, 0);
80 elog(ERROR,
"Failure reading projections from spatial_ref_sys.");
87 lwgeom->
srid = output_srid;
97 PG_FREE_IF_COPY(geom, 0);
99 PG_RETURN_POINTER(result);
116 projPJ input_pj, output_pj;
117 char *input_proj4, *output_proj4;
118 text *input_proj4_text;
119 text *output_proj4_text;
123 result_srid = PG_GETARG_INT32(3);
124 geom = PG_GETARG_GSERIALIZED_P_COPY(0);
130 input_proj4_text = (PG_GETARG_TEXT_P(1));
131 output_proj4_text = (PG_GETARG_TEXT_P(2));
139 if ( input_pj == NULL )
141 pj_errstr = pj_strerrno(*pj_get_errno_ref());
142 if ( ! pj_errstr ) pj_errstr =
"";
150 "transform_geom: could not parse proj4 string '%s' %s",
151 input_proj4, pj_errstr);
158 if ( output_pj == NULL )
160 pj_errstr = pj_strerrno(*pj_get_errno_ref());
161 if ( ! pj_errstr ) pj_errstr =
"";
169 "transform_geom: couldn't parse proj4 output string: '%s': %s",
170 output_proj4, pj_errstr);
178 lwgeom->
srid = result_srid;
193 PG_FREE_IF_COPY(geom, 0);
195 PG_RETURN_POINTER(result);
202 const char *ver = pj_get_release();
203 text *result = cstring_to_text(ver);
204 PG_RETURN_POINTER(result);
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)...
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.
projPJ lwproj_from_string(const char *txt)
Get a projection from a string representation.
void lwgeom_free(LWGEOM *geom)
int lwgeom_transform(LWGEOM *geom, projPJ inpj, projPJ outpj)
Transform (reproject) a geometry in-place.
#define SRID_UNKNOWN
Unknown SRID value.
This library is the generic geometry handling section of PostGIS.
char * text_to_cstring(const text *textptr)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
Datum transform_geom(PG_FUNCTION_ARGS)
Datum transform(PG_FUNCTION_ARGS)
Datum postgis_proj_version(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(transform)
transform( GEOMETRY, INT (output srid) ) tmpPts - if there is a nadgrid error (-38),...