28 #include "utils/builtins.h"
30 #include "../postgis_config.h"
32 #include "lwgeom_transform.h"
54 int32 srid_to, srid_from;
56 srid_to = PG_GETARG_INT32(1);
59 elog(ERROR,
"ST_Transform: %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,
"ST_Transform: Input geometry has unknown (%d) SRID",
SRID_UNKNOWN);
74 if ( srid_from == srid_to )
75 PG_RETURN_POINTER(geom);
77 if ( GetPJUsingFCInfo(fcinfo, srid_from, srid_to, &pj) ==
LW_FAILURE )
79 PG_FREE_IF_COPY(geom, 0);
80 elog(ERROR,
"ST_Transform: Failure reading projections from spatial_ref_sys.");
87 lwgeom->
srid = srid_to;
97 PG_FREE_IF_COPY(geom, 0);
99 PG_RETURN_POINTER(result);
115 char *input_srs, *output_srs;
120 gser = PG_GETARG_GSERIALIZED_P_COPY(0);
125 result_srid = PG_GETARG_INT32(3);
135 elog(ERROR,
"coordinate transformation failed");
140 geom->
srid = result_srid;
146 PG_FREE_IF_COPY(gser, 0);
148 PG_RETURN_POINTER(gser_result);
155 #if POSTGIS_PROJ_VERSION < 60
156 const char *ver = pj_get_release();
157 text *result = cstring_to_text(ver);
159 PJ_INFO pji = proj_info();
160 text *result = cstring_to_text(pji.version);
162 PG_RETURN_POINTER(result);
175 const char *default_prefix =
"";
177 const char *prefix = default_prefix;
179 const int32_t srid_to = 4326;
182 GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P_COPY(0);
184 text *prefix_text = PG_GETARG_TEXT_P(2);
189 PG_FREE_IF_COPY(geom, 0);
190 elog(ERROR,
"ST_AsKML: Input geometry has unknown (%d) SRID",
SRID_UNKNOWN);
200 if (VARSIZE_ANY_EXHDR(prefix_text) > 0)
203 prefixbuf = palloc(VARSIZE_ANY_EXHDR(prefix_text)+2);
204 memcpy(prefixbuf, VARDATA(prefix_text),
205 VARSIZE_ANY_EXHDR(prefix_text));
207 prefixbuf[VARSIZE_ANY_EXHDR(prefix_text)] =
':';
208 prefixbuf[VARSIZE_ANY_EXHDR(prefix_text)+1] =
'\0';
214 if (srid_from != srid_to)
217 if (GetPJUsingFCInfo(fcinfo, srid_from, srid_to, &pj) ==
LW_FAILURE)
219 PG_FREE_IF_COPY(geom, 0);
220 elog(ERROR,
"ST_AsKML: Failure reading projections from spatial_ref_sys.");
228 PG_FREE_IF_COPY(geom, 0);
233 result = cstring_to_text(kml);
236 PG_RETURN_POINTER(result);
int32_t gserialized_get_srid(const GSERIALIZED *g)
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.
int lwgeom_transform(LWGEOM *geom, LWPROJ *pj)
Transform (reproject) a geometry in-place.
void lwgeom_free(LWGEOM *geom)
char * lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix)
int lwgeom_transform_from_str(LWGEOM *geom, const char *instr, const char *outstr)
#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)
Datum LWGEOM_asKML(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(transform)
transform( GEOMETRY, INT (output srid) ) tmpPts - if there is a nadgrid error (-38),...