PostGIS  2.2.7dev-r@@SVN_REVISION@@
Datum ellipsoid_in ( PG_FUNCTION_ARGS  )

Definition at line 68 of file lwgeom_spheroid.c.

References SPHEROID::a, SPHEROID::b, SPHEROID::e, SPHEROID::e_sq, SPHEROID::f, and SPHEROID::name.

69 {
70  char *str = PG_GETARG_CSTRING(0);
71  SPHEROID *sphere = (SPHEROID *) palloc(sizeof(SPHEROID));
72  int nitems;
73  double rf;
74 
75  memset(sphere,0, sizeof(SPHEROID));
76 
77  if (strstr(str,"SPHEROID") != str )
78  {
79  elog(ERROR,"SPHEROID parser - doesn't start with SPHEROID");
80  pfree(sphere);
81  PG_RETURN_NULL();
82  }
83 
84  nitems = sscanf(str,"SPHEROID[\"%19[^\"]\",%lf,%lf]",
85  sphere->name, &sphere->a, &rf);
86 
87  if ( nitems==0)
88  nitems = sscanf(str,"SPHEROID(\"%19[^\"]\",%lf,%lf)",
89  sphere->name, &sphere->a, &rf);
90 
91  if (nitems != 3)
92  {
93  elog(ERROR,"SPHEROID parser - couldnt parse the spheroid");
94  pfree(sphere);
95  PG_RETURN_NULL();
96  }
97 
98  sphere->f = 1.0/rf;
99  sphere->b = sphere->a - (1.0/rf)*sphere->a;
100  sphere->e_sq = ((sphere->a*sphere->a) - (sphere->b*sphere->b)) /
101  (sphere->a*sphere->a);
102  sphere->e = sqrt(sphere->e_sq);
103 
104  PG_RETURN_POINTER(sphere);
105 
106 }
double b
Definition: liblwgeom.h:298
double f
Definition: liblwgeom.h:299
double e
Definition: liblwgeom.h:300
double e_sq
Definition: liblwgeom.h:301
double a
Definition: liblwgeom.h:297
char name[20]
Definition: liblwgeom.h:303