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