SAGA API  v9.5
grids.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 // grids.cpp //
15 // //
16 // Copyright (C) 2017 by //
17 // Olaf Conrad //
18 // //
19 //-------------------------------------------------------//
20 // //
21 // This file is part of 'SAGA - System for Automated //
22 // Geoscientific Analyses'. //
23 // //
24 // This library is free software; you can redistribute //
25 // it and/or modify it under the terms of the GNU Lesser //
26 // General Public License as published by the Free //
27 // Software Foundation, either version 2.1 of the //
28 // License, or (at your option) any later version. //
29 // //
30 // This library is distributed in the hope that it will //
31 // be useful, but WITHOUT ANY WARRANTY; without even the //
32 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
33 // PARTICULAR PURPOSE. See the GNU Lesser General Public //
34 // License for more details. //
35 // //
36 // You should have received a copy of the GNU Lesser //
37 // General Public License along with this program; if //
38 // not, see <http://www.gnu.org/licenses/>. //
39 // //
40 //-------------------------------------------------------//
41 // //
42 // e-mail: oconrad@saga-gis.org //
43 // //
44 // contact: Olaf Conrad //
45 // Institute of Geography //
46 // University of Hamburg //
47 // Germany //
48 // //
50 
51 //---------------------------------------------------------
52 #include "saga_api.h"
53 #include "grids.h"
54 #include "data_manager.h"
55 #include "tool_library.h"
56 
57 
59 // //
60 // //
61 // //
63 
64 //---------------------------------------------------------
66 {
67  return( new CSG_Grids );
68 }
69 
70 //---------------------------------------------------------
72 {
73  CSG_Grids *pGrids = new CSG_Grids(Grids);
74 
75  if( !pGrids->is_Valid() ) { delete(pGrids); pGrids = NULL; } return( pGrids );
76 }
77 
78 //---------------------------------------------------------
79 CSG_Grids * SG_Create_Grids(const CSG_Grids *_pGrids, bool bCopyData)
80 {
81  CSG_Grids *pGrids = new CSG_Grids(_pGrids, bCopyData);
82 
83  if( !pGrids->is_Valid() ) { delete(pGrids); pGrids = NULL; } return( pGrids );
84 }
85 
86 //---------------------------------------------------------
87 CSG_Grids * SG_Create_Grids(const char *FileName, bool bLoadData) { return( SG_Create_Grids(CSG_String(FileName), bLoadData) ); }
88 CSG_Grids * SG_Create_Grids(const wchar_t *FileName, bool bLoadData) { return( SG_Create_Grids(CSG_String(FileName), bLoadData) ); }
89 CSG_Grids * SG_Create_Grids(const CSG_String &FileName, bool bLoadData)
90 {
91  CSG_Grids *pGrids = new CSG_Grids(FileName, bLoadData);
92 
93  if( !pGrids->is_Valid() ) { delete(pGrids); pGrids = NULL; } return( pGrids );
94 }
95 
96 //---------------------------------------------------------
97 CSG_Grids * SG_Create_Grids(const CSG_Grid_System &System, int NZ, double zMin, TSG_Data_Type Type)
98 {
99  CSG_Grids *pGrids = new CSG_Grids(System, NZ, zMin, Type);
100 
101  if( !pGrids->is_Valid() ) { delete(pGrids); pGrids = NULL; } return( pGrids );
102 }
103 
104 //---------------------------------------------------------
105 CSG_Grids * SG_Create_Grids(const CSG_Grid_System &System, const CSG_Table &Attributes, int zAttribute, TSG_Data_Type Type, bool bCreateGrids)
106 {
107  CSG_Grids *pGrids = new CSG_Grids(System, Attributes, zAttribute, Type, bCreateGrids);
108 
109  if( bCreateGrids && !pGrids->is_Valid() ) { delete(pGrids); pGrids = NULL; } return( pGrids );
110 }
111 
112 //---------------------------------------------------------
113 CSG_Grids * SG_Create_Grids(int NX, int NY, int NZ, double Cellsize, double xMin, double yMin, double zMin, TSG_Data_Type Type)
114 {
115  CSG_Grids *pGrids = new CSG_Grids(NX, NY, NZ, Cellsize, xMin, yMin, zMin, Type);
116 
117  if( !pGrids->is_Valid() ) { delete(pGrids); pGrids = NULL; } return( pGrids );
118 }
119 
120 
122 // //
123 // //
124 // //
126 
127 //---------------------------------------------------------
131 //---------------------------------------------------------
133 {
134  _On_Construction();
135 }
136 
137 //---------------------------------------------------------
142 {
143  Destroy();
144 
145  delete(m_pGrids[0]); // The Dummy
146 }
147 
148 //---------------------------------------------------------
152 //---------------------------------------------------------
154 {
155  _On_Construction();
156 
157  Create(Grids);
158 }
159 
160 //---------------------------------------------------------
167 //---------------------------------------------------------
168 CSG_Grids::CSG_Grids(const CSG_Grids *pGrids, bool bCopyData)
169 {
170  _On_Construction();
171 
172  Create(pGrids, bCopyData);
173 }
174 
175 //---------------------------------------------------------
179 //---------------------------------------------------------
180 CSG_Grids::CSG_Grids(const char *FileName, bool bLoadData) { _On_Construction(); Create(FileName, bLoadData); }
181 CSG_Grids::CSG_Grids(const wchar_t *FileName, bool bLoadData) { _On_Construction(); Create(FileName, bLoadData); }
182 CSG_Grids::CSG_Grids(const CSG_String &FileName, bool bLoadData) { _On_Construction(); Create(FileName, bLoadData); }
183 
184 //---------------------------------------------------------
188 //---------------------------------------------------------
189 CSG_Grids::CSG_Grids(int NX, int NY, int NZ, double Cellsize, double xMin, double yMin, double zMin, TSG_Data_Type Type)
190 {
191  _On_Construction();
192 
193  Create(NX, NY, NZ, Cellsize, xMin, yMin, zMin, Type);
194 }
195 
196 //---------------------------------------------------------
200 //---------------------------------------------------------
201 CSG_Grids::CSG_Grids(const CSG_Grid_System &System, int NZ, double zMin, TSG_Data_Type Type)
202 {
203  _On_Construction();
204 
205  Create(System, NZ, zMin, Type);
206 }
207 
208 //---------------------------------------------------------
212 //---------------------------------------------------------
213 CSG_Grids::CSG_Grids(const CSG_Grid_System &System, const CSG_Table &Attributes, int zAttribute, TSG_Data_Type Type, bool bCreateGrids)
214 {
215  _On_Construction();
216 
217  Create(System, Attributes, zAttribute, Type, bCreateGrids);
218 }
219 
220 
222 // //
224 
225 //---------------------------------------------------------
226 void CSG_Grids::_On_Construction(void)
227 {
228  m_pGrids = (CSG_Grid **)m_Grids.Create(1);
229  m_pGrids[0] = SG_Create_Grid(); // The Dummy
230  m_pGrids[0]->Set_Owner(this);
231 
232  m_Attributes.Set_Owner(this);
233 
234  m_Index = NULL;
235 
236  Destroy();
237 
238  Set_Update_Flag();
239 }
240 
241 //---------------------------------------------------------
246 {
247  for(size_t i=1; i<m_Grids.Get_uSize(); i++)
248  {
249  delete(m_pGrids[i]); // do not delete the dummy before deconstruction
250  }
251 
252  m_pGrids = (CSG_Grid **)m_Grids.Get_Array(1);
253 
254  m_pGrids[0]->Destroy(); // The Dummy
255 
256  SG_FREE_SAFE(m_Index);
257 
258  m_Attributes.Destroy();
259  m_Attributes.Add_Field("Z", SG_DATATYPE_Double);
260  m_Z_Attribute = m_Z_Name = 0;
261 
262  return( CSG_Data_Object::Destroy() );
263 }
264 
265 
267 // //
269 
270 //---------------------------------------------------------
271 bool CSG_Grids::Create(const CSG_Grids &Grids)
272 {
273  return( Create((CSG_Grids *)&Grids, true) );
274 }
275 
276 //---------------------------------------------------------
277 bool CSG_Grids::Create(const CSG_Grids *pGrids, bool bCopyData)
278 {
279  if( pGrids && pGrids->is_Valid() && Create(pGrids->Get_System(), 0, 0., pGrids->Get_Type()) )
280  {
281  Set_NoData_Value_Range(pGrids->Get_NoData_Value(), pGrids->Get_NoData_Value(true));
282 
283  m_Attributes.Create(&pGrids->m_Attributes);
284  Set_Z_Attribute (pGrids->Get_Z_Attribute ());
286 
287  if( bCopyData )
288  {
289  for(int i=0; i<pGrids->Get_NZ(); i++)
290  {
291  Add_Grid(pGrids->Get_Attributes(i), pGrids->Get_Grid_Ptr(i));
292  }
293  }
294 
297 
298  Get_Projection().Create(pGrids->Get_Projection());
299 
300  return( true );
301  }
302 
303  return( false );
304 }
305 
306 //---------------------------------------------------------
307 bool CSG_Grids::Create(const char *FileName, bool bLoadData) { return( Load(CSG_String(FileName), bLoadData) ); }
308 bool CSG_Grids::Create(const wchar_t *FileName, bool bLoadData) { return( Load(CSG_String(FileName), bLoadData) ); }
309 bool CSG_Grids::Create(const CSG_String &FileName, bool bLoadData) { return( Load( FileName , bLoadData) ); }
310 
311 //---------------------------------------------------------
312 bool CSG_Grids::Create(const CSG_Grid_System &System, int NZ, double zMin, TSG_Data_Type Type)
313 {
314  Destroy();
315 
316  if( m_pGrids[0]->Create(System, Type) )
317  {
318  Set_NoData_Value_Range(m_pGrids[0]->Get_NoData_Value(), m_pGrids[0]->Get_NoData_Value(true));
319 
320  for(int i=0; i<NZ; i++, zMin+=System.Get_Cellsize())
321  {
322  if( !Add_Grid(zMin) )
323  {
324  return( false );
325  }
326  }
327 
328  return( true );
329  }
330 
331  return( false );
332 }
333 
334 //---------------------------------------------------------
335 bool CSG_Grids::Create(const CSG_Grid_System &System, const CSG_Table &Attributes, int zAttribute, TSG_Data_Type Type, bool bCreateGrids)
336 {
337  Destroy();
338 
339  if( m_Attributes.Create(&Attributes) && m_pGrids[0]->Create(System, Type) )
340  {
341  Set_Z_Attribute(zAttribute);
342 
343  if( bCreateGrids )
344  {
345  for(int i=0; i<Attributes.Get_Count(); i++)
346  {
347  if( !Add_Grid(Attributes[i]) )
348  {
349  return( false );
350  }
351  }
352  }
353 
354  return( true );
355  }
356 
357  return( false );
358 }
359 
360 //---------------------------------------------------------
361 bool CSG_Grids::Create(int NX, int NY, int NZ, double Cellsize, double xMin, double yMin, double zMin, TSG_Data_Type Type)
362 {
363  return( Create(CSG_Grid_System(Cellsize, xMin, yMin, NX, NY), NZ, zMin, Type) );
364 }
365 
366 
368 // //
369 // Header //
370 // //
372 
373 //---------------------------------------------------------
375 {
376  m_pGrids[0]->Set_Unit(Unit);
377 }
378 
379 //---------------------------------------------------------
380 void CSG_Grids::Set_Scaling(double Scale, double Offset)
381 {
382  m_pGrids[0]->Set_Scaling(Scale, Offset);
383 
384  for(int i=1; i<Get_Grid_Count(); i++)
385  {
386  m_pGrids[i]->Set_Scaling(Scale, Offset);
387  }
388 
389  Set_Update_Flag();
390 }
391 
392 //---------------------------------------------------------
393 bool CSG_Grids::Set_NoData_Value_Range(double loValue, double hiValue)
394 {
395  if( CSG_Data_Object::Set_NoData_Value_Range(loValue, hiValue) ) // this is a CSG_Data_Object base class property
396  {
397  m_pGrids[0]->Set_NoData_Value_Range(loValue, hiValue);
398 
399  for(int i=1; i<Get_Grid_Count(); i++)
400  {
401  m_pGrids[i]->Set_NoData_Value_Range(loValue, hiValue);
402  }
403 
404  return( true );
405  }
406 
407  return( false );
408 }
409 
410 //---------------------------------------------------------
411 void CSG_Grids::_Synchronize(CSG_Grid *pGrid)
412 {
413  if( !Get_Projection().is_Okay() && pGrid->Get_Projection().is_Okay() )
414  {
416  }
417 
418  pGrid->Set_Owner(this);
419 
420  if( pGrid == m_pGrids[0] )
421  {
422  Set_Scaling(pGrid->Get_Scaling(), pGrid->Get_Offset());
424  }
425  else // if( pGrid != m_pGrids[0] )
426  {
427  pGrid->Set_Scaling(Get_Scaling(), Get_Offset());
429  }
430 }
431 
432 
434 // //
435 // Checks //
436 // //
438 
439 //---------------------------------------------------------
440 bool CSG_Grids::is_Valid(void) const
441 {
442  return( Get_System().is_Valid() );
443 }
444 
445 //---------------------------------------------------------
447 {
448  return( pGrid && is_Compatible(pGrid->Get_System()) && Get_Type() == pGrid->Get_Type() );
449 }
450 
452 {
453  return( pGrids && is_Compatible(pGrids->Get_System()) && Get_NZ() == pGrids->Get_NZ() );//&& Get_Type() == pGrids->Get_Type() );
454 }
455 
456 bool CSG_Grids::is_Compatible(const CSG_Grid_System &System) const
457 {
458  return( Get_System() == System );
459 }
460 
461 bool CSG_Grids::is_Compatible(int NX, int NY, double Cellsize, double xMin, double yMin) const
462 {
463  return( is_Compatible(CSG_Grid_System(Cellsize, xMin, yMin, NX, NY)) );
464 }
465 
466 
468 // //
469 // Attributes //
470 // //
472 
473 //---------------------------------------------------------
475 {
476  if( i >= 0 && i < m_Attributes.Get_Field_Count() )
477  {
478  m_Z_Attribute = i;
479 
480  return( Update_Z_Order() );
481  }
482 
483  return( false );
484 }
485 
486 //---------------------------------------------------------
488 {
489  if( i >= 0 && i < m_Attributes.Get_Field_Count() )
490  {
491  m_Z_Name = i;
492 
493  return( true );
494  }
495 
496  return( false );
497 }
498 
500 {
501  return( m_Z_Name >= 0 && m_Z_Name < m_Attributes.Get_Field_Count() ? m_Z_Name : m_Z_Attribute );
502 }
503 
504 //---------------------------------------------------------
505 bool CSG_Grids::Add_Attribute(const char *Name, TSG_Data_Type Type, int Insert) { return( Add_Attribute(CSG_String(Name), Type, Insert) ); }
506 bool CSG_Grids::Add_Attribute(const wchar_t *Name, TSG_Data_Type Type, int Insert) { return( Add_Attribute(CSG_String(Name), Type, Insert) ); }
507 bool CSG_Grids::Add_Attribute(const CSG_String &Name, TSG_Data_Type Type, int Insert)
508 {
509  return( m_Attributes.Add_Field(Name, Type, Insert) );
510 }
511 
512 //---------------------------------------------------------
514 {
515  if( i != m_Z_Attribute && m_Attributes.Get_Field_Count() > 0 && m_Attributes.Del_Field(i) )
516  {
517  if( m_Z_Attribute > i )
518  {
519  m_Z_Attribute--;
520  }
521 
522  if( m_Z_Name > i )
523  {
524  m_Z_Name--;
525  }
526  else if( m_Z_Name == i )
527  {
528  m_Z_Name = -1; // same as m_Z_Attribute
529  }
530 
531  return( true );
532  }
533 
534  return( false );
535 }
536 
537 //---------------------------------------------------------
538 bool CSG_Grids::Set_Attribute(int i, const char *Field, const char *Value) { return( Set_Attribute(i, m_Attributes.Get_Field(Field), CSG_String(Value)) ); }
539 bool CSG_Grids::Set_Attribute(int i, const wchar_t *Field, const wchar_t *Value) { return( Set_Attribute(i, m_Attributes.Get_Field(Field), CSG_String(Value)) ); }
540 bool CSG_Grids::Set_Attribute(int i, const CSG_String &Field, const CSG_String &Value) { return( Set_Attribute(i, m_Attributes.Get_Field(Field), Value ) ); }
541 bool CSG_Grids::Set_Attribute(int i, int Field, const CSG_String &Value)
542 {
543  return( i >= 0 && i < (int)m_Attributes.Get_Count() && m_Attributes[i].Set_Value(Field, Value) );
544 }
545 
546 //---------------------------------------------------------
547 bool CSG_Grids::Set_Attribute(int i, const char *Field, double Value) { return( Set_Attribute(i, m_Attributes.Get_Field(Field), Value) ); }
548 bool CSG_Grids::Set_Attribute(int i, const wchar_t *Field, double Value) { return( Set_Attribute(i, m_Attributes.Get_Field(Field), Value) ); }
549 bool CSG_Grids::Set_Attribute(int i, const CSG_String &Field, double Value) { return( Set_Attribute(i, m_Attributes.Get_Field(Field), Value) ); }
550 bool CSG_Grids::Set_Attribute(int i, int Field, double Value)
551 {
552  return( i >= 0 && i < (int)m_Attributes.Get_Count() && m_Attributes[i].Set_Value(Field, Value) );
553 }
554 
555 //---------------------------------------------------------
556 bool CSG_Grids::Set_Z(int i, double Value)
557 {
558  return( i >= 0 && i < Get_NZ() && m_Attributes[i].Set_Value(m_Z_Attribute, Value) );
559 }
560 
561 //---------------------------------------------------------
563 {
564  bool bChanged = false;
565 
566  CSG_Table Attributes(m_Attributes);
567 
568  if( Attributes.Set_Index(m_Z_Attribute, TABLE_INDEX_Ascending) )
569  {
570  CSG_Array_Pointer Grids; CSG_Grid **pGrids = (CSG_Grid **)Grids.Create(m_Grids);
571 
572  for(int i=0; i<Get_Grid_Count(); i++)
573  {
574  int Index = (int)Attributes[i].Get_Index();
575 
576  if( Index != i )
577  {
578  bChanged = true;
579 
580  m_pGrids[i] = pGrids[Index];
581 
582  m_Attributes[i].Assign(&Attributes[i]);
583  }
584  }
585 
586  for(int i=0; i<Get_Grid_Count(); i++)
587  {
588  pGrids[i]->Set_Name(Get_Grid_Name(i));
589  }
590  }
591 
592  return( bChanged );
593 }
594 
595 
597 // //
598 // //
599 // //
601 
602 //---------------------------------------------------------
604 {
605  if( Count == Get_NZ() )
606  {
607  return( true );
608  }
609 
610  if( Count < 0 || !Get_System().is_Valid() ) // only allowed for initialized grid systems)
611  {
612  return( false );
613  }
614 
615  if( Count == 0 )
616  {
617  return( Del_Grids() );
618  }
619 
620  //-----------------------------------------------------
621  SG_FREE_SAFE(m_Index); // invalidate index
622 
623  if( Count < Get_NZ() )
624  {
625  for(int i=Count; i<Get_NZ(); i++)
626  {
627  delete(m_pGrids[i]);
628  }
629 
630  m_pGrids = (CSG_Grid **)m_Grids.Get_Array(Count);
631 
632  m_Attributes.Set_Count(Count);
633  }
634 
635  //-----------------------------------------------------
636  else if( Count > Get_NZ() )
637  {
638  double z = Get_ZMax();
639 
640  for(int i=Get_NZ(); i<=Count; i++, z+=Get_Cellsize())
641  {
642  if( !Add_Grid(z) )
643  {
644  return( false );
645  }
646  }
647  }
648 
649  return( true );
650 }
651 
652 
654 // //
656 
657 //---------------------------------------------------------
658 bool CSG_Grids::Add_Grid(double Z)
659 {
660  CSG_Table Attributes(&m_Attributes);
661 
662  Attributes.Add_Record();
663 
664  Attributes[0].Set_Value(m_Z_Attribute, Z);
665 
666  return( Add_Grid(Attributes[0]) );
667 }
668 
669 //---------------------------------------------------------
670 bool CSG_Grids::Add_Grid(double Z, CSG_Grid *pGrid, bool bAttach)
671 {
672  CSG_Table Attributes(&m_Attributes);
673 
674  Attributes.Add_Record();
675 
676  Attributes[0].Set_Value(m_Z_Attribute, Z);
677 
678  return( Add_Grid(Attributes[0], pGrid, bAttach) );
679 }
680 
681 //---------------------------------------------------------
683 {
684  if( !Get_System().is_Valid() ) // only allowed for initialized grid systems
685  {
686  return( false );
687  }
688 
689  //-----------------------------------------------------
690  int n = Get_NZ();
691 
692  if( n < 1 ) // do some initializations
693  {
694  _Synchronize(m_pGrids[0]);
695  }
696  else // use dummy grid (m_pGrids[0] is always present)
697  {
699 
700  if( !pGrid )
701  {
702  return( false );
703  }
704 
705  m_pGrids = (CSG_Grid **)m_Grids.Get_Array(n + 1);
706  m_pGrids[n] = pGrid;
707 
708  _Synchronize(pGrid);
709  }
710 
711  //-----------------------------------------------------
712  m_Attributes.Add_Record(&Attributes);
713 
714  SG_FREE_SAFE(m_Index); // invalidate index
715 
716  Update_Z_Order();
717 
718  return( true );
719 }
720 
721 //---------------------------------------------------------
722 bool CSG_Grids::Add_Grid(CSG_Table_Record &Attributes, CSG_Grid *pGrid, bool bAttach)
723 {
724  if( !pGrid || !pGrid->is_Valid() )
725  {
726  return( false );
727  }
728 
729  if( Get_NZ() > 0 && !is_Compatible(pGrid) ) // not allowed
730  {
731  return( false );
732  }
733 
734  //-----------------------------------------------------
735  int n = Get_NZ();
736 
737  if( n > 0 )
738  {
739  if( !bAttach && (pGrid = SG_Create_Grid(*pGrid)) == NULL ) // get a copy
740  {
741  return( false );
742  }
743 
744  m_pGrids = (CSG_Grid **)m_Grids.Get_Array(n + 1);
745  m_pGrids[n] = pGrid;
746  }
747  else if( bAttach ) // if( n == 0 )
748  {
749  delete(m_pGrids[0]);
750 
751  m_pGrids[0] = pGrid; // simply replace dummy
752  }
753  else if( m_pGrids[0]->Create(*pGrid) ) // make dummy a copy of grid
754  {
755  pGrid = m_pGrids[0];
756  }
757  else
758  {
759  return( false );
760  }
761 
762  _Synchronize(pGrid);
763 
764  //-----------------------------------------------------
765  m_Attributes.Add_Record(&Attributes);
766 
767  if( !Get_Projection().is_Okay() && pGrid->Get_Projection().is_Okay() )
768  {
769  Get_Projection() = pGrid->Get_Projection();
770  }
771 
772  SG_FREE_SAFE(m_Index); // invalidate index
773 
774  Update_Z_Order();
775 
776  return( true );
777 }
778 
779 
781 // //
783 
784 //---------------------------------------------------------
785 bool CSG_Grids::Del_Grid(int i, bool bDetach)
786 {
787  if( m_Attributes.Del_Record(i) ) // Get_NZ() is now decreased by one
788  {
789  SG_FREE_SAFE(m_Index); // invalidate index
790 
791  if( Get_NZ() > 0 )
792  {
793  if( bDetach )
794  {
795  m_pGrids[i]->Set_Owner(NULL);
796  }
797  else
798  {
799  delete(m_pGrids[i]);
800  }
801 
802  for( ; i<Get_NZ(); i++)
803  {
804  m_pGrids[i] = m_pGrids[i + 1];
805  }
806 
807  m_pGrids = (CSG_Grid **)m_Grids.Get_Array(Get_NZ());
808  }
809  else if( bDetach ) // if( Get_NZ() == 0 )
810  {
811  m_pGrids[0]->Set_Owner(NULL);
812  m_pGrids[0] = SG_Create_Grid(*m_pGrids[0]); // needs a new dummy
813  m_pGrids[0]->Set_Owner(this);
814  }
815 
816  return( true );
817  }
818 
819  return( false );
820 }
821 
822 //---------------------------------------------------------
823 bool CSG_Grids::Del_Grids(bool bDetach)
824 {
825  SG_FREE_SAFE(m_Index); // invalidate index
826 
827  if( bDetach )
828  {
829  for(size_t i=0; i<m_Grids.Get_uSize(); i++)
830  {
831  if( m_pGrids[i]->Get_Owner() == this )
832  {
833  m_pGrids[i]->Set_Owner(NULL);
834  }
835  }
836 
837  m_pGrids[0] = SG_Create_Grid(*m_pGrids[0]); // needs a new dummy
838  m_pGrids[0]->Set_Owner(this);
839  }
840  else
841  {
842  for(size_t i=1; i<m_Grids.Get_uSize(); i++)
843  {
844  delete(m_pGrids[i]); // do not delete the dummy before deconstruction
845  }
846  }
847 
848  m_pGrids = (CSG_Grid **)m_Grids.Get_Array(1);
849 
850  m_Attributes.Del_Records();
851 
852  return( true );
853 }
854 
855 
857 // //
859 
860 //---------------------------------------------------------
861 CSG_String CSG_Grids::Get_Grid_Name(int i, int Style) const
862 {
863  CSG_String s;
864 
865  if( i >= 0 && i < Get_Grid_Count() )
866  {
867  if( Style == 0 )
868  {
870  }
871 
872  if( (Style & SG_GRIDS_NAME_OWNER) != 0 )
873  {
874  s = CSG_String(Get_Name());
875  }
876 
877  if( (Style & SG_GRIDS_NAME_INDEX) != 0 )
878  {
879  if( !s.is_Empty() ) s += ".";
880 
881  s.Printf("%s %d", _TL("Band"), i + 1);
882  }
883 
884  if( (Style & SG_GRIDS_NAME_VALUE) != 0 )
885  {
886  if( !s.is_Empty() ) s += ".";
887 
888  s += SG_Get_String(Get_Z(i), -10);
889  }
890 
891  if( (Style & SG_GRIDS_NAME_GRID ) != 0 )
892  {
893  if( !s.is_Empty() ) s += ".";
894 
895  s += m_Attributes[i].asString(Get_Z_Name_Field());
896  }
897  }
898 
899  return( s );
900 }
901 
902 
904 // //
905 // //
906 // //
908 
909 //---------------------------------------------------------
911 {
912  for(int i=0; i<Get_Grid_Count(); i++)
913  {
914  m_pGrids[i]->Assign_NoData();
915  }
916 }
917 
918 //---------------------------------------------------------
919 bool CSG_Grids::Assign(double Value)
920 {
921  for(int i=0; i<Get_Grid_Count(); i++)
922  {
923  m_pGrids[i]->Assign(Value);
924  }
925 
926  return( true );
927 }
928 
929 //---------------------------------------------------------
931 {
932  if( pObject )
933  {
934  switch( pObject->Get_ObjectType() )
935  {
937  {
938  bool bResult = true;
939 
940  for(int i=0; i<Get_Grid_Count(); i++)
941  {
942  if( !m_pGrids[i]->Assign((CSG_Grid *)pObject) )
943  {
944  bResult = false;
945  }
946  }
947 
948  return( bResult );
949  }
950 
952  return( Assign((CSG_Grids *)pObject) );
953 
954  default:
955  break;
956  }
957  }
958 
959  return( false );
960 }
961 
962 //---------------------------------------------------------
963 bool CSG_Grids::Assign(CSG_Grids *pGrids, TSG_Grid_Resampling Interpolation)
964 {
965  if( pGrids && Get_Grid_Count() == pGrids->Get_Grid_Count() )
966  {
967  bool bResult = true;
968 
969  for(int i=0; i<Get_Grid_Count(); i++)
970  {
971  if( !m_pGrids[i]->Assign(pGrids->m_pGrids[i], Interpolation) )
972  {
973  bResult = false;
974  }
975  }
976 
977  return( bResult );
978  }
979 
980  return( false );
981 }
982 
983 
985 // //
987 
988 //---------------------------------------------------------
990 {
991  Create(Grids); return( *this );
992 }
993 
995 {
996  Assign(Value); return( *this );
997 }
998 
999 //---------------------------------------------------------
1001 {
1002  return( Add(Value) );
1003 }
1004 
1005 CSG_Grids & CSG_Grids::Add(double Value)
1006 {
1007  for(int i=0; i<Get_Grid_Count(); i++)
1008  {
1009  m_pGrids[i]->Add(Value);
1010  }
1011 
1012  return( *this );
1013 }
1014 
1015 //---------------------------------------------------------
1017 {
1018  return( Subtract(Value) );
1019 }
1020 
1022 {
1023  for(int i=0; i<Get_Grid_Count(); i++)
1024  {
1025  m_pGrids[i]->Subtract(Value);
1026  }
1027 
1028  return( *this );
1029 }
1030 
1031 //---------------------------------------------------------
1033 {
1034  return( Multiply(Value) );
1035 }
1036 
1038 {
1039  for(int i=0; i<Get_Grid_Count(); i++)
1040  {
1041  m_pGrids[i]->Multiply(Value);
1042  }
1043 
1044  return( *this );
1045 }
1046 
1047 //---------------------------------------------------------
1049 {
1050  return( Divide(Value) );
1051 }
1052 
1054 {
1055  for(int i=0; i<Get_Grid_Count(); i++)
1056  {
1057  m_pGrids[i]->Divide(Value);
1058  }
1059 
1060  return( *this );
1061 }
1062 
1063 
1065 // //
1066 // Value access by Position (-> Interpolation) //
1067 // //
1069 
1070 //---------------------------------------------------------
1071 double CSG_Grids::Get_Value(const TSG_Point_3D &p, TSG_Grid_Resampling Resampling, TSG_Grid_Resampling ZResampling) const
1072 {
1073  double Value;
1074 
1075  return( Get_Value(p.x, p.y, p.z, Value, Resampling, ZResampling) ? Value : Get_NoData_Value() );
1076 }
1077 
1078 double CSG_Grids::Get_Value(double x, double y, double z, TSG_Grid_Resampling Resampling, TSG_Grid_Resampling ZResampling) const
1079 {
1080  double Value;
1081 
1082  return( Get_Value(x, y, z, Value, Resampling, ZResampling) ? Value : Get_NoData_Value() );
1083 }
1084 
1085 bool CSG_Grids::Get_Value(const TSG_Point_3D &p, double &Value, TSG_Grid_Resampling Resampling, TSG_Grid_Resampling ZResampling) const
1086 {
1087  return( Get_Value(p.x, p.y, p.z, Value, Resampling, ZResampling) );
1088 }
1089 
1090 //---------------------------------------------------------
1091 bool CSG_Grids::Get_Value(double x, double y, double z, double &Value, TSG_Grid_Resampling Resampling, TSG_Grid_Resampling ZResampling) const
1092 {
1093  if( !Get_System().Get_Extent(true).Contains(x, y) )
1094  {
1095  return( false );
1096  }
1097 
1098  int iz; double dz;
1099 
1100  if( !_Get_Z(z, iz, dz) )
1101  {
1102  return( false );
1103  }
1104 
1105  if( dz == 0. )
1106  {
1107  return( m_pGrids[iz]->Get_Value(x, y, Value, Resampling) );
1108  }
1109 
1110  if( ZResampling == GRID_RESAMPLING_Undefined )
1111  {
1112  ZResampling = Resampling;
1113  }
1114 
1115  if( (ZResampling == GRID_RESAMPLING_BicubicSpline || ZResampling == GRID_RESAMPLING_BSpline)
1116  && (iz < 1 || iz >= m_Attributes.Get_Count() - 2) )
1117  {
1118  ZResampling = GRID_RESAMPLING_Bilinear;
1119  }
1120 
1121  switch( ZResampling )
1122  {
1123  case GRID_RESAMPLING_NearestNeighbour: default:
1124  return( m_pGrids[dz < 0.5 ? iz : iz + 1]->Get_Value(x, y, Value, Resampling) );
1125 
1127  {
1128  double v[2];
1129 
1130  if( m_pGrids[iz ]->Get_Value(x, y, v[0], Resampling)
1131  && m_pGrids[iz + 1]->Get_Value(x, y, v[1], Resampling) )
1132  {
1133  Value = v[0] + dz * (v[1] - v[0]);
1134 
1135  return( true );
1136  }
1137 
1138  return( false );
1139  }
1140 
1143  {
1144  CSG_Spline s;
1145 
1146  #define ADD_TO_SPLINE(i) if( i < 0 || i >= Get_NZ() || !m_pGrids[i]->Get_Value(x, y, Value, Resampling) ) return( false ); s.Add(Get_Z(i), Value);
1147 
1148  ADD_TO_SPLINE(iz - 1);
1149  ADD_TO_SPLINE(iz );
1150  ADD_TO_SPLINE(iz + 1);
1151  ADD_TO_SPLINE(iz + 2);
1152 
1153  return( s.Get_Value(z, Value) );
1154  }
1155  break;
1156  }
1157 
1158  return( false );
1159 }
1160 
1161 //---------------------------------------------------------
1162 bool CSG_Grids::_Get_Z(double z, int &iz, double &dz) const
1163 {
1164  if( z < m_Attributes[0 ].asDouble(m_Z_Attribute)
1165  || z > m_Attributes[m_Attributes.Get_Count() - 1].asDouble(m_Z_Attribute) )
1166  {
1167  return( false );
1168  }
1169 
1170  double z0, z1 = m_Attributes[0].asDouble(m_Z_Attribute);
1171 
1172  for(iz=0; iz<m_Attributes.Get_Count()-1; iz++)
1173  {
1174  z0 = z1; z1 = m_Attributes[iz + 1].asDouble(m_Z_Attribute);
1175 
1176  if( z < z1 )
1177  {
1178  dz = z0 < z1 ? (z - z0) / (z1 - z0) : 0.;
1179 
1180  return( true );
1181  }
1182  }
1183 
1184  return( (dz = z - z1) == 0. );
1185 }
1186 
1187 
1189 // //
1190 // Index //
1191 // //
1193 
1194 //---------------------------------------------------------
1195 #define SORT_SWAP(a,b) {itemp=(a);(a)=(b);(b)=itemp;}
1196 
1197 bool CSG_Grids::_Set_Index(void)
1198 {
1199  //-----------------------------------------------------
1200  if( m_Index == NULL && (m_Index = (sLong *)SG_Malloc((size_t)Get_NCells() * sizeof(sLong))) == NULL )
1201  {
1202  SG_UI_Msg_Add_Error(_TL("could not create index: insufficient memory"));
1203 
1204  return( false );
1205  }
1206 
1207  //-----------------------------------------------------
1208  const sLong M = 7;
1209 
1210  sLong i, j, k, l, ir, n, *istack, jstack, nstack, indxt, itemp, nData;
1211  double a;
1212 
1213  //-----------------------------------------------------
1214  SG_UI_Process_Set_Text(CSG_String::Format("%s: %s", _TL("Create index"), Get_Name()));
1215 
1216  for(i=0, j=0, nData=Get_NCells(); i<Get_NCells(); i++)
1217  {
1218  if( is_NoData(i) )
1219  {
1220  m_Index[--nData] = i;
1221  }
1222  else // if( !is_NoData(i) )
1223  {
1224  m_Index[j++] = i;
1225  }
1226  }
1227 
1228  //-----------------------------------------------------
1229  l = 0;
1230  n = 0;
1231  ir = nData - 1;
1232 
1233  nstack = 64;
1234  istack = (sLong *)SG_Malloc((size_t)nstack * sizeof(sLong));
1235  jstack = 0;
1236 
1237  for(;;)
1238  {
1239  if( ir - l < M )
1240  {
1241  if( !SG_UI_Process_Set_Progress((double)(n += M - 1), (double)nData) )
1242  {
1243  SG_FREE_SAFE(istack);
1244  SG_FREE_SAFE(m_Index);
1245 
1246  SG_UI_Msg_Add_Error(_TL("index creation stopped by user"));
1248 
1249  return( false );
1250  }
1251 
1252  for(j=l+1; j<=ir; j++)
1253  {
1254  indxt = m_Index[j];
1255  a = asDouble(indxt);
1256 
1257  for(i=j-1; i>=0; i--)
1258  {
1259  if( asDouble(m_Index[i]) <= a )
1260  {
1261  break;
1262  }
1263 
1264  m_Index[i + 1] = m_Index[i];
1265  }
1266 
1267  m_Index[i + 1] = indxt;
1268  }
1269 
1270  if( jstack == 0 )
1271  {
1272  break;
1273  }
1274 
1275  ir = istack[jstack--];
1276  l = istack[jstack--];
1277  }
1278 
1279  //-------------------------------------------------
1280  else
1281  {
1282  k = (l + ir) >> 1;
1283 
1284  SORT_SWAP(m_Index[k], m_Index[l + 1]);
1285 
1286  if( asDouble( m_Index[l + 1]) > asDouble(m_Index[ir]) )
1287  SORT_SWAP(m_Index[l + 1], m_Index[ir]);
1288 
1289  if( asDouble( m_Index[l ]) > asDouble(m_Index[ir]) )
1290  SORT_SWAP(m_Index[l ], m_Index[ir]);
1291 
1292  if( asDouble( m_Index[l + 1]) > asDouble(m_Index[l ]) )
1293  SORT_SWAP(m_Index[l + 1], m_Index[l ]);
1294 
1295  i = l + 1;
1296  j = ir;
1297  indxt = m_Index[l];
1298  a = asDouble(indxt);
1299 
1300  for(;;)
1301  {
1302  do i++; while(asDouble(m_Index[i]) < a);
1303  do j--; while(asDouble(m_Index[j]) > a);
1304 
1305  if( j < i )
1306  {
1307  break;
1308  }
1309 
1310  SORT_SWAP(m_Index[i], m_Index[j]);
1311  }
1312 
1313  m_Index[l] = m_Index[j];
1314  m_Index[j] = indxt;
1315  jstack += 2;
1316 
1317  if( jstack >= nstack )
1318  {
1319  nstack += 64;
1320  istack = (sLong *)SG_Realloc(istack, (size_t)nstack * sizeof(int));
1321  }
1322 
1323  if( ir - i + 1 >= j - l )
1324  {
1325  istack[jstack] = ir;
1326  istack[jstack - 1] = i;
1327  ir = j - 1;
1328  }
1329  else
1330  {
1331  istack[jstack] = j - 1;
1332  istack[jstack - 1] = l;
1333  l = i;
1334  }
1335  }
1336  }
1337 
1338  //-----------------------------------------------------
1339  SG_Free(istack);
1340 
1342 
1343  return( true );
1344 }
1345 #undef SORT_SWAP
1346 
1347 
1349 // //
1350 // Statistics //
1351 // //
1353 
1354 //---------------------------------------------------------
1356 {
1357  if( is_Valid() )
1358  {
1359  SG_FREE_SAFE(m_Index);
1360 
1361  m_Statistics.Invalidate();
1362  m_Histogram.Destroy();
1363 
1364  double Offset = Get_Offset(), Scaling = is_Scaled() ? Get_Scaling() : 0.;
1365 
1366  if( Get_Max_Samples() > 0 && Get_Max_Samples() < Get_NCells() )
1367  {
1368  double d = (double)Get_NCells() / (double)Get_Max_Samples();
1369 
1370  for(double i=0; i<(double)Get_NCells(); i+=d)
1371  {
1372  double Value = asDouble((sLong)i, false);
1373 
1374  if( !is_NoData_Value(Value) )
1375  {
1376  m_Statistics += Scaling ? Offset + Scaling * Value : Value;
1377  }
1378  }
1379 
1380  m_Statistics.Set_Count(m_Statistics.Get_Count() >= Get_Max_Samples() ? Get_NCells() // any no-data cells ?
1381  : (sLong)(Get_NCells() * (double)m_Statistics.Get_Count() / (double)Get_Max_Samples())
1382  );
1383  }
1384  else
1385  {
1386  for(sLong i=0; i<Get_NCells(); i++)
1387  {
1388  double Value = asDouble(i, false);
1389 
1390  if( !is_NoData_Value(Value) )
1391  {
1392  m_Statistics += Scaling ? Offset + Scaling * Value : Value;
1393  }
1394  }
1395  }
1396  }
1397 
1398  return( true );
1399 }
1400 
1401 //---------------------------------------------------------
1403 {
1404  Update(); return( m_Statistics.Get_Mean() );
1405 }
1406 
1408 {
1409  Update(); return( m_Statistics.Get_Minimum() );
1410 }
1411 
1413 {
1414  Update(); return( m_Statistics.Get_Maximum() );
1415 }
1416 
1418 {
1419  Update(); return( m_Statistics.Get_Range() );
1420 }
1421 
1423 {
1424  Update(); return( m_Statistics.Get_StdDev() );
1425 }
1426 
1428 {
1429  Update(); return( m_Statistics.Get_Variance() );
1430 }
1431 
1432 //---------------------------------------------------------
1434 {
1435  Update(); return( m_Statistics.Get_Count() );
1436 }
1437 
1439 {
1440  Update(); return( Get_NCells() - m_Statistics.Get_Count() );
1441 }
1442 
1443 //---------------------------------------------------------
1444 double CSG_Grids::Get_Quantile(double Quantile, bool bFromHistogram)
1445 {
1446  if( Quantile <= 0. ) { return( Get_Min() ); }
1447  if( Quantile >= 1. ) { return( Get_Max() ); }
1448 
1449  if( bFromHistogram )
1450  {
1451  return( Get_Histogram().Get_Quantile(Quantile) );
1452  }
1453  else
1454  {
1455  sLong n = (sLong)(Quantile * (Get_Data_Count() - 1));
1456 
1457  if( Get_Sorted(n, n, false) )
1458  {
1459  return( asDouble(n) );
1460  }
1461  }
1462 
1463  return( Get_NoData_Value() );
1464 }
1465 
1466 //---------------------------------------------------------
1467 double CSG_Grids::Get_Percentile(double Percentile, bool bFromHistogram)
1468 {
1469  return( Get_Quantile(0.01 * Percentile, bFromHistogram) );
1470 }
1471 
1472 
1474 // //
1476 
1477 //---------------------------------------------------------
1485 {
1486  Update(); return( m_Statistics );
1487 }
1488 
1489 //---------------------------------------------------------
1495 //---------------------------------------------------------
1496 bool CSG_Grids::Get_Statistics(const CSG_Rect &rWorld, CSG_Simple_Statistics &Statistics, bool bHoldValues) const
1497 {
1498  int xMin = Get_System().Get_xWorld_to_Grid(rWorld.Get_XMin()); if( xMin < 0 ) xMin = 0;
1499  int yMin = Get_System().Get_yWorld_to_Grid(rWorld.Get_YMin()); if( yMin < 0 ) yMin = 0;
1500  int xMax = Get_System().Get_xWorld_to_Grid(rWorld.Get_XMax()); if( xMax >= Get_NX() ) xMax = Get_NX() - 1;
1501  int yMax = Get_System().Get_yWorld_to_Grid(rWorld.Get_YMax()); if( yMax >= Get_NY() ) yMax = Get_NY() - 1;
1502 
1503  if( xMin > xMax || yMin > yMax )
1504  {
1505  return( false ); // no overlap
1506  }
1507 
1508  Statistics.Create(bHoldValues);
1509 
1510  int nx = 1 + (xMax - xMin);
1511  int ny = 1 + (yMax - yMin);
1512  sLong nCells = nx * ny;
1513 
1514  double Offset = Get_Offset(), Scaling = is_Scaled() ? Get_Scaling() : 0.;
1515 
1516  if( Get_Max_Samples() > 0 && Get_Max_Samples() < nCells )
1517  {
1518  double d = (double)nCells / (double)Get_Max_Samples();
1519 
1520  for(double i=0; i<(double)nCells; i+=d)
1521  {
1522  int y = yMin + (int)i / nx;
1523  int x = xMin + (int)i % nx;
1524 
1525  for(int z=0; z<Get_NZ(); z++)
1526  {
1527  double Value = asDouble(x, y, z, false);
1528 
1529  if( !is_NoData_Value(Value) )
1530  {
1531  Statistics += Scaling ? Offset + Scaling * Value : Value;
1532  }
1533  }
1534  }
1535  }
1536  else
1537  {
1538  for(int x=xMin; x<=xMax; x++)
1539  {
1540  for(int y=yMin; y<=yMax; y++)
1541  {
1542  for(int z=0; z<Get_NZ(); z++)
1543  {
1544  double Value = asDouble(x, y, z, false);
1545 
1546  if( !is_NoData_Value(Value) )
1547  {
1548  Statistics += Scaling ? Offset + Scaling * Value : Value;
1549  }
1550  }
1551  }
1552  }
1553  }
1554 
1555  return( Statistics.Get_Count() > 0 );
1556 }
1557 
1558 //---------------------------------------------------------
1560 {
1561  if( CSG_Data_Object::Set_Max_Samples(Max_Samples) )
1562  {
1563  for(int i=0; i<Get_Grid_Count(); i++)
1564  {
1565  Get_Grid_Ptr(i)->Set_Max_Samples(Max_Samples);
1566  }
1567 
1568  return( true );
1569  }
1570 
1571  return( false );
1572 }
1573 
1574 //---------------------------------------------------------
1575 #define SG_GRID_HISTOGRAM_CLASSES_DEFAULT 255
1576 
1577 //---------------------------------------------------------
1582 const CSG_Histogram & CSG_Grids::Get_Histogram(size_t nClasses)
1583 {
1584  Update();
1585 
1586  if( nClasses > 1 && nClasses != m_Histogram.Get_Class_Count() )
1587  {
1588  m_Histogram.Destroy();
1589  }
1590 
1591  if( m_Histogram.Get_Statistics().Get_Count() < 1 )
1592  {
1593  m_Histogram.Create(nClasses > 1 ? nClasses : SG_GRID_HISTOGRAM_CLASSES_DEFAULT, Get_Min(), Get_Max(), this, (size_t)Get_Max_Samples());
1594  }
1595 
1596  return( m_Histogram );
1597 }
1598 
1599 //---------------------------------------------------------
1600 bool CSG_Grids::Get_Histogram(const CSG_Rect &rWorld, CSG_Histogram &Histogram, size_t nClasses) const
1601 {
1602  CSG_Simple_Statistics Statistics;
1603 
1604  if( !Get_Statistics(rWorld, Statistics) )
1605  {
1606  return( false );
1607  }
1608 
1609  int xMin = Get_System().Get_xWorld_to_Grid(rWorld.Get_XMin()); if( xMin < 0 ) xMin = 0;
1610  int yMin = Get_System().Get_yWorld_to_Grid(rWorld.Get_YMin()); if( yMin < 0 ) yMin = 0;
1611  int xMax = Get_System().Get_xWorld_to_Grid(rWorld.Get_XMax()); if( xMax >= Get_NX() ) xMax = Get_NX() - 1;
1612  int yMax = Get_System().Get_yWorld_to_Grid(rWorld.Get_YMax()); if( yMax >= Get_NY() ) yMax = Get_NY() - 1;
1613 
1614  if( xMin > xMax || yMin > yMax )
1615  {
1616  return( false ); // no overlap
1617  }
1618 
1619  Histogram.Create(nClasses > 1 ? nClasses : SG_GRID_HISTOGRAM_CLASSES_DEFAULT, Statistics.Get_Minimum(), Statistics.Get_Maximum());
1620 
1621  int nx = 1 + (xMax - xMin);
1622  int ny = 1 + (yMax - yMin);
1623  sLong nCells = nx * ny;
1624 
1625  double Offset = Get_Offset(), Scaling = is_Scaled() ? Get_Scaling() : 0.;
1626 
1627  if( Get_Max_Samples() > 0 && Get_Max_Samples() < nCells )
1628  {
1629  double d = (double)nCells / (double)Get_Max_Samples();
1630 
1631  for(double i=0; i<(double)nCells; i+=d)
1632  {
1633  int y = yMin + (int)i / nx;
1634  int x = xMin + (int)i % nx;
1635 
1636  for(int z=0; z<Get_NZ(); z++)
1637  {
1638  double Value = asDouble(x, y, z, false);
1639 
1640  if( !is_NoData_Value(Value) )
1641  {
1642  Histogram += Scaling ? Offset + Scaling * Value : Value;
1643  }
1644  }
1645  }
1646  }
1647  else
1648  {
1649  for(int x=xMin; x<=xMax; x++)
1650  {
1651  for(int y=yMin; y<=yMax; y++)
1652  {
1653  for(int z=0; z<Get_NZ(); z++)
1654  {
1655  double Value = asDouble(x, y, z, false);
1656 
1657  if( !is_NoData_Value(Value) )
1658  {
1659  Histogram += Scaling ? Offset + Scaling * Value : Value;
1660  }
1661  }
1662  }
1663  }
1664  }
1665 
1666  return( Histogram.Update() );
1667 }
1668 
1669 
1671 // //
1672 // //
1673 // //
1675 
1676 //---------------------------------------------------------
1678 {
1679  return( Create(Get_File_Name(false)) );
1680 }
1681 
1682 //---------------------------------------------------------
1684 {
1685  CSG_String FileName = Get_File_Name(true);
1686 
1687  SG_File_Set_Extension(FileName, "sg-gds-z"); SG_File_Delete(FileName);
1688  SG_File_Set_Extension(FileName, "sg-gds" ); SG_File_Delete(FileName);
1689  SG_File_Set_Extension(FileName, "sg-info" ); SG_File_Delete(FileName);
1690  SG_File_Set_Extension(FileName, "sg-prj" ); SG_File_Delete(FileName);
1691 
1692  int i = 0;
1693 
1694  do
1695  {
1696  SG_File_Set_Extension(FileName, CSG_String::Format("sg-%03d", ++i));
1697  }
1698  while( SG_File_Delete(FileName) );
1699 
1700  return( true );
1701 }
1702 
1703 
1705 // //
1707 
1708 //---------------------------------------------------------
1709 bool CSG_Grids::Load(const CSG_String &FileName, bool bLoadData)
1710 {
1711  Destroy();
1712 
1713  SG_UI_Msg_Add(CSG_String::Format("%s: %s...", _TL("Loading grid collection"), FileName.c_str()), true);
1714 
1715  if( _Load_PGSQL (FileName)
1716  || _Load_Normal (FileName)
1717  || _Load_Compressed(FileName)
1718  || _Load_External (FileName) )
1719  {
1720  Set_Modified(false);
1721 
1722  Set_Name(SG_File_Get_Name(FileName, false));
1723 
1725  SG_UI_Msg_Add(_TL("okay"), false, SG_UI_MSG_STYLE_SUCCESS);
1726 
1727  return( true );
1728  }
1729 
1731  SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);
1732 
1733  return( false );
1734 }
1735 
1736 //---------------------------------------------------------
1737 bool CSG_Grids::Save(const CSG_String &FileName, int Format)
1738 {
1739  SG_UI_Msg_Add(CSG_String::Format("%s %s: %s...", _TL("Saving"), _TL("grid collection"), FileName.c_str()), true);
1740 
1741  if( Format == GRIDS_FILE_FORMAT_Undefined )
1742  {
1743  Format = GRIDS_FILE_FORMAT_Compressed; // default
1744 
1745  if( SG_File_Cmp_Extension(FileName, "sg-gds" ) ) Format = GRIDS_FILE_FORMAT_Normal ;
1746  if( SG_File_Cmp_Extension(FileName, "sg-gds-z") ) Format = GRIDS_FILE_FORMAT_Compressed;
1747  if( SG_File_Cmp_Extension(FileName, "tif" ) ) Format = GRIDS_FILE_FORMAT_GeoTIFF ;
1748  }
1749 
1750  bool bResult = false;
1751 
1752  switch( Format )
1753  {
1755  bResult = _Save_Normal (FileName);
1756  break;
1757 
1758  case GRIDS_FILE_FORMAT_Compressed: default:
1759  bResult = _Save_Compressed(FileName);
1760  break;
1761 
1763  SG_RUN_TOOL(bResult, "io_gdal", 2, // Export GeoTIFF
1764  SG_TOOL_PARAMLIST_ADD("GRIDS", this)
1765  && SG_TOOL_PARAMETER_SET("FILE" , FileName)
1766  );
1767  break;
1768  }
1769 
1770  //-----------------------------------------------------
1772 
1773  if( bResult )
1774  {
1775  Set_Modified(false);
1776 
1777  Set_File_Name(FileName, true);
1778 
1779  SG_UI_Msg_Add(_TL("okay"), false, SG_UI_MSG_STYLE_SUCCESS);
1780 
1781  return( true );
1782  }
1783 
1784  SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);
1785 
1786  return( false );
1787 }
1788 
1789 
1791 // //
1793 
1794 //---------------------------------------------------------
1795 bool CSG_Grids::_Load_External(const CSG_String &FileName)
1796 {
1797  bool bResult = false; CSG_Data_Manager Manager;
1798 
1799  CSG_Tool *pTool = SG_Get_Tool_Library_Manager().Create_Tool("io_gdal", 0); // import raster
1800 
1801  SG_UI_Msg_Lock(true);
1802 
1803  if( pTool && pTool->On_Before_Execution() && pTool->Settings_Push(&Manager)
1804  && pTool->Set_Parameter("FILES" , FileName)
1805  && pTool->Set_Parameter("MULTIPLE", 1 ) // output as grid collection
1806  && pTool->Execute()
1807  && Manager.Grids().Count() && Manager.Grids(0).is_Valid() )
1808  {
1809  CSG_Grids *pGrids = Manager.Grids(0).asGrids();
1810 
1811  m_Attributes.Create(&pGrids->m_Attributes);
1812 
1813  for(int i=0; i<pGrids->Get_Grid_Count(); i++)
1814  {
1815  Add_Grid(pGrids->Get_Attributes(i), pGrids->Get_Grid_Ptr(i), true);
1816  }
1817 
1818  Set_File_Name(FileName, false);
1819 
1820  Set_Name (pGrids->Get_Name ());
1821  Set_Description (pGrids->Get_Description ());
1822  Set_Z_Attribute (pGrids->Get_Z_Attribute ());
1824 
1825  pGrids->Del_Grids(true);
1826 
1827  bResult = true;
1828  }
1829 
1830  SG_UI_Msg_Lock(false);
1831 
1833 
1834  return( bResult );
1835 }
1836 
1837 //---------------------------------------------------------
1838 bool CSG_Grids::_Load_PGSQL(const CSG_String &FileName)
1839 {
1840  bool bResult = false;
1841 
1842  if( FileName.BeforeFirst(':').Cmp("PGSQL") == 0 ) // database source
1843  {
1844  CSG_String s(FileName);
1845 
1846  s = s.AfterFirst(':'); CSG_String Host (s.BeforeFirst(':'));
1847  s = s.AfterFirst(':'); CSG_String Port (s.BeforeFirst(':'));
1848  s = s.AfterFirst(':'); CSG_String DBName(s.BeforeFirst(':'));
1849  s = s.AfterFirst(':'); CSG_String Table (s.BeforeFirst(':'));
1850  s = s.AfterFirst(':'); CSG_String rid (s.BeforeFirst(':').AfterFirst('='));
1851 
1852  //-------------------------------------------------
1853  CSG_String_Tokenizer rids(rid, ","); rid.Clear();
1854 
1855  while( rids.Has_More_Tokens() )
1856  {
1857  if( !rid.is_Empty() )
1858  {
1859  rid += " OR ";
1860  }
1861 
1862  rid += "rid=\'" + rids.Get_Next_Token() + "\'";
1863  }
1864 
1865  //-------------------------------------------------
1866  CSG_Tool *pTool = SG_Get_Tool_Library_Manager().Create_Tool("db_pgsql", 0, true); // CGet_Connections
1867 
1868  if( pTool != NULL )
1869  {
1871 
1872  //---------------------------------------------
1873  CSG_Table Connections; CSG_String Connection = DBName + " [" + Host + ":" + Port + "]";
1874 
1875  pTool->Set_Manager(NULL);
1876  pTool->On_Before_Execution();
1877 
1878  if( SG_TOOL_PARAMETER_SET("CONNECTIONS", &Connections) && pTool->Execute() ) // CGet_Connections
1879  {
1880  for(int i=0; !bResult && i<Connections.Get_Count(); i++)
1881  {
1882  if( !Connection.Cmp(Connections[i].asString(0)) )
1883  {
1884  bResult = true;
1885  }
1886  }
1887  }
1888 
1890 
1891  //---------------------------------------------
1892  if( bResult && (bResult = (pTool = SG_Get_Tool_Library_Manager().Create_Tool("db_pgsql", 30, true)) != NULL) == true ) // CPGIS_Raster_Load
1893  {
1894  CSG_Data_Manager Manager;
1895 
1896  pTool->On_Before_Execution();
1897  pTool->Settings_Push(&Manager);
1898 
1899  bResult = SG_TOOL_PARAMETER_SET("CONNECTION", Connection)
1900  && SG_TOOL_PARAMETER_SET("TABLES" , Table)
1901  && SG_TOOL_PARAMETER_SET("MULTIPLE" , 1) // grid collection
1902  && SG_TOOL_PARAMETER_SET("WHERE" , rid)
1903  && pTool->Execute();
1904 
1906 
1907  //-----------------------------------------
1908  if( Manager.Grids().Count() && Manager.Grids(0).is_Valid() )
1909  {
1910  CSG_Grids *pGrids = Manager.Grids(0).asGrids();
1911 
1912  Set_File_Name(FileName);
1913 
1914  Create(pGrids);
1915 
1916  for(int i=0; i<pGrids->Get_Grid_Count(); i++)
1917  {
1918  Add_Grid(pGrids->Get_Attributes(i), pGrids->Get_Grid_Ptr(i), true);
1919  }
1920 
1921  pGrids->Del_Grids(true);
1922  }
1923  }
1924 
1926  }
1927  }
1928 
1929  return( Get_NZ() > 0 );
1930 }
1931 
1932 
1934 // //
1936 
1937 //---------------------------------------------------------
1938 bool CSG_Grids::_Load_Normal(const CSG_String &_FileName)
1939 {
1940  if( !SG_File_Cmp_Extension(_FileName, "sg-gds") ) // GRIDS_FILETYPE_Normal
1941  {
1942  return( false );
1943  }
1944 
1945  CSG_String FileName(_FileName);
1946 
1947  CSG_File Stream;
1948 
1949  //-----------------------------------------------------
1950  if( !Stream.Open(FileName, SG_FILE_R, false) || !_Load_Header(Stream) )
1951  {
1952  return( false );
1953  }
1954 
1955  SG_File_Set_Extension(FileName, "sg-att");
1956 
1957  if( m_Attributes.Get_Count() <= 0 ) // <<< DEPRECATED
1958  if( !Stream.Open(FileName, SG_FILE_R, false) || !_Load_Attributes(Stream) )
1959  {
1960  return( false );
1961  }
1962 
1963  //-----------------------------------------------------
1964  for(int i=0; i<Get_NZ() && SG_UI_Process_Set_Progress(i, Get_NZ()); i++)
1965  {
1966  SG_File_Set_Extension(FileName, CSG_String::Format("sg-%03d", i + 1));
1967 
1968  if( !Stream.Open(FileName, SG_FILE_R, true) || !_Load_Data(Stream, m_pGrids[i]) )
1969  {
1970  return( false );
1971  }
1972  }
1973 
1974  //-----------------------------------------------------
1975  Set_File_Name(_FileName, true);
1976 
1977  Load_MetaData(FileName);
1978 
1979  Get_Projection().Load(SG_File_Make_Path("", FileName, "sg-prj"));
1980 
1981  return( true );
1982 }
1983 
1984 //---------------------------------------------------------
1985 bool CSG_Grids::_Save_Normal(const CSG_String &_FileName)
1986 {
1987  CSG_String FileName(_FileName);
1988 
1989  CSG_File Stream;
1990 
1991  //-----------------------------------------------------
1992  SG_File_Set_Extension(FileName, "sg-gds");
1993 
1994  if( !Stream.Open(FileName, SG_FILE_W, false) || !_Save_Header(Stream) )
1995  {
1996  return( false );
1997  }
1998 
1999  SG_File_Set_Extension(FileName, "sg-att");
2000 
2001  if( !Stream.Open(FileName, SG_FILE_W, false) || !_Save_Attributes(Stream) )
2002  {
2003  return( false );
2004  }
2005 
2006  //-----------------------------------------------------
2007  for(int i=0; i<Get_NZ() && SG_UI_Process_Set_Progress(i, Get_NZ()); i++)
2008  {
2009  SG_File_Set_Extension(FileName, CSG_String::Format("sg-%03d", i + 1));
2010 
2011  if( !Stream.Open(FileName, SG_FILE_W, true) || !_Save_Data(Stream, m_pGrids[i]) )
2012  {
2013  return( false );
2014  }
2015  }
2016 
2017  //-----------------------------------------------------
2018  Save_MetaData(FileName);
2019 
2020  Get_Projection().Save(SG_File_Make_Path("", FileName, "sg-prj"));
2021 
2022  return( true );
2023 }
2024 
2025 
2027 // //
2029 
2030 //---------------------------------------------------------
2031 bool CSG_Grids::_Load_Compressed(const CSG_String &_FileName)
2032 {
2033  if( !SG_File_Cmp_Extension(_FileName, "sg-gds-z") ) // GRIDS_FILETYPE_Compressed
2034  {
2035  return( false );
2036  }
2037 
2038  CSG_File_Zip Stream(_FileName, SG_FILE_R);
2039 
2040  CSG_String FileName(SG_File_Get_Name(_FileName, false) + ".");
2041 
2042  //-----------------------------------------------------
2043  if( !Stream.Get_File(FileName + "sg-gds") || !_Load_Header(Stream) )
2044  {
2045  return( false );
2046  }
2047 
2048  if( m_Attributes.Get_Count() <= 0 ) // <<< DEPRECATED
2049  if( !Stream.Get_File(FileName + "sg-att") || !_Load_Attributes(Stream) )
2050  {
2051  return( false );
2052  }
2053 
2054  //-----------------------------------------------------
2055  for(int i=0; i<Get_NZ() && SG_UI_Process_Set_Progress(i, Get_NZ()); i++)
2056  {
2057  if( !Stream.Get_File(FileName + CSG_String::Format("sg-%03d", i + 1)) || !_Load_Data(Stream, m_pGrids[i]) )
2058  {
2059  return( false );
2060  }
2061  }
2062 
2063  //-----------------------------------------------------
2064  Set_File_Name(_FileName, true);
2065 
2066  if( Stream.Get_File(FileName + "sg-info") )
2067  {
2068  Load_MetaData(Stream);
2069  }
2070 
2071  if( Stream.Get_File(FileName + "sg-prj") )
2072  {
2073  Get_Projection().Load(Stream);
2074  }
2075 
2076  return( true );
2077 }
2078 
2079 //---------------------------------------------------------
2080 bool CSG_Grids::_Save_Compressed(const CSG_String &_FileName)
2081 {
2082  CSG_File_Zip Stream(_FileName, SG_FILE_W);
2083 
2084  CSG_String FileName(SG_File_Get_Name(_FileName, false) + ".");
2085 
2086  //-----------------------------------------------------
2087  if( !Stream.Add_File(FileName + "sg-gds") || !_Save_Header(Stream) )
2088  {
2089  return( false );
2090  }
2091 
2092  if( !Stream.Add_File(FileName + "sg-att") || !_Save_Attributes(Stream) )
2093  {
2094  return( false );
2095  }
2096 
2097  //-----------------------------------------------------
2098  for(int i=0; i<Get_NZ() && SG_UI_Process_Set_Progress(i, Get_NZ()); i++)
2099  {
2100  if( !Stream.Add_File(FileName + CSG_String::Format("sg-%03d", i + 1)) || !_Save_Data(Stream, m_pGrids[i]) )
2101  {
2102  return( false );
2103  }
2104  }
2105 
2106  //-----------------------------------------------------
2107  if( Stream.Add_File(FileName + "sg-info") )
2108  {
2109  Save_MetaData(Stream);
2110  }
2111 
2112  if( Stream.Add_File(FileName + "sg-prj") )
2113  {
2114  Get_Projection().Save(Stream);
2115  }
2116 
2117  return( true );
2118 }
2119 
2120 
2122 // //
2124 
2125 //---------------------------------------------------------
2126 bool CSG_Grids::_Load_Header(CSG_File &Stream)
2127 {
2128  CSG_MetaData Header;
2129 
2130  if( !Header.Load(Stream) )
2131  {
2132  return( false );
2133  }
2134 
2135  //-----------------------------------------------------
2136  if( !Header("NX") || !Header("NY") || !Header("XMIN") || !Header("YMIN") || !Header("CELLSIZE") || !Header("TYPE") ) // necessary minimum information !!!
2137  {
2138  return( false );
2139  }
2140 
2141  CSG_Grid_System System(Header["CELLSIZE"].Get_Content().asDouble(),
2142  Header["XMIN"].Get_Content().asDouble(), Header["YMIN"].Get_Content().asDouble(),
2143  Header["NX" ].Get_Content().asInt (), Header["NY" ].Get_Content().asInt ()
2144  );
2145 
2146  TSG_Data_Type Type = SG_Data_Type_Get_Type(Header["TYPE"].Get_Content());
2147 
2148  if( !System.is_Valid() || Type == SG_DATATYPE_Undefined || !m_pGrids[0]->Create(System, Type) )
2149  {
2150  return( false );
2151  }
2152 
2153  //-----------------------------------------------------
2154  if( Header("NAME" ) ) Set_Name (Header["NAME" ].Get_Content());
2155  if( Header("DESCRIPTION") ) Set_Description(Header["DESCRIPTION"].Get_Content());
2156  if( Header("UNIT" ) ) Set_Unit (Header["UNIT" ].Get_Content());
2157 
2158  Set_Scaling(
2159  Header("SCALE" ) ? Header["SCALE" ].Get_Content().asDouble() : 1.,
2160  Header("OFFSET") ? Header["OFFSET"].Get_Content().asDouble() : 0.
2161  );
2162 
2163  if( Header("NODATA_MIN") )
2164  {
2165  if( Header("NODATA_MAX") )
2166  {
2168  Header["NODATA_MIN"].Get_Content().asDouble(),
2169  Header["NODATA_MAX"].Get_Content().asDouble()
2170  );
2171  }
2172  else
2173  {
2175  Header["NODATA_MIN"].Get_Content().asDouble()
2176  );
2177  }
2178  }
2179 
2180  //-----------------------------------------------------
2181  m_Attributes.Destroy();
2182 
2183  if( Header("ATTRIBUTES") && Header["ATTRIBUTES"]("FIELDS") == NULL )
2184  {
2185  const CSG_MetaData &Fields = Header["ATTRIBUTES"];
2186 
2187  for(int iField=0; iField<Fields.Get_Children_Count(); iField++)
2188  {
2189  if( Fields[iField].Cmp_Name("FIELD") && Fields[iField].Get_Property("TYPE") )
2190  {
2191  m_Attributes.Add_Field(Fields[iField].Get_Content(), SG_Data_Type_Get_Type(Fields[iField].Get_Property("TYPE")));
2192  }
2193  }
2194 
2195  if( !Fields.Get_Property("Z_FIELD", m_Z_Attribute) || m_Z_Attribute >= m_Attributes.Get_Field_Count() )
2196  {
2197  m_Z_Attribute = 0;
2198  }
2199 
2200  if( !Fields.Get_Property("Z_NAME", m_Z_Name ) || m_Z_Name >= m_Attributes.Get_Field_Count() )
2201  {
2202  m_Z_Name = -1; // same as m_Z_Attribute
2203  }
2204  }
2205 
2206  //-----------------------------------------------------
2207  // >>> DEPRECATED >>> //
2208  if( Header("ATTRIBUTES") && Header["ATTRIBUTES"]("FIELDS") != NULL )
2209  {
2210  if( !Header["ATTRIBUTES"].Get_Property("ZATTRIBUTE", m_Z_Attribute) )
2211  {
2212  m_Z_Attribute = 0;
2213  }
2214 
2215  int iField;
2216 
2217  const CSG_MetaData &Fields = Header["ATTRIBUTES"]["FIELDS"];
2218 
2219  for(iField=0; iField<Fields.Get_Children_Count(); iField++)
2220  {
2221  if( Fields[iField].Cmp_Name("FIELD") && Fields[iField].Get_Property("TYPE") )
2222  {
2223  m_Attributes.Add_Field(Fields[iField].Get_Content(), SG_Data_Type_Get_Type(Fields[iField].Get_Property("TYPE")));
2224  }
2225  }
2226 
2227  if( m_Attributes.Get_Field_Count() > 0 && Header["ATTRIBUTES"]("RECORDS") )
2228  {
2229  CSG_Table Attributes(m_Attributes);
2230 
2231  const CSG_MetaData &Records = Header["ATTRIBUTES"]["RECORDS"];
2232 
2233  for(int iRecord=0; iRecord<Records.Get_Children_Count(); iRecord++)
2234  {
2235  if( Records[iRecord].Cmp_Name("RECORD") )
2236  {
2237  CSG_String_Tokenizer Values(Records[iRecord].Get_Content(), ";");
2238 
2239  if( Values.Get_Tokens_Count() == (size_t)Attributes.Get_Field_Count() )
2240  {
2241  CSG_Table_Record *pRecord = Attributes.Add_Record();
2242 
2243  for(int iField=0; iField<m_Attributes.Get_Field_Count(); iField++)
2244  {
2245  pRecord->Set_Value(iField, Values.Get_Next_Token());
2246  }
2247 
2248  if( !Add_Grid(*pRecord) )
2249  {
2250  return( false );
2251  }
2252  }
2253  }
2254  }
2255  }
2256  }
2257  else if( Header("NZ") && Header["NZ"].Get_Content().asInt() > 0 )
2258  {
2259  m_Attributes.Add_Field("ID", SG_DATATYPE_Int);
2260 
2261  for(int i=0, n=Header["NZ"].Get_Content().asInt(); i<n; i++)
2262  {
2263  if( !Add_Grid(i + 1.) )
2264  {
2265  return( false );
2266  }
2267  }
2268  }
2269  // <<< DEPRECATED <<< //
2270 
2271  //-----------------------------------------------------
2272  return( m_Attributes.Get_Field_Count() > 0 );
2273 }
2274 
2275 //---------------------------------------------------------
2276 bool CSG_Grids::_Save_Header(CSG_File &Stream)
2277 {
2278  CSG_MetaData Header;
2279 
2280  Header.Set_Name("GRIDS");
2281 
2282  Header.Add_Property("saga-version", SAGA_VERSION);
2283 
2284  //-----------------------------------------------------
2285  // general
2286 
2287  Header.Add_Child("NAME" , Get_Name ());
2288  Header.Add_Child("DESCRIPTION", Get_Description());
2289  Header.Add_Child("UNIT" , Get_Unit ());
2290 
2291  Header.Add_Child("SCALE" , Get_Scaling ());
2292  Header.Add_Child("OFFSET" , Get_Offset ());
2293 
2294  Header.Add_Child("NODATA_MIN" , Get_NoData_Value(false));
2295  Header.Add_Child("NODATA_MAX" , Get_NoData_Value(true ));
2296 
2297  Header.Add_Child("TYPE" , SG_Data_Type_Get_Identifier(Get_Type()));
2298 
2299  //-----------------------------------------------------
2300  // grid system
2301 
2302  Header.Add_Child("NX" , Get_NX ());
2303  Header.Add_Child("NY" , Get_NY ());
2304  Header.Add_Child("CELLSIZE" , Get_Cellsize());
2305  Header.Add_Child("XMIN" , Get_XMin ());
2306  Header.Add_Child("YMIN" , Get_YMin ());
2307 
2308  //-----------------------------------------------------
2309  // attributes
2310 
2311  CSG_MetaData &Attributes = *Header.Add_Child("ATTRIBUTES");
2312 
2313  Attributes.Add_Property("Z_FIELD", m_Z_Attribute);
2314  Attributes.Add_Property("Z_NAME" , m_Z_Name );
2315 
2316  for(int iField=0; iField<m_Attributes.Get_Field_Count(); iField++)
2317  {
2318  Attributes.Add_Child("FIELD", m_Attributes.Get_Field_Name(iField))->Add_Property(
2319  "TYPE", SG_Data_Type_Get_Identifier(m_Attributes.Get_Field_Type(iField))
2320  );
2321  }
2322 
2323  //-----------------------------------------------------
2324  return( Header.Save(Stream) );
2325 }
2326 
2327 
2329 // //
2331 
2332 //---------------------------------------------------------
2333 bool CSG_Grids::_Load_Attributes(CSG_File &Stream)
2334 {
2335  CSG_Table Attributes(m_Attributes);
2336 
2337  CSG_String sLine;
2338 
2339  while( Stream.Read_Line(sLine) && !sLine.is_Empty() )
2340  {
2341  CSG_String_Tokenizer Values(sLine, "\t", SG_TOKEN_RET_EMPTY_ALL);
2342 
2343  if( Values.Get_Tokens_Count() == (size_t)Attributes.Get_Field_Count() )
2344  {
2345  CSG_Table_Record *pRecord = Attributes.Add_Record();
2346 
2347  for(int iField=0; iField<m_Attributes.Get_Field_Count(); iField++)
2348  {
2349  pRecord->Set_Value(iField, Values.Get_Next_Token());
2350  }
2351 
2352  if( !Add_Grid(*pRecord) )
2353  {
2354  return( false );
2355  }
2356  }
2357  }
2358 
2359  return( true );
2360 }
2361 
2362 //---------------------------------------------------------
2363 bool CSG_Grids::_Save_Attributes(CSG_File &Stream)
2364 {
2365  for(int iRecord=0; iRecord<m_Attributes.Get_Count(); iRecord++)
2366  {
2367  for(int iField=0; iField<m_Attributes.Get_Field_Count(); iField++)
2368  {
2369  Stream.Write(m_Attributes[iRecord].asString(iField));
2370  Stream.Write(iField < m_Attributes.Get_Field_Count() - 1 ? "\t" : "\n");
2371  }
2372  }
2373 
2374  return( true );
2375 }
2376 
2377 
2379 // //
2381 
2382 //---------------------------------------------------------
2383 bool CSG_Grids::_Load_Data(CSG_File &Stream, CSG_Grid *pGrid)
2384 {
2385  if( !pGrid )
2386  {
2387  return( false );
2388  }
2389 
2390  TSG_Data_Type Type = Get_Type();
2391 
2392  CSG_Array Line(1, Get_nLineBytes());
2393 
2394  for(int y=0; y<Get_NY(); y++)
2395  {
2396  if( !Stream.Read(Line.Get_Array(), Get_nLineBytes()) )
2397  {
2398  return( false );
2399  }
2400 
2401  char *pValue = (char *)Line.Get_Array();
2402 
2403  for(int x=0, n=Get_nValueBytes(); x<Get_NX(); x++, pValue+=n)
2404  {
2405  switch( Type )
2406  {
2407  case SG_DATATYPE_Byte : pGrid->Set_Value(x, y, *(BYTE *)pValue, false); break;
2408  case SG_DATATYPE_Char : pGrid->Set_Value(x, y, *(char *)pValue, false); break;
2409  case SG_DATATYPE_Word : pGrid->Set_Value(x, y, *(WORD *)pValue, false); break;
2410  case SG_DATATYPE_Short : pGrid->Set_Value(x, y, *(short *)pValue, false); break;
2411  case SG_DATATYPE_DWord : pGrid->Set_Value(x, y, *(DWORD *)pValue, false); break;
2412  case SG_DATATYPE_Int : pGrid->Set_Value(x, y, *(int *)pValue, false); break;
2413  case SG_DATATYPE_Float : pGrid->Set_Value(x, y, *(float *)pValue, false); break;
2414  case SG_DATATYPE_Double: pGrid->Set_Value(x, y, *(double *)pValue, false); break;
2415  default: break;
2416  }
2417  }
2418  }
2419 
2420  return( true );
2421 }
2422 
2423 //---------------------------------------------------------
2424 bool CSG_Grids::_Save_Data(CSG_File &Stream, CSG_Grid *pGrid)
2425 {
2426  TSG_Data_Type Type = Get_Type();
2427 
2428  CSG_Array Line(1, Get_nLineBytes());
2429 
2430  for(int y=0; y<Get_NY(); y++)
2431  {
2432  char *pValue = (char *)Line.Get_Array();
2433 
2434  for(int x=0, n=Get_nValueBytes(); x<Get_NX(); x++, pValue+=n)
2435  {
2436  switch( Type )
2437  {
2438  case SG_DATATYPE_Byte : *(BYTE *)pValue = pGrid->asByte (x, y, false); break;
2439  case SG_DATATYPE_Char : *(char *)pValue = pGrid->asChar (x, y, false); break;
2440  case SG_DATATYPE_Word : *(WORD *)pValue = pGrid->asShort (x, y, false); break;
2441  case SG_DATATYPE_Short : *(short *)pValue = pGrid->asShort (x, y, false); break;
2442  case SG_DATATYPE_DWord : *(DWORD *)pValue = pGrid->asInt (x, y, false); break;
2443  case SG_DATATYPE_Int : *(int *)pValue = pGrid->asInt (x, y, false); break;
2444  case SG_DATATYPE_Float : *(float *)pValue = pGrid->asFloat (x, y, false); break;
2445  case SG_DATATYPE_Double: *(double *)pValue = pGrid->asDouble(x, y, false); break;
2446  default: break;
2447  }
2448  }
2449 
2450  if( !Stream.Write(Line.Get_Array(), Get_nLineBytes()) )
2451  {
2452  return( false );
2453  }
2454  }
2455 
2456  return( true );
2457 }
2458 
2459 
2461 // //
2463 
2464 //-----------------------------------------------------
2465 bool CSG_Grids::_Assign_Interpolated (CSG_Grids *pSource, TSG_Grid_Resampling Interpolation) { return( false ); }
2466 bool CSG_Grids::_Assign_MeanValue (CSG_Grids *pSource, bool bVolumeProportional ) { return( false ); }
2467 bool CSG_Grids::_Assign_ExtremeValue (CSG_Grids *pSource, bool bMaximum ) { return( false ); }
2468 bool CSG_Grids::_Assign_Majority (CSG_Grids *pSource ) { return( false ); }
2469 
2470 
2472 // //
2474 
2475 //-----------------------------------------------------
2476 CSG_Grids & CSG_Grids::_Operation_Arithmetic(const CSG_Grids &Grids, TSG_Grid_Operation Operation) { return( *this ); }
2477 CSG_Grids & CSG_Grids::_Operation_Arithmetic(double Value , TSG_Grid_Operation Operation) { return( *this ); }
2478 
2479 
2481 // //
2482 // //
2483 // //
2485 
2486 //---------------------------------------------------------
CSG_Grids::Set_Unit
void Set_Unit(const CSG_String &Unit)
Definition: grids.cpp:374
CSG_Grid::Get_Type
TSG_Data_Type Get_Type(void) const
Definition: grid.h:519
CSG_String::BeforeFirst
CSG_String BeforeFirst(char Character) const
Definition: api_string.cpp:666
CSG_Rect
Definition: geo_tools.h:471
CSG_Grids::Subtract
virtual CSG_Grids & Subtract(double Value)
Definition: grids.cpp:1021
GRIDS_FILE_FORMAT_Normal
@ GRIDS_FILE_FORMAT_Normal
Definition: grids.h:93
CSG_Grids::Get_NY
int Get_NY(void) const
Definition: grids.h:186
SG_DATATYPE_Int
@ SG_DATATYPE_Int
Definition: api_core.h:1000
CSG_File::Open
virtual bool Open(const CSG_String &FileName, int Mode=SG_FILE_R, bool bBinary=true, int Encoding=SG_FILE_ENCODING_ANSI)
Definition: api_file.cpp:111
CSG_Grids::Multiply
virtual CSG_Grids & Multiply(double Value)
Definition: grids.cpp:1037
CSG_Table::Assign
virtual bool Assign(CSG_Data_Object *pTable)
Definition: table.cpp:377
CSG_Grids::CSG_Grids
CSG_Grids(void)
Definition: grids.cpp:132
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_Grids::Set_Z
bool Set_Z(int i, double Value)
Definition: grids.cpp:556
GRID_RESAMPLING_NearestNeighbour
@ GRID_RESAMPLING_NearestNeighbour
Definition: grid.h:157
CSG_Projection::Save
bool Save(const CSG_String &File, ESG_CRS_Format Format=ESG_CRS_Format::WKT) const
Definition: projections.cpp:229
CSG_Grids::asInt
virtual int asInt(int x, int y, int z, bool bScaled=true) const
Definition: grids.h:391
CSG_Grids::Get_Data_Count
sLong Get_Data_Count(void)
Definition: grids.cpp:1433
CSG_String::Printf
int Printf(const char *Format,...)
Definition: api_string.cpp:308
CSG_Grid_System::Get_Cellsize
double Get_Cellsize(void) const
Definition: grid.h:231
CSG_Table::Set_Count
virtual bool Set_Count(sLong nRecords)
Definition: table.cpp:926
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
CSG_Table::Del_Records
virtual bool Del_Records(void)
Definition: table.cpp:908
CSG_Grids::Get_Sorted
sLong Get_Sorted(sLong Position, bool bDown=true, bool bCheckNoData=true)
Definition: grids.h:450
CSG_Grids::Get_Offset
double Get_Offset(void) const
Definition: grids.h:271
CSG_Data_Object::Set_File_Name
void Set_File_Name(const CSG_String &FileName)
Definition: dataobject.cpp:366
SAGA_VERSION
#define SAGA_VERSION
Definition: saga_api.h:90
CSG_Grids::Set_Value
virtual void Set_Value(sLong i, double Value, bool bScaled=true)
Definition: grids.h:422
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_MetaData::Get_Children_Count
int Get_Children_Count(void) const
Definition: metadata.h:147
CSG_Grids::~CSG_Grids
virtual ~CSG_Grids(void)
Definition: grids.cpp:141
CSG_Grids::operator=
virtual CSG_Grids & operator=(const CSG_Grids &Grids)
Definition: grids.cpp:989
CSG_Data_Collection::Count
size_t Count(void) const
Definition: data_manager.h:94
GRID_RESAMPLING_BicubicSpline
@ GRID_RESAMPLING_BicubicSpline
Definition: grid.h:159
CSG_Grids::Set_Z_Attribute
bool Set_Z_Attribute(int Field)
Definition: grids.cpp:474
SG_TOKEN_RET_EMPTY_ALL
@ SG_TOKEN_RET_EMPTY_ALL
Definition: api_core.h:752
CSG_Table_Record
Definition: table.h:130
CSG_Grids::Set_Attribute
bool Set_Attribute(int i, int Field, const CSG_String &Value)
Definition: grids.cpp:541
CSG_Grids::Assign
virtual bool Assign(double Value=0.)
Definition: grids.cpp:919
CSG_Grids::Get_Scaling
double Get_Scaling(void) const
Definition: grids.h:270
CSG_Simple_Statistics::Get_Variance
double Get_Variance(void)
Definition: mat_tools.h:752
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
CSG_Grids::Get_Attributes
const CSG_Table & Get_Attributes(void) const
Definition: grids.h:224
CSG_Grids::Get_Range
double Get_Range(void)
Definition: grids.cpp:1417
SG_UI_MSG_STYLE_SUCCESS
@ SG_UI_MSG_STYLE_SUCCESS
Definition: api_core.h:1505
SG_Get_String
SAGA_API_DLL_EXPORT CSG_String SG_Get_String(double Value, int Precision=-99)
Definition: api_string.cpp:1337
CSG_Grid_System
Definition: grid.h:200
CSG_Table::Del_Field
virtual bool Del_Field(int iField)
Definition: table.cpp:520
TSG_Grid_Resampling
TSG_Grid_Resampling
Definition: grid.h:156
CSG_Grid::Create
bool Create(const CSG_Grid &Grid)
Definition: grid.cpp:230
SG_File_Cmp_Extension
SAGA_API_DLL_EXPORT bool SG_File_Cmp_Extension(const CSG_String &FileName, const CSG_String &Extension)
Definition: api_file.cpp:952
CSG_Histogram
Definition: mat_tools.h:1001
SG_Malloc
SAGA_API_DLL_EXPORT void * SG_Malloc(size_t size)
Definition: api_memory.cpp:65
CSG_Grids::Get_Grid_Name
CSG_String Get_Grid_Name(int i, int Style=0) const
Definition: grids.cpp:861
CSG_Grids::On_Update
virtual bool On_Update(void)
Definition: grids.cpp:1355
CSG_Grids::Get_Grid_Count
int Get_Grid_Count(void) const
Definition: grids.h:249
CSG_Grids::Save
virtual bool Save(const CSG_String &File, int Format=0)
Definition: grids.cpp:1737
CSG_Data_Object::Save_MetaData
bool Save_MetaData(const CSG_String &FileName)
Definition: dataobject.cpp:677
CSG_Grid_System::Get_yWorld_to_Grid
int Get_yWorld_to_Grid(double yWorld) const
Definition: grid.h:291
CSG_Grids::Add_Attribute
bool Add_Attribute(const char *Name, TSG_Data_Type Type, int Insert=-1)
Definition: grids.cpp:505
SSG_Point_3D
Definition: geo_tools.h:264
CSG_Data_Object::is_NoData_Value
bool is_NoData_Value(double Value) const
Definition: dataobject.h:255
GRID_RESAMPLING_Undefined
@ GRID_RESAMPLING_Undefined
Definition: grid.h:168
SG_DATATYPE_Byte
@ SG_DATATYPE_Byte
Definition: api_core.h:995
CSG_Grids::Get_Extent
virtual const CSG_Rect & Get_Extent(void)
Definition: grids.h:183
CSG_Projection::is_Okay
bool is_Okay(void) const
Definition: geo_tools.h:857
saga_api.h
CSG_Tool
Definition: tool.h:151
CSG_Table::Destroy
virtual bool Destroy(void)
Definition: table.cpp:332
CSG_Grids::On_Delete
virtual bool On_Delete(void)
Definition: grids.cpp:1683
CSG_Data_Object::Get_Name
const SG_Char * Get_Name(void) const
Definition: dataobject.cpp:349
CSG_Tool::Execute
bool Execute(bool bAddHistory=false)
Definition: tool.cpp:258
SSG_Point_3D::x
double x
Definition: geo_tools.h:265
CSG_Histogram::Create
bool Create(const CSG_Histogram &Histogram)
Definition: mat_tools.cpp:1495
CSG_Grids::Get_NCells
sLong Get_NCells(void) const
Definition: grids.h:188
SG_DATAOBJECT_TYPE_Grids
@ SG_DATAOBJECT_TYPE_Grids
Definition: dataobject.h:119
CSG_Grids::is_Valid
virtual bool is_Valid(void) const
Definition: grids.cpp:440
CSG_Grids::Get_Type
TSG_Data_Type Get_Type(void) const
Definition: grids.h:169
SG_RUN_TOOL
#define SG_RUN_TOOL(bRetVal, LIBRARY, TOOL, CONDITION)
Definition: tool_library.h:257
CSG_Grids::Get_Z_Attribute
int Get_Z_Attribute(void) const
Definition: grids.h:214
CSG_Table::Get_Field_Count
int Get_Field_Count(void) const
Definition: table.h:356
CSG_Grids::is_Scaled
bool is_Scaled(void) const
Definition: grids.h:272
SG_File_Delete
SAGA_API_DLL_EXPORT bool SG_File_Delete(const CSG_String &FileName)
Definition: api_file.cpp:856
SG_Free
SAGA_API_DLL_EXPORT void SG_Free(void *memblock)
Definition: api_memory.cpp:83
CSG_Data_Object::Get_ObjectType
virtual TSG_Data_Object_Type Get_ObjectType(void) const =0
Returns the object type as defined by TSG_Data_Object_Type. Used for run time type checking.
CSG_Data_Object::Set_Max_Samples
virtual bool Set_Max_Samples(sLong Max_Samples)
Definition: dataobject.cpp:617
CSG_Grids::Get_Percentile
double Get_Percentile(double Percentile, bool bFromHistogram=true)
Definition: grids.cpp:1467
CSG_Grids::operator/=
virtual CSG_Grids & operator/=(double Value)
Definition: grids.cpp:1048
CSG_MetaData::Save
bool Save(const CSG_String &File, const SG_Char *Extension=NULL) const
Definition: metadata.cpp:879
SG_FILE_R
@ SG_FILE_R
Definition: api_core.h:1109
CSG_Grids::Del_Attribute
bool Del_Attribute(int Field)
Definition: grids.cpp:513
CSG_Grids::operator+=
virtual CSG_Grids & operator+=(double Value)
Definition: grids.cpp:1000
CSG_Array_Pointer::Create
void ** Create(const CSG_Array_Pointer &Array)
Definition: api_memory.cpp:469
CSG_File::Read
size_t Read(void *Buffer, size_t Size, size_t Count=1) const
Definition: api_file.cpp:328
SG_GRIDS_NAME_INDEX
#define SG_GRIDS_NAME_INDEX
Definition: grids.h:101
CSG_Tool_Library_Manager::Delete_Tool
bool Delete_Tool(CSG_Tool *pTool) const
Definition: tool_library.cpp:725
CSG_Grids::On_Reload
virtual bool On_Reload(void)
Definition: grids.cpp:1677
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_File
Definition: api_core.h:1124
CSG_String::Cmp
int Cmp(const CSG_String &String) const
Definition: api_string.cpp:515
CSG_Data_Object::Get_Owner
CSG_Data_Object * Get_Owner(void) const
Definition: dataobject.h:231
CSG_Grids::Set_Max_Samples
virtual bool Set_Max_Samples(sLong Max_Samples)
Definition: grids.cpp:1559
GRIDS_FILE_FORMAT_Undefined
@ GRIDS_FILE_FORMAT_Undefined
Definition: grids.h:92
SG_Data_Type_Get_Identifier
CSG_String SG_Data_Type_Get_Identifier(TSG_Data_Type Type)
Definition: api_core.cpp:146
CSG_Grid::Destroy
virtual bool Destroy(void)
Definition: grid.cpp:371
CSG_Grids::is_Compatible
bool is_Compatible(CSG_Grid *pGrid) const
Definition: grids.cpp:446
CSG_Tool::Set_Parameter
bool Set_Parameter(const CSG_String &ID, CSG_Parameter *pValue)
Definition: tool.cpp:1140
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
SG_File_Get_Name
SAGA_API_DLL_EXPORT CSG_String SG_File_Get_Name(const CSG_String &full_Path, bool bExtension)
Definition: api_file.cpp:878
CSG_Grids::Get_Unit
const SG_Char * Get_Unit(void) const
Definition: grids.h:175
CSG_Grid::Get_Scaling
double Get_Scaling(void) const
Definition: grid.cpp:414
SG_TOOL_PARAMLIST_ADD
#define SG_TOOL_PARAMLIST_ADD(IDENTIFIER, VALUE)
Definition: tool_library.h:353
CSG_Grids::Get_NX
int Get_NX(void) const
Definition: grids.h:185
CSG_Grid::Multiply
virtual CSG_Grid & Multiply(const CSG_Grid &Grid)
Definition: grid_operation.cpp:573
SG_TOOL_PARAMETER_SET
#define SG_TOOL_PARAMETER_SET(IDENTIFIER, VALUE)
Definition: tool_library.h:351
CSG_Grids::Create
virtual bool Create(const CSG_Grids &Grids)
Definition: grids.cpp:271
CSG_Grid::Add
virtual CSG_Grid & Add(const CSG_Grid &Grid)
Definition: grid_operation.cpp:503
SG_GRIDS_NAME_VALUE
#define SG_GRIDS_NAME_VALUE
Definition: grids.h:102
CSG_Data_Object
Definition: dataobject.h:180
CSG_Table::Get_Field_Name
const SG_Char * Get_Field_Name(int iField) const
Definition: table.h:357
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_Grids::Get_System
const CSG_Grid_System & Get_System(void) const
Definition: grids.h:181
CSG_Grid::Subtract
virtual CSG_Grid & Subtract(const CSG_Grid &Grid)
Definition: grid_operation.cpp:538
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
CSG_Grids::Get_nLineBytes
int Get_nLineBytes(void) const
Definition: grids.h:172
CSG_Simple_Statistics::Get_Minimum
double Get_Minimum(void)
Definition: mat_tools.h:746
CSG_Grids::Get_YMin
double Get_YMin(bool bCells=false) const
Definition: grids.h:201
CSG_Array_Pointer::Get_uSize
size_t Get_uSize(void) const
Definition: api_core.h:382
CSG_Grids::Get_Value
double Get_Value(double x, double y, double z, TSG_Grid_Resampling Resampling=GRID_RESAMPLING_BSpline, TSG_Grid_Resampling ZResampling=GRID_RESAMPLING_Undefined) const
Definition: grids.cpp:1078
CSG_MetaData::Del_Children
bool Del_Children(int Depth=0, const SG_Char *Name=NULL)
Definition: metadata.cpp:381
CSG_File::Read_Line
bool Read_Line(CSG_String &sLine) const
Definition: api_file.cpp:385
CSG_Tool_Library_Manager::Create_Tool
CSG_Tool * Create_Tool(const CSG_String &Library, int Index, bool bWithGUI=false) const
Definition: tool_library.cpp:696
SG_UI_Msg_Lock
int SG_UI_Msg_Lock(bool bOn)
Definition: api_callback.cpp:472
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_Grids::is_NoData
virtual bool is_NoData(int x, int y, int z) const
Definition: grids.h:370
sLong
signed long long sLong
Definition: api_core.h:158
CSG_Grids::Get_StdDev
double Get_StdDev(void)
Definition: grids.cpp:1422
SG_Get_Tool_Library_Manager
CSG_Tool_Library_Manager & SG_Get_Tool_Library_Manager(void)
Definition: tool_library.cpp:286
CSG_MetaData::Add_Property
bool Add_Property(const CSG_String &Name, const CSG_String &Value)
Definition: metadata.cpp:559
CSG_Grids::operator-=
virtual CSG_Grids & operator-=(double Value)
Definition: grids.cpp:1016
CSG_Simple_Statistics::Get_StdDev
double Get_StdDev(void)
Definition: mat_tools.h:753
CSG_Grids::Update_Z_Order
bool Update_Z_Order(void)
Definition: grids.cpp:562
CSG_Grids::Get_Grid_Ptr
CSG_Grid * Get_Grid_Ptr(int i) const
Definition: grids.h:260
GRIDS_FILE_FORMAT_Compressed
@ GRIDS_FILE_FORMAT_Compressed
Definition: grids.h:94
CSG_Table::Get_Count
sLong Get_Count(void) const
Definition: table.h:392
CSG_Grids::Get_Histogram
const CSG_Histogram & Get_Histogram(size_t nClasses=0)
Definition: grids.cpp:1582
SG_DATATYPE_Float
@ SG_DATATYPE_Float
Definition: api_core.h:1003
CSG_Grids::Set_Scaling
void Set_Scaling(double Scale=1., double Offset=0.)
Definition: grids.cpp:380
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::Assign
virtual bool Assign(double Value=0.0)
Definition: grid_operation.cpp:77
CSG_Data_Object::Get_File_Name
const SG_Char * Get_File_Name(bool bNative=true) const
Definition: dataobject.cpp:390
CSG_Grids::Destroy
virtual bool Destroy(void)
Definition: grids.cpp:245
GRID_RESAMPLING_BSpline
@ GRID_RESAMPLING_BSpline
Definition: grid.h:160
CSG_Grid::asShort
virtual short asShort(int x, int y, bool bScaled=true) const
Definition: grid.h:755
CSG_Table::Set_Value
virtual bool Set_Value(sLong Index, int iField, const SG_Char *Value)
Definition: table.cpp:1131
SG_GRIDS_NAME_GRID
#define SG_GRIDS_NAME_GRID
Definition: grids.h:103
SG_FILE_W
@ SG_FILE_W
Definition: api_core.h:1110
CSG_Grids::Set_Grid_Count
bool Set_Grid_Count(int Count)
Definition: grids.cpp:603
CSG_Grids::Assign_NoData
void Assign_NoData(void)
Definition: grids.cpp:910
CSG_Grids::Set_Z_Name_Field
bool Set_Z_Name_Field(int Field)
Definition: grids.cpp:487
CSG_Projection::Load
bool Load(const CSG_String &File)
Definition: projections.cpp:221
CSG_Grids::Get_Min
double Get_Min(void)
Definition: grids.cpp:1407
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
SG_DATAOBJECT_TYPE_Grid
@ SG_DATAOBJECT_TYPE_Grid
Definition: dataobject.h:118
CSG_Grid::Assign_NoData
void Assign_NoData(void)
Definition: grid_operation.cpp:65
CSG_Data_Object::Set_Name
void Set_Name(const CSG_String &Name)
Definition: dataobject.cpp:300
CSG_MetaData::Add_Children
bool Add_Children(const CSG_MetaData &MetaData)
Definition: metadata.cpp:359
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
SG_Create_Grids
CSG_Grids * SG_Create_Grids(void)
Definition: grids.cpp:65
CSG_String::Format
static CSG_String Format(const char *Format,...)
Definition: api_string.cpp:270
CSG_Grids::Get_ZMax
double Get_ZMax(bool bCells=false) const
Definition: grids.h:206
CSG_Grids::Get_XMin
double Get_XMin(bool bCells=false) const
Definition: grids.h:197
CSG_Table::Add_Field
virtual bool Add_Field(const CSG_String &Name, TSG_Data_Type Type, int Position=-1)
Definition: table.cpp:481
CSG_Table
Definition: table.h:283
SG_File_Set_Extension
SAGA_API_DLL_EXPORT bool SG_File_Set_Extension(CSG_String &FileName, const CSG_String &Extension)
Definition: api_file.cpp:958
CSG_Grids::Load
virtual bool Load(const CSG_String &File, bool bLoadData=true)
Definition: grids.cpp:1709
CSG_Grids::asDouble
virtual double asDouble(sLong i, bool bScaled=true) const
Definition: grids.h:399
CSG_Table::Del_Record
virtual bool Del_Record(sLong Index)
Definition: table.cpp:869
CSG_Spline
Definition: mat_tools.h:1414
CSG_Spline::Get_Value
bool Get_Value(double x, double &y)
Definition: mat_spline.cpp:206
CSG_Array
Definition: api_core.h:308
CSG_String
Definition: api_core.h:563
CSG_Grids::Get_Z
double Get_Z(int i) const
Definition: grids.h:240
CSG_Grids::Add
virtual CSG_Grids & Add(double Value)
Definition: grids.cpp:1005
CSG_Array_Pointer
Definition: api_core.h:368
CSG_Histogram::Destroy
bool Destroy(void)
Definition: mat_tools.cpp:1272
CSG_Tool::Set_Manager
bool Set_Manager(class CSG_Data_Manager *pManager)
Definition: tool.cpp:570
CSG_Grid::asDouble
virtual double asDouble(sLong i, bool bScaled=true) const
Definition: grid.h:765
CSG_Data_Manager
Definition: data_manager.h:129
CSG_MetaData
Definition: metadata.h:88
CSG_Data_Object::Set_Description
void Set_Description(const CSG_String &Description)
Definition: dataobject.cpp:355
CSG_Simple_Statistics::Get_Range
double Get_Range(void)
Definition: mat_tools.h:748
CSG_Data_Object::Get_MetaData_DB
CSG_MetaData & Get_MetaData_DB(void) const
Definition: dataobject.h:235
CSG_Grid::asFloat
virtual float asFloat(int x, int y, bool bScaled=true) const
Definition: grid.h:761
SSG_Point_3D::y
double y
Definition: geo_tools.h:265
CSG_MetaData::Load
bool Load(const CSG_String &File, const SG_Char *Extension=NULL)
Definition: metadata.cpp:786
CSG_Tool::Settings_Push
bool Settings_Push(class CSG_Data_Manager *pManager=NULL)
Definition: tool.cpp:621
ADD_TO_SPLINE
#define ADD_TO_SPLINE(i)
CSG_String::is_Empty
bool is_Empty(void) const
Definition: api_string.cpp:178
SG_GRIDS_NAME_OWNER
#define SG_GRIDS_NAME_OWNER
Definition: grids.h:100
SG_UI_Process_Set_Progress
bool SG_UI_Process_Set_Progress(int Position, int Range)
Definition: api_callback.cpp:256
CSG_Table_Record::Set_Value
bool Set_Value(int Field, const CSG_String &Value)
Definition: table_record.cpp:270
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
CSG_Data_Object::Load_MetaData
bool Load_MetaData(const CSG_String &FileName)
Definition: dataobject.cpp:654
CSG_Grids::Get_Mean
double Get_Mean(void)
Definition: grids.cpp:1402
SORT_SWAP
#define SORT_SWAP(a, b)
Definition: grids.cpp:1195
CSG_Rect::Get_XMin
double Get_XMin(void) const
Definition: geo_tools.h:502
CSG_Data_Object::Set_Owner
void Set_Owner(CSG_Data_Object *pOwner)
Definition: dataobject.h:232
CSG_Grids::Get_Z_Name_Field
int Get_Z_Name_Field(void) const
Definition: grids.cpp:499
CSG_Grid::Divide
virtual CSG_Grid & Divide(const CSG_Grid &Grid)
Definition: grid_operation.cpp:608
CSG_Grid
Definition: grid.h:473
CSG_Grids::Get_Variance
double Get_Variance(void)
Definition: grids.cpp:1427
CSG_Grids::Get_Cellsize
double Get_Cellsize(void) const
Definition: grids.h:192
CSG_Array_Pointer::Get_Array
void ** Get_Array(void) const
Definition: api_core.h:384
CSG_Grids::Get_Max
double Get_Max(void)
Definition: grids.cpp:1412
CSG_MetaData::Set_Name
void Set_Name(const CSG_String &Name)
Definition: metadata.h:129
CSG_Data_Object::Set_NoData_Value
virtual bool Set_NoData_Value(double Value)
Definition: dataobject.cpp:572
CSG_Data_Manager::Grids
CSG_Data_Collection & Grids(void) const
Definition: data_manager.h:139
SSG_Point_3D::z
double z
Definition: geo_tools.h:265
TABLE_INDEX_Ascending
@ TABLE_INDEX_Ascending
Definition: table.h:105
CSG_Grids::Set_Modified
virtual void Set_Modified(bool bModified=true)
Definition: grids.h:314
CSG_Grid::asByte
virtual BYTE asByte(int x, int y, bool bScaled=true) const
Definition: grid.h:751
CSG_Table::Create
bool Create(void)
Definition: table.cpp:139
CSG_Tool::On_Before_Execution
virtual bool On_Before_Execution(void)
Definition: tool.h:244
SG_File_Make_Path
SAGA_API_DLL_EXPORT CSG_String SG_File_Make_Path(const CSG_String &Directory, const CSG_String &Name)
Definition: api_file.cpp:919
CSG_Grids::Set_NoData_Value_Range
virtual bool Set_NoData_Value_Range(double loValue, double hiValue)
Definition: grids.cpp:393
SG_UI_ProgressAndMsg_Lock
void SG_UI_ProgressAndMsg_Lock(bool bOn)
Definition: api_callback.cpp:590
CSG_String::c_str
const SG_Char * c_str(void) const
Definition: api_string.cpp:236
tool_library.h
CSG_Grids::Add_Grid
bool Add_Grid(double Z)
Definition: grids.cpp:658
CSG_File::Write
size_t Write(void *Buffer, size_t Size, size_t Count=1) const
Definition: api_file.cpp:360
CSG_Grid::asChar
virtual char asChar(int x, int y, bool bScaled=true) const
Definition: grid.h:753
CSG_Grids::Get_NoData_Count
sLong Get_NoData_Count(void)
Definition: grids.cpp:1438
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
SG_Data_Type_Get_Type
TSG_Data_Type SG_Data_Type_Get_Type(const CSG_String &Identifier)
Definition: api_core.cpp:152
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
CSG_Table::Set_Index
bool Set_Index(CSG_Index &Index, int Field, bool bAscending=true) const
Definition: table.cpp:1426
CSG_MetaData::Add_Child
CSG_MetaData * Add_Child(void)
Definition: metadata.cpp:166
SG_UI_Msg_Add_Error
void SG_UI_Msg_Add_Error(const char *Message)
Definition: api_callback.cpp:557
SG_GRID_HISTOGRAM_CLASSES_DEFAULT
#define SG_GRID_HISTOGRAM_CLASSES_DEFAULT
Definition: grids.cpp:1575
CSG_Grid::Set_Unit
void Set_Unit(const CSG_String &Unit)
Definition: grid.cpp:392
CSG_Table::Get_Field_Type
TSG_Data_Type Get_Field_Type(int iField) const
Definition: table.h:358
CSG_Table::Add_Record
virtual CSG_Table_Record * Add_Record(CSG_Table_Record *pCopy=NULL)
Definition: table.cpp:795
CSG_String_Tokenizer
Definition: api_core.h:760
CSG_Grids::Del_Grid
bool Del_Grid(int i, bool bDetach=false)
Definition: grids.cpp:785
CSG_Projection::Create
bool Create(const CSG_Projection &Projection)
Definition: projections.cpp:96
CSG_Table::Get_Field
int Get_Field(const CSG_String &Name) const
Definition: table.cpp:695
CSG_Grids
Definition: grids.h:119
CSG_Grids::Get_nValueBytes
int Get_nValueBytes(void) const
Definition: grids.h:171
CSG_Simple_Statistics
Definition: mat_tools.h:723
CSG_Grids::Get_Quantile
double Get_Quantile(double Quantile, bool bFromHistogram=true)
Definition: grids.cpp:1444
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_Grids::Get_Statistics
const CSG_Simple_Statistics & Get_Statistics(void)
Definition: grids.cpp:1484
CSG_Data_Object::Destroy
virtual bool Destroy(void)
Definition: dataobject.cpp:281
CSG_MetaData::Get_Property
const SG_Char * Get_Property(int Index) const
Definition: metadata.h:180
CSG_Grid::asInt
virtual int asInt(int x, int y, bool bScaled=true) const
Definition: grid.h:757
CSG_File_Zip
Definition: api_core.h:1196
CSG_Grids::operator*=
virtual CSG_Grids & operator*=(double Value)
Definition: grids.cpp:1032
CSG_Grids::Divide
virtual CSG_Grids & Divide(double Value)
Definition: grids.cpp:1053
CSG_Histogram::Get_Statistics
const CSG_Simple_Statistics & Get_Statistics(void) const
Definition: mat_tools.h:1066
CSG_Grids::Del_Grids
bool Del_Grids(bool bDetach=false)
Definition: grids.cpp:823
TSG_Grid_Operation
TSG_Grid_Operation
Definition: grid.h:174
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_Grids::Get_NZ
int Get_NZ(void) const
Definition: grids.h:187
GRIDS_FILE_FORMAT_GeoTIFF
@ GRIDS_FILE_FORMAT_GeoTIFF
Definition: grids.h:95
grids.h
SG_DATATYPE_Double
@ SG_DATATYPE_Double
Definition: api_core.h:1004