4. Constructors

Constructors within pgSphere are functions needed to create spherical data types from other data types. For actual use, there isn't a difference to usual PostgreSQL functions. pgSphere constructor functions are named by returned data type. Constructor functions expecting one parameter only are implemented as casting operators, too. These are not mentioned here.

4.1. Point

There is only one constructor function for spherical points.

spoint(float8 lng, float8 lat);

where lng is the longitude of the spherical point in radians, lng is the latitude of the spherical point in radians.

Example 17. A spherical point from longitude and latitude

Get a spherical position with 270° of longitude and -30° of latitude.


sql> SELECT spoint ( 270.0*pi()/180.0,-30.0*pi()/180.0 ) AS spoint;
            

4.2. Euler transformation

There are two constructor functions for an Euler transformation:

strans(float8 phi, float8 theta, float8 psi);

strans(float8 phi, float8 theta, float8 psi, character axis);

where phi, theta and psi are the three angles of Euler transformation. The fourth parameter is the three letter code of Euler the transformation axis. If that parameter is omitted, pgSphere will assume ZXZ. For more information about that parameter, see Section 3.3.

Example 18. Create an Euler transformation object

Create a transformation object to rotate a spherical object counterclockwise, first 20° around the x-axis, second -270° around the z-axis, and last 70.5° around the y-axis.


sql> SELECT strans ( 20.0*pi()/180.0, -270.0*pi()/180.0, 70.5*pi()/180.0, 'XZY');
            

4.3. Circle

The function

scircle(spoint center, float8 radius);

returns a spherical circle with center at center and a radius radius in radians. The circle radius has to be larger than or equal to zero but less or equal to 90°. Otherwise, this function returns an error.

Example 19. A circle around the north pole

Get a spherical circle around the North Pole with a radius of 30°.


sql> SELECT set_sphere_output('DEG');
 set_sphere_output 
-------------------
 SET DEG
(1 row)

sql> SELECT scircle ( spoint '(0d,90d)', 30.0*pi()/180.0 );
      scircle       
--------------------
 <(0d , 90d) , 30d>
(1 row)
           

4.4. Line

The input of spherical lines using Euler transformation and length is quite circumstantial (see Section 3.5). For short