SAGA API  v9.2
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 //---------------------------------------------------------
474 bool CSG_Grids::Add_Attribute(const CSG_String &Name, TSG_Data_Type Type, int i)
475 {
476  return( m_Attributes.Add_Field(Name, Type, i) );
477 }
478 
479 //---------------------------------------------------------
481 {
482  if( i != m_Z_Attribute && m_Attributes.Get_Field_Count() > 0 && m_Attributes.Del_Field(i) )
483  {
484  if( m_Z_Attribute > i )
485  {
486  m_Z_Attribute--;
487  }
488 
489  if( m_Z_Name > i )
490  {
491  m_Z_Name--;
492  }
493  else if( m_Z_Name == i )
494  {
495  m_Z_Name = -1; // same as m_Z_Attribute
496  }
497 
498  return( true );
499  }
500 
501  return( false );
502 }
503 
504 //---------------------------------------------------------
506 {
507  if( i >= 0 && i < m_Attributes.Get_Field_Count() )
508  {
509  m_Z_Attribute = i;
510 
511  return( Update_Z_Order() );
512  }
513 
514  return( false );
515 }
516 
517 //---------------------------------------------------------
519 {
520  if( i >= 0 && i < m_Attributes.Get_Field_Count() )
521  {
522  m_Z_Name = i;
523 
524  return( true );
525  }
526 
527  return( false );
528 }
529 
531 {
532  return( m_Z_Name >= 0 && m_Z_Name < m_Attributes.Get_Field_Count() ? m_Z_Name : m_Z_Attribute );
533 }
534 
535 //---------------------------------------------------------
536 bool CSG_Grids::Set_Z(int i, double Value)
537 {
538  return( i >= 0 && i < Get_NZ() && m_Attributes[i].Set_Value(m_Z_Attribute, Value) );
539 }
540 
541 //---------------------------------------------------------
543 {
544  bool bChanged = false;
545 
546  CSG_Table Attributes(m_Attributes);
547 
548  if( Attributes.Set_Index(m_Z_Attribute, TABLE_INDEX_Ascending) )
549  {
550  CSG_Array_Pointer Grids; CSG_Grid **pGrids = (CSG_Grid **)Grids.Create(m_Grids);
551 
552  for(int i=0; i<Get_Grid_Count(); i++)
553  {
554  int Index = (int)Attributes[i].Get_Index();
555 
556  if( Index != i )
557  {
558  bChanged = true;
559 
560  m_pGrids[i] = pGrids[Index];
561 
562  m_Attributes[i].Assign(&Attributes[i]);
563  }
564  }
565 
566  for(int i=0; i<Get_Grid_Count(); i++)
567  {
568  pGrids[i]->Set_Name(Get_Grid_Name(i));
569  }
570  }
571 
572  return( bChanged );
573 }
574 
575 
577 // //
578 // //
579 // //
581 
582 //---------------------------------------------------------
584 {
585  if( Count == Get_NZ() )
586  {
587  return( true );
588  }
589 
590  if( Count < 0 || !Get_System().is_Valid() ) // only allowed for initialized grid systems)
591  {
592  return( false );
593  }
594 
595  if( Count == 0 )
596  {
597  return( Del_Grids() );
598  }
599 
600  //-----------------------------------------------------
601  SG_FREE_SAFE(m_Index); // invalidate index
602 
603  if( Count < Get_NZ() )
604  {
605  for(int i=Count; i<Get_NZ(); i++)
606  {
607  delete(m_pGrids[i]);
608  }
609 
610  m_pGrids = (CSG_Grid **)m_Grids.Get_Array(Count);
611 
612  m_Attributes.Set_Count(Count);
613  }
614 
615  //-----------------------------------------------------
616  else if( Count > Get_NZ() )
617  {
618  double z = Get_ZMax();
619 
620  for(int i=Get_NZ(); i<=Count; i++, z+=Get_Cellsize())
621  {
622  if( !Add_Grid(z) )
623  {
624  return( false );
625  }
626  }
627  }
628 
629  return( true );
630 }
631 
632 
634 // //
636 
637 //---------------------------------------------------------
638 bool CSG_Grids::Add_Grid(double Z)
639 {
640  CSG_Table Attributes(&m_Attributes);
641 
642  Attributes.Add_Record();
643 
644  Attributes[0].Set_Value(m_Z_Attribute, Z);
645 
646  return( Add_Grid(Attributes[0]) );
647 }
648 
649 //---------------------------------------------------------
650 bool CSG_Grids::Add_Grid(double Z, CSG_Grid *pGrid, bool bAttach)
651 {
652  CSG_Table Attributes(&m_Attributes);
653 
654  Attributes.Add_Record();
655 
656  Attributes[0].Set_Value(m_Z_Attribute, Z);
657 
658  return( Add_Grid(Attributes[0], pGrid, bAttach) );
659 }
660 
661 //---------------------------------------------------------
663 {
664  if( !Get_System().is_Valid() ) // only allowed for initialized grid systems
665  {
666  return( false );
667  }
668 
669  //-----------------------------------------------------
670  int n = Get_NZ();
671 
672  if( n < 1 ) // do some initializations
673  {
674  _Synchronize(m_pGrids[0]);
675  }
676  else // use dummy grid (m_pGrids[0] is always present)
677  {
679 
680  if( !pGrid )
681  {
682  return( false );
683  }
684 
685  m_pGrids = (CSG_Grid **)m_Grids.Get_Array(n + 1);
686  m_pGrids[n] = pGrid;
687 
688  _Synchronize(pGrid);
689  }
690 
691  //-----------------------------------------------------
692  m_Attributes.Add_Record(&Attributes);
693 
694  SG_FREE_SAFE(m_Index); // invalidate index
695 
696  Update_Z_Order();
697 
698  return( true );
699 }
700 
701 //---------------------------------------------------------
702 bool CSG_Grids::Add_Grid(CSG_Table_Record &Attributes, CSG_Grid *pGrid, bool bAttach)
703 {
704  if( !pGrid || !pGrid->is_Valid() )
705  {
706  return( false );
707  }
708 
709  if( Get_NZ() > 0 && !is_Compatible(pGrid) ) // not allowed
710  {
711  return( false );
712  }
713 
714  //-----------------------------------------------------
715  int n = Get_NZ();
716 
717  if( n > 0 )
718  {
719  if( !bAttach && (pGrid = SG_Create_Grid(*pGrid)) == NULL ) // get a copy
720  {
721  return( false );
722  }
723 
724  m_pGrids = (CSG_Grid **)m_Grids.Get_Array(n + 1);
725  m_pGrids[n] = pGrid;
726  }
727  else if( bAttach ) // if( n == 0 )
728  {
729  delete(m_pGrids[0]);
730 
731  m_pGrids[0] = pGrid; // simply replace dummy
732  }
733  else if( m_pGrids[0]->Create(*pGrid) ) // make dummy a copy of grid
734  {
735  pGrid = m_pGrids[0];
736  }
737  else
738  {
739  return( false );
740  }
741 
742  _Synchronize(pGrid);
743 
744  //-----------------------------------------------------
745  m_Attributes.Add_Record(&Attributes);
746 
747  if( !Get_Projection().is_Okay() && pGrid->Get_Projection().is_Okay() )
748  {
749  Get_Projection() = pGrid->Get_Projection();
750  }
751 
752  SG_FREE_SAFE(m_Index); // invalidate index
753 
754  Update_Z_Order();
755 
756  return( true );
757 }
758 
759 
761 // //
763 
764 //---------------------------------------------------------
765 bool CSG_Grids::Del_Grid(int i, bool bDetach)
766 {
767  if( m_Attributes.Del_Record(i) ) // Get_NZ() is now decreased by one
768  {
769  SG_FREE_SAFE(m_Index); // invalidate index
770 
771  if( Get_NZ() > 0 )
772  {
773  if( bDetach )
774  {
775  m_pGrids[i]->Set_Owner(NULL);
776  }
777  else
778  {
779  delete(m_pGrids[i]);
780  }
781 
782  for( ; i<Get_NZ(); i++)
783  {
784  m_pGrids[i] = m_pGrids[i + 1];
785  }
786 
787  m_pGrids = (CSG_Grid **)m_Grids.Get_Array(Get_NZ());
788  }
789  else if( bDetach ) // if( Get_NZ() == 0 )
790  {
791  m_pGrids[0]->Set_Owner(NULL);
792  m_pGrids[0] = SG_Create_Grid(*m_pGrids[0]); // needs a new dummy
793  m_pGrids[0]->Set_Owner(this);
794  }
795 
796  return( true );
797  }
798 
799  return( false );
800 }
801 
802 //---------------------------------------------------------
803 bool CSG_Grids::Del_Grids(bool bDetach)
804 {
805  SG_FREE_SAFE(m_Index); // invalidate index
806 
807  if( bDetach )
808  {
809  for(size_t i=0; i<m_Grids.Get_uSize(); i++)
810  {
811  if( m_pGrids[i]->Get_Owner() == this )
812  {
813  m_pGrids[i]->Set_Owner(NULL);
814  }
815  }
816 
817  m_pGrids[0] = SG_Create_Grid(*m_pGrids[0]); // needs a new dummy
818  m_pGrids[0]->Set_Owner(this);
819  }
820  else
821  {
822  for(size_t i=1; i<m_Grids.Get_uSize(); i++)
823  {
824  delete(m_pGrids[i]); // do not delete the dummy before deconstruction
825  }
826  }
827 
828  m_pGrids = (CSG_Grid **)m_Grids.Get_Array(1);
829 
830  m_Attributes.Del_Records();
831 
832  return( true );
833 }
834 
835 
837 // //
839 
840 //---------------------------------------------------------
841 CSG_String CSG_Grids::Get_Grid_Name(int i, int Style) const
842 {
843  CSG_String s;
844 
845  if( i >= 0 && i < Get_Grid_Count() )
846  {
847  if( Style == 0 )
848  {
850  }
851 
852  if( (Style & SG_GRIDS_NAME_OWNER) != 0 )
853  {
854  s = CSG_String(Get_Name());
855  }
856 
857  if( (Style & SG_GRIDS_NAME_INDEX) != 0 )
858  {
859  if( !s.is_Empty() ) s += ".";
860 
861  s.Printf("%s %d", _TL("Band"), i + 1);
862  }
863 
864  if( (Style & SG_GRIDS_NAME_VALUE) != 0 )
865  {
866  if( !s.is_Empty() ) s += ".";
867 
868  s += SG_Get_String(Get_Z(i), -10);
869  }
870 
871  if( (Style & SG_GRIDS_NAME_GRID ) != 0 )
872  {
873  if( !s.is_Empty() ) s += ".";
874 
875  s += m_Attributes[i].asString(Get_Z_Name_Field());
876  }
877  }
878 
879  return( s );
880 }
881 
882 
884 // //
885 // //
886 // //
888 
889 //---------------------------------------------------------
891 {
892  for(int i=0; i<Get_Grid_Count(); i++)
893  {
894  m_pGrids[i]->Assign_NoData();
895  }
896 }
897 
898 //---------------------------------------------------------
899 bool CSG_Grids::Assign(double Value)
900 {
901  for(int i=0; i<Get_Grid_Count(); i++)
902  {
903  m_pGrids[i]->Assign(Value);
904  }
905 
906  return( true );
907 }
908 
909 //---------------------------------------------------------
911 {
912  if( pObject )
913  {
914  switch( pObject->Get_ObjectType() )
915  {
917  {
918  bool bResult = true;
919 
920  for(int i=0; i<Get_Grid_Count(); i++)
921  {
922  if( !m_pGrids[i]->Assign((CSG_Grid *)pObject) )
923  {
924  bResult = false;
925  }
926  }
927 
928  return( bResult );
929  }
930 
932  return( Assign((CSG_Grids *)pObject) );
933 
934  default:
935  break;
936  }
937  }
938 
939  return( false );
940 }
941 
942 //---------------------------------------------------------
943 bool CSG_Grids::Assign(CSG_Grids *pGrids, TSG_Grid_Resampling Interpolation)
944 {
945  if( pGrids && Get_Grid_Count() == pGrids->Get_Grid_Count() )
946  {
947  bool bResult = true;
948 
949  for(int i=0; i<Get_Grid_Count(); i++)
950  {
951  if( !m_pGrids[i]->Assign(pGrids->m_pGrids[i], Interpolation) )
952  {
953  bResult = false;
954  }
955  }
956 
957  return( bResult );
958  }
959 
960  return( false );
961 }
962 
963 
965 // //
967 
968 //---------------------------------------------------------
970 {
971  Create(Grids); return( *this );
972 }
973 
975 {
976  Assign(Value); return( *this );
977 }
978 
979 //---------------------------------------------------------
981 {
982  return( Add(Value) );
983 }
984 
985 CSG_Grids & CSG_Grids::Add(double Value)
986 {
987  for(int i=0; i<Get_Grid_Count(); i++)
988  {
989  m_pGrids[i]->Add(Value);
990  }
991 
992  return( *this );
993 }
994 
995 //---------------------------------------------------------
997 {
998  return( Subtract(Value) );
999 }
1000 
1002 {
1003  for(int i=0; i<Get_Grid_Count(); i++)
1004  {
1005  m_pGrids[i]->Subtract(Value);
1006  }
1007 
1008  return( *this );
1009 }
1010 
1011 //---------------------------------------------------------
1013 {
1014  return( Multiply(Value) );
1015 }
1016 
1018 {
1019  for(int i=0; i<Get_Grid_Count(); i++)
1020  {
1021  m_pGrids[i]->Multiply(Value);
1022  }
1023 
1024  return( *this );
1025 }
1026 
1027 //---------------------------------------------------------
1029 {
1030  return( Divide(Value) );
1031 }
1032 
1034 {
1035  for(int i=0; i<Get_Grid_Count(); i++)
1036  {
1037  m_pGrids[i]->Divide(Value);
1038  }
1039 
1040  return( *this );
1041 }
1042 
1043 
1045 // //
1046 // Value access by Position (-> Interpolation) //
1047 // //
1049 
1050 //---------------------------------------------------------
1051 double CSG_Grids::Get_Value(const TSG_Point_3D &p, TSG_Grid_Resampling Resampling, TSG_Grid_Resampling ZResampling) const
1052 {
1053  double Value;
1054 
1055  return( Get_Value(p.x, p.y, p.z, Value, Resampling, ZResampling) ? Value : Get_NoData_Value() );
1056 }
1057 
1058 double CSG_Grids::Get_Value(double x, double y, double z, TSG_Grid_Resampling Resampling, TSG_Grid_Resampling ZResampling) const
1059 {
1060  double Value;
1061 
1062  return( Get_Value(x, y, z, Value, Resampling, ZResampling) ? Value : Get_NoData_Value() );
1063 }
1064 
1065 bool CSG_Grids::Get_Value(const TSG_Point_3D &p, double &Value, TSG_Grid_Resampling Resampling, TSG_Grid_Resampling ZResampling) const
1066 {
1067  return( Get_Value(p.x, p.y, p.z, Value, Resampling, ZResampling) );
1068 }
1069 
1070 //---------------------------------------------------------
1071 bool CSG_Grids::Get_Value(double x, double y, double z, double &Value, TSG_Grid_Resampling Resampling, TSG_Grid_Resampling ZResampling) const
1072 {
1073  if( !Get_System().Get_Extent(true).Contains(x, y) )
1074  {
1075  return( false );
1076  }
1077 
1078  int iz; double dz;
1079 
1080  if( !_Get_Z(z, iz, dz) )
1081  {
1082  return( false );
1083  }
1084 
1085  if( dz == 0. )
1086  {
1087  return( m_pGrids[iz]->Get_Value(x, y, Value, Resampling) );
1088  }
1089 
1090  if( ZResampling == GRID_RESAMPLING_Undefined )
1091  {
1092  ZResampling = Resampling;
1093  }
1094 
1095  if( (ZResampling == GRID_RESAMPLING_BicubicSpline || ZResampling == GRID_RESAMPLING_BSpline)
1096  && (iz < 1 || iz >= m_Attributes.Get_Count() - 2) )
1097  {
1098  ZResampling = GRID_RESAMPLING_Bilinear;
1099  }
1100 
1101  switch( ZResampling )
1102  {
1103  case GRID_RESAMPLING_NearestNeighbour: default:
1104  return( m_pGrids[dz < 0.5 ? iz : iz + 1]->Get_Value(x, y, Value, Resampling) );
1105 
1107  {
1108  double v[2];
1109 
1110  if( m_pGrids[iz ]->Get_Value(x, y, v[0], Resampling)
1111  && m_pGrids[iz + 1]->Get_Value(x, y, v[1], Resampling) )
1112  {
1113  Value = v[0] + dz * (v[1] - v[0]);
1114 
1115  return( true );
1116  }
1117 
1118  return( false );
1119  }
1120 
1123  {
1124  CSG_Spline s;
1125 
1126  #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);
1127 
1128  ADD_TO_SPLINE(iz - 1);
1129  ADD_TO_SPLINE(iz );
1130  ADD_TO_SPLINE(iz + 1);
1131  ADD_TO_SPLINE(iz + 2);
1132 
1133  return( s.Get_Value(z, Value) );
1134  }
1135  break;
1136  }
1137 
1138  return( false );
1139 }
1140 
1141 //---------------------------------------------------------
1142 bool CSG_Grids::_Get_Z(double z, int &iz, double &dz) const
1143 {
1144  if( z < m_Attributes[0 ].asDouble(m_Z_Attribute)
1145  || z > m_Attributes[m_Attributes.Get_Count() - 1].asDouble(m_Z_Attribute) )
1146  {
1147  return( false );
1148  }
1149 
1150  double z0, z1 = m_Attributes[0].asDouble(m_Z_Attribute);
1151 
1152  for(iz=0; iz<m_Attributes.Get_Count()-1; iz++)
1153  {
1154  z0 = z1; z1 = m_Attributes[iz + 1].asDouble(m_Z_Attribute);
1155 
1156  if( z < z1 )
1157  {
1158  dz = z0 < z1 ? (z - z0) / (z1 - z0) : 0.;
1159 
1160  return( true );
1161  }
1162  }
1163 
1164  return( (dz = z - z1) == 0. );
1165 }
1166 
1167 
1169 // //
1170 // Index //
1171 // //
1173 
1174 //---------------------------------------------------------
1175 #define SORT_SWAP(a,b) {itemp=(a);(a)=(b);(b)=itemp;}
1176 
1177 bool CSG_Grids::_Set_Index(void)
1178 {
1179  //-----------------------------------------------------
1180  if( m_Index == NULL && (m_Index = (sLong *)SG_Malloc((size_t)Get_NCells() * sizeof(sLong))) == NULL )
1181  {
1182  SG_UI_Msg_Add_Error(_TL("could not create index: insufficient memory"));
1183 
1184  return( false );
1185  }
1186 
1187  //-----------------------------------------------------
1188  const sLong M = 7;
1189 
1190  sLong i, j, k, l, ir, n, *istack, jstack, nstack, indxt, itemp, nData;
1191  double a;
1192 
1193  //-----------------------------------------------------
1194  SG_UI_Process_Set_Text(CSG_String::Format("%s: %s", _TL("Create index"), Get_Name()));
1195 
1196  for(i=0, j=0, nData=Get_NCells(); i<Get_NCells(); i++)
1197  {
1198  if( is_NoData(i) )
1199  {
1200  m_Index[--nData] = i;
1201  }
1202  else // if( !is_NoData(i) )
1203  {
1204  m_Index[j++] = i;
1205  }
1206  }
1207 
1208  //-----------------------------------------------------
1209  l = 0;
1210  n = 0;
1211  ir = nData - 1;
1212 
1213  nstack = 64;
1214  istack = (sLong *)SG_Malloc((size_t)nstack * sizeof(sLong));
1215  jstack = 0;
1216 
1217  for(;;)
1218  {
1219  if( ir - l < M )
1220  {
1221  if( !SG_UI_Process_Set_Progress((double)(n += M - 1), (double)nData) )
1222  {
1223  SG_FREE_SAFE(istack);
1224  SG_FREE_SAFE(m_Index);
1225 
1226  SG_UI_Msg_Add_Error(_TL("index creation stopped by user"));
1228 
1229  return( false );
1230  }
1231 
1232  for(j=l+1; j<=ir; j++)
1233  {
1234  indxt = m_Index[j];
1235  a = asDouble(indxt);
1236 
1237  for(i=j-1; i>=0; i--)
1238  {
1239  if( asDouble(m_Index[i]) <= a )
1240  {
1241  break;
1242  }
1243 
1244  m_Index[i + 1] = m_Index[i];
1245  }
1246 
1247  m_Index[i + 1] = indxt;
1248  }
1249 
1250  if( jstack == 0 )
1251  {
1252  break;
1253  }
1254 
1255  ir = istack[jstack--];
1256  l = istack[jstack--];
1257  }
1258 
1259  //-------------------------------------------------
1260  else
1261  {
1262  k = (l + ir) >> 1;
1263 
1264  SORT_SWAP(m_Index[k], m_Index[l + 1]);
1265 
1266  if( asDouble( m_Index[l + 1]) > asDouble(m_Index[ir]) )
1267  SORT_SWAP(m_Index[l + 1], m_Index[ir]);
1268 
1269  if( asDouble( m_Index[l ]) > asDouble(m_Index[ir]) )
1270  SORT_SWAP(m_Index[l ], m_Index[ir]);
1271 
1272  if( asDouble( m_Index[l + 1]) > asDouble(m_Index[l ]) )
1273  SORT_SWAP(m_Index[l + 1], m_Index[l ]);
1274 
1275  i = l + 1;
1276  j = ir;
1277  indxt = m_Index[l];
1278  a = asDouble(indxt);
1279 
1280  for(;;)
1281  {
1282  do i++; while(asDouble(m_Index[i]) < a);
1283  do j--; while(asDouble(m_Index[j]) > a);
1284 
1285  if( j < i )
1286  {
1287  break;
1288  }
1289 
1290  SORT_SWAP(m_Index[i], m_Index[j]);
1291  }
1292 
1293  m_Index[l] = m_Index[j];
1294  m_Index[j] = indxt;
1295  jstack += 2;
1296 
1297  if( jstack >= nstack )
1298  {
1299  nstack += 64;
1300  istack = (sLong *)SG_Realloc(istack, (size_t)nstack * sizeof(int));
1301  }
1302 
1303  if( ir - i + 1 >= j - l )
1304  {
1305  istack[jstack] = ir;
1306  istack[jstack - 1] = i;
1307  ir = j - 1;
1308  }
1309  else
1310  {
1311  istack[jstack] = j - 1;
1312  istack[jstack - 1] = l;
1313  l = i;
1314  }
1315  }
1316  }
1317 
1318  //-----------------------------------------------------
1319  SG_Free(istack);
1320 
1322 
1323  return( true );
1324 }
1325 #undef SORT_SWAP
1326 
1327 
1329 // //
1330 // Statistics //
1331 // //
1333 
1334 //---------------------------------------------------------
1336 {
1337  if( is_Valid() )
1338  {
1339  SG_FREE_SAFE(m_Index);
1340 
1341  m_Statistics.Invalidate();
1342  m_Histogram.Destroy();
1343 
1344  double Offset = Get_Offset(), Scaling = is_Scaled() ? Get_Scaling() : 0.;
1345 
1346  if( Get_Max_Samples() > 0 && Get_Max_Samples() < Get_NCells() )
1347  {
1348  double d = (double)Get_NCells() / (double)Get_Max_Samples();
1349 
1350  for(double i=0; i<(double)Get_NCells(); i+=d)
1351  {
1352  double Value = asDouble((sLong)i, false);
1353 
1354  if( !is_NoData_Value(Value) )
1355  {
1356  m_Statistics += Scaling ? Offset + Scaling * Value : Value;
1357  }
1358  }
1359 
1360  m_Statistics.Set_Count(m_Statistics.Get_Count() >= Get_Max_Samples() ? Get_NCells() // any no-data cells ?
1361  : (sLong)(Get_NCells() * (double)m_Statistics.Get_Count() / (double)Get_Max_Samples())
1362  );
1363  }
1364  else
1365  {
1366  for(sLong i=0; i<Get_NCells(); i++)
1367  {
1368  double Value = asDouble(i, false);
1369 
1370  if( !is_NoData_Value(Value) )
1371  {
1372  m_Statistics += Scaling ? Offset + Scaling * Value : Value;
1373  }
1374  }
1375  }
1376  }
1377 
1378  return( true );
1379 }
1380 
1381 //---------------------------------------------------------
1383 {
1384  Update(); return( m_Statistics.Get_Mean() );
1385 }
1386 
1388 {
1389  Update(); return( m_Statistics.Get_Minimum() );
1390 }
1391 
1393 {
1394  Update(); return( m_Statistics.Get_Maximum() );
1395 }
1396 
1398 {
1399  Update(); return( m_Statistics.Get_Range() );
1400 }
1401 
1403 {
1404  Update(); return( m_Statistics.Get_StdDev() );
1405 }
1406 
1408 {
1409  Update(); return( m_Statistics.Get_Variance() );
1410 }
1411 
1412 //---------------------------------------------------------
1414 {
1415  Update(); return( m_Statistics.Get_Count() );
1416 }
1417 
1419 {
1420  Update(); return( Get_NCells() - m_Statistics.Get_Count() );
1421 }
1422 
1423 //---------------------------------------------------------
1424 double CSG_Grids::Get_Quantile(double Quantile, bool bFromHistogram)
1425 {
1426  if( Quantile <= 0. ) { return( Get_Min() ); }
1427  if( Quantile >= 1. ) { return( Get_Max() ); }
1428 
1429  if( bFromHistogram )
1430  {
1431  return( Get_Histogram().Get_Quantile(Quantile) );
1432  }
1433  else
1434  {
1435  sLong n = (sLong)(Quantile * (Get_Data_Count() - 1));
1436 
1437  if( Get_Sorted(n, n, false) )
1438  {
1439  return( asDouble(n) );
1440  }
1441  }
1442 
1443  return( Get_NoData_Value() );
1444 }
1445 
1446 //---------------------------------------------------------
1447 double CSG_Grids::Get_Percentile(double Percentile, bool bFromHistogram)
1448 {
1449  return( Get_Quantile(0.01 * Percentile, bFromHistogram) );
1450 }
1451 
1452 
1454 // //
1456 
1457 //---------------------------------------------------------
1465 {
1466  Update(); return( m_Statistics );
1467 }
1468 
1469 //---------------------------------------------------------
1475 //---------------------------------------------------------
1476 bool CSG_Grids::Get_Statistics(const CSG_Rect &rWorld, CSG_Simple_Statistics &Statistics, bool bHoldValues) const
1477 {
1478  int xMin = Get_System().Get_xWorld_to_Grid(rWorld.Get_XMin()); if( xMin < 0 ) xMin = 0;
1479  int yMin = Get_System().Get_yWorld_to_Grid(rWorld.Get_YMin()); if( yMin < 0 ) yMin = 0;
1480  int xMax = Get_System().Get_xWorld_to_Grid(rWorld.Get_XMax()); if( xMax >= Get_NX() ) xMax = Get_NX() - 1;
1481  int yMax = Get_System().Get_yWorld_to_Grid(rWorld.Get_YMax()); if( yMax >= Get_NY() ) yMax = Get_NY() - 1;
1482 
1483  if( xMin > xMax || yMin > yMax )
1484  {
1485  return( false ); // no overlap
1486  }
1487 
1488  Statistics.Create(bHoldValues);
1489 
1490  int nx = 1 + (xMax - xMin);
1491  int ny = 1 + (yMax - yMin);
1492  sLong nCells = nx * ny;
1493 
1494  double Offset = Get_Offset(), Scaling = is_Scaled() ? Get_Scaling() : 0.;
1495 
1496  if( Get_Max_Samples() > 0 && Get_Max_Samples() < nCells )
1497  {
1498  double d = (double)nCells / (double)Get_Max_Samples();
1499 
1500  for(double i=0; i<(double)nCells; i+=d)
1501  {
1502  int y = yMin + (int)i / nx;
1503  int x = xMin + (int)i % nx;
1504 
1505  for(int z=0; z<Get_NZ(); z++)
1506  {
1507  double Value = asDouble(x, y, z, false);
1508 
1509  if( !is_NoData_Value(Value) )
1510  {
1511  Statistics += Scaling ? Offset + Scaling * Value : Value;
1512  }
1513  }
1514  }
1515  }
1516  else
1517  {
1518  for(int x=xMin; x<=xMax; x++)
1519  {
1520  for(int y=yMin; y<=yMax; y++)
1521  {
1522  for(int z=0; z<Get_NZ(); z++)
1523  {
1524  double Value = asDouble(x, y, z, false);
1525 
1526  if( !is_NoData_Value(Value) )
1527  {
1528  Statistics += Scaling ? Offset + Scaling * Value : Value;
1529  }
1530  }
1531  }
1532  }
1533  }
1534 
1535  return( Statistics.Get_Count() > 0 );
1536 }
1537 
1538 //---------------------------------------------------------
1540 {
1541  if( CSG_Data_Object::Set_Max_Samples(Max_Samples) )
1542  {
1543  for(int i=0; i<Get_Grid_Count(); i++)
1544  {
1545  Get_Grid_Ptr(i)->Set_Max_Samples(Max_Samples);
1546  }
1547 
1548  return( true );
1549  }
1550 
1551  return( false );
1552 }
1553 
1554 //---------------------------------------------------------
1555 #define SG_GRID_HISTOGRAM_CLASSES_DEFAULT 255
1556 
1557 //---------------------------------------------------------
1562 const CSG_Histogram & CSG_Grids::Get_Histogram(size_t nClasses)
1563 {
1564  Update();
1565 
1566  if( nClasses > 1 && nClasses != m_Histogram.Get_Class_Count() )
1567  {
1568  m_Histogram.Destroy();
1569  }
1570 
1571  if( m_Histogram.Get_Statistics().Get_Count() < 1 )
1572  {
1573  m_Histogram.Create(nClasses > 1 ? nClasses : SG_GRID_HISTOGRAM_CLASSES_DEFAULT, Get_Min(), Get_Max(), this, (size_t)Get_Max_Samples());
1574  }
1575 
1576  return( m_Histogram );
1577 }
1578 
1579 //---------------------------------------------------------
1580 bool CSG_Grids::Get_Histogram(const CSG_Rect &rWorld, CSG_Histogram &Histogram, size_t nClasses) const
1581 {
1582  CSG_Simple_Statistics Statistics;
1583 
1584  if( !Get_Statistics(rWorld, Statistics) )
1585  {
1586  return( false );
1587  }
1588 
1589  int xMin = Get_System().Get_xWorld_to_Grid(rWorld.Get_XMin()); if( xMin < 0 ) xMin = 0;
1590  int yMin = Get_System().Get_yWorld_to_Grid(rWorld.Get_YMin()); if( yMin < 0 ) yMin = 0;
1591  int xMax = Get_System().Get_xWorld_to_Grid(rWorld.Get_XMax()); if( xMax >= Get_NX() ) xMax = Get_NX() - 1;
1592  int yMax = Get_System().Get_yWorld_to_Grid(rWorld.Get_YMax()); if( yMax >= Get_NY() ) yMax = Get_NY() - 1;
1593 
1594  if( xMin > xMax || yMin > yMax )
1595  {
1596  return( false ); // no overlap
1597  }
1598 
1599  Histogram.Create(nClasses > 1 ? nClasses : SG_GRID_HISTOGRAM_CLASSES_DEFAULT, Statistics.Get_Minimum(), Statistics.Get_Maximum());
1600 
1601  int nx = 1 + (xMax - xMin);
1602  int ny = 1 + (yMax - yMin);
1603  sLong nCells = nx * ny;
1604 
1605  double Offset = Get_Offset(), Scaling = is_Scaled() ? Get_Scaling() : 0.;
1606 
1607  if( Get_Max_Samples() > 0 && Get_Max_Samples() < nCells )
1608  {
1609  double d = (double)nCells / (double)Get_Max_Samples();
1610 
1611  for(double i=0; i<(double)nCells; i+=d)
1612  {
1613  int y = yMin + (int)i / nx;
1614  int x = xMin + (int)i % nx;
1615 
1616  for(int z=0; z<Get_NZ(); z++)
1617  {
1618  double Value = asDouble(x, y, z, false);
1619 
1620  if( !is_NoData_Value(Value) )
1621  {
1622  Histogram += Scaling ? Offset + Scaling * Value : Value;
1623  }
1624  }
1625  }
1626  }
1627  else
1628  {
1629  for(int x=xMin; x<=xMax; x++)
1630  {
1631  for(int y=yMin; y<=yMax; y++)
1632  {
1633  for(int z=0; z<Get_NZ(); z++)
1634  {
1635  double Value = asDouble(x, y, z, false);
1636 
1637  if( !is_NoData_Value(Value) )
1638  {
1639  Histogram += Scaling ? Offset + Scaling * Value : Value;
1640  }
1641  }
1642  }
1643  }
1644  }
1645 
1646  return( Histogram.Update() );
1647 }
1648 
1649 
1651 // //
1652 // //
1653 // //
1655 
1656 //---------------------------------------------------------
1658 {
1659  return( Create(Get_File_Name(false)) );
1660 }
1661 
1662 //---------------------------------------------------------
1664 {
1665  CSG_String FileName = Get_File_Name(true);
1666 
1667  SG_File_Set_Extension(FileName, "sg-gds-z"); SG_File_Delete(FileName);
1668  SG_File_Set_Extension(FileName, "sg-gds" ); SG_File_Delete(FileName);
1669  SG_File_Set_Extension(FileName, "sg-info" ); SG_File_Delete(FileName);
1670  SG_File_Set_Extension(FileName, "sg-prj" ); SG_File_Delete(FileName);
1671 
1672  int i = 0;
1673 
1674  do
1675  {
1676  SG_File_Set_Extension(FileName, CSG_String::Format("sg-%03d", ++i));
1677  }
1678  while( SG_File_Delete(FileName) );
1679 
1680  return( true );
1681 }
1682 
1683 
1685 // //
1687 
1688 //---------------------------------------------------------
1689 bool CSG_Grids::Load(const CSG_String &FileName, bool bLoadData)
1690 {
1691  Destroy();
1692 
1693  SG_UI_Msg_Add(CSG_String::Format("%s: %s...", _TL("Loading grid collection"), FileName.c_str()), true);
1694 
1695  if( _Load_PGSQL (FileName)
1696  || _Load_Normal (FileName)
1697  || _Load_Compressed(FileName)
1698  || _Load_External (FileName) )
1699  {
1700  Set_Modified(false);
1701 
1702  Set_Name(SG_File_Get_Name(FileName, false));
1703 
1705  SG_UI_Msg_Add(_TL("okay"), false, SG_UI_MSG_STYLE_SUCCESS);
1706 
1707  return( true );
1708  }
1709 
1711  SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);
1712 
1713  return( false );
1714 }
1715 
1716 //---------------------------------------------------------
1717 bool CSG_Grids::Save(const CSG_String &FileName, int Format)
1718 {
1719  SG_UI_Msg_Add(CSG_String::Format("%s %s: %s...", _TL("Saving"), _TL("grid collection"), FileName.c_str()), true);
1720 
1721  if( Format == GRIDS_FILE_FORMAT_Undefined )
1722  {
1723  Format = GRIDS_FILE_FORMAT_Compressed; // default
1724 
1725  if( SG_File_Cmp_Extension(FileName, "sg-gds" ) ) Format = GRIDS_FILE_FORMAT_Normal ;
1726  if( SG_File_Cmp_Extension(FileName, "sg-gds-z") ) Format = GRIDS_FILE_FORMAT_Compressed;
1727  if( SG_File_Cmp_Extension(FileName, "tif" ) ) Format = GRIDS_FILE_FORMAT_GeoTIFF ;
1728  }
1729 
1730  bool bResult = false;
1731 
1732  switch( Format )
1733  {
1735  bResult = _Save_Normal (FileName);
1736  break;
1737 
1738  case GRIDS_FILE_FORMAT_Compressed: default:
1739  bResult = _Save_Compressed(FileName);
1740  break;
1741 
1743  SG_RUN_TOOL(bResult, "io_gdal", 2, // Export GeoTIFF
1744  SG_TOOL_PARAMLIST_ADD("GRIDS", this)
1745  && SG_TOOL_PARAMETER_SET("FILE" , FileName)
1746  );
1747  break;
1748  }
1749 
1750  //-----------------------------------------------------
1752 
1753  if( bResult )
1754  {
1755  Set_Modified(false);
1756 
1757  Set_File_Name(FileName, true);
1758 
1759  SG_UI_Msg_Add(_TL("okay"), false, SG_UI_MSG_STYLE_SUCCESS);
1760 
1761  return( true );
1762  }
1763 
1764  SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);
1765 
1766  return( false );
1767 }
1768 
1769 
1771 // //
1773 
1774 //---------------------------------------------------------
1775 bool CSG_Grids::_Load_External(const CSG_String &FileName)
1776 {
1777  bool bResult = false;
1778 
1779  CSG_Data_Manager Data;
1780 
1781  CSG_Tool *pTool = SG_Get_Tool_Library_Manager().Create_Tool("io_gdal", 0); // import raster
1782 
1783  SG_UI_Msg_Lock(true);
1784 
1785  if( pTool && pTool->On_Before_Execution() && pTool->Settings_Push(&Data)
1786  && pTool->Set_Parameter("FILES" , FileName)
1787  && pTool->Set_Parameter("MULTIPLE", 1 ) // output as grid collection
1788  && pTool->Execute()
1789  && Data.Grid_System_Count() > 0 && Data.Get_Grid_System(0)->Count() > 0 && Data.Get_Grid_System(0)->Get(0)->is_Valid() )
1790  {
1791  CSG_Grids *pGrids = (CSG_Grids *)Data.Get_Grid_System(0)->Get(0);
1792 
1793  m_Attributes.Create(&pGrids->m_Attributes);
1794 
1795  for(int i=0; i<pGrids->Get_Grid_Count(); i++)
1796  {
1797  Add_Grid(pGrids->Get_Attributes(i), pGrids->Get_Grid_Ptr(i), true);
1798  }
1799 
1800  Set_File_Name(FileName, false);
1801 
1802  Set_Name (pGrids->Get_Name ());
1803  Set_Description (pGrids->Get_Description ());
1804  Set_Z_Attribute (pGrids->Get_Z_Attribute ());
1806 
1807  pGrids->Del_Grids(true);
1808 
1809  bResult = true;
1810  }
1811 
1812  SG_UI_Msg_Lock(false);
1813 
1815 
1816  return( bResult );
1817 }
1818 
1819 //---------------------------------------------------------
1820 bool CSG_Grids::_Load_PGSQL(const CSG_String &FileName)
1821 {
1822  bool bResult = false;
1823 
1824  if( FileName.BeforeFirst(':').Cmp("PGSQL") == 0 ) // database source
1825  {
1826  CSG_String s(FileName);
1827 
1828  s = s.AfterFirst(':'); CSG_String Host (s.BeforeFirst(':'));
1829  s = s.AfterFirst(':'); CSG_String Port (s.BeforeFirst(':'));
1830  s = s.AfterFirst(':'); CSG_String DBName(s.BeforeFirst(':'));
1831  s = s.AfterFirst(':'); CSG_String Table (s.BeforeFirst(':'));
1832  s = s.AfterFirst(':'); CSG_String rid (s.BeforeFirst(':').AfterFirst('='));
1833 
1834  //-------------------------------------------------
1835  CSG_String_Tokenizer rids(rid, ","); rid.Clear();
1836 
1837  while( rids.Has_More_Tokens() )
1838  {
1839  if( !rid.is_Empty() )
1840  {
1841  rid += " OR ";
1842  }
1843 
1844  rid += "rid=\'" + rids.Get_Next_Token() + "\'";
1845  }
1846 
1847  //-------------------------------------------------
1848  CSG_Tool *pTool = SG_Get_Tool_Library_Manager().Create_Tool("db_pgsql", 0, true); // CGet_Connections
1849 
1850  if( pTool != NULL )
1851  {
1853 
1854  //---------------------------------------------
1855  CSG_Table Connections;
1856  CSG_String Connection = DBName + " [" + Host + ":" + Port + "]";
1857 
1858  pTool->Set_Manager(NULL);
1859  pTool->On_Before_Execution();
1860 
1861  if( SG_TOOL_PARAMETER_SET("CONNECTIONS", &Connections) && pTool->Execute() ) // CGet_Connections
1862  {
1863  for(int i=0; !bResult && i<Connections.Get_Count(); i++)
1864  {
1865  if( !Connection.Cmp(Connections[i].asString(0)) )
1866  {
1867  bResult = true;
1868  }
1869  }
1870  }
1871 
1873 
1874  //---------------------------------------------
1875  if( bResult && (bResult = (pTool = SG_Get_Tool_Library_Manager().Create_Tool("db_pgsql", 30, true)) != NULL) == true ) // CPGIS_Raster_Load
1876  {
1877  CSG_Data_Manager Grids;
1878 
1879  pTool->On_Before_Execution();
1880  pTool->Settings_Push(&Grids);
1881 
1882  bResult = SG_TOOL_PARAMETER_SET("CONNECTION", Connection)
1883  && SG_TOOL_PARAMETER_SET("TABLES" , Table)
1884  && SG_TOOL_PARAMETER_SET("MULTIPLE" , 1) // grid collection
1885  && SG_TOOL_PARAMETER_SET("WHERE" , rid)
1886  && pTool->Execute();
1887 
1889 
1890  //-----------------------------------------
1891  if( Grids.Grid_System_Count() > 0 && Grids.Get_Grid_System(0)->Get(0) && Grids.Get_Grid_System(0)->Get(0)->is_Valid() )
1892  {
1893  CSG_Grids *pGrids = (CSG_Grids *)Grids.Get_Grid_System(0)->Get(0);
1894 
1895  Set_File_Name(FileName);
1896 
1897  Create(pGrids);
1898 
1899  for(int i=0; i<pGrids->Get_Grid_Count(); i++)
1900  {
1901  Add_Grid(pGrids->Get_Attributes(i), pGrids->Get_Grid_Ptr(i), true);
1902  }
1903 
1904  pGrids->Del_Grids(true);
1905  }
1906  }
1907 
1909  }
1910  }
1911 
1912  return( Get_NZ() > 0 );
1913 }
1914 
1915 
1917 // //
1919 
1920 //---------------------------------------------------------
1921 bool CSG_Grids::_Load_Normal(const CSG_String &_FileName)
1922 {
1923  if( !SG_File_Cmp_Extension(_FileName, "sg-gds") ) // GRIDS_FILETYPE_Normal
1924  {
1925  return( false );
1926  }
1927 
1928  CSG_String FileName(_FileName);
1929 
1930  CSG_File Stream;
1931 
1932  //-----------------------------------------------------
1933  if( !Stream.Open(FileName, SG_FILE_R, false) || !_Load_Header(Stream) )
1934  {
1935  return( false );
1936  }
1937 
1938  SG_File_Set_Extension(FileName, "sg-att");
1939 
1940  if( m_Attributes.Get_Count() <= 0 ) // <<< DEPRECATED
1941  if( !Stream.Open(FileName, SG_FILE_R, false) || !_Load_Attributes(Stream) )
1942  {
1943  return( false );
1944  }
1945 
1946  //-----------------------------------------------------
1947  for(int i=0; i<Get_NZ() && SG_UI_Process_Set_Progress(i, Get_NZ()); i++)
1948  {
1949  SG_File_Set_Extension(FileName, CSG_String::Format("sg-%03d", i + 1));
1950 
1951  if( !Stream.Open(FileName, SG_FILE_R, true) || !_Load_Data(Stream, m_pGrids[i]) )
1952  {
1953  return( false );
1954  }
1955  }
1956 
1957  //-----------------------------------------------------
1958  Set_File_Name(_FileName, true);
1959 
1960  Load_MetaData(FileName);
1961 
1962  Get_Projection().Load(SG_File_Make_Path("", FileName, "sg-prj"), SG_PROJ_FMT_WKT);
1963 
1964  return( true );
1965 }
1966 
1967 //---------------------------------------------------------
1968 bool CSG_Grids::_Save_Normal(const CSG_String &_FileName)
1969 {
1970  CSG_String FileName(_FileName);
1971 
1972  CSG_File Stream;
1973 
1974  //-----------------------------------------------------
1975  SG_File_Set_Extension(FileName, "sg-gds");
1976 
1977  if( !Stream.Open(FileName, SG_FILE_W, false) || !_Save_Header(Stream) )
1978  {
1979  return( false );
1980  }
1981 
1982  SG_File_Set_Extension(FileName, "sg-att");
1983 
1984  if( !Stream.Open(FileName, SG_FILE_W, false) || !_Save_Attributes(Stream) )
1985  {
1986  return( false );
1987  }
1988 
1989  //-----------------------------------------------------
1990  for(int i=0; i<Get_NZ() && SG_UI_Process_Set_Progress(i, Get_NZ()); i++)
1991  {
1992  SG_File_Set_Extension(FileName, CSG_String::Format("sg-%03d", i + 1));
1993 
1994  if( !Stream.Open(FileName, SG_FILE_W, true) || !_Save_Data(Stream, m_pGrids[i]) )
1995  {
1996  return( false );
1997  }
1998  }
1999 
2000  //-----------------------------------------------------
2001  Save_MetaData(FileName);
2002 
2003  Get_Projection().Save(SG_File_Make_Path("", FileName, "sg-prj"), SG_PROJ_FMT_WKT);
2004 
2005  return( true );
2006 }
2007 
2008 
2010 // //
2012 
2013 //---------------------------------------------------------
2014 bool CSG_Grids::_Load_Compressed(const CSG_String &_FileName)
2015 {
2016  if( !SG_File_Cmp_Extension(_FileName, "sg-gds-z") ) // GRIDS_FILETYPE_Compressed
2017  {
2018  return( false );
2019  }
2020 
2021  CSG_File_Zip Stream(_FileName, SG_FILE_R);
2022 
2023  CSG_String FileName(SG_File_Get_Name(_FileName, false) + ".");
2024 
2025  //-----------------------------------------------------
2026  if( !Stream.Get_File(FileName + "sg-gds") || !_Load_Header(Stream) )
2027  {
2028  return( false );
2029  }
2030 
2031  if( m_Attributes.Get_Count() <= 0 ) // <<< DEPRECATED
2032  if( !Stream.Get_File(FileName + "sg-att") || !_Load_Attributes(Stream) )
2033  {
2034  return( false );
2035  }
2036 
2037  //-----------------------------------------------------
2038  for(int i=0; i<Get_NZ() && SG_UI_Process_Set_Progress(i, Get_NZ()); i++)
2039  {
2040  if( !Stream.Get_File(FileName + CSG_String::Format("sg-%03d", i + 1)) || !_Load_Data(Stream, m_pGrids[i]) )
2041  {
2042  return( false );
2043  }
2044  }
2045 
2046  //-----------------------------------------------------
2047  Set_File_Name(_FileName, true);
2048 
2049  if( Stream.Get_File(FileName + "sg-info") )
2050  {
2051  Load_MetaData(Stream);
2052  }
2053 
2054  if( Stream.Get_File(FileName + "sg-prj") )
2055  {
2056  Get_Projection().Load(Stream, SG_PROJ_FMT_WKT);
2057  }
2058 
2059  return( true );
2060 }
2061 
2062 //---------------------------------------------------------
2063 bool CSG_Grids::_Save_Compressed(const CSG_String &_FileName)
2064 {
2065  CSG_File_Zip Stream(_FileName, SG_FILE_W);
2066 
2067  CSG_String FileName(SG_File_Get_Name(_FileName, false) + ".");
2068 
2069  //-----------------------------------------------------
2070  if( !Stream.Add_File(FileName + "sg-gds") || !_Save_Header(Stream) )
2071  {
2072  return( false );
2073  }
2074 
2075  if( !Stream.Add_File(FileName + "sg-att") || !_Save_Attributes(Stream) )
2076  {
2077  return( false );
2078  }
2079 
2080  //-----------------------------------------------------
2081  for(int i=0; i<Get_NZ() && SG_UI_Process_Set_Progress(i, Get_NZ()); i++)
2082  {
2083  if( !Stream.Add_File(FileName + CSG_String::Format("sg-%03d", i + 1)) || !_Save_Data(Stream, m_pGrids[i]) )
2084  {
2085  return( false );
2086  }
2087  }
2088 
2089  //-----------------------------------------------------
2090  if( Stream.Add_File(FileName + "sg-info") )
2091  {
2092  Save_MetaData(Stream);
2093  }
2094 
2095  if( Stream.Add_File(FileName + "sg-prj") )
2096  {
2097  Get_Projection().Save(Stream, SG_PROJ_FMT_WKT);
2098  }
2099 
2100  return( true );
2101 }
2102 
2103 
2105 // //
2107 
2108 //---------------------------------------------------------
2109 bool CSG_Grids::_Load_Header(CSG_File &Stream)
2110 {
2111  CSG_MetaData Header;
2112 
2113  if( !Header.Load(Stream) )
2114  {
2115  return( false );
2116  }
2117 
2118  //-----------------------------------------------------
2119  if( !Header("NX") || !Header("NY") || !Header("XMIN") || !Header("YMIN") || !Header("CELLSIZE") || !Header("TYPE") ) // necessary minimum information !!!
2120  {
2121  return( false );
2122  }
2123 
2124  CSG_Grid_System System(Header["CELLSIZE"].Get_Content().asDouble(),
2125  Header["XMIN"].Get_Content().asDouble(), Header["YMIN"].Get_Content().asDouble(),
2126  Header["NX" ].Get_Content().asInt (), Header["NY" ].Get_Content().asInt ()
2127  );
2128 
2129  TSG_Data_Type Type = SG_Data_Type_Get_Type(Header["TYPE"].Get_Content());
2130 
2131  if( !System.is_Valid() || Type == SG_DATATYPE_Undefined || !m_pGrids[0]->Create(System, Type) )
2132  {
2133  return( false );
2134  }
2135 
2136  //-----------------------------------------------------
2137  if( Header("NAME" ) ) Set_Name (Header["NAME" ].Get_Content());
2138  if( Header("DESCRIPTION") ) Set_Description(Header["DESCRIPTION"].Get_Content());
2139  if( Header("UNIT" ) ) Set_Unit (Header["UNIT" ].Get_Content());
2140 
2141  Set_Scaling(
2142  Header("SCALE" ) ? Header["SCALE" ].Get_Content().asDouble() : 1.,
2143  Header("OFFSET") ? Header["OFFSET"].Get_Content().asDouble() : 0.
2144  );
2145 
2146  if( Header("NODATA_MIN") )
2147  {
2148  if( Header("NODATA_MAX") )
2149  {
2151  Header["NODATA_MIN"].Get_Content().asDouble(),
2152  Header["NODATA_MAX"].Get_Content().asDouble()
2153  );
2154  }
2155  else
2156  {
2158  Header["NODATA_MIN"].Get_Content().asDouble()
2159  );
2160  }
2161  }
2162 
2163  //-----------------------------------------------------
2164  m_Attributes.Destroy();
2165 
2166  if( Header("ATTRIBUTES") && Header["ATTRIBUTES"]("FIELDS") == NULL )
2167  {
2168  const CSG_MetaData &Fields = Header["ATTRIBUTES"];
2169 
2170  for(int iField=0; iField<Fields.Get_Children_Count(); iField++)
2171  {
2172  if( Fields[iField].Cmp_Name("FIELD") && Fields[iField].Get_Property("TYPE") )
2173  {
2174  m_Attributes.Add_Field(Fields[iField].Get_Content(), SG_Data_Type_Get_Type(Fields[iField].Get_Property("TYPE")));
2175  }
2176  }
2177 
2178  if( !Fields.Get_Property("Z_FIELD", m_Z_Attribute) || m_Z_Attribute >= m_Attributes.Get_Field_Count() )
2179  {
2180  m_Z_Attribute = 0;
2181  }
2182 
2183  if( !Fields.Get_Property("Z_NAME", m_Z_Name ) || m_Z_Name >= m_Attributes.Get_Field_Count() )
2184  {
2185  m_Z_Name = -1; // same as m_Z_Attribute
2186  }
2187  }
2188 
2189  //-----------------------------------------------------
2190  // >>> DEPRECATED >>> //
2191  if( Header("ATTRIBUTES") && Header["ATTRIBUTES"]("FIELDS") != NULL )
2192  {
2193  if( !Header["ATTRIBUTES"].Get_Property("ZATTRIBUTE", m_Z_Attribute) )
2194  {
2195  m_Z_Attribute = 0;
2196  }
2197 
2198  int iField;
2199 
2200  const CSG_MetaData &Fields = Header["ATTRIBUTES"]["FIELDS"];
2201 
2202  for(iField=0; iField<Fields.Get_Children_Count(); iField++)
2203  {
2204  if( Fields[iField].Cmp_Name("FIELD") && Fields[iField].Get_Property("TYPE") )
2205  {
2206  m_Attributes.Add_Field(Fields[iField].Get_Content(), SG_Data_Type_Get_Type(Fields[iField].Get_Property("TYPE")));
2207  }
2208  }
2209 
2210  if( m_Attributes.Get_Field_Count() > 0 && Header["ATTRIBUTES"]("RECORDS") )
2211  {
2212  CSG_Table Attributes(m_Attributes);
2213 
2214  const CSG_MetaData &Records = Header["ATTRIBUTES"]["RECORDS"];
2215 
2216  for(int iRecord=0; iRecord<Records.Get_Children_Count(); iRecord++)
2217  {
2218  if( Records[iRecord].Cmp_Name("RECORD") )
2219  {
2220  CSG_String_Tokenizer Values(Records[iRecord].Get_Content(), ";");
2221 
2222  if( Values.Get_Tokens_Count() == (size_t)Attributes.Get_Field_Count() )
2223  {
2224  CSG_Table_Record *pRecord = Attributes.Add_Record();
2225 
2226  for(int iField=0; iField<m_Attributes.Get_Field_Count(); iField++)
2227  {
2228  pRecord->Set_Value(iField, Values.Get_Next_Token());
2229  }
2230 
2231  if( !Add_Grid(*pRecord) )
2232  {
2233  return( false );
2234  }
2235  }
2236  }
2237  }
2238  }
2239  }
2240  else if( Header("NZ") && Header["NZ"].Get_Content().asInt() > 0 )
2241  {
2242  m_Attributes.Add_Field("ID", SG_DATATYPE_Int);
2243 
2244  for(int i=0, n=Header["NZ"].Get_Content().asInt(); i<n; i++)
2245  {
2246  if( !Add_Grid(i + 1.) )
2247  {
2248  return( false );
2249  }
2250  }
2251  }
2252  // <<< DEPRECATED <<< //
2253 
2254  //-----------------------------------------------------
2255  return( m_Attributes.Get_Field_Count() > 0 );
2256 }
2257 
2258 //---------------------------------------------------------
2259 bool CSG_Grids::_Save_Header(CSG_File &Stream)
2260 {
2261  CSG_MetaData Header;
2262 
2263  Header.Set_Name("GRIDS");
2264 
2265  Header.Add_Property("saga-version", SAGA_VERSION);
2266 
2267  //-----------------------------------------------------
2268  // general
2269 
2270  Header.Add_Child("NAME" , Get_Name ());
2271  Header.Add_Child("DESCRIPTION", Get_Description());
2272  Header.Add_Child("UNIT" , Get_Unit ());
2273 
2274  Header.Add_Child("SCALE" , Get_Scaling ());
2275  Header.Add_Child("OFFSET" , Get_Offset ());
2276 
2277  Header.Add_Child("NODATA_MIN" , Get_NoData_Value(false));
2278  Header.Add_Child("NODATA_MAX" , Get_NoData_Value(true ));
2279 
2280  Header.Add_Child("TYPE" , SG_Data_Type_Get_Identifier(Get_Type()));
2281 
2282  //-----------------------------------------------------
2283  // grid system
2284 
2285  Header.Add_Child("NX" , Get_NX ());
2286  Header.Add_Child("NY" , Get_NY ());
2287  Header.Add_Child("CELLSIZE" , Get_Cellsize());
2288  Header.Add_Child("XMIN" , Get_XMin ());
2289  Header.Add_Child("YMIN" , Get_YMin ());
2290 
2291  //-----------------------------------------------------
2292  // attributes
2293 
2294  CSG_MetaData &Attributes = *Header.Add_Child("ATTRIBUTES");
2295 
2296  Attributes.Add_Property("Z_FIELD", m_Z_Attribute);
2297  Attributes.Add_Property("Z_NAME" , m_Z_Name );
2298 
2299  for(int iField=0; iField<m_Attributes.Get_Field_Count(); iField++)
2300  {
2301  Attributes.Add_Child("FIELD", m_Attributes.Get_Field_Name(iField))->Add_Property(
2302  "TYPE", SG_Data_Type_Get_Identifier(m_Attributes.Get_Field_Type(iField))
2303  );
2304  }
2305 
2306  //-----------------------------------------------------
2307  return( Header.Save(Stream) );
2308 }
2309 
2310 
2312 // //
2314 
2315 //---------------------------------------------------------
2316 bool CSG_Grids::_Load_Attributes(CSG_File &Stream)
2317 {
2318  CSG_Table Attributes(m_Attributes);
2319 
2320  CSG_String sLine;
2321 
2322  while( Stream.Read_Line(sLine) && !sLine.is_Empty() )
2323  {
2324  CSG_String_Tokenizer Values(sLine, "\t", SG_TOKEN_RET_EMPTY_ALL);
2325 
2326  if( Values.Get_Tokens_Count() == (size_t)Attributes.Get_Field_Count() )
2327  {
2328  CSG_Table_Record *pRecord = Attributes.Add_Record();
2329 
2330  for(int iField=0; iField<m_Attributes.Get_Field_Count(); iField++)
2331  {
2332  pRecord->Set_Value(iField, Values.Get_Next_Token());
2333  }
2334 
2335  if( !Add_Grid(*pRecord) )
2336  {
2337  return( false );
2338  }
2339  }
2340  }
2341 
2342  return( true );
2343 }
2344 
2345 //---------------------------------------------------------
2346 bool CSG_Grids::_Save_Attributes(CSG_File &Stream)
2347 {
2348  for(int iRecord=0; iRecord<m_Attributes.Get_Count(); iRecord++)
2349  {
2350  for(int iField=0; iField<m_Attributes.Get_Field_Count(); iField++)
2351  {
2352  Stream.Write(m_Attributes[iRecord].asString(iField));
2353  Stream.Write(iField < m_Attributes.Get_Field_Count() - 1 ? "\t" : "\n");
2354  }
2355  }
2356 
2357  return( true );
2358 }
2359 
2360 
2362 // //
2364 
2365 //---------------------------------------------------------
2366 bool CSG_Grids::_Load_Data(CSG_File &Stream, CSG_Grid *pGrid)
2367 {
2368  if( !pGrid )
2369  {
2370  return( false );
2371  }
2372 
2373  TSG_Data_Type Type = Get_Type();
2374 
2375  CSG_Array Line(1, Get_nLineBytes());
2376 
2377  for(int y=0; y<Get_NY(); y++)
2378  {
2379  if( !Stream.Read(Line.Get_Array(), Get_nLineBytes()) )
2380  {
2381  return( false );
2382  }
2383 
2384  char *pValue = (char *)Line.Get_Array();
2385 
2386  for(int x=0, n=Get_nValueBytes(); x<Get_NX(); x++, pValue+=n)
2387  {
2388  switch( Type )
2389  {
2390  case SG_DATATYPE_Byte : pGrid->Set_Value(x, y, *(BYTE *)pValue, false); break;
2391  case SG_DATATYPE_Char : pGrid->Set_Value(x, y, *(char *)pValue, false); break;
2392  case SG_DATATYPE_Word : pGrid->Set_Value(x, y, *(WORD *)pValue, false); break;
2393  case SG_DATATYPE_Short : pGrid->Set_Value(x, y, *(short *)pValue, false); break;
2394  case SG_DATATYPE_DWord : pGrid->Set_Value(x, y, *(DWORD *)pValue, false); break;
2395  case SG_DATATYPE_Int : pGrid->Set_Value(x, y, *(int *)pValue, false); break;
2396  case SG_DATATYPE_Float : pGrid->Set_Value(x, y, *(float *)pValue, false); break;
2397  case SG_DATATYPE_Double: pGrid->Set_Value(x, y, *(double *)pValue, false); break;
2398  default: break;
2399  }
2400  }
2401  }
2402 
2403  return( true );
2404 }
2405 
2406 //---------------------------------------------------------
2407 bool CSG_Grids::_Save_Data(CSG_File &Stream, CSG_Grid *pGrid)
2408 {
2409  TSG_Data_Type Type = Get_Type();
2410 
2411  CSG_Array Line(1, Get_nLineBytes());
2412 
2413  for(int y=0; y<Get_NY(); y++)
2414  {
2415  char *pValue = (char *)Line.Get_Array();
2416 
2417  for(int x=0, n=Get_nValueBytes(); x<Get_NX(); x++, pValue+=n)
2418  {
2419  switch( Type )
2420  {
2421  case SG_DATATYPE_Byte : *(BYTE *)pValue = pGrid->asByte (x, y, false); break;
2422  case SG_DATATYPE_Char : *(char *)pValue = pGrid->asChar (x, y, false); break;
2423  case SG_DATATYPE_Word : *(WORD *)pValue = pGrid->asShort (x, y, false); break;
2424  case SG_DATATYPE_Short : *(short *)pValue = pGrid->asShort (x, y, false); break;
2425  case SG_DATATYPE_DWord : *(DWORD *)pValue = pGrid->asInt (x, y, false); break;
2426  case SG_DATATYPE_Int : *(int *)pValue = pGrid->asInt (x, y, false); break;
2427  case SG_DATATYPE_Float : *(float *)pValue = pGrid->asFloat (x, y, false); break;
2428  case SG_DATATYPE_Double: *(double *)pValue = pGrid->asDouble(x, y, false); break;
2429  default: break;
2430  }
2431  }
2432 
2433  if( !Stream.Write(Line.Get_Array(), Get_nLineBytes()) )
2434  {
2435  return( false );
2436  }
2437  }
2438 
2439  return( true );
2440 }
2441 
2442 
2444 // //
2446 
2447 //-----------------------------------------------------
2448 bool CSG_Grids::_Assign_Interpolated (CSG_Grids *pSource, TSG_Grid_Resampling Interpolation) { return( false ); }
2449 bool CSG_Grids::_Assign_MeanValue (CSG_Grids *pSource, bool bVolumeProportional ) { return( false ); }
2450 bool CSG_Grids::_Assign_ExtremeValue (CSG_Grids *pSource, bool bMaximum ) { return( false ); }
2451 bool CSG_Grids::_Assign_Majority (CSG_Grids *pSource ) { return( false ); }
2452 
2453 
2455 // //
2457 
2458 //-----------------------------------------------------
2459 CSG_Grids & CSG_Grids::_Operation_Arithmetic(const CSG_Grids &Grids, TSG_Grid_Operation Operation) { return( *this ); }
2460 CSG_Grids & CSG_Grids::_Operation_Arithmetic(double Value , TSG_Grid_Operation Operation) { return( *this ); }
2461 
2462 
2464 // //
2465 // //
2466 // //
2468 
2469 //---------------------------------------------------------
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:1001
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:992
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:1017
CSG_Table::Assign
virtual bool Assign(CSG_Data_Object *pTable)
Definition: table.cpp:372
CSG_Grids::CSG_Grids
CSG_Grids(void)
Definition: grids.cpp:132
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_Grids::Set_Z
bool Set_Z(int i, double Value)
Definition: grids.cpp:536
GRID_RESAMPLING_NearestNeighbour
@ GRID_RESAMPLING_NearestNeighbour
Definition: grid.h:157
CSG_Grids::asInt
virtual int asInt(int x, int y, int z, bool bScaled=true) const
Definition: grids.h:379
CSG_Grids::Get_Data_Count
sLong Get_Data_Count(void)
Definition: grids.cpp:1413
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:930
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
CSG_Table::Del_Records
virtual bool Del_Records(void)
Definition: table.cpp:912
CSG_Grids::Get_Sorted
sLong Get_Sorted(sLong Position, bool bDown=true, bool bCheckNoData=true)
Definition: grids.h:438
CSG_Grids::Get_Offset
double Get_Offset(void) const
Definition: grids.h:259
CSG_Data_Collection::Get
CSG_Data_Object * Get(size_t i) const
Definition: data_manager.h:96
CSG_Data_Object::Set_File_Name
void Set_File_Name(const CSG_String &FileName)
Definition: dataobject.cpp:307
SAGA_VERSION
#define SAGA_VERSION
Definition: saga_api.h:90
CSG_Grids::Del_Attribute
bool Del_Attribute(int iField)
Definition: grids.cpp:480
CSG_Grids::Set_Value
virtual void Set_Value(sLong i, double Value, bool bScaled=true)
Definition: grids.h:410
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_MetaData::Get_Children_Count
int Get_Children_Count(void) const
Definition: metadata.h:149
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:969
SG_PROJ_FMT_WKT
@ SG_PROJ_FMT_WKT
Definition: geo_tools.h:771
CSG_Data_Collection::Count
size_t Count(void) const
Definition: data_manager.h:94
GRID_RESAMPLING_BicubicSpline
@ GRID_RESAMPLING_BicubicSpline
Definition: grid.h:159
SG_TOKEN_RET_EMPTY_ALL
@ SG_TOKEN_RET_EMPTY_ALL
Definition: api_core.h:746
CSG_Table_Record
Definition: table.h:130
CSG_Grids::Assign
virtual bool Assign(double Value=0.)
Definition: grids.cpp:899
CSG_Grids::Get_Scaling
double Get_Scaling(void) const
Definition: grids.h:258
CSG_Simple_Statistics::Get_Variance
double Get_Variance(void)
Definition: mat_tools.h:737
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
CSG_Grids::Get_Attributes
const CSG_Table & Get_Attributes(void) const
Definition: grids.h:216
CSG_Grids::Get_Range
double Get_Range(void)
Definition: grids.cpp:1397
SG_UI_MSG_STYLE_SUCCESS
@ SG_UI_MSG_STYLE_SUCCESS
Definition: api_core.h:1496
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:526
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:928
CSG_Histogram
Definition: mat_tools.h:986
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:841
CSG_Grids::On_Update
virtual bool On_Update(void)
Definition: grids.cpp:1335
CSG_Grids::Get_Grid_Count
int Get_Grid_Count(void) const
Definition: grids.h:237
CSG_Grids::Save
virtual bool Save(const CSG_String &File, int Format=0)
Definition: grids.cpp:1717
CSG_Data_Object::Save_MetaData
bool Save_MetaData(const CSG_String &FileName)
Definition: dataobject.cpp:618
CSG_Grid_System::Get_yWorld_to_Grid
int Get_yWorld_to_Grid(double yWorld) const
Definition: grid.h:291
SSG_Point_3D
Definition: geo_tools.h:264
CSG_Data_Object::is_NoData_Value
bool is_NoData_Value(double Value) const
Definition: dataobject.h:246
GRID_RESAMPLING_Undefined
@ GRID_RESAMPLING_Undefined
Definition: grid.h:168
SG_DATATYPE_Byte
@ SG_DATATYPE_Byte
Definition: api_core.h:987
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:861
saga_api.h
CSG_Tool
Definition: tool.h:149
CSG_Table::Destroy
virtual bool Destroy(void)
Definition: table.cpp:327
CSG_Grids::On_Delete
virtual bool On_Delete(void)
Definition: grids.cpp:1663
CSG_Data_Object::Get_Name
const SG_Char * Get_Name(void) const
Definition: dataobject.cpp:290
CSG_Tool::Execute
bool Execute(bool bAddHistory=false)
Definition: tool.cpp:246
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:222
CSG_Table::Get_Field_Count
int Get_Field_Count(void) const
Definition: table.h:355
CSG_Grids::is_Scaled
bool is_Scaled(void) const
Definition: grids.h:260
SG_File_Delete
SAGA_API_DLL_EXPORT bool SG_File_Delete(const CSG_String &FileName)
Definition: api_file.cpp:840
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:558
CSG_Grids::Get_Percentile
double Get_Percentile(double Percentile, bool bFromHistogram=true)
Definition: grids.cpp:1447
CSG_Grids::operator/=
virtual CSG_Grids & operator/=(double Value)
Definition: grids.cpp:1028
CSG_MetaData::Save
bool Save(const CSG_String &File, const SG_Char *Extension=NULL) const
Definition: metadata.cpp:883
SG_FILE_R
@ SG_FILE_R
Definition: api_core.h:1101
CSG_Grids::operator+=
virtual CSG_Grids & operator+=(double Value)
Definition: grids.cpp:980
CSG_Data_Manager::Get_Grid_System
CSG_Grid_Collection * Get_Grid_System(size_t i) const
Definition: data_manager.h:175
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:322
CSG_Grids::Set_Z_Attribute
bool Set_Z_Attribute(int i)
Definition: grids.cpp:505
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:726
CSG_Grids::On_Reload
virtual bool On_Reload(void)
Definition: grids.cpp:1657
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_File
Definition: api_core.h:1116
CSG_String::Cmp
int Cmp(const CSG_String &String) const
Definition: api_string.cpp:515
CSG_Grids::Set_Z_Name_Field
bool Set_Z_Name_Field(int i)
Definition: grids.cpp:518
CSG_Data_Object::Get_Owner
CSG_Data_Object * Get_Owner(void) const
Definition: dataobject.h:222
CSG_Grids::Set_Max_Samples
virtual bool Set_Max_Samples(sLong Max_Samples)
Definition: grids.cpp:1539
GRIDS_FILE_FORMAT_Undefined
@ GRIDS_FILE_FORMAT_Undefined
Definition: grids.h:92
CSG_MetaData::Get_Property
const SG_Char * Get_Property(int i) const
Definition: metadata.h:181
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:350
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:1144
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
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:862
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:430
CSG_Projection::Load
bool Load(const CSG_String &FileName, TSG_Projection_Format Format=SG_PROJ_FMT_WKT)
Definition: projections.cpp:413
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:356
GRID_RESAMPLING_Bilinear
@ GRID_RESAMPLING_Bilinear
Definition: grid.h:158
CSG_Grids::Add_Attribute
bool Add_Attribute(const CSG_String &Name, TSG_Data_Type Type, int iField=-1)
Definition: grids.cpp:474
CSG_Rect::Get_YMin
double Get_YMin(void) const
Definition: geo_tools.h:502
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:728
CSG_Grid::is_Valid
virtual bool is_Valid(void) const
Definition: grid.cpp:449
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:731
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:1058
CSG_MetaData::Del_Children
bool Del_Children(int Depth=0, const SG_Char *Name=NULL)
Definition: metadata.cpp:373
CSG_File::Read_Line
bool Read_Line(CSG_String &sLine) const
Definition: api_file.cpp:379
CSG_Tool_Library_Manager::Create_Tool
CSG_Tool * Create_Tool(const CSG_String &Library, int Index, bool bWithGUI=false) const
Definition: tool_library.cpp:697
SG_UI_Msg_Lock
int SG_UI_Msg_Lock(bool bOn)
Definition: api_callback.cpp:465
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_Grids::is_NoData
virtual bool is_NoData(int x, int y, int z) const
Definition: grids.h:358
sLong
signed long long sLong
Definition: api_core.h:158
CSG_Grids::Get_StdDev
double Get_StdDev(void)
Definition: grids.cpp:1402
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:544
CSG_Grids::operator-=
virtual CSG_Grids & operator-=(double Value)
Definition: grids.cpp:996
CSG_Simple_Statistics::Get_StdDev
double Get_StdDev(void)
Definition: mat_tools.h:738
CSG_Grids::Update_Z_Order
bool Update_Z_Order(void)
Definition: grids.cpp:542
CSG_Grids::Get_Grid_Ptr
CSG_Grid * Get_Grid_Ptr(int i) const
Definition: grids.h:248
GRIDS_FILE_FORMAT_Compressed
@ GRIDS_FILE_FORMAT_Compressed
Definition: grids.h:94
CSG_Table::Get_Count
sLong Get_Count(void) const
Definition: table.h:385
CSG_Grids::Get_Histogram
const CSG_Histogram & Get_Histogram(size_t nClasses=0)
Definition: grids.cpp:1562
SG_DATATYPE_Float
@ SG_DATATYPE_Float
Definition: api_core.h:995
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:436
SG_UI_Process_Set_Text
void SG_UI_Process_Set_Text(const CSG_String &Text)
Definition: api_callback.cpp:317
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:331
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:1135
SG_GRIDS_NAME_GRID
#define SG_GRIDS_NAME_GRID
Definition: grids.h:103
SG_FILE_W
@ SG_FILE_W
Definition: api_core.h:1102
CSG_Grids::Set_Grid_Count
bool Set_Grid_Count(int Count)
Definition: grids.cpp:583
CSG_Grids::Assign_NoData
void Assign_NoData(void)
Definition: grids.cpp:890
CSG_Grids::Get_Min
double Get_Min(void)
Definition: grids.cpp:1387
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
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:235
CSG_MetaData::Add_Children
bool Add_Children(const CSG_MetaData &MetaData)
Definition: metadata.cpp:351
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
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:487
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:934
CSG_Grids::Load
virtual bool Load(const CSG_String &File, bool bLoadData=true)
Definition: grids.cpp:1689
CSG_Grids::asDouble
virtual double asDouble(sLong i, bool bScaled=true) const
Definition: grids.h:387
CSG_Table::Del_Record
virtual bool Del_Record(sLong Index)
Definition: table.cpp:873
CSG_Spline
Definition: mat_tools.h:1399
CSG_Table::Create
bool Create(const CSG_Table &Table)
Definition: table.cpp:146
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:557
CSG_Grids::Get_Z
double Get_Z(int i) const
Definition: grids.h:228
CSG_Grids::Add
virtual CSG_Grids & Add(double Value)
Definition: grids.cpp:985
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:549
CSG_Grid::asDouble
virtual double asDouble(sLong i, bool bScaled=true) const
Definition: grid.h:765
CSG_Data_Manager
Definition: data_manager.h:164
CSG_MetaData
Definition: metadata.h:88
CSG_Data_Object::Set_Description
void Set_Description(const CSG_String &Description)
Definition: dataobject.cpp:296
CSG_Simple_Statistics::Get_Range
double Get_Range(void)
Definition: mat_tools.h:733
CSG_Data_Object::Get_MetaData_DB
CSG_MetaData & Get_MetaData_DB(void) const
Definition: dataobject.h:226
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:790
CSG_Tool::Settings_Push
bool Settings_Push(class CSG_Data_Manager *pManager=NULL)
Definition: tool.cpp:600
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:249
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: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
CSG_Data_Object::Load_MetaData
bool Load_MetaData(const CSG_String &FileName)
Definition: dataobject.cpp:595
CSG_Grids::Get_Mean
double Get_Mean(void)
Definition: grids.cpp:1382
SORT_SWAP
#define SORT_SWAP(a, b)
Definition: grids.cpp:1175
CSG_Rect::Get_XMin
double Get_XMin(void) const
Definition: geo_tools.h:500
CSG_Data_Object::Set_Owner
void Set_Owner(CSG_Data_Object *pOwner)
Definition: dataobject.h:223
CSG_Grids::Get_Z_Name_Field
int Get_Z_Name_Field(void) const
Definition: grids.cpp:530
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:1407
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:1392
CSG_MetaData::Set_Name
void Set_Name(const CSG_String &Name)
Definition: metadata.h:133
CSG_Data_Manager::Grid_System_Count
size_t Grid_System_Count(void) const
Definition: data_manager.h:174
CSG_Data_Object::Set_NoData_Value
virtual bool Set_NoData_Value(double Value)
Definition: dataobject.cpp:513
CSG_Projection::Save
bool Save(const CSG_String &FileName, TSG_Projection_Format Format=SG_PROJ_FMT_WKT) const
Definition: projections.cpp:421
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:302
CSG_Grid::asByte
virtual BYTE asByte(int x, int y, bool bScaled=true) const
Definition: grid.h:751
CSG_Tool::On_Before_Execution
virtual bool On_Before_Execution(void)
Definition: tool.h:239
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:903
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:577
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:638
CSG_File::Write
size_t Write(void *Buffer, size_t Size, size_t Count=1) const
Definition: api_file.cpp:354
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:1418
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
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:985
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:1430
CSG_MetaData::Add_Child
CSG_MetaData * Add_Child(void)
Definition: metadata.cpp:174
SG_UI_Msg_Add_Error
void SG_UI_Msg_Add_Error(const char *Message)
Definition: api_callback.cpp:544
SG_GRID_HISTOGRAM_CLASSES_DEFAULT
#define SG_GRID_HISTOGRAM_CLASSES_DEFAULT
Definition: grids.cpp:1555
CSG_Grid::Set_Unit
void Set_Unit(const CSG_String &Unit)
Definition: grid.cpp:408
CSG_Table::Get_Field_Type
TSG_Data_Type Get_Field_Type(int iField) const
Definition: table.h:357
CSG_Table::Add_Record
virtual CSG_Table_Record * Add_Record(CSG_Table_Record *pCopy=NULL)
Definition: table.cpp:799
CSG_String_Tokenizer
Definition: api_core.h:754
CSG_Grids::Del_Grid
bool Del_Grid(int i, bool bDetach=false)
Definition: grids.cpp:765
CSG_Projection::Create
bool Create(const CSG_Projection &Projection)
Definition: projections.cpp:252
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:708
CSG_Grids::Get_Quantile
double Get_Quantile(double Quantile, bool bFromHistogram=true)
Definition: grids.cpp:1424
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_Grids::Get_Statistics
const CSG_Simple_Statistics & Get_Statistics(void)
Definition: grids.cpp:1464
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
CSG_File_Zip
Definition: api_core.h:1188
CSG_Grids::operator*=
virtual CSG_Grids & operator*=(double Value)
Definition: grids.cpp:1012
CSG_Grids::Divide
virtual CSG_Grids & Divide(double Value)
Definition: grids.cpp:1033
CSG_Data_Object::is_Valid
virtual bool is_Valid(void) const =0
CSG_Histogram::Get_Statistics
const CSG_Simple_Statistics & Get_Statistics(void) const
Definition: mat_tools.h:1051
CSG_Grids::Del_Grids
bool Del_Grids(bool bDetach=false)
Definition: grids.cpp:803
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:490
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:996