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