6. Functions

The functions described below are implemented without having an operator. If you are missing some functions, see Section 5 and use the operators.

6.1. Area function

The area function returns the area of a spherical object in square radians. Supported data types are: scircle, spolygon (if the polygon is convex), sbox, and smoc.

Example 39. Area of a spherical circle as a multiple of π


sql> SELECT area( scircle '<(0d,90d),60d>' ) / pi() AS area;
 area
------
 1
(1 row)
sql> SELECT area(smoc '0/1-3');
       area
-------------------
 3.141592653589793
(1 row)
              

6.2. spoint functions

6.2.1. Longitude and latitude

The functions

long(spoint p);

lat(spoint p);

returns the longitude or latitude value of a spherical position p in radians.

Example 40. Get the longitude and latitude of a spherical point in degrees


sql> SELECT long ( spoint '(10d,20d)' ) * 180.0 / pi() AS longitude;
 longitude
------------
 10
(1 row)

sql> SELECT lat ( spoint '(10d,20d)' ) * 180.0 / pi() AS latitude;
 latitude
----------
 20
(1 row)
              

6.2.2. Cartesian coordinates

The functions

x(spoint p);

y(spoint p);

z(spoint p);

return the Cartesian x, y or z value of a spherical position p. The returned values are always between -1.0 and +1.0.

Example 41. Get the Cartesian z-value of a spherical point


sql> SELECT z ( spoint '(10d,-90d)' ) AS z;
 z
----
 -1
(1 row)
              

You can get a float8 array of Cartesian values using the function

xyz(spoint p);

Example 42. Get the Cartesian values of a spherical point


sql> SELECT xyz ( spoint '(0d,0d)' ) AS cart;
  cart
---------
 {1,0,0}
(1 row)
              

6.3. strans functions

6.3.1. Converting to ZXZ

Using the function strans_zxz(strans), you can convert an Euler transformation to ZXZ axes transformation.

Example 43. Change the transformation axes to ZXZ

Convert the transformation strans '20d, -270d, 70.5d, XZY' to a ZXZ transformation.


sql> SELECT strans_zxz ( strans '20d, -270d, 70.5d, XZY' );
                  

6.3.2. Angles and axes

It is possible to get the components of an Euler transformation.

Table 4. Getting Euler transformation attributes

function description
phi first angle of a transformation
theta second angle of a transformation
psi third angle of a transformation
axes transformation axes as a three letter code

The angles will always returned as a float8 value in radians. The axes are returned as a three letter code.

Example 44. Get the second axis and its rotation angle


sql> SELECT theta( strans '20d,30d,40d,XZY' ) * 180 / pi() AS theta;
 theta
-------
 30
(1 row)
sql> SELECT substring ( axes ( strans '20d,30d,40d,XZY' ) from 2 for 1 ) AS axis;
 axis
------
  Z
(1 row)
                  

6.4. scircle functions

You can get the radius of a spherical circle in radians using the radius function. The center of the circle is available with the operator @@ (Section 5.7).

Example 45. Radius of a spherical circle in degrees


sql> SELECT 180.0 * radius( scircle '<(0d,90d),60d>' ) / pi() AS radius;
 radius
--------
     60
(1 row)
              

6.5. sellipse functions

pgSphere provides 4 functions to get the parameters of a spherical ellipse:

Table 5. Getting spherical ellipse attributes

function description
lrad the major radius of the ellipse
srad the