SAGA API  v9.7
grid.cpp
Go to the documentation of this file.
1 
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // Application Programming Interface //
9 // //
10 // Library: SAGA_API //
11 // //
12 //-------------------------------------------------------//
13 // //
14 // grid.cpp //
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 Hamburg //
44 // Germany //
45 // //
46 // e-mail: oconrad@saga-gis.org //
47 // //
49 
50 //---------------------------------------------------------
51 #include "grid.h"
52 #include "data_manager.h"
53 
54 
56 // //
57 // //
58 // //
60 
61 //---------------------------------------------------------
62 BYTE CSG_Grid::m_Bitmask[8] = { 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80 };
63 
64 
66 // //
67 // //
68 // //
70 
71 //---------------------------------------------------------
73 {
74  return( new CSG_Grid );
75 }
76 
77 //---------------------------------------------------------
79 {
80  CSG_Grid *pGrid = new CSG_Grid(Grid);
81 
82  if( !pGrid->is_Valid() ) { delete(pGrid); return( NULL ); } return( pGrid );
83 }
84 
85 //---------------------------------------------------------
86 CSG_Grid * SG_Create_Grid(const char *File, TSG_Data_Type Type, bool bCached, bool bLoadData) { return( SG_Create_Grid(CSG_String(File), Type, bCached, bLoadData) ); }
87 CSG_Grid * SG_Create_Grid(const wchar_t *File, TSG_Data_Type Type, bool bCached, bool bLoadData) { return( SG_Create_Grid(CSG_String(File), Type, bCached, bLoadData) ); }
88 CSG_Grid * SG_Create_Grid(const CSG_String &File, TSG_Data_Type Type, bool bCached, bool bLoadData)
89 {
90  CSG_Grid *pGrid = new CSG_Grid();
91 
92  if( pGrid->Create(File, Type, bCached, bLoadData) )
93  {
94  return( pGrid );
95  }
96 
97  delete(pGrid); return( NULL );
98 }
99 
100 //---------------------------------------------------------
101 CSG_Grid * SG_Create_Grid(CSG_Grid *pGrid, TSG_Data_Type Type, bool bCached)
102 {
103  pGrid = new CSG_Grid(pGrid, Type, bCached);
104 
105  if( !pGrid->is_Valid() ) { delete(pGrid); return( NULL ); } return( pGrid );
106 }
107 
108 //---------------------------------------------------------
109 CSG_Grid * SG_Create_Grid(const CSG_Grid_System &System, TSG_Data_Type Type, bool bCached)
110 {
111  CSG_Grid *pGrid = new CSG_Grid(System, Type, bCached);
112 
113  if( !pGrid->is_Valid() ) { delete(pGrid); return( NULL ); } return( pGrid );
114 }
115 
116 //---------------------------------------------------------
117 CSG_Grid * SG_Create_Grid(TSG_Data_Type Type, int NX, int NY, double Cellsize, double xMin, double yMin, bool bCached)
118 {
119  CSG_Grid *pGrid = new CSG_Grid(Type, NX, NY, Cellsize > 0. ? Cellsize : 1., xMin, yMin, bCached);
120 
121  if( !pGrid->is_Valid() ) { delete(pGrid); return( NULL ); } return( pGrid );
122 }
123 
124 
126 // //
127 // //
128 // //
130 
131 //---------------------------------------------------------
135 //---------------------------------------------------------
137  : CSG_Data_Object()
138 {
140 }
141 
142 //---------------------------------------------------------
146 //---------------------------------------------------------
148  : CSG_Data_Object()
149 {
150  _On_Construction(); Create(Grid);
151 }
152 
153 //---------------------------------------------------------
157 //---------------------------------------------------------
158 CSG_Grid::CSG_Grid(const char *File, TSG_Data_Type Type, bool bCached, bool bLoadData) : CSG_Grid(CSG_String(File), Type, bCached, bLoadData) {}
159 CSG_Grid::CSG_Grid(const wchar_t *File, TSG_Data_Type Type, bool bCached, bool bLoadData) : CSG_Grid(CSG_String(File), Type, bCached, bLoadData) {}
160 CSG_Grid::CSG_Grid(const CSG_String &File, TSG_Data_Type Type, bool bCached, bool bLoadData)
161  : CSG_Data_Object()
162 {
163  _On_Construction(); Create(File, Type, bCached, bLoadData);
164 }
165 
166 //---------------------------------------------------------
170 //---------------------------------------------------------
171 CSG_Grid::CSG_Grid(CSG_Grid *pGrid, TSG_Data_Type Type, bool bCached)
172  : CSG_Data_Object()
173 {
174  _On_Construction(); Create(pGrid, Type, bCached);
175 }
176 
177 //---------------------------------------------------------
181 //---------------------------------------------------------
182 CSG_Grid::CSG_Grid(const CSG_Grid_System &System, TSG_Data_Type Type, bool bCached)
183  : CSG_Data_Object()
184 {
185  _On_Construction(); Create(System, Type, bCached);
186 }
187 
188 //---------------------------------------------------------
195 //---------------------------------------------------------
196 CSG_Grid::CSG_Grid(TSG_Data_Type Type, int NX, int NY, double Cellsize, double xMin, double yMin, bool bCached)
197  : CSG_Data_Object()
198 {
199  _On_Construction(); Create(Type, NX, NY, Cellsize, xMin, yMin, bCached);
200 }
201 
202 
204 // //
206 
207 //---------------------------------------------------------
208 void CSG_Grid::_On_Construction(void)
209 {
210  m_Type = SG_DATATYPE_Undefined;
211 
212  m_Values = NULL;
213 
214  m_Cache_Stream = NULL;
215  m_Cache_Offset = 0;
216  m_Cache_bSwap = false;
217  m_Cache_bFlip = false;
218 
219  m_zScale = 1.;
220  m_zOffset = 0.;
221 
222  m_Index = NULL;
223 
224  m_pOwner = NULL;
225 
226  Set_Update_Flag();
227 }
228 
229 
231 // //
233 
234 //---------------------------------------------------------
235 bool CSG_Grid::Create(const CSG_Grid &Grid)
236 {
237  if( Create(Grid.Get_System(), Grid.Get_Type()) )
238  {
239  Set_Name (Grid.Get_Name ());
241  Set_Unit (Grid.Get_Unit ());
243  Set_Scaling (Grid.Get_Scaling(), Grid.Get_Offset());
244  Get_MetaData ().Create(Grid.Get_MetaData ());
246 
247  #pragma omp parallel for
248  for(int y=0; y<Get_NY(); y++) for(int x=0; x<Get_NX(); x++)
249  {
250  Set_Value(x, y, Grid.asDouble(x, y, false), false);
251  }
252 
253  return( true );
254  }
255 
256  return( false );
257 }
258 
259 //---------------------------------------------------------
260 bool CSG_Grid::Create(CSG_Grid *pGrid, TSG_Data_Type Type, bool bCached)
261 {
262  if( pGrid && Create(pGrid->Get_System(), Type == SG_DATATYPE_Undefined ? pGrid->Get_Type() : Type, bCached) )
263  {
265 
266  Get_Projection() = pGrid->Get_Projection();
267 
268  return( true );
269  }
270 
271  return( false );
272 }
273 
274 //---------------------------------------------------------
275 bool CSG_Grid::Create(const CSG_Grid_System &_System, TSG_Data_Type Type, bool bCached)
276 {
277  CSG_Grid_System System(_System); // just in case _System is identical with this->m_System
278 
279  Destroy();
280 
281  switch( (m_Type = Type) )
282  {
283  case SG_DATATYPE_Bit : Set_NoData_Value( 0.); break;
284  case SG_DATATYPE_Byte : Set_NoData_Value( 0.); break;
285  case SG_DATATYPE_Char : Set_NoData_Value( -127.); break;
286  case SG_DATATYPE_Word : Set_NoData_Value( 65535.); break;
287  case SG_DATATYPE_Short : Set_NoData_Value( -32767.); break;
288  case SG_DATATYPE_DWord : Set_NoData_Value( 4294967295.); break;
289  case SG_DATATYPE_Int : Set_NoData_Value(-2147483647.); break;
290  case SG_DATATYPE_ULong : Set_NoData_Value( 4294967295.); break;
291  case SG_DATATYPE_Long : Set_NoData_Value(-2147483647.); break;
292  case SG_DATATYPE_Float : Set_NoData_Value( -99999.); break;
293  case SG_DATATYPE_Double: Set_NoData_Value( -99999.); break;
294  case SG_DATATYPE_Color : Set_NoData_Value( 4294967295.); break;
295 
296  default : Set_NoData_Value( -99999.);
297  m_Type = SG_DATATYPE_Float;
298  break;
299  }
300 
301  if( m_System.Create(System) == false )
302  {
303  m_System.Create(1., System.Get_XMin(), System.Get_YMin(), System.Get_NX(), System.Get_NY());
304  }
305 
306  m_Statistics.Invalidate();
307 
308  m_nBytes_Value = SG_Data_Type_Get_Size(m_Type);
309  m_nBytes_Line = m_Type == SG_DATATYPE_Bit ? 1 + (size_t)Get_NX() / 8 : (size_t)Get_NX() * m_nBytes_Value;
310 
312 
313  return( _Memory_Create(bCached) );
314 }
315 
316 //---------------------------------------------------------
317 bool CSG_Grid::Create(const char *File, TSG_Data_Type Type, bool bCached, bool bLoadData) { return( Create(CSG_String(File), Type, bCached, bLoadData) ); }
318 bool CSG_Grid::Create(const wchar_t *File, TSG_Data_Type Type, bool bCached, bool bLoadData) { return( Create(CSG_String(File), Type, bCached, bLoadData) ); }
319 bool CSG_Grid::Create(const CSG_String &File, TSG_Data_Type Type, bool bCached, bool bLoadData)
320 {
321  Destroy();
322 
323  SG_UI_Msg_Add(CSG_String::Format("%s: %s...", _TL("Loading grid"), File.c_str()), true);
324 
325  m_Type = Type;
326 
327  if( _Load_PGSQL (File, bCached, bLoadData)
328  || _Load_Native (File, bCached, bLoadData)
329  || _Load_Compressed(File, bCached, bLoadData)
330  || _Load_Surfer (File, bCached, bLoadData)
331  || _Load_External (File, bCached, bLoadData) )
332  {
334 
335  Set_Modified(false);
336  Set_Update_Flag();
337 
339  SG_UI_Msg_Add(_TL("okay"), false, SG_UI_MSG_STYLE_SUCCESS);
340 
341  return( true );
342  }
343 
344  Destroy();
345 
347  SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);
348 
349  return( false );
350 }
351 
352 //---------------------------------------------------------
353 bool CSG_Grid::Create(TSG_Data_Type Type, int NX, int NY, double Cellsize, double xMin, double yMin, bool bCached)
354 {
355  Destroy();
356 
357  return( Create(CSG_Grid_System(Cellsize, xMin, yMin, NX, NY), Type, bCached) );
358 }
359 
360 
362 // //
363 // Destruction //
364 // //
366 
367 //---------------------------------------------------------
372 {
373  Destroy();
374 }
375 
380 {
381  _Memory_Destroy();
382 
383  m_Type = SG_DATATYPE_Undefined;
384 
385  m_zScale = 1.;
386  m_zOffset = 0.;
387 
388  m_Unit .Clear ();
389  m_System.Destroy();
390 
391  return( CSG_Data_Object::Destroy() );
392 }
393 
394 
396 // //
398 
399 //---------------------------------------------------------
401 {
402  m_Unit = Unit;
403 }
404 
405 //---------------------------------------------------------
406 void CSG_Grid::Set_Scaling(double Scale, double Offset)
407 {
408  if( (Scale != m_zScale && Scale != 0.) || Offset != m_zOffset )
409  {
410  if( Scale != 0. )
411  {
412  m_zScale = Scale;
413  }
414 
415  m_zOffset = Offset;
416 
417  Set_Update_Flag();
418  }
419 }
420 
421 //---------------------------------------------------------
422 double CSG_Grid::Get_Scaling(void) const
423 {
424  return( m_zScale );
425 }
426 
427 //---------------------------------------------------------
428 double CSG_Grid::Get_Offset(void) const
429 {
430  return( m_zOffset );
431 }
432 
433 
435 // //
436 // Checks //
437 // //
439 
440 //---------------------------------------------------------
441 bool CSG_Grid::is_Valid(void) const
442 {
443  if( m_System.is_Valid() && m_Type != SG_DATATYPE_Undefined )
444  {
445  return( m_Values != NULL || is_Cached() );
446  }
447 
448  return( false );
449 }
450 
451 //---------------------------------------------------------
453 {
454  return( Get_Extent().Intersects(Extent) );
455 }
456 
458 {
459  return( Get_Extent().Intersects(Extent) );
460 }
461 
462 TSG_Intersection CSG_Grid::is_Intersecting(double xMin, double yMin, double xMax, double yMax) const
463 {
464  return( is_Intersecting(CSG_Rect(xMin, yMin, xMax, yMax)) );
465 }
466 
467 //---------------------------------------------------------
469 {
470  return( pGrid && is_Compatible(pGrid->Get_System()) );
471 }
472 
473 bool CSG_Grid::is_Compatible(const CSG_Grid_System &System) const
474 {
475  return( m_System == System );
476 }
477 
478 bool CSG_Grid::is_Compatible(int NX, int NY, double Cellsize, double xMin, double yMin) const
479 {
480  return( is_Compatible(CSG_Grid_System(Cellsize, xMin, yMin, NX, NY)) );
481 }
482 
483 
485 // //
486 // value access by row //
487 // //
489 
490 //---------------------------------------------------------
492 {
493  CSG_Vector Values;
494 
495  if( y >= 0 && y < Get_NY() )
496  {
497  Values.Create(Get_NX());
498 
499  for(int x=0; x<Get_NX(); x++)
500  {
501  Values[x] = asDouble(x, y);
502  }
503  }
504 
505  return( Values );
506 }
507 
508 //---------------------------------------------------------
509 bool CSG_Grid::Set_Row(int y, const CSG_Vector &Values)
510 {
511  if( y >= 0 && y < Get_NY() && Values.Get_N() == Get_NX() )
512  {
513  for(int x=0; x<Get_NX(); x++)
514  {
515  Set_Value(x, y, Values[x]);
516  }
517 
518  return( true );
519  }
520 
521  return( false );
522 }
523 
524 
526 // //
527 // Value access by Position (-> Interpolation) //
528 // //
530 
531 //---------------------------------------------------------
532 double CSG_Grid::Get_Value(const TSG_Point &p, TSG_Grid_Resampling Resampling, bool bByteWise) const
533 {
534  double Value;
535 
536  return( Get_Value(p.x, p.y, Value, Resampling, false, bByteWise) ? Value : Get_NoData_Value() );
537 }
538 
539 double CSG_Grid::Get_Value(double x, double y, TSG_Grid_Resampling Resampling, bool bByteWise) const
540 {
541  double Value;
542 
543  return( Get_Value(x, y, Value, Resampling, false, bByteWise) ? Value : Get_NoData_Value() );
544 }
545 
546 bool CSG_Grid::Get_Value(const TSG_Point &p, double &Value, TSG_Grid_Resampling Resampling, bool bNoData, bool bByteWise) const
547 {
548  return( Get_Value(p.x, p.y, Value, Resampling, bNoData, bByteWise) );
549 }
550 
551 //---------------------------------------------------------
552 bool CSG_Grid::Get_Value(double x, double y, double &Value, TSG_Grid_Resampling Resampling, bool bNoData, bool bByteWise) const
553 {
554  if( m_System.Get_Extent(true).Contains(x, y) )
555  {
556  int ix = (int)floor(x = (x - Get_XMin()) / Get_Cellsize()); double dx = x - ix;
557  int iy = (int)floor(y = (y - Get_YMin()) / Get_Cellsize()); double dy = y - iy;
558 
559  if( bNoData || is_InGrid(ix + (int)(0.5 + dx), iy + (int)(0.5 + dy)) )
560  {
561  switch( Resampling )
562  {
563  case GRID_RESAMPLING_NearestNeighbour: return( _Get_ValAtPos_NearestNeighbour(Value, ix, iy, dx, dy ) );
564  case GRID_RESAMPLING_Bilinear : return( _Get_ValAtPos_BiLinear (Value, ix, iy, dx, dy, bByteWise) );
565  case GRID_RESAMPLING_BicubicSpline : return( _Get_ValAtPos_BiCubicSpline (Value, ix, iy, dx, dy, bByteWise) );
566  case GRID_RESAMPLING_BSpline: default: return( _Get_ValAtPos_BSpline (Value, ix, iy, dx, dy, bByteWise) );
567  }
568  }
569  }
570 
571  Value = Get_NoData_Value();
572 
573  return( false );
574 }
575 
576 
578 // //
580 
581 //---------------------------------------------------------
582 inline bool CSG_Grid::_Get_ValAtPos_NearestNeighbour(double &Value, int x, int y, double dx, double dy) const
583 {
584  if( is_InGrid(x = x + (int)(0.5 + dx), y = y + (int)(0.5 + dy)) )
585  {
586  Value = asDouble(x, y);
587 
588  return( true );
589  }
590 
591  return( false );
592 }
593 
594 
596 // //
598 
599 //---------------------------------------------------------
600 #define BILINEAR_ADD(ix, iy, d) if( is_InGrid(ix, iy) ) {\
601  n += d; z += d * asDouble(ix, iy);\
602 }
603 
604 //---------------------------------------------------------
605 #define BILINEAR_ADD_BYTE(ix, iy, d) if( is_InGrid(ix, iy) ) {\
606  n += d; sLong v = asInt(ix, iy);\
607  z[0] += d * SG_GET_BYTE_0(v);\
608  z[1] += d * SG_GET_BYTE_1(v);\
609  z[2] += d * SG_GET_BYTE_2(v);\
610  z[3] += d * SG_GET_BYTE_3(v);\
611 }
612 
613 //---------------------------------------------------------
614 inline bool CSG_Grid::_Get_ValAtPos_BiLinear(double &Value, int x, int y, double dx, double dy, bool bByteWise) const
615 {
616  if( !bByteWise )
617  {
618  double z = 0., n = 0.;
619 
620  BILINEAR_ADD(x , y , (1. - dx) * (1. - dy));
621  BILINEAR_ADD(x + 1, y , ( dx) * (1. - dy));
622  BILINEAR_ADD(x , y + 1, (1. - dx) * ( dy));
623  BILINEAR_ADD(x + 1, y + 1, ( dx) * ( dy));
624 
625  if( n > 0. )
626  {
627  Value = z / n;
628 
629  return( true );
630  }
631  }
632 
633  //-----------------------------------------------------
634  else
635  {
636  double n = 0.;
637  CSG_Vector z(4);
638 
639  BILINEAR_ADD_BYTE(x , y , (1. - dx) * (1. - dy));
640  BILINEAR_ADD_BYTE(x + 1, y , ( dx) * (1. - dy));
641  BILINEAR_ADD_BYTE(x , y + 1, (1. - dx) * ( dy));
642  BILINEAR_ADD_BYTE(x + 1, y + 1, ( dx) * ( dy));
643 
644  if( n > 0. )
645  {
646  z *= 1. / n;
647 
648  Value = SG_GET_LONG(z[0], z[1], z[2], z[3]);
649 
650  return( true );
651  }
652  }
653 
654  return( false );
655 }
656 
657 
659 // //
661 
662 //---------------------------------------------------------
663 inline double CSG_Grid::_Get_ValAtPos_BiCubicSpline(double dx, double dy, double v_xy[4][4]) const
664 {
665  #define BiCubicSpline(d, v) (v[1] + 0.5 * d * (v[2] - v[0] + d * (2 * v[0] - 5 * v[1] + 4 * v[2] - v[3] + d * (3 * (v[1] - v[2]) + v[3] - v[0]))))
666 
667  double v_x[4];
668 
669  for(int ix=0; ix<4; ix++)
670  {
671  v_x[ix] = BiCubicSpline(dy, v_xy[ix]);
672  }
673 
674  return( BiCubicSpline(dx, v_x) );
675 }
676 
677 //---------------------------------------------------------
678 inline bool CSG_Grid::_Get_ValAtPos_BiCubicSpline(double &Value, int x, int y, double dx, double dy, bool bByteWise) const
679 {
680  if( !bByteWise )
681  {
682  double v_xy[4][4];
683 
684  if( _Get_ValAtPos_Fill4x4Submatrix(x, y, v_xy) )
685  {
686  Value = _Get_ValAtPos_BiCubicSpline(dx, dy, v_xy);
687 
688  return( true );
689  }
690  }
691  else
692  {
693  double v_xy[4][4][4];
694 
695  if( _Get_ValAtPos_Fill4x4Submatrix(x, y, v_xy) )
696  {
697  Value = SG_GET_LONG(
698  _Get_ValAtPos_BiCubicSpline(dx, dy, v_xy[0]),
699  _Get_ValAtPos_BiCubicSpline(dx, dy, v_xy[1]),
700  _Get_ValAtPos_BiCubicSpline(dx, dy, v_xy[2]),
701  _Get_ValAtPos_BiCubicSpline(dx, dy, v_xy[3])
702  );
703 
704  return( true );
705  }
706  }
707 
708  return( false );
709 }
710 
711 
713 // //
715 
716 //---------------------------------------------------------
717 inline double CSG_Grid::_Get_ValAtPos_BSpline(double dx, double dy, double v_xy[4][4]) const
718 {
719  double Rx[4], Ry[4];
720 
721  for(int i=0; i<4; i++)
722  {
723  double d, s;
724 
725  s = 0.;
726  if( (d = i - dx + 1.) > 0. ) s += d*d*d;
727  if( (d = i - dx + 0.) > 0. ) s += -4. * d*d*d;
728  if( (d = i - dx - 1.) > 0. ) s += 6. * d*d*d;
729  if( (d = i - dx - 2.) > 0. ) s += -4. * d*d*d;
730  // if( (d = i - dx - 3.) > 0. ) s += d*d*d;
731  Rx[i] = s / 6.;
732 
733  s = 0.;
734  if( (d = i - dy + 1.) > 0. ) s += d*d*d;
735  if( (d = i - dy + 0.) > 0. ) s += -4. * d*d*d;
736  if( (d = i - dy - 1.) > 0. ) s += 6. * d*d*d;
737  if( (d = i - dy - 2.) > 0. ) s += -4. * d*d*d;
738  // if( (d = i - dy - 3.) > 0. ) s += d*d*d;
739  Ry[i] = s / 6.;
740  }
741 
742  double z = 0.;
743 
744  for(int iy=0; iy<4; iy++)
745  {
746  for(int ix=0; ix<4; ix++)
747  {
748  z += v_xy[ix][iy] * Rx[ix] * Ry[iy];
749  }
750  }
751 
752  return( z );
753 }
754 
755 //---------------------------------------------------------
756 inline bool CSG_Grid::_Get_ValAtPos_BSpline(double &Value, int x, int y, double dx, double dy, bool bByteWise) const
757 {
758  if( !bByteWise )
759  {
760  double v_xy[4][4];
761 
762  if( _Get_ValAtPos_Fill4x4Submatrix(x, y, v_xy) )
763  {
764  Value = _Get_ValAtPos_BSpline(dx, dy, v_xy);
765 
766  return( true );
767  }
768  }
769  else
770  {
771  double v_xy[4][4][4];
772 
773  if( _Get_ValAtPos_Fill4x4Submatrix(x, y, v_xy) )
774  {
775  Value = SG_GET_LONG(
776  _Get_ValAtPos_BSpline(dx, dy, v_xy[0]),
777  _Get_ValAtPos_BSpline(dx, dy, v_xy[1]),
778  _Get_ValAtPos_BSpline(dx, dy, v_xy[2]),
779  _Get_ValAtPos_BSpline(dx, dy, v_xy[3])
780  );
781 
782  return( true );
783  }
784  }
785 
786  return( false );
787 }
788 
789 
791 // //
793 
794 //---------------------------------------------------------
795 inline bool CSG_Grid::_Get_ValAtPos_Fill4x4Submatrix(int x, int y, double v_xy[4][4]) const
796 {
797  int ix, iy, jx, jy, nNoData = 0;
798 
799  //-----------------------------------------------------
800  for(iy=0, jy=y-1; iy<4; iy++, jy++)
801  {
802  for(ix=0, jx=x-1; ix<4; ix++, jx++)
803  {
804  if( is_InGrid(jx, jy) )
805  {
806  v_xy[ix][iy] = asDouble(jx, jy);
807  }
808  else
809  {
810  v_xy[ix][iy] = Get_NoData_Value();
811 
812  nNoData++;
813  }
814  }
815  }
816 
817  //-----------------------------------------------------
818  for(int i=0; nNoData>0 && nNoData<16 && i<16; i++) // guess missing values as average of surrounding data values
819  {
820  double t_xy[4][4];
821 
822  for(iy=0; iy<4; iy++) for(ix=0; ix<4; ix++)
823  {
824  t_xy[ix][iy] = v_xy[ix][iy];
825  }
826 
827  for(iy=0; iy<4; iy++) for(ix=0; ix<4; ix++)
828  {
829  if( is_NoData_Value(t_xy[ix][iy]) )
830  {
831  int n = 0;
832  double s = 0.;
833 
834  for(jy=iy-1; jy<=iy+1; jy++) for(jx=ix-1; jx<=ix+1; jx++)
835  {
836  if( is_InGrid(jx + x - 1, jy + y - 1) )
837  {
838  s += asDouble(jx + x - 1, jy + y - 1);
839  n ++;
840  }
841  else if( jy >= 0 && jy < 4 && jx >= 0 && jx < 4 && !is_NoData_Value(t_xy[jx][jy]) )
842  {
843  s += t_xy[jx][jy];
844  n ++;
845  }
846  }
847 
848  if( n > 0 )
849  {
850  v_xy[ix][iy] = s / n;
851 
852  nNoData--;
853  }
854  }
855  }
856  }
857 
858  //-----------------------------------------------------
859  return( nNoData == 0 );
860 }
861 
862 //---------------------------------------------------------
863 inline bool CSG_Grid::_Get_ValAtPos_Fill4x4Submatrix(int x, int y, double v_xy[4][4][4]) const
864 {
865  int ix, iy, jx, jy, nNoData = 0;
866 
867  //-----------------------------------------------------
868  for(iy=0, jy=y-1; iy<4; iy++, jy++)
869  {
870  for(ix=0, jx=x-1; ix<4; ix++, jx++)
871  {
872  if( is_InGrid(jx, jy) )
873  {
874  int z = asInt(jx, jy);
875 
876  v_xy[0][ix][iy] = SG_GET_BYTE_0(z);
877  v_xy[1][ix][iy] = SG_GET_BYTE_1(z);
878  v_xy[2][ix][iy] = SG_GET_BYTE_2(z);
879  v_xy[3][ix][iy] = SG_GET_BYTE_3(z);
880  }
881  else
882  {
883  v_xy[0][ix][iy] = -1;
884 
885  nNoData++;
886  }
887  }
888  }
889 
890  //-----------------------------------------------------
891  for(int i=0; nNoData>0 && nNoData<16 && i<16; i++) // guess missing values as average of surrounding data values
892  {
893  double t_xy[4][4][4];
894 
895  for(iy=0; iy<4; iy++) for(ix=0; ix<4; ix++)
896  {
897  t_xy[0][ix][iy] = v_xy[0][ix][iy];
898  t_xy[1][ix][iy] = v_xy[1][ix][iy];
899  t_xy[2][ix][iy] = v_xy[2][ix][iy];
900  t_xy[3][ix][iy] = v_xy[3][ix][iy];
901  }
902 
903  for(iy=0; iy<4; iy++) for(ix=0; ix<4; ix++)
904  {
905  if( t_xy[0][ix][iy] < 0 )
906  {
907  int n = 0;
908  double s[4]; s[0] = s[1] = s[2] = s[3] = 0.;
909 
910  for(jy=iy-1; jy<=iy+1; jy++) for(jx=ix-1; jx<=ix+1; jx++)
911  {
912  if( is_InGrid(jx + x - 1, jy + y - 1) )
913  {
914  int z = asInt(jx + x - 1, jy + y - 1);
915 
916  s[0] += SG_GET_BYTE_0(z);
917  s[1] += SG_GET_BYTE_1(z);
918  s[2] += SG_GET_BYTE_2(z);
919  s[3] += SG_GET_BYTE_3(z);
920  n ++;
921  }
922  else if( jy >= 0 && jy < 4 && jx >= 0 && jx < 4 && !is_NoData_Value(t_xy[0][jx][jy]) )
923  {
924  s[0] += t_xy[0][jx][jy];
925  s[1] += t_xy[1][jx][jy];
926  s[2] += t_xy[2][jx][jy];
927  s[3] += t_xy[3][jx][jy];
928  n ++;
929  }
930  }
931 
932  if( n > 0 )
933  {
934  v_xy[0][ix][iy] = s[0] / n;
935  v_xy[1][ix][iy] = s[1] / n;
936  v_xy[2][ix][iy] = s[2] / n;
937  v_xy[3][ix][iy] = s[3] / n;
938 
939  nNoData--;
940  }
941  }
942  }
943  }
944 
945  //-----------------------------------------------------
946  return( nNoData == 0 );
947 }
948 
949 
951 // //
952 // Statistics //
953 // //
955 
956 //---------------------------------------------------------
958 {
959  if( !is_Valid() )
960  {
961  return( false );
962  }
963 
964  SG_FREE_SAFE(m_Index);
965 
966  m_Statistics.Invalidate();
967  m_Histogram.Destroy();
968 
969  double Offset = Get_Offset(), Scaling = is_Scaled() ? Get_Scaling() : 0.;
970 
971  if( Get_Max_Samples() > 0 && Get_Max_Samples() < Get_NCells() )
972  {
973  double d = (double)Get_NCells() / (double)Get_Max_Samples();
974 
975  for(double i=0; i<(double)Get_NCells(); i+=d)
976  {
977  double Value = asDouble((sLong)i, false);
978 
979  if( !is_NoData_Value(Value) )
980  {
981  m_Statistics += Scaling ? Offset + Scaling * Value : Value;
982  }
983  }
984 
985  m_Statistics.Set_Count(m_Statistics.Get_Count() >= Get_Max_Samples() ? Get_NCells() // any no-data cells ?
986  : (sLong)(Get_NCells() * (double)m_Statistics.Get_Count() / (double)Get_Max_Samples())
987  );
988  }
989  else
990  {
991  for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
992  {
993  for(int x=0; x<Get_NX(); x++)
994  {
995  double Value = asDouble(x, y, false);
996 
997  if( !is_NoData_Value(Value) )
998  {
999  m_Statistics += Scaling ? Offset + Scaling * Value : Value;
1000  }
1001  }
1002  }
1003 
1005  }
1006 
1007  return( true );
1008 }
1009 
1010 //---------------------------------------------------------
1012 {
1013  Update(); return( m_Statistics.Get_Mean() );
1014 }
1015 
1016 double CSG_Grid::Get_Min(void)
1017 {
1018  Update(); return( m_Statistics.Get_Minimum() );
1019 }
1020 
1021 double CSG_Grid::Get_Max(void)
1022 {
1023  Update(); return( m_Statistics.Get_Maximum() );
1024 }
1025 
1027 {
1028  Update(); return( m_Statistics.Get_Range() );
1029 }
1030 
1032 {
1033  Update(); return( m_Statistics.Get_StdDev() );
1034 }
1035 
1037 {
1038  Update(); return( m_Statistics.Get_Variance() );
1039 }
1040 
1041 //---------------------------------------------------------
1043 {
1044  Update(); return( m_Statistics.Get_Count() );
1045 }
1046 
1048 {
1049  Update(); return( Get_NCells() - m_Statistics.Get_Count() );
1050 }
1051 
1052 //---------------------------------------------------------
1053 double CSG_Grid::Get_Quantile(double Quantile, bool bFromHistogram)
1054 {
1055  if( Quantile <= 0. ) { return( Get_Min() ); }
1056  if( Quantile >= 1. ) { return( Get_Max() ); }
1057 
1058  if( bFromHistogram )
1059  {
1060  return( Get_Histogram().Get_Quantile(Quantile) );
1061  }
1062  else
1063  {
1064  sLong n = (sLong)(Quantile * (Get_Data_Count() - 1));
1065 
1066  if( Get_Sorted(n, n, false) )
1067  {
1068  return( asDouble(n) );
1069  }
1070  }
1071 
1072  return( Get_NoData_Value() );
1073 }
1074 
1075 //---------------------------------------------------------
1076 double CSG_Grid::Get_Percentile(double Percentile, bool bFromHistogram)
1077 {
1078  return( Get_Quantile(0.01 * Percentile, bFromHistogram) );
1079 }
1080 
1081 
1083 // //
1085 
1086 //---------------------------------------------------------
1094 {
1095  Update(); return( m_Statistics );
1096 }
1097 
1098 //---------------------------------------------------------
1104 //---------------------------------------------------------
1105 bool CSG_Grid::Get_Statistics(const CSG_Rect &rWorld, CSG_Simple_Statistics &Statistics, bool bHoldValues) const
1106 {
1107  int xMin = Get_System().Get_xWorld_to_Grid(rWorld.Get_XMin()); if( xMin < 0 ) xMin = 0;
1108  int yMin = Get_System().Get_yWorld_to_Grid(rWorld.Get_YMin()); if( yMin < 0 ) yMin = 0;
1109  int xMax = Get_System().Get_xWorld_to_Grid(rWorld.Get_XMax()); if( xMax >= Get_NX() ) xMax = Get_NX() - 1;
1110  int yMax = Get_System().Get_yWorld_to_Grid(rWorld.Get_YMax()); if( yMax >= Get_NY() ) yMax = Get_NY() - 1;
1111 
1112  if( xMin > xMax || yMin > yMax )
1113  {
1114  return( false ); // no overlap
1115  }
1116 
1117  Statistics.Create(bHoldValues);
1118 
1119  int nx = 1 + (xMax - xMin);
1120  int ny = 1 + (yMax - yMin);
1121  sLong nCells = nx * ny;
1122 
1123  double Offset = Get_Offset(), Scaling = is_Scaled() ? Get_Scaling() : 0.;
1124 
1125  if( Get_Max_Samples() > 0 && Get_Max_Samples() < nCells )
1126  {
1127  double d = (double)nCells / (double)Get_Max_Samples();
1128 
1129  for(double i=0; i<(double)nCells; i+=d)
1130  {
1131  int y = yMin + (int)i / nx;
1132  int x = xMin + (int)i % nx;
1133 
1134  double Value = asDouble(x, y, false);
1135 
1136  if( !is_NoData_Value(Value) )
1137  {
1138  Statistics += Scaling ? Offset + Scaling * Value : Value;
1139  }
1140  }
1141  }
1142  else
1143  {
1144  for(int y=yMin; y<=yMax; y++)
1145  {
1146  for(int x=xMin; x<=xMax; x++)
1147  {
1148  double Value = asDouble(x, y, false);
1149 
1150  if( !is_NoData_Value(Value) )
1151  {
1152  Statistics += Scaling ? Offset + Scaling * Value : Value;
1153  }
1154  }
1155  }
1156  }
1157 
1158  return( Statistics.Get_Count() > 0 );
1159 }
1160 
1161 //---------------------------------------------------------
1162 #define SG_GRID_HISTOGRAM_CLASSES_DEFAULT 255
1163 
1164 //---------------------------------------------------------
1169 const CSG_Histogram & CSG_Grid::Get_Histogram(size_t nClasses)
1170 {
1171  Update();
1172 
1173  if( nClasses > 1 && nClasses != m_Histogram.Get_Class_Count() )
1174  {
1175  m_Histogram.Destroy();
1176  }
1177 
1178  if( m_Histogram.Get_Statistics().Get_Count() < 1 )
1179  {
1180  m_Histogram.Create(nClasses > 1 ? nClasses : SG_GRID_HISTOGRAM_CLASSES_DEFAULT, Get_Min(), Get_Max(), this, (size_t)Get_Max_Samples());
1181  }
1182 
1183  return( m_Histogram );
1184 }
1185 
1186 //---------------------------------------------------------
1187 bool CSG_Grid::Get_Histogram(const CSG_Rect &rWorld, CSG_Histogram &Histogram, size_t nClasses) const
1188 {
1189  CSG_Simple_Statistics Statistics;
1190 
1191  if( !Get_Statistics(rWorld, Statistics) )
1192  {
1193  return( false );
1194  }
1195 
1196  int xMin = Get_System().Get_xWorld_to_Grid(rWorld.Get_XMin()); if( xMin < 0 ) xMin = 0;
1197  int yMin = Get_System().Get_yWorld_to_Grid(rWorld.Get_YMin()); if( yMin < 0 ) yMin = 0;
1198  int xMax = Get_System().Get_xWorld_to_Grid(rWorld.Get_XMax()); if( xMax >= Get_NX() ) xMax = Get_NX() - 1;
1199  int yMax = Get_System().Get_yWorld_to_Grid(rWorld.Get_YMax()); if( yMax >= Get_NY() ) yMax = Get_NY() - 1;
1200 
1201  if( xMin > xMax || yMin > yMax )
1202  {
1203  return( false ); // no overlap
1204  }
1205 
1206  Histogram.Create(nClasses > 1 ? nClasses : SG_GRID_HISTOGRAM_CLASSES_DEFAULT, Statistics.Get_Minimum(), Statistics.Get_Maximum());
1207 
1208  int nx = 1 + (xMax - xMin);
1209  int ny = 1 + (yMax - yMin);
1210  sLong nCells = nx * ny;
1211 
1212  double Offset = Get_Offset(), Scaling = is_Scaled() ? Get_Scaling() : 0.;
1213 
1214  if( Get_Max_Samples() > 0 && Get_Max_Samples() < nCells )
1215  {
1216  double d = (double)nCells / (double)Get_Max_Samples();
1217 
1218  for(double i=0; i<(double)nCells; i+=d)
1219  {
1220  int y = yMin + (int)i / nx;
1221  int x = xMin + (int)i % nx;
1222 
1223  double Value = asDouble(x, y, false);
1224 
1225  if( !is_NoData_Value(Value) )
1226  {
1227  Histogram += Scaling ? Offset + Scaling * Value : Value;
1228  }
1229  }
1230  }
1231  else
1232  {
1233  for(int y=yMin; y<=yMax; y++)
1234  {
1235  for(int x=xMin; x<=xMax; x++)
1236  {
1237  double Value = asDouble(x, y, false);
1238 
1239  if( !is_NoData_Value(Value) )
1240  {
1241  Histogram += Scaling ? Offset + Scaling * Value : Value;
1242  }
1243  }
1244  }
1245  }
1246 
1247  return( Histogram.Update() );
1248 }
1249 
1250 
1252 // //
1253 // Index //
1254 // //
1256 
1257 //---------------------------------------------------------
1258 bool CSG_Grid::_Set_Index(void)
1259 {
1260  //-----------------------------------------------------
1261  if( m_Index == NULL && (m_Index = (sLong *)SG_Malloc((size_t)Get_NCells() * sizeof(sLong))) == NULL )
1262  {
1263  SG_UI_Msg_Add_Error(_TL("could not create index: insufficient memory"));
1264 
1265  return( false );
1266  }
1267 
1268  //-----------------------------------------------------
1269  const sLong M = 7;
1270 
1271  sLong i, j, k, l, ir, n, *istack, jstack, nstack, indxt, itemp, nData;
1272  double a;
1273 
1274  //-----------------------------------------------------
1275  SG_UI_Process_Set_Text(CSG_String::Format("%s: %s", _TL("Create index"), Get_Name()));
1276 
1277  for(i=0, j=0, nData=Get_NCells(); i<Get_NCells(); i++)
1278  {
1279  if( is_NoData(i) )
1280  {
1281  m_Index[--nData] = i;
1282  }
1283  else // if( !is_NoData(i) )
1284  {
1285  m_Index[j++] = i;
1286  }
1287  }
1288 
1289  if( nData <= 0 )
1290  {
1291  // SG_FREE_SAFE(m_Index);
1292 
1293  return( false ); // nothing to do
1294  }
1295 
1296  //-----------------------------------------------------
1297  l = 0;
1298  n = 0;
1299  ir = nData - 1;
1300 
1301  nstack = 64;
1302  istack = (sLong *)SG_Malloc((size_t)nstack * sizeof(sLong));
1303  jstack = 0;
1304 
1305  for(;;)
1306  {
1307  if( ir - l < M )
1308  {
1309  if( !SG_UI_Process_Set_Progress((double)(n += M - 1), (double)nData) )
1310  {
1311  SG_FREE_SAFE(istack);
1312  SG_FREE_SAFE(m_Index);
1313 
1314  SG_UI_Msg_Add_Error(_TL("index creation stopped by user"));
1316 
1317  return( false );
1318  }
1319 
1320  for(j=l+1; j<=ir; j++)
1321  {
1322  indxt = m_Index[j];
1323  a = asDouble(indxt);
1324 
1325  for(i=j-1; i>=0; i--)
1326  {
1327  if( asDouble(m_Index[i]) <= a )
1328  {
1329  break;
1330  }
1331 
1332  m_Index[i + 1] = m_Index[i];
1333  }
1334 
1335  m_Index[i + 1] = indxt;
1336  }
1337 
1338  if( jstack == 0 )
1339  {
1340  break;
1341  }
1342 
1343  ir = istack[jstack--];
1344  l = istack[jstack--];
1345  }
1346 
1347  //-------------------------------------------------
1348  else
1349  {
1350  #define SORT_SWAP(a,b) {itemp=(a);(a)=(b);(b)=itemp;}
1351 
1352  k = (l + ir) >> 1;
1353 
1354  SORT_SWAP(m_Index[k], m_Index[l + 1]);
1355 
1356  if( asDouble( m_Index[l + 1]) > asDouble(m_Index[ir]) )
1357  SORT_SWAP(m_Index[l + 1], m_Index[ir]);
1358 
1359  if( asDouble( m_Index[l ]) > asDouble(m_Index[ir]) )
1360  SORT_SWAP(m_Index[l ], m_Index[ir]);
1361 
1362  if( asDouble( m_Index[l + 1]) > asDouble(m_Index[l ]) )
1363  SORT_SWAP(m_Index[l + 1], m_Index[l ]);
1364 
1365  i = l + 1;
1366  j = ir;
1367  indxt = m_Index[l];
1368  a = asDouble(indxt);
1369 
1370  for(;;)
1371  {
1372  do i++; while(asDouble(m_Index[i]) < a);
1373  do j--; while(asDouble(m_Index[j]) > a);
1374 
1375  if( j < i )
1376  {
1377  break;
1378  }
1379 
1380  SORT_SWAP(m_Index[i], m_Index[j]);
1381  }
1382 
1383  #undef SORT_SWAP
1384 
1385  m_Index[l] = m_Index[j];
1386  m_Index[j] = indxt;
1387  jstack += 2;
1388 
1389  if( jstack >= nstack )
1390  {
1391  nstack += 64;
1392  istack = (sLong *)SG_Realloc(istack, (size_t)nstack * sizeof(int));
1393  }
1394 
1395  if( ir - i + 1 >= j - l )
1396  {
1397  istack[jstack] = ir;
1398  istack[jstack - 1] = i;
1399  ir = j - 1;
1400  }
1401  else
1402  {
1403  istack[jstack] = j - 1;
1404  istack[jstack - 1] = l;
1405  l = i;
1406  }
1407  }
1408  }
1409 
1410  //-----------------------------------------------------
1411  SG_Free(istack);
1412 
1414 
1415  return( true );
1416 }
1417 
1418 
1420 // //
1421 // //
1422 // //
1424 
1425 //---------------------------------------------------------
CSG_Grid::Get_Type
TSG_Data_Type Get_Type(void) const
Definition: grid.h:521
CSG_Rect
Definition: geo_tools.h:474
SG_DATATYPE_Color
@ SG_DATATYPE_Color
Definition: api_core.h:1008
SG_DATATYPE_Int
@ SG_DATATYPE_Int
Definition: api_core.h:1001
CSG_Grid::is_InGrid
bool is_InGrid(int x, int y, bool bCheckNoData=true) const
Definition: grid.h:595
SG_DATATYPE_Undefined
@ SG_DATATYPE_Undefined
Definition: api_core.h:1010
CSG_Data_Object::Get_Max_Samples
sLong Get_Max_Samples(void) const
Definition: dataobject.h:263
SG_FREE_SAFE
#define SG_FREE_SAFE(PTR)
Definition: api_core.h:205
CSG_Data_Object::m_pOwner
CSG_Data_Object * m_pOwner
Definition: dataobject.h:271
GRID_RESAMPLING_NearestNeighbour
@ GRID_RESAMPLING_NearestNeighbour
Definition: grid.h:157
TSG_Intersection
TSG_Intersection
Definition: geo_tools.h:101
CSG_Histogram::Update
bool Update(void)
Definition: mat_tools.cpp:1366
_TL
#define _TL(s)
Definition: api_core.h:1507
SG_DATATYPE_DWord
@ SG_DATATYPE_DWord
Definition: api_core.h:1000
BILINEAR_ADD_BYTE
#define BILINEAR_ADD_BYTE(ix, iy, d)
Definition: grid.cpp:605
BILINEAR_ADD
#define BILINEAR_ADD(ix, iy, d)
Definition: grid.cpp:600
CSG_Data_Object::Get_Description
const SG_Char * Get_Description(void) const
Definition: dataobject.cpp:360
CSG_Data_Object::Update
bool Update(bool bForce=false)
Definition: dataobject.cpp:777
CSG_Grid::is_Scaled
bool is_Scaled(void) const
Definition: grid.h:561
GRID_RESAMPLING_BicubicSpline
@ GRID_RESAMPLING_BicubicSpline
Definition: grid.h:159
CSG_Grid_System::Get_XMin
double Get_XMin(bool bCells=false) const
Definition: grid.h:240
CSG_Simple_Statistics::Get_Variance
double Get_Variance(void)
Definition: mat_tools.h:752
CSG_Grid::is_Intersecting
TSG_Intersection is_Intersecting(const CSG_Rect &Extent) const
Definition: grid.cpp:452
data_manager.h
CSG_Data_Object::Get_NoData_Value
double Get_NoData_Value(bool bUpper=false) const
Definition: dataobject.h:253
CSG_Rect::Get_XMax
double Get_XMax(void) const
Definition: geo_tools.h:506
SG_UI_MSG_STYLE_SUCCESS
@ SG_UI_MSG_STYLE_SUCCESS
Definition: api_core.h:1523
CSG_Grid_System
Definition: grid.h:200
TSG_Grid_Resampling
TSG_Grid_Resampling
Definition: grid.h:156
CSG_Grid::Create
bool Create(const CSG_Grid &Grid)
Definition: grid.cpp:235
CSG_Grid::Get_Statistics
const CSG_Simple_Statistics & Get_Statistics(void)
Definition: grid.cpp:1093
CSG_Histogram
Definition: mat_tools.h:1011
CSG_Grid::CSG_Grid
CSG_Grid(void)
Definition: grid.cpp:136
SG_Malloc
SAGA_API_DLL_EXPORT void * SG_Malloc(size_t size)
Definition: api_memory.cpp:65
SG_GET_BYTE_1
#define SG_GET_BYTE_1(vLong)
Definition: api_core.h:195
CSG_Grid_System::Get_yWorld_to_Grid
int Get_yWorld_to_Grid(double yWorld) const
Definition: grid.h:293
SG_Data_Type_Get_Size
size_t SG_Data_Type_Get_Size(TSG_Data_Type Type)
Definition: api_core.h:1061
CSG_Data_Object::is_NoData_Value
bool is_NoData_Value(double Value) const
Definition: dataobject.h:255
SG_DATATYPE_Byte
@ SG_DATATYPE_Byte
Definition: api_core.h:996
grid.h
CSG_Data_Object::Get_Name
const SG_Char * Get_Name(void) const
Definition: dataobject.cpp:349
CSG_Histogram::Create
bool Create(const CSG_Histogram &Histogram)
Definition: mat_tools.cpp:1498
CSG_Grid_System::Create
bool Create(const CSG_Grid_System &System, int Precision=-1)
Definition: grid_system.cpp:140
SG_Free
SAGA_API_DLL_EXPORT void SG_Free(void *memblock)
Definition: api_memory.cpp:83
CSG_Data_Object::Set_Max_Samples
virtual bool Set_Max_Samples(sLong Max_Samples)
Definition: dataobject.cpp:617
CSG_Grid::Get_Quantile
double Get_Quantile(double Quantile, bool bFromHistogram=true)
Definition: grid.cpp:1053
SSG_Point
Definition: geo_tools.h:128
CSG_Data_Object::Set_Update_Flag
void Set_Update_Flag(bool bOn=true)
Definition: dataobject.h:285
CSG_Grid::Get_System
const CSG_Grid_System & Get_System(void) const
Definition: grid.h:533
CSG_Rect::Contains
bool Contains(double x, double y) const
Definition: geo_classes.cpp:870
SSG_Rect
Definition: geo_tools.h:467
CSG_Grid::Get_Data_Count
sLong Get_Data_Count(void)
Definition: grid.cpp:1042
CSG_Grid::Destroy
virtual bool Destroy(void)
Definition: grid.cpp:379
SG_UI_MSG_STYLE_FAILURE
@ SG_UI_MSG_STYLE_FAILURE
Definition: api_core.h:1524
CSG_Simple_Statistics::Get_Maximum
double Get_Maximum(void)
Definition: mat_tools.h:747
CSG_Grid::Get_Variance
double Get_Variance(void)
Definition: grid.cpp:1036
CSG_Grid::Get_Scaling
double Get_Scaling(void) const
Definition: grid.cpp:422
CSG_Grid::Get_YMin
double Get_YMin(bool bCells=false) const
Definition: grid.h:550
SG_DATATYPE_Long
@ SG_DATATYPE_Long
Definition: api_core.h:1003
CSG_Grid::Get_Cellsize
double Get_Cellsize(void) const
Definition: grid.h:541
SG_GET_BYTE_3
#define SG_GET_BYTE_3(vLong)
Definition: api_core.h:197
CSG_Vector
Definition: mat_tools.h:360
CSG_Data_Object
Definition: dataobject.h:180
GRID_RESAMPLING_Bilinear
@ GRID_RESAMPLING_Bilinear
Definition: grid.h:158
CSG_Rect::Get_YMin
double Get_YMin(void) const
Definition: geo_tools.h:507
CSG_Grid::Get_Mean
double Get_Mean(void)
Definition: grid.cpp:1011
CSG_Simple_Statistics::Get_Count
sLong Get_Count(void) const
Definition: mat_tools.h:743
CSG_Grid::is_Valid
virtual bool is_Valid(void) const
Definition: grid.cpp:441
SG_DataObject_Get_Max_Samples
sLong SG_DataObject_Get_Max_Samples(void)
Definition: dataobject.cpp:139
CSG_Vector::Create
bool Create(const CSG_Vector &Vector)
Definition: mat_matrix.cpp:87
CSG_Simple_Statistics::Get_Minimum
double Get_Minimum(void)
Definition: mat_tools.h:746
SORT_SWAP
#define SORT_SWAP(a, b)
CSG_Grid::Get_Max
double Get_Max(void)
Definition: grid.cpp:1021
CSG_Grid::Set_Value
virtual void Set_Value(sLong i, double Value, bool bScaled=true)
Definition: grid.h:817
CSG_Grid::Set_Scaling
void Set_Scaling(double Scale=1.0, double Offset=0.0)
Definition: grid.cpp:406
CSG_Grid::Set_Row
bool Set_Row(int y, const CSG_Vector &Values)
Definition: grid.cpp:509
sLong
signed long long sLong
Definition: api_core.h:158
CSG_Simple_Statistics::Get_StdDev
double Get_StdDev(void)
Definition: mat_tools.h:753
CSG_Grid::Get_Unit
const CSG_String & Get_Unit(void) const
Definition: grid.h:527
CSG_Grid::Get_NY
int Get_NY(void) const
Definition: grid.h:538
CSG_Grid_System::Destroy
bool Destroy(void)
Definition: grid_system.cpp:223
SG_DATATYPE_Float
@ SG_DATATYPE_Float
Definition: api_core.h:1004
CSG_Simple_Statistics::Invalidate
void Invalidate(void)
Definition: mat_tools.cpp:447
CSG_Grid::Get_Offset
double Get_Offset(void) const
Definition: grid.cpp:428
SG_UI_Process_Set_Text
void SG_UI_Process_Set_Text(const CSG_String &Text)
Definition: api_callback.cpp:323
CSG_Grid::Get_XMin
double Get_XMin(bool bCells=false) const
Definition: grid.h:546
SG_GRID_HISTOGRAM_CLASSES_DEFAULT
#define SG_GRID_HISTOGRAM_CLASSES_DEFAULT
Definition: grid.cpp:1162
CSG_Grid::Get_Value
double Get_Value(double x, double y, TSG_Grid_Resampling Resampling=GRID_RESAMPLING_BSpline, bool bByteWise=false) const
Definition: grid.cpp:539
CSG_Grid::Get_Percentile
double Get_Percentile(double Percentile, bool bFromHistogram=true)
Definition: grid.cpp:1076
CSG_Vector::Get_N
int Get_N(void) const
Definition: mat_tools.h:382
CSG_Grid::Get_Histogram
const CSG_Histogram & Get_Histogram(size_t nClasses=0)
Definition: grid.cpp:1169
GRID_RESAMPLING_BSpline
@ GRID_RESAMPLING_BSpline
Definition: grid.h:160
CSG_Grid::Get_Sorted
sLong Get_Sorted(sLong Position, bool bDown=true, bool bCheckNoData=true)
Definition: grid.h:664
CSG_Simple_Statistics::Get_Mean
double Get_Mean(void)
Definition: mat_tools.h:751
SG_DATATYPE_Word
@ SG_DATATYPE_Word
Definition: api_core.h:998
CSG_Grid_System::Get_NY
int Get_NY(void) const
Definition: grid.h:235
CSG_Data_Object::Set_Name
void Set_Name(const CSG_String &Name)
Definition: dataobject.cpp:300
CSG_Histogram::Get_Class_Count
size_t Get_Class_Count(void) const
Definition: mat_tools.h:1043
CSG_Simple_Statistics::Set_Count
bool Set_Count(sLong Count)
Definition: mat_tools.cpp:424
CSG_String::Format
static CSG_String Format(const char *Format,...)
Definition: api_string.cpp:270
CSG_Grid::is_Compatible
bool is_Compatible(CSG_Grid *pGrid) const
Definition: grid.cpp:468
CSG_String::Clear
void Clear(void)
Definition: api_string.cpp:259
CSG_Grid_System::Get_Extent
const CSG_Rect & Get_Extent(bool bCells=false) const
Definition: grid.h:238
CSG_String
Definition: api_core.h:563
CSG_Grid::Get_Range
double Get_Range(void)
Definition: grid.cpp:1026
CSG_Histogram::Destroy
bool Destroy(void)
Definition: mat_tools.cpp:1275
SG_GET_LONG
#define SG_GET_LONG(b0, b1, b2, b3)
Definition: api_core.h:192
CSG_Grid::asDouble
virtual double asDouble(sLong i, bool bScaled=true) const
Definition: grid.h:767
CSG_Grid::Get_Min
double Get_Min(void)
Definition: grid.cpp:1016
CSG_Data_Object::Set_Description
void Set_Description(const CSG_String &Description)
Definition: dataobject.cpp:355
CSG_Grid::Get_NX
int Get_NX(void) const
Definition: grid.h:537
CSG_Simple_Statistics::Get_Range
double Get_Range(void)
Definition: mat_tools.h:748
SG_UI_Process_Set_Progress
bool SG_UI_Process_Set_Progress(int Position, int Range)
Definition: api_callback.cpp:255
CSG_Data_Object::Get_MetaData
CSG_MetaData & Get_MetaData(void) const
Definition: dataobject.h:234
SSG_Point::x
double x
Definition: geo_tools.h:129
CSG_Grid::Get_Row
CSG_Vector Get_Row(int y) const
Definition: grid.cpp:491
CSG_Grid::Get_NoData_Count
sLong Get_NoData_Count(void)
Definition: grid.cpp:1047
SG_DATATYPE_Short
@ SG_DATATYPE_Short
Definition: api_core.h:999
CSG_Simple_Statistics::Create
bool Create(bool bHoldValues=false)
Definition: mat_tools.cpp:350
CSG_Grid_System::Get_xWorld_to_Grid
int Get_xWorld_to_Grid(double xWorld) const
Definition: grid.h:292
CSG_Rect::Get_YMax
double Get_YMax(void) const
Definition: geo_tools.h:508
SG_GET_BYTE_0
#define SG_GET_BYTE_0(vLong)
Definition: api_core.h:194
CSG_Rect::Get_XMin
double Get_XMin(void) const
Definition: geo_tools.h:505
CSG_Grid::On_Update
virtual bool On_Update(void)
Definition: grid.cpp:957
BiCubicSpline
#define BiCubicSpline(d, v)
SSG_Point::y
double y
Definition: geo_tools.h:129
CSG_Grid::is_Cached
bool is_Cached(void) const
Definition: grid.h:607
CSG_Grid
Definition: grid.h:475
SG_DATATYPE_Bit
@ SG_DATATYPE_Bit
Definition: api_core.h:995
CSG_Data_Object::Set_NoData_Value
virtual bool Set_NoData_Value(double Value)
Definition: dataobject.cpp:572
CSG_MetaData::Create
bool Create(void)
Definition: metadata.cpp:73
SG_GET_BYTE_2
#define SG_GET_BYTE_2(vLong)
Definition: api_core.h:196
CSG_Grid_System::Get_NX
int Get_NX(void) const
Definition: grid.h:234
CSG_String::c_str
const SG_Char * c_str(void) const
Definition: api_string.cpp:236
SG_UI_Process_Set_Ready
bool SG_UI_Process_Set_Ready(void)
Definition: api_callback.cpp:305
SG_Create_Grid
CSG_Grid * SG_Create_Grid(void)
Definition: grid.cpp:72
TSG_Data_Type
TSG_Data_Type
Definition: api_core.h:994
SG_Realloc
SAGA_API_DLL_EXPORT void * SG_Realloc(void *memblock, size_t size)
Definition: api_memory.cpp:77
SG_UI_Msg_Add_Error
void SG_UI_Msg_Add_Error(const char *Message)
Definition: api_callback.cpp:556
CSG_Grid::~CSG_Grid
virtual ~CSG_Grid(void)
Definition: grid.cpp:371
CSG_Grid::Set_Unit
void Set_Unit(const CSG_String &Unit)
Definition: grid.cpp:400
CSG_Grid::is_NoData
virtual bool is_NoData(int x, int y) const
Definition: grid.h:701
CSG_Projection::Create
bool Create(const CSG_Projection &Projection)
Definition: projections.cpp:96
CSG_Grid::Get_Extent
virtual const CSG_Rect & Get_Extent(void)
Definition: grid.h:535
CSG_Simple_Statistics
Definition: mat_tools.h:723
CSG_Grid_System::Get_YMin
double Get_YMin(bool bCells=false) const
Definition: grid.h:244
CSG_Data_Object::Set_NoData_Value_Range
virtual bool Set_NoData_Value_Range(double Lower, double Upper)
Definition: dataobject.cpp:578
SG_DATATYPE_Char
@ SG_DATATYPE_Char
Definition: api_core.h:997
CSG_Data_Object::Get_Projection
CSG_Projection & Get_Projection(void)
Definition: dataobject.cpp:637
CSG_Data_Object::Destroy
virtual bool Destroy(void)
Definition: dataobject.cpp:281
CSG_Grid::asInt
virtual int asInt(int x, int y, bool bScaled=true) const
Definition: grid.h:759
SG_DATATYPE_ULong
@ SG_DATATYPE_ULong
Definition: api_core.h:1002
CSG_Grid::Get_StdDev
double Get_StdDev(void)
Definition: grid.cpp:1031
CSG_Grid_System::is_Valid
bool is_Valid(void) const
Definition: grid_system.cpp:258
CSG_Histogram::Get_Statistics
const CSG_Simple_Statistics & Get_Statistics(void) const
Definition: mat_tools.h:1076
CSG_Grid::Get_NCells
sLong Get_NCells(void) const
Definition: grid.h:539
SG_UI_Msg_Add
void SG_UI_Msg_Add(const char *Message, bool bNewLine, TSG_UI_MSG_STYLE Style)
Definition: api_callback.cpp:502
CSG_Table::_On_Construction
virtual void _On_Construction(void)
Definition: table.cpp:295
CSG_Grid::Set_Modified
virtual void Set_Modified(bool bModified=true)
Definition: grid.h:638
SG_DATATYPE_Double
@ SG_DATATYPE_Double
Definition: api_core.h:1005