OmniSciDB  72c90bc290
geoCoord.h File Reference

Geodetic (lat/lon) functions. More...

`#include "QueryEngine/ExtensionFunctions/h3lib/include/constants.h"`
`#include "QueryEngine/ExtensionFunctions/h3lib/include/h3api.h"`
`#include "QueryEngine/ExtensionFunctions/h3lib/lib/geoCoord.hpp"`
Include dependency graph for geoCoord.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Functions

EXTENSION_INLINE double constrainLng (double lng)

EXTENSION_NOINLINE double _geoAzimuthRads (const GeoCoord(p1), const GeoCoord(p2))

EXTENSION_NOINLINE bool _geoAzDistanceRads (const GeoCoord(p1), double az, double distance, GeoCoord(p2))

## Detailed Description

Geodetic (lat/lon) functions.

Definition in file geoCoord.h.

## Function Documentation

 EXTENSION_NOINLINE bool _geoAzDistanceRads ( const GeoCoordp1, double az, double distance, GeoCoord(p2) )

Computes the point on the sphere a specified azimuth and distance from another point.

Parameters
 p1 The first spherical coordinates. az The desired azimuth from p1. distance The desired distance from p1, must be non-negative. p2 The spherical coordinates at the desired azimuth and distance from p1.

Definition at line 204 of file geoCoord.hpp.

References _posAngleRads(), constrainLng(), EPSILON, GeoCoordCopy, LAT_INDEX, LON_INDEX, M_PI, and M_PI_2.

Referenced by _hex2dToGeo().

207  {
208  if (distance < EPSILON) {
209  GeoCoordCopy(p2, p1);
210  return true;
211  }
212
213  double sinlat, sinlon, coslon;
214
216
217  // check for due north/south azimuth
218  if (az < EPSILON || fabs(az - M_PI) < EPSILON) {
219  if (az < EPSILON) // due north
220  p2[LAT_INDEX] = p1[LAT_INDEX] + distance;
221  else // due south
222  p2[LAT_INDEX] = p1[LAT_INDEX] - distance;
223
224  if (fabs(p2[LAT_INDEX] - M_PI_2) < EPSILON) // north pole
225  {
226  p2[LAT_INDEX] = M_PI_2;
227  p2[LON_INDEX] = 0.0;
228  } else if (fabs(p2[LAT_INDEX] + M_PI_2) < EPSILON) // south pole
229  {
230  p2[LAT_INDEX] = -M_PI_2;
231  p2[LON_INDEX] = 0.0;
232  } else
233  p2[LON_INDEX] = constrainLng(p1[LON_INDEX]);
234  } else // not due north or south
235  {
236  sinlat =
237  sin(p1[LAT_INDEX]) * cos(distance) + cos(p1[LAT_INDEX]) * sin(distance) * cos(az);
238  if (sinlat > 1.0)
239  sinlat = 1.0;
240  if (sinlat < -1.0)
241  sinlat = -1.0;
242  p2[LAT_INDEX] = asin(sinlat);
243  if (fabs(p2[LAT_INDEX] - M_PI_2) < EPSILON) // north pole
244  {
245  p2[LAT_INDEX] = M_PI_2;
246  p2[LON_INDEX] = 0.0;
247  } else if (fabs(p2[LAT_INDEX] + M_PI_2) < EPSILON) // south pole
248  {
249  p2[LAT_INDEX] = -M_PI_2;
250  p2[LON_INDEX] = 0.0;
251  } else {
252  sinlon = sin(az) * sin(distance) / cos(p2[LAT_INDEX]);
253  coslon = (cos(distance) - sin(p1[LAT_INDEX]) * sin(p2[LAT_INDEX])) /
254  cos(p1[LAT_INDEX]) / cos(p2[LAT_INDEX]);
255  if (sinlon > 1.0)
256  sinlon = 1.0;
257  if (sinlon < -1.0)
258  sinlon = -1.0;
259  if (coslon > 1.0)
260  coslon = 1.0;
261  if (coslon < -1.0)
262  coslon = -1.0;
263  p2[LON_INDEX] = constrainLng(p1[LON_INDEX] + atan2(sinlon, coslon));
264  }
265  }
266  return true;
267 }
EXTENSION_INLINE double constrainLng(double lng)
Definition: geoCoord.hpp:134
#define M_PI
Definition: constants.h:25
#define LAT_INDEX
Definition: h3api.h:92
Definition: geoCoord.hpp:35
#define M_PI_2
Definition: constants.h:30
#define EPSILON
Definition: constants.h:42
#define LON_INDEX
Definition: h3api.h:93
#define GeoCoordCopy(dest_coord, src_coord)
Definition: h3api.h:96

Here is the call graph for this function:

Here is the caller graph for this function:

 EXTENSION_NOINLINE double _geoAzimuthRads ( const GeoCoordp1, const GeoCoordp2 )

The great circle distance in radians between two spherical coordinates.

This function uses the Haversine formula. For math details, see: https://en.wikipedia.org/wiki/Haversine_formula https://www.movable-type.co.uk/scripts/latlong.html

Parameters
 a the first lat/lng pair (in radians) b the second lat/lng pair (in radians)
Returns
the great circle distance in radians between a and b The great circle distance in kilometers between two spherical coordinates. The great circle distance in meters between two spherical coordinates. Determines the azimuth to p2 from p1 in radians.
Parameters
 p1 The first spherical coordinates. p2 The second spherical coordinates.
Returns
The azimuth in radians from p1 to p2.

Definition at line 187 of file geoCoord.hpp.

References LAT_INDEX, and LON_INDEX.

Referenced by _geoToHex2d().

187  {
188  return atan2(
189  cos(p2[LAT_INDEX]) * sin(p2[LON_INDEX] - p1[LON_INDEX]),
190  cos(p1[LAT_INDEX]) * sin(p2[LAT_INDEX]) -
191  sin(p1[LAT_INDEX]) * cos(p2[LAT_INDEX]) * cos(p2[LON_INDEX] - p1[LON_INDEX]));
192 }
#define LAT_INDEX
Definition: h3api.h:92
#define LON_INDEX
Definition: h3api.h:93

Here is the caller graph for this function:

Normalizes radians to a value between 0.0 and two PI.

Parameters
Returns

Definition at line 35 of file geoCoord.hpp.

References M_2PI.

Referenced by _geoAzDistanceRads(), _geoToHex2d(), and _hex2dToGeo().

35  {
38  tmp -= M_2PI;
39  return tmp;
40 }
#define M_2PI
Definition: constants.h:34

Here is the caller graph for this function:

 EXTENSION_INLINE double constrainLng ( double lng )

epsilon of ~0.1mm in degrees epsilon of ~0.1mm in radians

constrainLat makes sure latitudes are in the proper bounds

Parameters
 lat The original lat value
Returns
The corrected lat value constrainLng makes sure longitudes are in the proper bounds
Parameters
 lng The origin lng value
Returns
The corrected lng value

Definition at line 134 of file geoCoord.hpp.

References M_PI.

134  {
135  while (lng > M_PI) {
136  lng = lng - (2 * M_PI);
137  }
138  while (lng < -M_PI) {
139  lng = lng + (2 * M_PI);
140  }
141  return lng;
142 }
#define M_PI
Definition: constants.h:25

Here is the caller graph for this function: