PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ ellipsoid_in()

Datum ellipsoid_in ( PG_FUNCTION_ARGS  )

Definition at line 80 of file lwgeom_spheroid.c.

81 {
82  char *str = PG_GETARG_CSTRING(0);
83  SPHEROID *sphere = (SPHEROID *) palloc(sizeof(SPHEROID));
84  int nitems;
85  double rf;
86 
87  memset(sphere,0, sizeof(SPHEROID));
88 
89  if (strstr(str,"SPHEROID") != str )
90  {
91  elog(ERROR,"SPHEROID parser - doesn't start with SPHEROID");
92  pfree(sphere);
93  PG_RETURN_NULL();
94  }
95 
96  nitems = sscanf(str,"SPHEROID[\"%19[^\"]\",%lf,%lf]",
97  sphere->name, &sphere->a, &rf);
98 
99  if ( nitems==0)
100  nitems = sscanf(str,"SPHEROID(\"%19[^\"]\",%lf,%lf)",
101  sphere->name, &sphere->a, &rf);
102 
103  if (nitems != 3)
104  {
105  elog(ERROR,"SPHEROID parser - couldnt parse the spheroid");
106  pfree(sphere);
107  PG_RETURN_NULL();
108  }
109 
110  sphere->f = 1.0/rf;
111  sphere->b = sphere->a - (1.0/rf)*sphere->a;
112  sphere->e_sq = ((sphere->a*sphere->a) - (sphere->b*sphere->b)) /
113  (sphere->a*sphere->a);
114  sphere->e = sqrt(sphere->e_sq);
115 
116  PG_RETURN_POINTER(sphere);
117 
118 }
#define str(s)
double e_sq
Definition: liblwgeom.h:365
double e
Definition: liblwgeom.h:364
double a
Definition: liblwgeom.h:361
double b
Definition: liblwgeom.h:362
double f
Definition: liblwgeom.h:363
char name[20]
Definition: liblwgeom.h:367

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