40 #ifndef INCLUDED_GLS_MAP_UTIL_H
41 #define INCLUDED_GLS_MAP_UTIL_H
49 #if( defined( GLSGEN_EXPORT_GLSMAPUTIL ) || defined( GLSGEN_IMPORT_GLSMAPUTIL ) || defined( GLS_EXPORT_GENERATED ) || defined( GLS_IMPORT_GENERATED ) ) \
50 && defined( _MSC_VER )
51 # if defined( GLSGEN_EXPORT_GLSMAPUTIL ) || defined( GLS_EXPORT_GENERATED )
52 # define GLSGEN_GLSMAPUTIL_EXPORT __declspec( dllexport )
54 # define GLSGEN_GLSMAPUTIL_EXPORT __declspec( dllimport )
57 # define GLSGEN_GLSMAPUTIL_EXPORT
78 void SetEllipsoid(
double radius,
double flattening );
80 double Radius()
const {
return _a; }
81 double Flattening()
const {
return _f; }
85 double a()
const {
return _a; }
86 double f()
const {
return _f; }
87 double a_sq()
const {
return _a_sq; }
88 double b()
const {
return _b; }
89 double b_sq()
const {
return _b_sq; }
91 double e()
const {
return _e; }
92 double c1()
const {
return _c1; }
93 double a_b()
const {
return _a_b; }
94 double a_sq_sq()
const {
return _a_sq_sq; }
95 double b_sq_sq()
const {
return _b_sq_sq; }
101 double e_sq()
const {
return _e_sq; }
102 double ep_sq()
const {
return _ep_sq; }
103 double ef()
const {
return _ef; }
104 double e_sq_to_3()
const {
return _e_sq_to_3; }
105 double ef_to_3()
const {
return _ef_to_3; }
106 double ef_to4()
const {
return _ef_to_4; }
108 double poly1_a()
const {
return _poly1_a; }
109 double poly2_a()
const {
return _poly2_a; }
110 double poly3_a()
const {
return _poly3_a; }
111 double poly4_a()
const {
return _poly4_a; }
112 double poly5_a()
const {
return _poly5_a; }
113 double poly1_b()
const {
return _poly1_b; }
114 double poly2_b()
const {
return _poly2_b; }
115 double poly3_b()
const {
return _poly3_b; }
116 double poly4_b()
const {
return _poly4_b; }
162 SetGeodetic( lonLatAlt.x, lonLatAlt.y, lonLatAlt.z, ellipsoid );
173 if( &ellipsoid == &WGS84 )
178 _validValues = VAL_GEODETIC_WGS84;
182 SetGeodeticNonWGS84( longitude, latitude, altitude, ellipsoid );
192 double lon, lat, alt;
194 lonLatAlt->x = float( lon );
195 lonLatAlt->y = float( lat );
196 lonLatAlt->z = float( alt );
207 if( &ellipsoid == &WGS84 )
209 if( !( _validValues & VAL_GEODETIC_WGS84 ) )
211 UpdateGeodeticWGS84Value();
220 GetGeodeticNonWGS84( longitude, latitude, altitude, ellipsoid );
240 _validValues = VAL_GEOCENTRIC;
249 value->x = float( x );
250 value->y = float( y );
251 value->z = float( z );
260 if( !( _validValues & VAL_GEOCENTRIC ) )
262 UpdateGeocentricValue();
274 if( this->_validValues & VAL_GEODETIC_WGS84 && other._validValues & VAL_GEODETIC_WGS84 )
277 return closeValues( this->_lon, other._lon ) && closeValues( this->_lat, other._lat ) && closeValues( this->_alt, other._alt );
283 if( !( _validValues & VAL_GEOCENTRIC ) )
285 UpdateGeocentricValue();
288 if( !( other._validValues & VAL_GEOCENTRIC ) )
290 other.UpdateGeocentricValue();
293 return closeValues( this->_x, other._x ) && closeValues( this->_y, other._y ) && closeValues( this->_z, other._z );
301 return !( *
this == other );
306 double* lon,
double* lat,
double* alt,
307 const EllipsoidParams& ellipsoid = GeoCoord::WGS84 );
311 double* xp,
double* yp,
double* zp,
312 const EllipsoidParams& ellipsoid = GeoCoord::WGS84 );
314 static void UTMToGeodetic(
const double northing,
const double easting,
315 double& lat_degrees,
double& lon_degrees );
317 static void UTMToGeodetic(
const double northing,
const double easting,
const int zone,
const int latZoneIndex,
318 double& lat_degrees,
double& lon_degrees );
320 static void GeodeticToUTM(
const double lat_degrees,
const double lon_degrees,
321 double& northing,
double& easting );
323 static int CalcZone(
double lon_radians );
324 static int CalcZoneDeg(
double longitude_degrees );
326 static char CalcLatZoneDeg(
double lat_degrees );
327 static int CalcLatZoneDegIndex(
double lat_degrees );
339 double* distance,
double* bearing,
340 const double radius = 6372795.477598 );
352 double bearing,
GeoCoord* destination,
353 const double radius = 6372795.477598 );
356 static bool closeValues(
double lv,
double rv )
358 const double PRECISION( 1e-7 );
359 return ( lv - PRECISION ) <= rv && rv <= ( lv + PRECISION );
362 void GetGeodeticNonWGS84(
double* longitude,
double* latitude,
double* altitude,
const EllipsoidParams& ellipsoid = GeoCoord::WGS84 )
const;
363 void SetGeodeticNonWGS84(
double longitude,
double latitude,
double altitude,
const EllipsoidParams& ellipsoid = GeoCoord::WGS84 );
364 void UpdateGeodeticWGS84Value()
const;
365 void UpdateGeocentricValue()
const;
367 static void CalcFalseNorthEast(
double lat_radians );
368 static void CalcLambda0();
372 VAL_GEODETIC_WGS84 = 1,
376 mutable unsigned char _validValues;
388 static double _False_Northing;
389 static double _False_Easting;
391 static double _Lambda0;
392 static const char _LatZone[ 20 ];
396 static const EllipsoidParams WGS84;
405 GLSGEN_GLSMAPUTIL_EXPORT std::istream& operator>>( std::istream& instr, GeoCoord& coord );
411 GLSGEN_GLSMAPUTIL_EXPORT std::ostream&
operator<<( std::ostream& outstr,
const GeoCoord& coord );
423 GeoRect(
double minLongitude,
double minLatitude,
double maxLongitude,
double maxLatitude )
425 SetRect( minLongitude, minLatitude, maxLongitude, maxLatitude );
429 void SetRect(
double minLongitude,
double minLatitude,
double maxLongitude,
double maxLatitude )
431 _minLon = minLongitude;
432 _minLat = minLatitude;
433 _maxLon = maxLongitude;
434 _maxLat = maxLatitude;
437 void MinLongitude(
double value ) { _minLon = value; }
438 void MinLatitude(
double value ) { _minLat = value; }
439 void MaxLongitude(
double value ) { _maxLon = value; }
440 void MaxLatitude(
double value ) { _maxLat = value; }
442 double MinLongitude()
const {
return _minLon; }
443 double MinLatitude()
const {
return _minLat; }
444 double MaxLongitude()
const {
return _maxLon; }
445 double MaxLatitude()
const {
return _maxLat; }
450 double lon, lat, alt;
458 return ( lon <= _maxLon && lon >= _minLon && lat <= _maxLat && lat >= _minLat );
464 _minLat = _minLon = DBL_MAX;
465 _maxLat = _maxLon = -DBL_MAX;
473 return ( ( ( DBL_MAX == _minLat ) && ( DBL_MAX == _minLon ) && ( -DBL_MAX == _maxLat ) && ( -DBL_MAX == _maxLon ) ) || ( ( _minLat > _maxLat ) || ( _minLon > _maxLon ) ) );
488 _minLon = _maxLon = lon;
489 _minLat = _maxLat = lat;
495 double lon, lat, alt;
524 if( ( _minLat > other._maxLat ) || ( _maxLat < other._minLat ) || ( _minLon > other._maxLon ) || ( _maxLon < other._minLon ) )
531 if( _maxLat < _minLat || _maxLon < _minLon || other._maxLat < other._minLat || other._maxLon < other._minLon )
545 _minLon = ( rect1._minLon > rect2._minLon ) ? rect1._minLon : rect2._minLon;
546 _minLat = ( rect1._minLat > rect2._minLat ) ? rect1._minLat : rect2._minLat;
547 _maxLon = ( rect1._maxLon < rect2._maxLon ) ? rect1._maxLon : rect2._maxLon;
548 _maxLat = ( rect1._maxLat < rect2._maxLat ) ? rect1._maxLat : rect2._maxLat;
553 void Scale(
const double scaleFactor )
555 double centerLon = ( _minLon + _maxLon ) / 2.0;
556 double centerLat = ( _minLat + _maxLat ) / 2.0;
558 _minLon = ( _minLon - centerLon ) * scaleFactor + centerLon;
559 _maxLon = ( _maxLon - centerLon ) * scaleFactor + centerLon;
560 _minLat = ( _minLat - centerLat ) * scaleFactor + centerLat;
561 _maxLat = ( _maxLat - centerLat ) * scaleFactor + centerLat;
567 return os <<
"{ { " << r._minLat <<
", " << r._minLon <<
" }, { " << r._maxLat <<
", " << r._maxLon <<
"} }";
586 template<
class X,
class Y,
class Z>
587 bool Equal(
const X x,
const Y y, Z tolerance = Z( 0.001 ) )
589 return ( ( x - tolerance ) <= y )
590 && ( ( x + tolerance ) >= y );
601 return Equal( lhs.MinLatitude(), rhs.MinLatitude(), tolerance )
602 &&
Equal( lhs.MaxLatitude(), rhs.MaxLatitude(), tolerance )
603 &&
Equal( lhs.MinLongitude(), rhs.MinLongitude(), tolerance )
604 &&
Equal( lhs.MaxLongitude(), rhs.MaxLongitude(), tolerance );
614 lat = -90 + fmod( lat - 90, 180 );
618 lat = 90 + fmod( lat + 90, 180 );
623 lon = -180.0 + fmod( lon - 180.0, 360.0 );
625 else if( lon < -180.0 )
627 lon = 180.0 + fmod( lon + 180.0, 360.0 );
635 double minLongitude = rect.MinLongitude();
636 double minLatitude = rect.MinLatitude();
637 double maxLongitude = rect.MaxLongitude();
638 double maxLatitude = rect.MaxLatitude();
643 rect.
SetRect( minLongitude, minLatitude, maxLongitude, maxLatitude );
655 else if( lat < -90.0 )
664 else if( lon < -180.0 )
674 double minLongitude = rect.MinLongitude();
675 double minLatitude = rect.MinLatitude();
676 double maxLongitude = rect.MaxLongitude();
677 double maxLatitude = rect.MaxLatitude();
682 rect.
SetRect( minLongitude, minLatitude, maxLongitude, maxLatitude );
void SetToPoint(const GeoCoord &point)
Definition: gls_map_util.h:477
bool Intersects(const GeoRect &other) const
Definition: gls_map_util.h:522
void SetToPoint(double lon, double lat)
Definition: gls_map_util.h:486
void GrowToContainPoint(double lon, double lat)
Definition: gls_map_util.h:501
double _poly2_a
3.0 * _ef / 2.0 - 27.0 * _ef_to_3 / 32.0
Definition: gls_map_util.h:146
double _a_sq
radius squared
Definition: gls_map_util.h:124
double _poly3_b
15.0 * _e_sq * _e_sq / 256.0 + 45.0 * _e_sq_to_3 / 1024.0
Definition: gls_map_util.h:152
void SetGeocentric(const Vector &value)
Definition: gls_map_util.h:226
double _a_b
(a * b)
Definition: gls_map_util.h:130
double _e_sq
eccentricity squared
Definition: gls_map_util.h:138
void GetGeodetic(Vector *lonLatAlt, const EllipsoidParams &ellipsoid=GeoCoord::WGS84) const
Definition: gls_map_util.h:190
double _b_sq
polar semi-diameter squared
Definition: gls_map_util.h:126
double _poly3_a
21.0 * _ef * _ef / 16.0 - 55.0 * _ef_to_4 / 32.0
Definition: gls_map_util.h:147
double _two_over_a_sq
2/(a * a)
Definition: gls_map_util.h:135
void Scale(const double scaleFactor)
Definition: gls_map_util.h:553
void ClampCoords(double &lon, double &lat)
Definition: gls_map_util.h:649
Definition: gls_map_util.h:414
void GlsMapToolkitInit(const char *)
double _poly5_a
1097.0 * _ef_to_4 / 512.0
Definition: gls_map_util.h:149
bool IsNull() const
Definition: gls_map_util.h:471
static void GetPointAtDistanceAndBearingSpherical(const GeoCoord &origin, double distance, double bearing, GeoCoord *destination, const double radius=6372795.477598)
double _f
flattening (a-b)/a
Definition: gls_map_util.h:121
Definition: gls_map_util.h:67
double _poly1_a
1.0 - _e_sq / 4.0 - 3.0 * _e_sq * _e_sq / 64.0 - 5.0 * _e_sq_to_3 / 256.0
Definition: gls_map_util.h:145
bool ContainsPoint(const GeoCoord &point) const
Definition: gls_map_util.h:448
bool operator!=(const GeoCoord &other) const
Definition: gls_map_util.h:299
void WrapCoords(double &lon, double &lat)
Definition: gls_map_util.h:610
void SetToNull()
Definition: gls_map_util.h:462
std::ostream & operator<<(std::ostream &outstr, const AttributeName &name)
Defines the stream out operator.
void SetToIntersection(const GeoRect &rect1, const GeoRect &rect2)
Definition: gls_map_util.h:543
double _poly1_b
1.0 - (_e_sq / 4.0) - (3.0 * _e_sq * _e_sq) / 64.0 - 5.0 * _e_sq_to_3 / 256.0
Definition: gls_map_util.h:150
double _two_over_b_sq
2/(b * b)
Definition: gls_map_util.h:136
void GetGeocentric(double *x, double *y, double *z) const
Definition: gls_map_util.h:258
void GetGeodetic(double *longitude, double *latitude, double *altitude, const EllipsoidParams &ellipsoid=GeoCoord::WGS84) const
Definition: gls_map_util.h:205
double _e_sq_to_3
pow(e_sq,3.0)
Definition: gls_map_util.h:141
double _ef_to_3
pow(ef,3.0)
Definition: gls_map_util.h:142
Definition: gls_map_util.h:74
double _ep_sq
e-prime squared
Definition: gls_map_util.h:139
bool operator==(const GeoCoord &other) const
Definition: gls_map_util.h:272
double _a_sq_over_b
a*a/b
Definition: gls_map_util.h:127
double _two_over_a
(2/a)
Definition: gls_map_util.h:133
double _ef_to_4
pow(ef,4.0)
Definition: gls_map_util.h:143
The disti::Vertex class. A class for manipulating 3D vertices.
static void GeodeticToGeocentric(double lon, double lat, double alt, double *xp, double *yp, double *zp, const EllipsoidParams &ellipsoid=GeoCoord::WGS84)
double _two_over_b
(2/b)
Definition: gls_map_util.h:134
void SetGeodetic(double longitude, double latitude, double altitude, const EllipsoidParams &ellipsoid=GeoCoord::WGS84)
Definition: gls_map_util.h:171
double _b
polar semi-diameter
Definition: gls_map_util.h:125
void SetGeocentric(double x, double y, double z)
Definition: gls_map_util.h:235
double _b_sq_sq
(b * b * b * b)
Definition: gls_map_util.h:132
static void GetSphericalDistanceAndBearing(const GeoCoord &coord1, const GeoCoord &coord2, double *distance, double *bearing, const double radius=6372795.477598)
bool Equal(T1 x, T2 y, float precision=0.001f)
Definition: util.h:421
friend std::ostream & operator<<(std::ostream &os, const GeoRect &r)
Definition: gls_map_util.h:565
double _a_sq_sq
(a * a * a * a)
Definition: gls_map_util.h:131
void SetRect(double minLongitude, double minLatitude, double maxLongitude, double maxLatitude)
Definition: gls_map_util.h:429
double _c1
(1-f)*(1-f)
Definition: gls_map_util.h:129
GeoRect()
Definition: gls_map_util.h:418
void SetGeodetic(const Vector &lonLatAlt, const EllipsoidParams &ellipsoid=GeoCoord::WGS84)
Definition: gls_map_util.h:160
double _poly4_a
151.0 * _ef_to_3 / 96.0
Definition: gls_map_util.h:148
double _poly2_b
3.0 * _e_sq / 8.0 + (3.0 * _e_sq * _e_sq) / 32.0 + 45.0 * _e_sq_to_3 / 1024.0
Definition: gls_map_util.h:151
bool ContainsPoint(double lon, double lat) const
Definition: gls_map_util.h:456
double _poly4_b
35.0 * _e_sq_to_3 / 3072.0
Definition: gls_map_util.h:153
void GrowToContainPoint(const GeoCoord &point)
Definition: gls_map_util.h:493
double _ef
e-factor
Definition: gls_map_util.h:140
static void GeocentricToGeodetic(double xp, double yp, double zp, double *lon, double *lat, double *alt, const EllipsoidParams &ellipsoid=GeoCoord::WGS84)
Definition: bmpimage.h:46
void GetGeocentric(Vector *value) const
Definition: gls_map_util.h:245
double _a
equatorial radius
Definition: gls_map_util.h:120
double _e
ellipticity 2f-f*f
Definition: gls_map_util.h:128