1 2 /////////////////////////////////////////////////////////// 3 // // 4 // SAGA // 5 // // 6 // System for Automated Geoscientific Analyses // 7 // // 8 // Application Programming Interface // 9 // // 10 // Library: SAGA_API // 11 // // 12 //-------------------------------------------------------// 13 // // 14 // geo_tools.h // 15 // // 16 // Copyright (C) 2005 by Olaf Conrad // 17 // // 18 //-------------------------------------------------------// 19 // // 20 // This file is part of 'SAGA - System for Automated // 21 // Geoscientific Analyses'. // 22 // // 23 // This library is free software; you can redistribute // 24 // it and/or modify it under the terms of the GNU Lesser // 25 // General Public License as published by the Free // 26 // Software Foundation, either version 2.1 of the // 27 // License, or (at your option) any later version. // 28 // // 29 // This library is distributed in the hope that it will // 30 // be useful, but WITHOUT ANY WARRANTY; without even the // 31 // implied warranty of MERCHANTABILITY or FITNESS FOR A // 32 // PARTICULAR PURPOSE. See the GNU Lesser General Public // 33 // License for more details. // 34 // // 35 // You should have received a copy of the GNU Lesser // 36 // General Public License along with this program; if // 37 // not, see <http://www.gnu.org/licenses/>. // 38 // // 39 //-------------------------------------------------------// 40 // // 41 // contact: Olaf Conrad // 42 // Institute of Geography // 43 // University of Goettingen // 44 // Goldschmidtstr. 5 // 45 // 37077 Goettingen // 46 // Germany // 47 // // 48 // e-mail: oconrad@saga-gis.org // 49 // // 50 /////////////////////////////////////////////////////////// 51 52 //--------------------------------------------------------- 53 #ifndef HEADER_INCLUDED__SAGA_API__geo_tools_H 54 #define HEADER_INCLUDED__SAGA_API__geo_tools_H 55 56 57 /////////////////////////////////////////////////////////// 58 // // 59 // // 60 // // 61 /////////////////////////////////////////////////////////// 62 63 //--------------------------------------------------------- 64 /** \file geo_tools.h 65 * Tools for geometric/geographic data types and related functions. 66 * @see CSG_Point 67 * @see CSG_Rect 68 * @see CSG_Projections 69 */ 70 71 72 /////////////////////////////////////////////////////////// 73 // // 74 // // 75 // // 76 /////////////////////////////////////////////////////////// 77 78 //--------------------------------------------------------- 79 #include "api_core.h" 80 #include "metadata.h" 81 82 83 /////////////////////////////////////////////////////////// 84 // // 85 // // 86 // // 87 /////////////////////////////////////////////////////////// 88 89 //--------------------------------------------------------- 90 #define SG_IS_BETWEEN(a, x, b) (((a) <= (x) && (x) <= (b)) || ((b) <= (x) && (x) <= (a))) 91 92 93 /////////////////////////////////////////////////////////// 94 // // 95 // // 96 // // 97 /////////////////////////////////////////////////////////// 98 99 //--------------------------------------------------------- 100 typedef enum ESG_Intersection 101 { 102 INTERSECTION_None = 0, 103 INTERSECTION_Identical, 104 INTERSECTION_Overlaps, 105 INTERSECTION_Contained, 106 INTERSECTION_Contains 107 } 108 TSG_Intersection; 109 110 //--------------------------------------------------------- 111 typedef enum ESG_Point_Type 112 { 113 SG_POINT_TYPE_XY = 0, 114 SG_POINT_TYPE_XYZ, 115 SG_POINT_TYPE_XYZM, 116 SG_POINT_TYPE_XY_Int 117 } 118 TSG_Point_Type; 119 120 121 /////////////////////////////////////////////////////////// 122 // // 123 // // 124 // // 125 /////////////////////////////////////////////////////////// 126 127 //--------------------------------------------------------- 128 typedef struct SSG_Point 129 { 130 double x, y; 131 } 132 TSG_Point; 133 134 //--------------------------------------------------------- 135 typedef struct SSG_Point_Z 136 { 137 double x, y, z; 138 } 139 TSG_Point_Z; 140 141 //--------------------------------------------------------- 142 typedef struct SSG_Point_ZM 143 { 144 double x, y, z, m; 145 } 146 TSG_Point_ZM; 147 148 //--------------------------------------------------------- 149 typedef struct SSG_Point_Int 150 { 151 int x, y; 152 } 153 TSG_Point_Int; 154 155 //--------------------------------------------------------- 156 typedef struct SSG_Rect 157 { 158 double xMin, yMin, xMax, yMax; 159 } 160 TSG_Rect; 161 162 163 /////////////////////////////////////////////////////////// 164 // // 165 // // 166 // // 167 /////////////////////////////////////////////////////////// 168 169 //--------------------------------------------------------- 170 SAGA_API_DLL_EXPORT bool SG_Is_Equal (double a, double b, double epsilon = 0.); 171 SAGA_API_DLL_EXPORT bool SG_Is_Equal (const TSG_Point &A, const TSG_Point &B, double epsilon = 0.); 172 173 SAGA_API_DLL_EXPORT bool SG_Is_Between (double x, double a, double b, double epsilon = 0.); 174 SAGA_API_DLL_EXPORT bool SG_Is_Between (const TSG_Point &Point, const TSG_Point &Corner_A, const TSG_Point &Corner_B, double epsilon = 0.); 175 176 177 /////////////////////////////////////////////////////////// 178 // // 179 // // 180 // // 181 /////////////////////////////////////////////////////////// 182 183 //--------------------------------------------------------- 184 class SAGA_API_DLL_EXPORT CSG_Point 185 { 186 public: 187 188 double x, y; 189 190 191 CSG_Point(void); 192 CSG_Point(const CSG_Point &Point); 193 CSG_Point(const TSG_Point &Point); 194 CSG_Point(double x, double y); 195 ~CSG_Point(void)196 virtual ~CSG_Point(void) {} 197 Get_Type(void)198 virtual TSG_Point_Type Get_Type (void) const { return( SG_POINT_TYPE_XY ); } 199 TSG_Point(void)200 operator TSG_Point (void) const { TSG_Point p; p.x = x; p.y = y; return( p ); } 201 Get_X(void)202 double Get_X (void) const { return( x ); } Set_X(double Value)203 void Set_X (double Value) { x = Value; } Get_Y(void)204 double Get_Y (void) const { return( y ); } Set_Y(double Value)205 void Set_Y (double Value) { y = Value; } 206 207 virtual bool operator == (const CSG_Point &Point) const { return( is_Equal(Point) ); } 208 virtual bool operator != (const CSG_Point &Point) const { return( !is_Equal(Point) ); } 209 210 virtual CSG_Point operator + (const CSG_Point &Point) const { return( CSG_Point(x + Point.x, y + Point.y) ); } 211 virtual CSG_Point operator - (const CSG_Point &Point) const { return( CSG_Point(x - Point.x, y - Point.y) ); } 212 213 virtual CSG_Point & operator = (const CSG_Point &Point) { Assign (Point); return( *this ); } 214 virtual CSG_Point & operator += (const CSG_Point &Point) { Add (Point); return( *this ); } 215 virtual CSG_Point & operator -= (const CSG_Point &Point) { Subtract(Point); return( *this ); } 216 virtual CSG_Point & operator *= (const CSG_Point &Point) { Multiply(Point); return( *this ); } 217 218 CSG_Point operator * (double Value) const { return( CSG_Point(x * Value, y * Value) ); } 219 CSG_Point operator / (double Value) const { return( CSG_Point(x / Value, y / Value) ); } 220 virtual CSG_Point & operator *= (double Value) { Multiply(Value); return( *this ); } 221 virtual CSG_Point & operator /= (double Value) { Divide (Value); return( *this ); } 222 223 virtual void Assign (double x, double y); 224 virtual void Assign (const CSG_Point &Point); 225 226 virtual void Add (const CSG_Point &Point); 227 virtual void Subtract (const CSG_Point &Point); 228 virtual void Multiply (const CSG_Point &Point); 229 230 virtual void Multiply (double Value); 231 virtual void Divide (double Value); 232 233 virtual double Get_Length (void) const; 234 235 virtual bool is_Equal (double _x, double _y , double epsilon = 0.) const { return( is_Equal(CSG_Point(x, y), epsilon) ); } 236 virtual bool is_Equal (const CSG_Point &Point, double epsilon = 0.) const 237 { return( SG_Is_Equal(x, Point.x, epsilon) 238 && SG_Is_Equal(y, Point.y, epsilon) ); 239 } 240 241 }; 242 243 //--------------------------------------------------------- 244 class SAGA_API_DLL_EXPORT CSG_Point_Z : public CSG_Point 245 { 246 public: 247 248 double z; 249 250 251 CSG_Point_Z(void); 252 CSG_Point_Z(const CSG_Point_Z &Point); 253 CSG_Point_Z(const TSG_Point_Z &Point); 254 CSG_Point_Z(double x, double y, double z); 255 ~CSG_Point_Z(void)256 virtual ~CSG_Point_Z(void) {} 257 Get_Type(void)258 virtual TSG_Point_Type Get_Type (void) const { return( SG_POINT_TYPE_XYZ ); } 259 TSG_Point_Z(void)260 operator TSG_Point_Z (void) const { TSG_Point_Z p; p.x = x; p.y = y; p.z = z; return( p ); } 261 Get_Z(void)262 double Get_Z (void) const { return( z ); } Set_Z(double Value)263 void Set_Z (double Value) { z = Value; } 264 265 virtual bool operator == (const CSG_Point_Z &Point) const { return( is_Equal(Point) ); } 266 virtual bool operator != (const CSG_Point_Z &Point) const { return( !is_Equal(Point) ); } 267 268 virtual CSG_Point_Z operator + (const CSG_Point_Z &Point) const { return( CSG_Point_Z(x + Point.x, y + Point.y, z + Point.z) ); } 269 virtual CSG_Point_Z operator - (const CSG_Point_Z &Point) const { return( CSG_Point_Z(x - Point.x, y - Point.y, z - Point.z) ); } 270 271 virtual CSG_Point_Z & operator = (const CSG_Point_Z &Point) { Assign (Point); return( *this ); } 272 virtual CSG_Point_Z & operator += (const CSG_Point_Z &Point) { Add (Point); return( *this ); } 273 virtual CSG_Point_Z & operator -= (const CSG_Point_Z &Point) { Subtract(Point); return( *this ); } 274 virtual CSG_Point_Z & operator *= (const CSG_Point_Z &Point) { Multiply(Point); return( *this ); } 275 276 CSG_Point_Z operator * (double Value) const { return( CSG_Point_Z(x * Value, y * Value, z * Value) ); } 277 CSG_Point_Z operator / (double Value) const { return( CSG_Point_Z(x / Value, y / Value, z / Value) ); } 278 virtual CSG_Point_Z & operator *= (double Value) { Multiply(Value); return( *this ); } 279 virtual CSG_Point_Z & operator /= (double Value) { Divide (Value); return( *this ); } 280 281 virtual void Assign (double x, double y, double z); 282 virtual void Assign (const CSG_Point_Z &Point); 283 284 virtual void Add (const CSG_Point_Z &Point); 285 virtual void Subtract (const CSG_Point_Z &Point); 286 virtual void Multiply (const CSG_Point_Z &Point); 287 288 virtual void Multiply (double Value); 289 virtual void Divide (double Value); 290 291 virtual double Get_Length (void) const; 292 293 virtual bool is_Equal (double _x, double _y, double _z, double epsilon = 0.) const { return( is_Equal(CSG_Point_Z(x, y, z), epsilon) ); } 294 virtual bool is_Equal (const CSG_Point_Z &Point , double epsilon = 0.) const 295 { return( SG_Is_Equal(x, Point.x, epsilon) 296 && SG_Is_Equal(y, Point.y, epsilon) 297 && SG_Is_Equal(z, Point.z, epsilon) ); 298 } 299 300 }; 301 302 //--------------------------------------------------------- 303 class SAGA_API_DLL_EXPORT CSG_Point_ZM : public CSG_Point_Z 304 { 305 public: 306 307 double m; 308 309 310 CSG_Point_ZM(void); 311 CSG_Point_ZM(const CSG_Point_ZM &Point); 312 CSG_Point_ZM(const TSG_Point_ZM &Point); 313 CSG_Point_ZM(double x, double y, double z, double m); 314 ~CSG_Point_ZM(void)315 virtual ~CSG_Point_ZM(void) {} 316 Get_Type(void)317 virtual TSG_Point_Type Get_Type (void) const { return( SG_POINT_TYPE_XYZM ); } 318 TSG_Point_ZM(void)319 operator TSG_Point_ZM (void) const { TSG_Point_ZM p; p.x = x; p.y = y; p.z = z; p.m = m; return( p ); } 320 Get_M(void)321 double Get_M (void) const { return( m ); } Set_M(double Value)322 void Set_M (double Value) { m = Value; } 323 324 virtual bool operator == (const CSG_Point_ZM &Point) const { return( is_Equal(Point) ); } 325 virtual bool operator != (const CSG_Point_ZM &Point) const { return( !is_Equal(Point) ); } 326 327 virtual CSG_Point_ZM operator + (const CSG_Point_ZM &Point) const { return( CSG_Point_ZM(x + Point.x, y + Point.y, z + Point.z, m + Point.m) ); } 328 virtual CSG_Point_ZM operator - (const CSG_Point_ZM &Point) const { return( CSG_Point_ZM(x - Point.x, y - Point.y, z - Point.z, m - Point.m) ); } 329 330 CSG_Point_ZM operator * (double Value) const { return( CSG_Point_ZM(x * Value, y * Value, z * Value, m * Value) ); } 331 CSG_Point_ZM operator / (double Value) const { return( CSG_Point_ZM(x / Value, y / Value, z / Value, m * Value) ); } 332 virtual CSG_Point_ZM & operator *= (double Value) { Multiply(Value); return( *this ); } 333 virtual CSG_Point_ZM & operator /= (double Value) { Divide (Value); return( *this ); } 334 335 virtual CSG_Point_ZM & operator = (const CSG_Point_ZM &Point) { Assign (Point); return( *this ); } 336 virtual CSG_Point_ZM & operator += (const CSG_Point_ZM &Point) { Add (Point); return( *this ); } 337 virtual CSG_Point_ZM & operator -= (const CSG_Point_ZM &Point) { Subtract(Point); return( *this ); } 338 virtual CSG_Point_ZM & operator *= (const CSG_Point_ZM &Point) { Multiply(Point); return( *this ); } 339 340 virtual void Assign (double x, double y, double z, double m); 341 virtual void Assign (const CSG_Point_ZM &Point); 342 343 virtual void Add (const CSG_Point_ZM &Point); 344 virtual void Subtract (const CSG_Point_ZM &Point); 345 virtual void Multiply (const CSG_Point_ZM &Point); 346 347 virtual void Multiply (double Value); 348 virtual void Divide (double Value); 349 350 virtual double Get_Length (void) const; 351 352 virtual bool is_Equal (double x, double y, double z, double m, double epsilon = 0.) const { return( is_Equal(CSG_Point_ZM(x, y, z, m), epsilon) ); } 353 virtual bool is_Equal (const CSG_Point_ZM &Point , double epsilon = 0.) const 354 { return( SG_Is_Equal(x, Point.x, epsilon) 355 && SG_Is_Equal(y, Point.y, epsilon) 356 && SG_Is_Equal(z, Point.z, epsilon) 357 && SG_Is_Equal(m, Point.m, epsilon) ); 358 } 359 360 }; 361 362 363 /////////////////////////////////////////////////////////// 364 // // 365 // // 366 // // 367 /////////////////////////////////////////////////////////// 368 369 //--------------------------------------------------------- 370 class SAGA_API_DLL_EXPORT CSG_Points 371 { 372 public: 373 CSG_Points(void); 374 virtual ~CSG_Points(void); 375 376 void Clear (void); 377 378 CSG_Points & operator = (const CSG_Points &Points); 379 bool Assign (const CSG_Points &Points); 380 381 bool Add (double x, double y); 382 bool Add (const TSG_Point &Point); 383 bool Del (int Index); 384 385 bool Set_Count (int nPoints); Get_Count(void)386 int Get_Count (void) const { return( m_nPoints ); } 387 388 TSG_Point & operator [] (int Index) { return( m_Points[Index] ); } Get_Point(int Index)389 TSG_Point & Get_Point (int Index) { return( m_Points[Index] ); } Get_X(int Index)390 double Get_X (int Index) const { return( m_Points[Index].x ); } Get_Y(int Index)391 double Get_Y (int Index) const { return( m_Points[Index].y ); } 392 393 394 private: 395 396 int m_nPoints, m_nBuffer; 397 398 TSG_Point *m_Points; 399 400 }; 401 402 //--------------------------------------------------------- 403 class SAGA_API_DLL_EXPORT CSG_Points_Int 404 { 405 public: 406 CSG_Points_Int(void); 407 virtual ~CSG_Points_Int(void); 408 409 void Clear (void); 410 411 CSG_Points_Int & operator = (const CSG_Points_Int &Points); 412 bool Assign (const CSG_Points_Int &Points); 413 414 bool Add (int x, int y); 415 bool Add (const TSG_Point_Int &Point); 416 bool Del (int Index); 417 418 bool Set_Count (int nPoints); Get_Count(void)419 int Get_Count (void) const { return( m_nPoints ); } 420 421 TSG_Point_Int & operator [] (int Index) { return( m_Points[Index] ); } Get_Point(int Index)422 TSG_Point_Int & Get_Point (int Index) { return( m_Points[Index] ); } Get_X(int Index)423 int Get_X (int Index) const { return( m_Points[Index].x ); } Get_Y(int Index)424 int Get_Y (int Index) const { return( m_Points[Index].y ); } 425 426 427 private: 428 429 int m_nPoints, m_nBuffer; 430 431 TSG_Point_Int *m_Points; 432 433 }; 434 435 //--------------------------------------------------------- 436 class SAGA_API_DLL_EXPORT CSG_Points_Z 437 { 438 public: 439 CSG_Points_Z(void); 440 virtual ~CSG_Points_Z(void); 441 442 void Clear (void); 443 444 CSG_Points_Z & operator = (const CSG_Points_Z &Points); 445 bool Assign (const CSG_Points_Z &Points); 446 447 bool Add (double x, double y, double z); 448 bool Add (const TSG_Point_Z &Point); 449 bool Del (int Index); 450 451 bool Set_Count (int nPoints); Get_Count(void)452 int Get_Count (void) const { return( m_nPoints ); } 453 454 TSG_Point_Z & operator [] (int Index) { return( m_Points[Index] ); } Get_Point(int Index)455 TSG_Point_Z & Get_Point (int Index) { return( m_Points[Index] ); } Get_X(int Index)456 double Get_X (int Index) const { return( m_Points[Index].x ); } Get_Y(int Index)457 double Get_Y (int Index) const { return( m_Points[Index].y ); } Get_Z(int Index)458 double Get_Z (int Index) const { return( m_Points[Index].z ); } 459 460 461 private: 462 463 int m_nPoints, m_nBuffer; 464 465 TSG_Point_Z *m_Points; 466 467 }; 468 469 470 /////////////////////////////////////////////////////////// 471 // // 472 // // 473 // // 474 /////////////////////////////////////////////////////////// 475 476 //--------------------------------------------------------- 477 class SAGA_API_DLL_EXPORT CSG_Rect 478 { 479 public: 480 CSG_Rect(void); 481 CSG_Rect(const CSG_Rect &Rect); 482 CSG_Rect(const TSG_Rect &Rect); 483 CSG_Rect(const CSG_Point &A, const CSG_Point &B); 484 CSG_Rect(double xMin, double yMin, double xMax, double yMax); 485 486 ~CSG_Rect(void); 487 488 operator const TSG_Rect & (void) const { return( m_rect ); } 489 490 bool operator == (const CSG_Rect &Rect) const; 491 bool operator != (const CSG_Rect &Rect) const; 492 493 CSG_Rect & operator = (const CSG_Rect &Rect); 494 void operator += (const CSG_Point &Point); 495 void operator -= (const CSG_Point &Point); 496 497 void Assign (double xMin, double yMin, double xMax, double yMax); 498 void Assign (const CSG_Point &A, const CSG_Point &B); 499 void Assign (const CSG_Rect &Rect); 500 501 void Set_BottomLeft (double x, double y); 502 void Set_BottomLeft (const CSG_Point &Point); 503 void Set_TopRight (double x, double y); 504 void Set_TopRight (const CSG_Point &Point); 505 506 bool is_Equal (double xMin, double yMin, double xMax, double yMax, double epsilon = 0.) const; 507 bool is_Equal (const CSG_Rect &Rect , double epsilon = 0.) const; 508 Get_XMin(void)509 double Get_XMin (void) const { return( m_rect.xMin ); } Get_XMax(void)510 double Get_XMax (void) const { return( m_rect.xMax ); } Get_YMin(void)511 double Get_YMin (void) const { return( m_rect.yMin ); } Get_YMax(void)512 double Get_YMax (void) const { return( m_rect.yMax ); } 513 Get_XRange(void)514 double Get_XRange (void) const { return( m_rect.xMax - m_rect.xMin ); } Get_YRange(void)515 double Get_YRange (void) const { return( m_rect.yMax - m_rect.yMin ); } 516 Get_Area(void)517 double Get_Area (void) const { return( Get_XRange() * Get_YRange() ); } Get_Diameter(void)518 double Get_Diameter (void) const { return( sqrt(Get_XRange()*Get_XRange() + Get_YRange()*Get_YRange()) ); } 519 Get_TopLeft(void)520 CSG_Point Get_TopLeft (void) const { return( CSG_Point(m_rect.xMin, m_rect.yMax) ); } Get_BottomRight(void)521 CSG_Point Get_BottomRight (void) const { return( CSG_Point(m_rect.xMax, m_rect.yMin) ); } 522 Get_Center(void)523 CSG_Point Get_Center (void) const { return( CSG_Point(Get_XCenter(), Get_YCenter()) ); } Get_XCenter(void)524 double Get_XCenter (void) const { return( (m_rect.xMin + m_rect.xMax) / 2. ); } Get_YCenter(void)525 double Get_YCenter (void) const { return( (m_rect.yMin + m_rect.yMax) / 2. ); } 526 527 void Move (double dx, double dy); 528 void Move (const CSG_Point &Point); 529 530 void Inflate (double d, bool bPercent = true); 531 void Deflate (double d, bool bPercent = true); 532 void Inflate (double dx, double dy, bool bPercent = true); 533 void Deflate (double dx, double dy, bool bPercent = true); 534 535 void Union (const CSG_Point &Point); 536 void Union (const CSG_Rect &Rect); 537 bool Intersect (const CSG_Rect &Rect); 538 539 TSG_Intersection Intersects (const CSG_Rect &Rect) const; 540 541 bool Contains (double x, double y) const; 542 bool Contains (const CSG_Point &Point) const; 543 544 545 //----------------------------------------------------- 546 TSG_Rect m_rect; 547 548 }; 549 550 //--------------------------------------------------------- 551 class SAGA_API_DLL_EXPORT CSG_Rects 552 { 553 public: 554 CSG_Rects(void); 555 virtual ~CSG_Rects(void); 556 557 void Clear (void); 558 559 CSG_Rects & operator = (const CSG_Rects &Points); 560 bool Assign (const CSG_Rects &Points); 561 562 bool Add (void); 563 bool Add (double xMin, double yMin, double xMax, double yMax); 564 bool Add (const CSG_Rect &Rect); 565 Get_Count(void)566 int Get_Count (void) const { return( m_nRects ); } 567 568 CSG_Rect & operator [] (int Index) { return( *m_Rects[Index] ); } Get_Rect(int Index)569 CSG_Rect & Get_Rect (int Index) { return( *m_Rects[Index] ); } 570 571 572 private: 573 574 int m_nRects; 575 576 CSG_Rect **m_Rects; 577 578 }; 579 580 581 /////////////////////////////////////////////////////////// 582 // // 583 // // 584 // // 585 /////////////////////////////////////////////////////////// 586 587 //--------------------------------------------------------- 588 typedef enum ESG_Distance_Weighting 589 { 590 SG_DISTWGHT_None = 0, 591 SG_DISTWGHT_IDW, 592 SG_DISTWGHT_EXP, 593 SG_DISTWGHT_GAUSS 594 } 595 TSG_Distance_Weighting; 596 597 598 /////////////////////////////////////////////////////////// 599 // // 600 /////////////////////////////////////////////////////////// 601 602 //--------------------------------------------------------- 603 class SAGA_API_DLL_EXPORT CSG_Distance_Weighting 604 { 605 public: 606 CSG_Distance_Weighting(void); 607 virtual ~CSG_Distance_Weighting(void); 608 609 static bool Enable_Parameters (class CSG_Parameters &Parameters); 610 bool Create_Parameters (class CSG_Parameters &Parameters, const CSG_String &Parent = "", bool bIDW_Offset = false); 611 static bool Add_Parameters (class CSG_Parameters &Parameters, const CSG_String &Parent = "", bool bIDW_Offset = false); 612 bool Set_Parameters (class CSG_Parameters &Parameters); 613 Get_Weighting(void)614 TSG_Distance_Weighting Get_Weighting (void) const { return( m_Weighting ); } 615 bool Set_Weighting (TSG_Distance_Weighting Weighting); 616 Get_IDW_Power(void)617 double Get_IDW_Power (void) const { return( m_IDW_Power ); } 618 bool Set_IDW_Power (double Value); 619 Get_IDW_Offset(void)620 bool Get_IDW_Offset (void) const { return( m_IDW_bOffset ); } 621 bool Set_IDW_Offset (bool bOn = true); 622 Get_BandWidth(void)623 double Get_BandWidth (void) const { return( m_Bandwidth ); } 624 bool Set_BandWidth (double Value); 625 626 //----------------------------------------------------- Get_Weight(double Distance)627 double Get_Weight (double Distance) const 628 { 629 if( Distance < 0. ) 630 { 631 return( 0. ); 632 } 633 634 switch( m_Weighting ) 635 { 636 case SG_DISTWGHT_IDW : 637 return( m_IDW_bOffset 638 ? pow(1. + Distance, -m_IDW_Power) : Distance > 0. 639 ? pow( Distance, -m_IDW_Power) : 0. 640 ); 641 642 case SG_DISTWGHT_EXP : 643 return( exp(-Distance / m_Bandwidth) ); 644 645 case SG_DISTWGHT_GAUSS: 646 Distance /= m_Bandwidth; 647 return( exp(-0.5 * Distance*Distance) ); 648 649 default: // case SG_DISTWGHT_None: 650 return( 1. ); 651 } 652 } 653 654 655 private: 656 657 bool m_IDW_bOffset; 658 659 double m_IDW_Power, m_Bandwidth; 660 661 TSG_Distance_Weighting m_Weighting; 662 663 }; 664 665 666 /////////////////////////////////////////////////////////// 667 // // 668 // // 669 // // 670 /////////////////////////////////////////////////////////// 671 672 //--------------------------------------------------------- 673 typedef enum ESG_Projection_Format 674 { 675 SG_PROJ_FMT_WKT, 676 SG_PROJ_FMT_Proj4, 677 SG_PROJ_FMT_EPSG, 678 SG_PROJ_FMT_Undefined 679 } 680 TSG_Projection_Format; 681 682 //--------------------------------------------------------- 683 typedef enum ESG_Projection_Type 684 { 685 SG_PROJ_TYPE_CS_Projected, 686 SG_PROJ_TYPE_CS_Geographic, 687 SG_PROJ_TYPE_CS_Geocentric, 688 SG_PROJ_TYPE_CS_Undefined 689 } 690 TSG_Projection_Type; 691 692 //--------------------------------------------------------- 693 typedef enum ESG_Projection_Unit 694 { 695 SG_PROJ_UNIT_Kilometer, 696 SG_PROJ_UNIT_Meter, 697 SG_PROJ_UNIT_Decimeter, 698 SG_PROJ_UNIT_Centimeter, 699 SG_PROJ_UNIT_Millimeter, 700 SG_PROJ_UNIT_Int_Nautical_Mile, 701 SG_PROJ_UNIT_Int_Inch, 702 SG_PROJ_UNIT_Int_Foot, 703 SG_PROJ_UNIT_Int_Yard, 704 SG_PROJ_UNIT_Int_Statute_Mile, 705 SG_PROJ_UNIT_Int_Fathom, 706 SG_PROJ_UNIT_Int_Chain, 707 SG_PROJ_UNIT_Int_Link, 708 SG_PROJ_UNIT_US_Inch, 709 SG_PROJ_UNIT_US_Foot, 710 SG_PROJ_UNIT_US_Yard, 711 SG_PROJ_UNIT_US_Chain, 712 SG_PROJ_UNIT_US_Statute_Mile, 713 SG_PROJ_UNIT_Indian_Yard, 714 SG_PROJ_UNIT_Indian_Foot, 715 SG_PROJ_UNIT_Indian_Chain, 716 SG_PROJ_UNIT_Undefined 717 } 718 TSG_Projection_Unit; 719 720 //--------------------------------------------------------- 721 SAGA_API_DLL_EXPORT TSG_Projection_Type SG_Get_Projection_Type (const CSG_String &Identifier); 722 SAGA_API_DLL_EXPORT CSG_String SG_Get_Projection_Type_Identifier (TSG_Projection_Type Type); 723 SAGA_API_DLL_EXPORT CSG_String SG_Get_Projection_Type_Name (TSG_Projection_Type Type); 724 725 SAGA_API_DLL_EXPORT TSG_Projection_Unit SG_Get_Projection_Unit (const CSG_String &Identifier); 726 SAGA_API_DLL_EXPORT CSG_String SG_Get_Projection_Unit_Identifier (TSG_Projection_Unit Unit); 727 SAGA_API_DLL_EXPORT CSG_String SG_Get_Projection_Unit_Name (TSG_Projection_Unit Unit, bool bSimple = false); 728 SAGA_API_DLL_EXPORT double SG_Get_Projection_Unit_To_Meter (TSG_Projection_Unit Unit); 729 730 731 /////////////////////////////////////////////////////////// 732 // // 733 /////////////////////////////////////////////////////////// 734 735 //--------------------------------------------------------- 736 class SAGA_API_DLL_EXPORT CSG_Projection 737 { 738 friend class CSG_Projections; 739 740 public: 741 CSG_Projection(void); 742 virtual ~CSG_Projection(void); 743 744 void Destroy (void); 745 746 CSG_Projection (const CSG_Projection &Projection); 747 bool Create (const CSG_Projection &Projection); 748 bool Assign (const CSG_Projection &Projection); 749 CSG_Projection & operator = (const CSG_Projection &Projection) { Assign(Projection); return( *this ); } 750 751 CSG_Projection (int Authority_ID, const SG_Char *Authority = NULL); 752 bool Create (int Authority_ID, const SG_Char *Authority = NULL); 753 bool Assign (int Authority_ID, const SG_Char *Authority = NULL); 754 CSG_Projection & operator = (int Authority_ID) { Assign(Authority_ID); return( *this ); } 755 756 CSG_Projection (const CSG_String &Projection, TSG_Projection_Format Format = SG_PROJ_FMT_WKT); 757 bool Create (const CSG_String &Projection, TSG_Projection_Format Format = SG_PROJ_FMT_WKT); 758 bool Assign (const CSG_String &Projection, TSG_Projection_Format Format = SG_PROJ_FMT_WKT); 759 CSG_Projection & operator = (const CSG_String &Projection) { Assign(Projection); return( *this ); } 760 761 CSG_Projection (const CSG_String &WKT, const CSG_String &Proj4); 762 bool Create (const CSG_String &WKT, const CSG_String &Proj4); 763 bool Assign (const CSG_String &WKT, const CSG_String &Proj4); 764 is_Okay(void)765 bool is_Okay (void) const { return( m_Type != SG_PROJ_TYPE_CS_Undefined ); } 766 bool is_Equal (const CSG_Projection &Projection) const; 767 bool operator == (const CSG_Projection &Projection) const { return( is_Equal(Projection) == true ); } 768 bool operator != (const CSG_Projection &Projection) const { return( is_Equal(Projection) == false ); } 769 770 bool Set_GCS_WGS84 (void); 771 bool Set_UTM_WGS84 (int Zone, bool bSouth = false); 772 773 bool Load (const CSG_String &FileName, TSG_Projection_Format Format = SG_PROJ_FMT_WKT); 774 bool Save (const CSG_String &FileName, TSG_Projection_Format Format = SG_PROJ_FMT_WKT) const; 775 776 bool Load (CSG_File &Stream, TSG_Projection_Format Format = SG_PROJ_FMT_WKT); 777 bool Save (CSG_File &Stream, TSG_Projection_Format Format = SG_PROJ_FMT_WKT) const; 778 779 bool Load (const CSG_MetaData &Projection); 780 bool Save ( CSG_MetaData &Projection) const; 781 Get_Name(void)782 const CSG_String & Get_Name (void) const { return( m_Name ); } Get_WKT(void)783 const CSG_String & Get_WKT (void) const { return( m_WKT ); } Get_Proj4(void)784 const CSG_String & Get_Proj4 (void) const { return( m_Proj4 ); } Get_Authority(void)785 const CSG_String & Get_Authority (void) const { return( m_Authority ); } Get_Authority_ID(void)786 int Get_Authority_ID (void) const { return( m_Authority_ID ); } Get_EPSG(void)787 int Get_EPSG (void) const { return( m_Authority.Cmp("EPSG") ? -1 : m_Authority_ID ); } 788 789 CSG_String Get_Description (void) const; 790 Get_Type(void)791 TSG_Projection_Type Get_Type (void) const { return( m_Type ); } Get_Type_Identifier(void)792 CSG_String Get_Type_Identifier (void) const { return( SG_Get_Projection_Type_Identifier(m_Type) ); } Get_Type_Name(void)793 CSG_String Get_Type_Name (void) const { return( SG_Get_Projection_Type_Name (m_Type) ); } 794 is_Projection(void)795 bool is_Projection (void) const { return( m_Type == SG_PROJ_TYPE_CS_Projected ); } is_Geographic(void)796 bool is_Geographic (void) const { return( m_Type == SG_PROJ_TYPE_CS_Geographic ); } is_Geocentric(void)797 bool is_Geocentric (void) const { return( m_Type == SG_PROJ_TYPE_CS_Geocentric ); } 798 799 Get_Unit(void)800 TSG_Projection_Unit Get_Unit (void) const { return( m_Unit ); } Get_Unit_Identifier(void)801 CSG_String Get_Unit_Identifier (void) const { return( SG_Get_Projection_Unit_Identifier(m_Unit) ); } Get_Unit_Name(void)802 CSG_String Get_Unit_Name (void) const { return( m_Unit_Name ); } Get_Unit_To_Meter(void)803 double Get_Unit_To_Meter (void) const { return( m_Unit_To_Meter ); } 804 805 806 private: 807 808 int m_Authority_ID; 809 810 double m_Unit_To_Meter; 811 812 TSG_Projection_Type m_Type; 813 814 TSG_Projection_Unit m_Unit; 815 816 CSG_String m_Name, m_WKT, m_Proj4, m_Authority, m_Unit_Name; 817 818 819 }; 820 821 822 /////////////////////////////////////////////////////////// 823 // // 824 /////////////////////////////////////////////////////////// 825 826 //--------------------------------------------------------- 827 /** CSG_Projections is a projections dictionary and translator 828 * for EPSG codes, OGC Well-Known-Text, and Proj.4. 829 */ 830 //--------------------------------------------------------- 831 class SAGA_API_DLL_EXPORT CSG_Projections 832 { 833 public: 834 CSG_Projections(void); 835 virtual ~CSG_Projections(void); 836 837 CSG_Projections (bool bLoad_DB); 838 bool Create (bool bLoad_DB = true); 839 840 CSG_Projections (const CSG_String &File_DB); 841 bool Create (const CSG_String &File_DB); 842 843 void Destroy (void); 844 845 bool Reset_Dictionary (void); 846 bool Load_Dictionary (const CSG_String &FileName); 847 bool Save_Dictionary (const CSG_String &FileName); 848 849 bool Load_DB (const CSG_String &FileName, bool bAppend = false); 850 bool Save_DB (const CSG_String &FileName); 851 852 int Get_Count (void) const; 853 854 bool Add (const CSG_Projection &Projection); 855 bool Add (const SG_Char *WKT, const SG_Char *Proj4, const SG_Char *Authority, int Authority_ID); 856 857 CSG_Projection Get_Projection (int Index) const; 858 CSG_Projection operator [] (int Index) const { return( Get_Projection(Index) ); } 859 860 bool Get_Projection (CSG_Projection &Projection, int EPSG_ID) const; 861 bool Get_Projection (CSG_Projection &Projection, const CSG_String &Authority, int Authority_ID) const; 862 863 CSG_String Get_Names_List (TSG_Projection_Type Type = SG_PROJ_TYPE_CS_Undefined) const; 864 865 static CSG_MetaData WKT_to_MetaData (const CSG_String &WKT); 866 867 bool WKT_to_Proj4 (CSG_String &Proj4, const CSG_String &WKT ) const; 868 bool WKT_from_Proj4 (CSG_String &WKT , const CSG_String &Proj4) const; 869 870 bool EPSG_to_Proj4 (CSG_String &Proj4, int EPSG_Code) const; 871 bool EPSG_to_WKT (CSG_String &WKT , int EPSG_Code) const; 872 873 static const CSG_Projection & Get_GCS_WGS84 (void); 874 875 876 private: 877 878 CSG_Translator m_WKT_to_Proj4, m_Proj4_to_WKT, m_EPSG_to_Idx; 879 880 class CSG_Table *m_pProjections; 881 882 883 void _On_Construction (void); 884 885 static bool _WKT_to_MetaData (CSG_MetaData &MetaData, const CSG_String &WKT); 886 887 bool _WKT_to_Proj4_Set_Datum (CSG_String &Proj4, const CSG_MetaData &WKT) const; 888 889 bool _Proj4_Find_Parameter ( const CSG_String &Proj4, const CSG_String &Key) const; 890 bool _Proj4_Read_Parameter (CSG_String &Value, const CSG_String &Proj4, const CSG_String &Key) const; 891 bool _Proj4_Get_Ellipsoid (CSG_String &Value, const CSG_String &Proj4) const; 892 bool _Proj4_Get_Datum (CSG_String &Value, const CSG_String &Proj4) const; 893 bool _Proj4_Get_Prime_Meridian (CSG_String &Value, const CSG_String &Proj4) const; 894 bool _Proj4_Get_Unit (CSG_String &Value, const CSG_String &Proj4) const; 895 896 bool _Set_Dictionary (CSG_Table &Dictionary, int Direction); 897 bool _Set_Dictionary (CSG_Translator &Dictionary, int Direction); 898 899 }; 900 901 //--------------------------------------------------------- 902 SAGA_API_DLL_EXPORT CSG_Projections & SG_Get_Projections (void); 903 904 //--------------------------------------------------------- 905 SAGA_API_DLL_EXPORT bool SG_Get_Projected (class CSG_Shapes *pSource, class CSG_Shapes *pTarget, const CSG_Projection &Target); 906 907 SAGA_API_DLL_EXPORT bool SG_Get_Projected (const CSG_Projection &Source, const CSG_Projection &Target, TSG_Point &Point ); 908 SAGA_API_DLL_EXPORT bool SG_Get_Projected (const CSG_Projection &Source, const CSG_Projection &Target, TSG_Rect &Rectangle); 909 910 //--------------------------------------------------------- 911 SAGA_API_DLL_EXPORT bool SG_Grid_Get_Geographic_Coordinates (CSG_Grid *pGrid, CSG_Grid *pLon, CSG_Grid *pLat); 912 913 914 /////////////////////////////////////////////////////////// 915 // // 916 // Functions // 917 // // 918 /////////////////////////////////////////////////////////// 919 920 //--------------------------------------------------------- 921 SAGA_API_DLL_EXPORT double SG_Get_Length (double dx, double dy); 922 923 SAGA_API_DLL_EXPORT double SG_Get_Distance (double ax, double ay, double bx, double by, bool bPolar); 924 SAGA_API_DLL_EXPORT double SG_Get_Distance (const TSG_Point &A, const TSG_Point &B , bool bPolar); 925 926 SAGA_API_DLL_EXPORT double SG_Get_Distance (double ax, double ay, double bx, double by); 927 SAGA_API_DLL_EXPORT double SG_Get_Distance (const TSG_Point &A, const TSG_Point &B); 928 929 SAGA_API_DLL_EXPORT double SG_Get_Distance (double ax, double ay, double az, double bx, double by, double bz); 930 SAGA_API_DLL_EXPORT double SG_Get_Distance (const TSG_Point_Z &A, const TSG_Point_Z &B); 931 932 SAGA_API_DLL_EXPORT double SG_Get_Distance_Polar (double aLon, double aLat, double bLon, double bLat, double a = 6378137., double e = 298.257223563, bool bDegree = true); 933 SAGA_API_DLL_EXPORT double SG_Get_Distance_Polar (const TSG_Point &A , const TSG_Point &B , double a = 6378137., double e = 298.257223563, bool bDegree = true); 934 935 SAGA_API_DLL_EXPORT double SG_Get_Angle_Of_Direction (double dx, double dy); 936 SAGA_API_DLL_EXPORT double SG_Get_Angle_Of_Direction (double ax, double ay, double bx, double by); 937 SAGA_API_DLL_EXPORT double SG_Get_Angle_Of_Direction (const TSG_Point &A); 938 SAGA_API_DLL_EXPORT double SG_Get_Angle_Of_Direction (const TSG_Point &A, const TSG_Point &B); 939 SAGA_API_DLL_EXPORT double SG_Get_Angle_Difference (double a, double b); 940 SAGA_API_DLL_EXPORT bool SG_is_Angle_Between (double Angle, double Angle_Min, double Angle_Max, bool bCheckRange = true); 941 942 SAGA_API_DLL_EXPORT bool SG_Get_Crossing (TSG_Point &Crossing, const TSG_Point &a1, const TSG_Point &a2, const TSG_Point &b1, const TSG_Point &b2, bool bExactMatch = true); 943 SAGA_API_DLL_EXPORT bool SG_Get_Crossing_InRegion (TSG_Point &Crossing, const TSG_Point &a , const TSG_Point & b, const TSG_Rect &Region); 944 945 SAGA_API_DLL_EXPORT bool SG_Is_Point_On_Line (const TSG_Point &Point, const TSG_Point &Ln_A, const TSG_Point &Ln_B, bool bExactMatch = false, double Epsilon = 0.); 946 SAGA_API_DLL_EXPORT double SG_Get_Nearest_Point_On_Line (const TSG_Point &Point, const TSG_Point &Ln_A, const TSG_Point &Ln_B, TSG_Point &Ln_Point, bool bExactMatch = true); 947 948 SAGA_API_DLL_EXPORT bool SG_Get_Triangle_CircumCircle (TSG_Point Triangle[3], TSG_Point &Point, double &Radius); 949 950 SAGA_API_DLL_EXPORT double SG_Get_Polygon_Area (TSG_Point *Points, int nPoints); 951 SAGA_API_DLL_EXPORT double SG_Get_Polygon_Area (const CSG_Points &Points); 952 953 954 /////////////////////////////////////////////////////////// 955 // // 956 // // 957 // // 958 /////////////////////////////////////////////////////////// 959 960 //--------------------------------------------------------- 961 #endif // #ifndef HEADER_INCLUDED__SAGA_API__geo_tools_H 962