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