PostGIS  2.3.8dev-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 2006 of file lwgeodetic.c.

Referenced by geography_project().

2007 {
2008  GEOGRAPHIC_POINT geo_source, geo_dest;
2009  POINT4D pt_dest;
2010  double x, y;
2011  POINTARRAY *pa;
2012  LWPOINT *lwp;
2013
2014  /* Check the azimuth validity, convert to radians */
2015  if ( azimuth < -2.0 * M_PI || azimuth > 2.0 * M_PI )
2016  {
2017  lwerror("Azimuth must be between -2PI and 2PI");
2018  return NULL;
2019  }
2020
2021  /* Check the distance validity */
2022  if ( distance < 0.0 || distance > (M_PI * spheroid->radius) )
2023  {
2024  lwerror("Distance must be between 0 and %g", M_PI * spheroid->radius);
2025  return NULL;
2026  }
2027
2028  /* Convert to ta geodetic point */
2029  x = lwpoint_get_x(r);
2030  y = lwpoint_get_y(r);
2031  geographic_point_init(x, y, &geo_source);
2032
2033  /* Try the projection */
2034  if( spheroid_project(&geo_source, spheroid, distance, azimuth, &geo_dest) == LW_FAILURE )
2035  {
2036  LWDEBUGF(3, "Unable to project from (%g %g) with azimuth %g and distance %g", x, y, azimuth, distance);
2037  lwerror("Unable to project from (%g %g) with azimuth %g and distance %g", x, y, azimuth, distance);
2038  return NULL;
2039  }
2040
2041  /* Build the output LWPOINT */
2042  pa = ptarray_construct(0, 0, 1);
2045  pt_dest.z = pt_dest.m = 0.0;
2046  ptarray_set_point4d(pa, 0, &pt_dest);
2047  lwp = lwpoint_construct(r->srid, NULL, pa);
2049  return lwp;
2050 }
void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d)
Definition: lwgeom_api.c:549
double x
Definition: liblwgeom.h:351
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
Convert a longitude to the range of -PI,PI.
Definition: lwgeodetic.c:41
double m
Definition: liblwgeom.h:351
Definition: liblwgeom.h:317
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:47
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:359
#define LW_FAILURE
Definition: liblwgeom.h:78
double lwpoint_get_x(const LWPOINT *point)
Definition: lwpoint.c:63
Definition: lwgeodetic.h:75
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
double z
Definition: liblwgeom.h:351
Datum distance(PG_FUNCTION_ARGS)
void lwgeom_set_geodetic(LWGEOM *geom, int value)
Set the FLAGS geodetic bit on geometry an all sub-geometries and pointlists.
Definition: lwgeom.c:871
int32_t srid
Definition: liblwgeom.h:409
Convert a latitude to the range of -PI/2,PI/2.
Definition: lwgeodetic.c:69
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
Definition: lwgeodetic.c:171
double lwpoint_get_y(const LWPOINT *point)
Definition: lwpoint.c:73
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:267
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:111
double y
Definition: liblwgeom.h:351
#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:102
Here is the call graph for this function:
Here is the caller graph for this function: