PostGIS  2.5.7dev-r@@SVN_REVISION@@

## ◆ lwgeom_project_spheroid()

 LWPOINT* lwgeom_project_spheroid ( const LWPOINT * r, const SPHEROID * spheroid, double distance, double azimuth )

Calculate the location of a point on a spheroid, give a start point, bearing and distance.

Calculate the location of a point on a spheroid, give a start point, bearing and distance.

Parameters
 r - location of first point. spheroid - spheroid definition. distance - distance, in units of the spheroid def'n. azimuth - azimuth in radians.
Returns
s - location of projected point.

Definition at line 2099 of file lwgeodetic.c.

2100 {
2101  GEOGRAPHIC_POINT geo_source, geo_dest;
2102  POINT4D pt_dest;
2103  double x, y;
2104  POINTARRAY *pa;
2105  LWPOINT *lwp;
2106
2107  /* Normalize distance to be positive*/
2108  if ( distance < 0.0 ) {
2109  distance = -distance;
2110  azimuth += M_PI;
2111  }
2112
2113  /* Normalize azimuth */
2114  azimuth -= 2.0 * M_PI * floor(azimuth / (2.0 * M_PI));
2115
2116  /* Check the distance validity */
2117  if ( distance > (M_PI * spheroid->radius) )
2118  {
2119  lwerror("Distance must not be greater than %g", M_PI * spheroid->radius);
2120  return NULL;
2121  }
2122
2123  /* Convert to ta geodetic point */
2124  x = lwpoint_get_x(r);
2125  y = lwpoint_get_y(r);
2126  geographic_point_init(x, y, &geo_source);
2127
2128  /* Try the projection */
2129  if( spheroid_project(&geo_source, spheroid, distance, azimuth, &geo_dest) == LW_FAILURE )
2130  {
2131  LWDEBUGF(3, "Unable to project from (%g %g) with azimuth %g and distance %g", x, y, azimuth, distance);
2132  lwerror("Unable to project from (%g %g) with azimuth %g and distance %g", x, y, azimuth, distance);
2133  return NULL;
2134  }
2135
2136  /* Build the output LWPOINT */
2137  pa = ptarray_construct(0, 0, 1);
2140  pt_dest.z = pt_dest.m = 0.0;
2141  ptarray_set_point4d(pa, 0, &pt_dest);
2142  lwp = lwpoint_construct(r->srid, NULL, pa);
2144  return lwp;
2145 }
char * r
Definition: cu_in_wkt.c:24
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
Definition: lwgeom.c:952
#define LW_FAILURE
Definition: liblwgeom.h:79
double lwpoint_get_x(const LWPOINT *point)
Definition: lwpoint.c:63
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
Definition: ptarray.c:62
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:335
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:129
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
Definition: lwgeom_api.c:435
double lwpoint_get_y(const LWPOINT *point)
Definition: lwpoint.c:76
Convert a longitude to the range of -PI,PI.
Definition: lwgeodetic.c:50
Convert a latitude to the range of -PI/2,PI/2.
Definition: lwgeodetic.c:78
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
Definition: lwgeodetic.c:180
Definition: lwgeodetic.h:80
int spheroid_project(const GEOGRAPHIC_POINT *r, const SPHEROID *spheroid, double distance, double azimuth, GEOGRAPHIC_POINT *g)
Given a location, an azimuth and a distance, computes the location of the projected point.
Definition: lwspheroid.c:364
Datum distance(PG_FUNCTION_ARGS)
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:53
double m
Definition: liblwgeom.h:355
double x
Definition: liblwgeom.h:355
double z
Definition: liblwgeom.h:355
double y
Definition: liblwgeom.h:355