PostGIS  2.5.0beta1dev-r@@SVN_REVISION@@

◆ lwgeom_project_spheroid()

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

Calculate a projected point given a source point, a distance and a bearing.

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 2012 of file lwgeodetic.c.

References distance(), geographic_point_init(), GEOGRAPHIC_POINT::lat, latitude_radians_normalize(), GEOGRAPHIC_POINT::lon, longitude_radians_normalize(), LW_FAILURE, LW_TRUE, LWDEBUGF, lwerror(), lwgeom_set_geodetic(), lwpoint_as_lwgeom(), lwpoint_construct(), lwpoint_get_x(), lwpoint_get_y(), POINT4D::m, ptarray_construct(), ptarray_set_point4d(), rad2deg, SPHEROID::radius, spheroid_project(), LWPOINT::srid, pixval::x, POINT4D::x, pixval::y, POINT4D::y, and POINT4D::z.

Referenced by geography_project().

2013 {
2014  GEOGRAPHIC_POINT geo_source, geo_dest;
2015  POINT4D pt_dest;
2016  double x, y;
2017  POINTARRAY *pa;
2018  LWPOINT *lwp;
2019 
2020  /* Normalize distance to be positive*/
2021  if ( distance < 0.0 ) {
2022  distance = -distance;
2023  azimuth += M_PI;
2024  }
2025 
2026  /* Normalize azimuth */
2027  azimuth -= 2.0 * M_PI * floor(azimuth / (2.0 * M_PI));
2028 
2029  /* Check the distance validity */
2030  if ( distance > (M_PI * spheroid->radius) )
2031  {
2032  lwerror("Distance must not be greater than %g", M_PI * spheroid->radius);
2033  return NULL;
2034  }
2035 
2036  /* Convert to ta geodetic point */
2037  x = lwpoint_get_x(r);
2038  y = lwpoint_get_y(r);
2039  geographic_point_init(x, y, &geo_source);
2040 
2041  /* Try the projection */
2042  if( spheroid_project(&geo_source, spheroid, distance, azimuth, &geo_dest) == LW_FAILURE )
2043  {
2044  LWDEBUGF(3, "Unable to project from (%g %g) with azimuth %g and distance %g", x, y, azimuth, distance);
2045  lwerror("Unable to project from (%g %g) with azimuth %g and distance %g", x, y, azimuth, distance);
2046  return NULL;
2047  }
2048 
2049  /* Build the output LWPOINT */
2050  pa = ptarray_construct(0, 0, 1);
2051  pt_dest.x = rad2deg(longitude_radians_normalize(geo_dest.lon));
2052  pt_dest.y = rad2deg(latitude_radians_normalize(geo_dest.lat));
2053  pt_dest.z = pt_dest.m = 0.0;
2054  ptarray_set_point4d(pa, 0, &pt_dest);
2055  lwp = lwpoint_construct(r->srid, NULL, pa);
2057  return lwp;
2058 }
double x
Definition: liblwgeom.h:354
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
double longitude_radians_normalize(double lon)
Convert a longitude to the range of -PI,PI.
Definition: lwgeodetic.c:41
double m
Definition: liblwgeom.h:354
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
Definition: lwgeom_api.c:425
double radius
Definition: liblwgeom.h:320
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
#define rad2deg(r)
Definition: lwgeodetic.h:75
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
double z
Definition: liblwgeom.h:354
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:952
int32_t srid
Definition: liblwgeom.h:412
double latitude_radians_normalize(double lat)
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:76
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:335
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:129
double y
Definition: liblwgeom.h:354
#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
Here is the call graph for this function:
Here is the caller graph for this function: