29 #include "../postgis_config.h" 31 #include "lwgeom_transform.h" 52 projPJ input_pj, output_pj;
53 int32 output_srid, input_srid;
55 output_srid = PG_GETARG_INT32(1);
62 geom = PG_GETARG_GSERIALIZED_P_COPY(0);
66 PG_FREE_IF_COPY(geom, 0);
67 elog(ERROR,
"Input geometry has unknown (%d) SRID",
SRID_UNKNOWN);
75 if ( input_srid == output_srid )
76 PG_RETURN_POINTER(PG_GETARG_DATUM(0));
78 if ( GetProjectionsUsingFCInfo(fcinfo, input_srid, output_srid, &input_pj, &output_pj) ==
LW_FAILURE )
80 PG_FREE_IF_COPY(geom, 0);
81 elog(ERROR,
"Failure reading projections from spatial_ref_sys.");
88 lwgeom->
srid = output_srid;
99 PG_FREE_IF_COPY(geom, 0);
101 PG_RETURN_POINTER(result);
118 projPJ input_pj, output_pj;
119 char *input_proj4, *output_proj4;
120 text *input_proj4_text;
121 text *output_proj4_text;
125 result_srid = PG_GETARG_INT32(3);
126 geom = PG_GETARG_GSERIALIZED_P_COPY(0);
132 input_proj4_text = (PG_GETARG_TEXT_P(1));
133 output_proj4_text = (PG_GETARG_TEXT_P(2));
141 if ( input_pj == NULL )
143 pj_errstr = pj_strerrno(*pj_get_errno_ref());
144 if ( ! pj_errstr ) pj_errstr =
"";
152 "transform_geom: could not parse proj4 string '%s' %s",
153 input_proj4, pj_errstr);
160 if ( output_pj == NULL )
162 pj_errstr = pj_strerrno(*pj_get_errno_ref());
163 if ( ! pj_errstr ) pj_errstr =
"";
171 "transform_geom: couldn't parse proj4 output string: '%s': %s",
172 output_proj4, pj_errstr);
180 lwgeom->
srid = result_srid;
196 PG_FREE_IF_COPY(geom, 0);
198 PG_RETURN_POINTER(result);
205 const char *ver = pj_get_release();
206 text *result = cstring2text(ver);
207 PG_RETURN_POINTER(result);
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Datum transform(PG_FUNCTION_ARGS)
void lwgeom_free(LWGEOM *geom)
int lwgeom_transform(LWGEOM *geom, projPJ inpj, projPJ outpj)
Transform (reproject) a geometry in-place.
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
projPJ lwproj_from_string(const char *txt)
Get a projection from a string representation.
#define SRID_UNKNOWN
Unknown SRID value.
char * text2cstring(const text *textptr)
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), we re-try the transform on a copy of points.
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Datum transform_geom(PG_FUNCTION_ARGS)
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)...
This library is the generic geometry handling section of PostGIS.