#include <stdarg.h>
#include <stdio.h>
#include <stdint.h>
-#include "projects.h"
#include "proj_api.h"
/**
#define WKBSRIDFLAG 0x20000000
#define WKBBBOXFLAG 0x10000000
+/**********************************************************************
+** Spherical radius.
+** Moritz, H. (1980). Geodetic Reference System 1980, by resolution of
+** the XVII General Assembly of the IUGG in Canberra.
+** http://en.wikipedia.org/wiki/Earth_radius
+** http://en.wikipedia.org/wiki/World_Geodetic_System
+*/
+
+#define WGS84_MAJOR_AXIS 6378137.0
+#define WGS84_INVERSE_FLATTENING 298.257223563
+#define WGS84_MINOR_AXIS (WGS84_MAJOR_AXIS - WGS84_MAJOR_AXIS / WGS84_INVERSE_FLATTENING)
+#define WGS84_RADIUS ((2.0 * WGS84_MAJOR_AXIS + WGS84_MINOR_AXIS ) / 3.0)
+
+
/**
* Macros for manipulating the 'flags' byte. A uint8_t used as follows:
* ---RGBMZ
/**
* PI
*/
-#define LW_PI 3.1415926535897932384626433832795
+#define PI 3.1415926535897932384626433832795
+
/**
* Floating point comparitors.
{
projPJ pj1;
projPJ pj2;
- PJ *p;
if ( GetProjectionsUsingFCInfo(fcinfo, srid, srid, &pj1, &pj2) == LW_FAILURE)
return LW_FAILURE;
if ( ! pj_is_latlong(pj1) )
return LW_FAILURE;
-
- /* Get the proj string
- char *proj_str;
- proj_str = pj_get_def(pj1, 0);
- POSTGIS_DEBUGF(4, "proj_str = %s", proj_str);
- */
-
- /* Get access to the proj internals */
- p = (PJ*)pj1;
-
- /* Initialize */
- s->a = p->a;
- s->e_sq = p->es;
- s->b = s->a * sqrt(p->one_es);
- s->f = (s->a - s->b) / s->a;
- s->radius = (2.0 * s->a + s->b ) / 3.0;
+
+#if POSTGIS_PROJ_VERSION >= 48
+ /* For newer versions of Proj we can pull the spheroid paramaeters and initialize */
+ /* using them */
+ /* TODO actually implement this using the API function when it exists */
+ spheroid_init(s, WGS84_MAJOR_AXIS, WGS84_MINOR_AXIS);
+#else
+ /* For old versions of Proj we cannot lookup the spheroid parameters from the API */
+ /* So we use the WGS84 parameters (boo!) */
+ spheroid_init(s, WGS84_MAJOR_AXIS, WGS84_MINOR_AXIS);
+#endif
return LW_SUCCESS;
}
**********************************************************************/
-/**********************************************************************
-** Spherical radius.
-** Moritz, H. (1980). Geodetic Reference System 1980, by resolution of
-** the XVII General Assembly of the IUGG in Canberra.
-** http://en.wikipedia.org/wiki/Earth_radius
-** http://en.wikipedia.org/wiki/World_Geodetic_System
-*/
-
-#define WGS84_MAJOR_AXIS 6378137.0
-#define WGS84_INVERSE_FLATTENING 298.257223563
-#define WGS84_MINOR_AXIS (WGS84_MAJOR_AXIS - WGS84_MAJOR_AXIS / WGS84_INVERSE_FLATTENING)
-#define WGS84_RADIUS ((2.0 * WGS84_MAJOR_AXIS + WGS84_MINOR_AXIS ) / 3.0)
-
/**********************************************************************
** Useful functions for all GSERIALIZED handlers.
** TODO: Move to common.h in pgcommon