26 #include "../postgis_config.h"
52 uint8_t source_is_latlong =
LW_FALSE;
53 double semi_major_metre = DBL_MAX, semi_minor_metre = DBL_MAX;
56 if (! (str_in && str_out))
59 PJ* pj = proj_create_crs_to_crs(PJ_DEFAULT_CTX, str_in, str_out, NULL);
66 if (strcmp(str_in, str_out) == 0)
68 PJ *pj_source_crs = proj_get_source_crs(PJ_DEFAULT_CTX, pj);
70 PJ_TYPE pj_type = proj_get_type(pj_source_crs);
71 if (pj_type == PJ_TYPE_UNKNOWN)
74 lwerror(
"%s: unable to access source crs type", __func__);
77 source_is_latlong = (pj_type == PJ_TYPE_GEOGRAPHIC_2D_CRS) || (pj_type == PJ_TYPE_GEOGRAPHIC_3D_CRS);
79 pj_ellps = proj_get_ellipsoid(PJ_DEFAULT_CTX, pj_source_crs);
80 proj_destroy(pj_source_crs);
84 lwerror(
"%s: unable to access source crs ellipsoid", __func__);
87 if (!proj_ellipsoid_get_parameters(PJ_DEFAULT_CTX,
94 proj_destroy(pj_ellps);
96 lwerror(
"%s: unable to access source crs ellipsoid parameters", __func__);
99 proj_destroy(pj_ellps);
103 PJ* pj_norm = proj_normalize_for_visualization(PJ_DEFAULT_CTX, pj);
108 else if (pj != pj_norm)
128 PJ* pj = proj_create(PJ_DEFAULT_CTX, str_pipeline);
137 PJ* pj_norm = proj_normalize_for_visualization(PJ_DEFAULT_CTX, pj);
141 else if (pj != pj_norm)
162 PJ *pj_in = proj_create(PJ_DEFAULT_CTX, instr);
165 proj_errno_reset(NULL);
166 lwerror(
"could not parse proj string '%s'", instr);
170 PJ *pj_out = proj_create(PJ_DEFAULT_CTX, outstr);
173 proj_errno_reset(NULL);
174 lwerror(
"could not parse proj string '%s'", outstr);
176 proj_destroy(pj_out);
177 lwerror(
"%s: Failed to transform", __func__);
181 proj_destroy(lp->
pj);
192 PJ *pj_in = proj_create(PJ_DEFAULT_CTX, pipelinestr);
195 proj_errno_reset(NULL);
196 lwerror(
"could not parse coordinate operation '%s'", pipelinestr);
199 lwerror(
"%s: Failed to transform", __func__);
203 proj_destroy(lp->
pj);
243 if (proj_angular_input(pj->
pj, direction))
245 for (i = 0; i < pa->
npoints; i++)
256 PJ_XYZT v = {pa_double[0], pa_double[1], has_z ? pa_double[2] : 0.0, 0.0};
259 PJ_COORD t = proj_trans(pj->
pj, direction, c);
261 int pj_errno_val = proj_errno_reset(pj->
pj);
264 lwerror(
"transform: %s (%d)", proj_errno_string(pj_errno_val), pj_errno_val);
267 pa_double[0] = (t.xyzt).
x;
268 pa_double[1] = (t.xyzt).
y;
270 pa_double[2] = (t.xyzt).z;
282 n_converted = proj_trans_generic(pj->
pj,
290 has_z ? pa_double + 2 : NULL,
291 has_z ? point_size : 0,
292 has_z ? n_points : 0,
298 if (n_converted != n_points)
300 lwerror(
"ptarray_transform: converted (%d) != input (%d)", n_converted, n_points);
304 int pj_errno_val = proj_errno_reset(pj->
pj);
307 lwerror(
"transform: %s (%d)", proj_errno_string(pj_errno_val), pj_errno_val);
313 if (proj_angular_output(pj->
pj, direction))
315 for (i = 0; i < pa->
npoints; i++)
353 for ( i = 0; i < g->
nrings; i++ )
371 for ( i = 0; i < g->
ngeoms; i++ )
379 lwerror(
"lwgeom_transform: Cannot handle type '%s'",
int ptarray_calculate_gbox_cartesian(const POINTARRAY *pa, GBOX *gbox)
Calculate box (x/y) and add values to gbox.
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
#define POLYHEDRALSURFACETYPE
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
void * lwalloc(size_t size)
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
int ptarray_has_z(const POINTARRAY *pa)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
static size_t ptarray_point_size(const POINTARRAY *pa)
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
uint8_t source_is_latlong
double source_semi_major_metre
double source_semi_minor_metre
uint8_t * serialized_pointlist