From 87a2a38faad96a02b737a10dab10f6f2be1994e6 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Wed, 8 Feb 2012 18:51:32 +0000 Subject: [PATCH] Stop relying on private projects.h PROJ header (#1541) git-svn-id: http://svn.osgeo.org/postgis/trunk@9108 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/liblwgeom.h.in | 15 ++++++++++++++- liblwgeom/liblwgeom_internal.h | 3 ++- libpgcommon/lwgeom_transform.c | 28 +++++++++++----------------- postgis/geography.h | 13 ------------- 4 files changed, 27 insertions(+), 32 deletions(-) diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index a5dfad141..05162a3a6 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -19,7 +19,6 @@ #include #include #include -#include "projects.h" #include "proj_api.h" /** @@ -86,6 +85,20 @@ #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 diff --git a/liblwgeom/liblwgeom_internal.h b/liblwgeom/liblwgeom_internal.h index 481646301..a7a5579f3 100644 --- a/liblwgeom/liblwgeom_internal.h +++ b/liblwgeom/liblwgeom_internal.h @@ -34,7 +34,8 @@ /** * PI */ -#define LW_PI 3.1415926535897932384626433832795 +#define PI 3.1415926535897932384626433832795 + /** * Floating point comparitors. diff --git a/libpgcommon/lwgeom_transform.c b/libpgcommon/lwgeom_transform.c index 706b2f80e..cb7545a29 100644 --- a/libpgcommon/lwgeom_transform.c +++ b/libpgcommon/lwgeom_transform.c @@ -714,29 +714,23 @@ spheroid_init_from_srid(FunctionCallInfo fcinfo, int srid, SPHEROID *s) { 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; } diff --git a/postgis/geography.h b/postgis/geography.h index cf07dd4fa..5b777702a 100644 --- a/postgis/geography.h +++ b/postgis/geography.h @@ -10,19 +10,6 @@ **********************************************************************/ -/********************************************************************** -** 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 -- 2.50.1