PostGIS  3.4.0dev-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 2105 of file lwgeodetic.c.

2106 {
2107  GEOGRAPHIC_POINT geo_source, geo_dest;
2108  POINT4D pt_dest;
2109  double x, y;
2110  LWPOINT *lwp;
2111  int has_z, has_m;
2112 
2113  /* Normalize distance to be positive*/
2114  if ( distance < 0.0 ) {
2115  distance = -distance;
2116  azimuth += M_PI;
2117  }
2118 
2119  /* Normalize azimuth */
2120  azimuth -= 2.0 * M_PI * floor(azimuth / (2.0 * M_PI));
2121 
2122  /* Check the distance validity */
2123  if ( distance > (M_PI * spheroid->radius) )
2124  {
2125  lwerror("Distance must not be greater than %g", M_PI * spheroid->radius);
2126  return NULL;
2127  }
2128 
2129  /* Convert to ta geodetic point */
2130  x = lwpoint_get_x(r);
2131  y = lwpoint_get_y(r);
2132  has_z = lwgeom_has_z(lwpoint_as_lwgeom(r));
2133  has_m = lwgeom_has_m(lwpoint_as_lwgeom(r));
2134  geographic_point_init(x, y, &geo_source);
2135 
2136  /* Try the projection */
2137  if( spheroid_project(&geo_source, spheroid, distance, azimuth, &geo_dest) == LW_FAILURE )
2138  {
2139  LWDEBUGF(3, "Unable to project from (%g %g) with azimuth %g and distance %g", x, y, azimuth, distance);
2140  lwerror("Unable to project from (%g %g) with azimuth %g and distance %g", x, y, azimuth, distance);
2141  return NULL;
2142  }
2143 
2144  /* Build the output LWPOINT */
2145  pt_dest.x = rad2deg(longitude_radians_normalize(geo_dest.lon));
2146  pt_dest.y = rad2deg(latitude_radians_normalize(geo_dest.lat));
2147  pt_dest.z = has_z ? lwpoint_get_z(r) : 0.0;
2148  pt_dest.m = has_m ? lwpoint_get_m(r) : 0.0;
2149  lwp = lwpoint_make(r->srid, has_z, has_m, &pt_dest);
2151  return lwp;
2152 }
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:964
double lwpoint_get_m(const LWPOINT *point)
Definition: lwpoint.c:107
#define LW_FAILURE
Definition: liblwgeom.h:96
double lwpoint_get_x(const LWPOINT *point)
Definition: lwpoint.c:63
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:934
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:344
double lwpoint_get_z(const LWPOINT *point)
Definition: lwpoint.c:89
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:941
double lwpoint_get_y(const LWPOINT *point)
Definition: lwpoint.c:76
LWPOINT * lwpoint_make(int32_t srid, int hasz, int hasm, const POINT4D *p)
Definition: lwpoint.c:206
double longitude_radians_normalize(double lon)
Convert a longitude to the range of -PI,PI.
Definition: lwgeodetic.c:50
double latitude_radians_normalize(double lat)
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
#define rad2deg(r)
Definition: lwgeodetic.h:81
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:128
#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
static double distance(double x1, double y1, double x2, double y2)
Definition: lwtree.c:1032
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:54
double m
Definition: liblwgeom.h:414
double x
Definition: liblwgeom.h:414
double z
Definition: liblwgeom.h:414
double y
Definition: liblwgeom.h:414
double radius
Definition: liblwgeom.h:380

References distance(), geographic_point_init(), GEOGRAPHIC_POINT::lat, latitude_radians_normalize(), GEOGRAPHIC_POINT::lon, longitude_radians_normalize(), LW_FAILURE, LW_TRUE, LWDEBUGF, lwerror(), lwgeom_has_m(), lwgeom_has_z(), lwgeom_set_geodetic(), lwpoint_as_lwgeom(), lwpoint_get_m(), lwpoint_get_x(), lwpoint_get_y(), lwpoint_get_z(), lwpoint_make(), POINT4D::m, r, rad2deg, SPHEROID::radius, spheroid_project(), POINT4D::x, pixval::x, POINT4D::y, pixval::y, and POINT4D::z.

Referenced by geography_project(), and lwgeom_project_spheroid_lwpoint().

Here is the call graph for this function:
Here is the caller graph for this function: