SAGA API  v9.7
grid_io.cpp
Go to the documentation of this file.
1 
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // Application Programming Interface //
9 // //
10 // Library: SAGA_API //
11 // //
12 //-------------------------------------------------------//
13 // //
14 // grid_io.cpp //
15 // //
16 // Copyright (C) 2005 by Olaf Conrad //
17 // //
18 //-------------------------------------------------------//
19 // //
20 // This file is part of 'SAGA - System for Automated //
21 // Geoscientific Analyses'. //
22 // //
23 // This library is free software; you can redistribute //
24 // it and/or modify it under the terms of the GNU Lesser //
25 // General Public License as published by the Free //
26 // Software Foundation, either version 2.1 of the //
27 // License, or (at your option) any later version. //
28 // //
29 // This library is distributed in the hope that it will //
30 // be useful, but WITHOUT ANY WARRANTY; without even the //
31 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
32 // PARTICULAR PURPOSE. See the GNU Lesser General Public //
33 // License for more details. //
34 // //
35 // You should have received a copy of the GNU Lesser //
36 // General Public License along with this program; if //
37 // not, see <http://www.gnu.org/licenses/>. //
38 // //
39 //-------------------------------------------------------//
40 // //
41 // contact: Olaf Conrad //
42 // Institute of Geography //
43 // University of Hamburg //
44 // Germany //
45 // //
46 // e-mail: oconrad@saga-gis.org //
47 // //
49 
50 //---------------------------------------------------------
51 #include <stdint.h>
52 #include <string.h>
53 
54 #ifdef _SAGA_LINUX
55 #include "config.h"
56 #include <arpa/inet.h>
57 #include <netinet/in.h>
58 #else
59 #include <WinSock2.h>
60 #endif
61 
62 #include "grid.h"
63 #include "data_manager.h"
64 #include "tool_library.h"
65 
66 
68 // //
69 // //
70 // //
72 
73 //---------------------------------------------------------
75 {
76  return( Create(Get_File_Name(false)) );
77 }
78 
79 //---------------------------------------------------------
81 {
82  CSG_String FileName = Get_File_Name(true);
83 
84  SG_File_Set_Extension(FileName, "sg-grd-z"); SG_File_Delete(FileName);
85  SG_File_Set_Extension(FileName, "sg-grd" ); SG_File_Delete(FileName);
86  SG_File_Set_Extension(FileName, "sgrd" ); SG_File_Delete(FileName);
87  SG_File_Set_Extension(FileName, "sdat" ); SG_File_Delete(FileName); SG_File_Delete(FileName + ".aux.xml");
88  SG_File_Set_Extension(FileName, "mgrd" ); SG_File_Delete(FileName);
89  SG_File_Set_Extension(FileName, "dgm" ); SG_File_Delete(FileName);
90  SG_File_Set_Extension(FileName, "dat" ); SG_File_Delete(FileName);
91 
92  return( true );
93 }
94 
95 
97 // //
98 // //
99 // //
101 
102 //---------------------------------------------------------
104 
105 //---------------------------------------------------------
107 {
108  switch( Format )
109  {
116  return( true );
117  }
118 
119  return( false );
120 }
121 
122 //---------------------------------------------------------
124 {
126 }
127 
128 //---------------------------------------------------------
130 {
132  {
133  default:
134  case GRID_FILE_FORMAT_Compressed: return( "sg-grd-z" );
135  case GRID_FILE_FORMAT_Binary : return( "sg-grd" );
136  case GRID_FILE_FORMAT_Binary_old: return( "sgrd" );
137  case GRID_FILE_FORMAT_GeoTIFF : return( "tif" );
138  }
139 }
140 
141 
143 // //
145 
146 //---------------------------------------------------------
147 bool CSG_Grid::Save(const CSG_String &FileName, int Format)
148 {
149  SG_UI_Msg_Add(CSG_String::Format("%s %s: %s...", _TL("Saving"), _TL("grid"), FileName.c_str()), true);
150 
151  //-----------------------------------------------------
152  if( Format == GRID_FILE_FORMAT_Undefined )
153  {
155 
156  if( SG_File_Cmp_Extension(FileName, "sg-grd-z") ) Format = GRID_FILE_FORMAT_Compressed;
157  if( SG_File_Cmp_Extension(FileName, "sg-grd" ) ) Format = GRID_FILE_FORMAT_Binary ;
158  if( SG_File_Cmp_Extension(FileName, "sgrd" ) ) Format = GRID_FILE_FORMAT_Binary_old;
159  if( SG_File_Cmp_Extension(FileName, "tif" ) ) Format = GRID_FILE_FORMAT_GeoTIFF ;
160  }
161 
162  //-----------------------------------------------------
163  bool bResult = false;
164 
165  switch( Format )
166  {
167  default:
168  bResult = _Save_Native(FileName, (TSG_Grid_File_Format)Format);
169  break;
170 
172  bResult = _Save_Compressed(FileName);
173  break;
174 
176  SG_UI_Msg_Lock(true);
177  SG_RUN_TOOL(bResult, "io_gdal", 2, // Export GeoTIFF
178  SG_TOOL_PARAMLIST_ADD("GRIDS" , this)
179  && SG_TOOL_PARAMETER_SET("FILE" , FileName)
180  && SG_TOOL_PARAMETER_SET("OPTIONS" , SG_T("COMPRESS=LZW BIGTIFF=YES")) // enable bigtiff as the 'if needed' default setting is not available for compressed files
181  );
182  SG_UI_Msg_Lock(false);
183  break;
184  }
185 
187 
188  //-----------------------------------------------------
189  if( bResult )
190  {
191  Set_Modified(false);
192 
193  Set_File_Name(FileName, true);
194 
195  SG_UI_Msg_Add(_TL("okay"), false, SG_UI_MSG_STYLE_SUCCESS);
196 
197  return( true );
198  }
199 
200  SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);
201 
202  return( false );
203 }
204 
205 
207 // //
208 // //
209 // //
211 
212 //---------------------------------------------------------
213 bool CSG_Grid::_Load_External(const CSG_String &FileName, bool bCached, bool bLoadData)
214 {
215  bool bResult = false; CSG_Data_Manager Manager; CSG_Tool *pTool = NULL;
216 
217  SG_UI_Msg_Lock(true);
218 
219  //-----------------------------------------------------
220  // Image Import
221 
222  if( (SG_File_Cmp_Extension(FileName, "bmp")
223  || SG_File_Cmp_Extension(FileName, "gif")
224  || SG_File_Cmp_Extension(FileName, "jpg")
225  || SG_File_Cmp_Extension(FileName, "png")
226  || SG_File_Cmp_Extension(FileName, "pcx") )
227  && !bResult && (pTool = SG_Get_Tool_Library_Manager().Create_Tool("io_grid_image", 1)) != NULL )
228  {
229  pTool->Settings_Push(&Manager);
230 
231  bResult = pTool->Set_Parameter("FILE", FileName) && pTool->Execute();
232 
234  }
235 
236  //-----------------------------------------------------
237  // GDAL Import
238 
239  if( !bResult && (pTool = SG_Get_Tool_Library_Manager().Create_Tool("io_gdal", 0)) != NULL )
240  {
241  pTool->Settings_Push(&Manager);
242 
243  bResult = pTool->Set_Parameter("FILES" , FileName)
244  && pTool->Set_Parameter("MULTIPLE", 0 ) // output as single grid(s)
245  && pTool->Execute();
246 
248  }
249 
250  SG_UI_Msg_Lock(false);
251 
252  //-----------------------------------------------------
253  if( bResult && Manager.Grid().Count() && Manager.Grid(0).is_Valid() )
254  {
255  CSG_Grid *pGrid = Manager.Grid(0).asGrid();
256 
257  if( pGrid->is_Cached() )
258  {
259  return( Create(*pGrid) );
260  }
261 
262  Set_File_Name(FileName, false);
263 
264  Set_Name (pGrid->Get_Name());
265  Set_Description (pGrid->Get_Description());
266 
267  m_System = pGrid->m_System;
268  m_Type = pGrid->m_Type;
269  m_Values = pGrid->m_Values; pGrid->m_Values = NULL; // take ownership of data array
270 
271  m_zOffset = pGrid->m_zOffset;
272  m_zScale = pGrid->m_zScale;
273  m_Unit = pGrid->m_Unit;
274 
275  m_nBytes_Value = pGrid->m_nBytes_Value;
276  m_nBytes_Line = pGrid->m_nBytes_Line;
277 
278  Get_MetaData () = pGrid->Get_MetaData ();
279  Get_Projection() = pGrid->Get_Projection();
280 
282 
283  return( true );
284  }
285 
286  return( false );
287 }
288 
289 //---------------------------------------------------------
290 bool CSG_Grid::_Load_PGSQL(const CSG_String &FileName, bool bCached, bool bLoadData)
291 {
292  bool bResult = false;
293 
294  if( FileName.BeforeFirst(':').Cmp("PGSQL") == 0 ) // database source
295  {
296  CSG_String s(FileName);
297 
298  s = s.AfterFirst(':'); CSG_String Host (s.BeforeFirst(':'));
299  s = s.AfterFirst(':'); CSG_String Port (s.BeforeFirst(':'));
300  s = s.AfterFirst(':'); CSG_String DBase(s.BeforeFirst(':'));
301  s = s.AfterFirst(':'); CSG_String Table(s.BeforeFirst(':'));
302  s = s.AfterFirst(':'); CSG_String rid (s.BeforeFirst(':').AfterFirst('='));
303 
304  CSG_Tool *pTool = SG_Get_Tool_Library_Manager().Create_Tool("db_pgsql", 33); // CPGIS_Raster_Load_Band
305 
306  if( pTool )
307  {
309 
310  CSG_String Connection(DBase + " [" + Host + ":" + Port + "]");
311 
312  bResult = pTool->Set_Manager(NULL) && pTool->On_Before_Execution()
313  && pTool->Set_Parameter("CONNECTION", Connection)
314  && pTool->Set_Parameter("DB_TABLE" , Table )
315  && pTool->Set_Parameter("RID" , rid )
316  && pTool->Set_Parameter("GRID" , this )
317  && pTool->Execute();
318 
320 
322  }
323  }
324 
325  return( bResult );
326 }
327 
328 
330 // //
331 // Native //
332 // //
334 
335 //---------------------------------------------------------
336 bool CSG_Grid::_Load_Native(const CSG_String &FileName, bool bCached, bool bLoadData)
337 {
338  CSG_Grid_File_Info Info;
339 
340  if( !Info.Create(FileName) )
341  {
342  return( false );
343  }
344 
345  Set_File_Name(FileName, true);
346 
347  Set_Name (Info.m_Name);
349  Set_Unit (Info.m_Unit);
350 
351  Set_NoData_Value_Range(Info.m_NoData[0], Info.m_NoData[1]);
352 
353  m_System = Info.m_System;
354  m_Type = Info.m_Type;
355  m_zScale = Info.m_zScale;
356  m_zOffset = Info.m_zOffset;
357 
358  m_nBytes_Value = SG_Data_Type_Get_Size(m_Type);
359  m_nBytes_Line = m_Type == SG_DATATYPE_Bit ? 1 + Get_NX() / 8 : Get_NX() * m_nBytes_Value;
360 
361  Get_Projection().Load(SG_File_Make_Path("", FileName, "prj"));
362 
363  if( !bLoadData )
364  {
365  return( _Memory_Create(bCached) );
366  }
367 
368  Load_MetaData(FileName);
369 
370  //-----------------------------------------------------
371  CSG_File Stream;
372 
373  if( !SG_Data_Type_is_Numeric(m_Type) ) // ASCII...
374  {
375  if( Stream.Open(Info.m_Data_File , SG_FILE_R, false)
376  || Stream.Open(SG_File_Make_Path("", FileName, "dat"), SG_FILE_R, false)
377  || Stream.Open(SG_File_Make_Path("", FileName, "sdat"), SG_FILE_R, false) )
378  {
379  Stream.Seek(Info.m_Offset);
380 
381  return( _Load_ASCII(Stream, bCached, Info.m_bFlip) );
382  }
383  }
384 
385  //-----------------------------------------------------
386  else // Binary...
387  {
388  if( bCached || _Cache_Check() )
389  {
390  if( _Cache_Create(Info.m_Data_File , m_Type, Info.m_Offset, Info.m_bSwapBytes, Info.m_bFlip)
391  || _Cache_Create(SG_File_Make_Path("", FileName, "dat"), m_Type, Info.m_Offset, Info.m_bSwapBytes, Info.m_bFlip)
392  || _Cache_Create(SG_File_Make_Path("", FileName, "sdat"), m_Type, Info.m_Offset, Info.m_bSwapBytes, Info.m_bFlip) )
393  {
394  return( true );
395  }
396  }
397 
398  m_Cache_File = Info.m_Data_File;
399  m_Cache_Offset = Info.m_Offset;
400  m_Cache_bSwap = Info.m_bSwapBytes;
401  m_Cache_bFlip = Info.m_bFlip;
402 
403  if( _Memory_Create(bCached) )
404  {
405  if( Stream.Open(Info.m_Data_File , SG_FILE_R, true)
406  || Stream.Open(SG_File_Make_Path("", FileName, "dat"), SG_FILE_R, true)
407  || Stream.Open(SG_File_Make_Path("", FileName, "sdat"), SG_FILE_R, true) )
408  {
409  Stream.Seek(Info.m_Offset);
410 
411  return( _Load_Binary(Stream, m_Type, Info.m_bFlip, Info.m_bSwapBytes) );
412  }
413  }
414  }
415 
416  return( false );
417 }
418 
419 //---------------------------------------------------------
420 bool CSG_Grid::_Save_Native(const CSG_String &_FileName, TSG_Grid_File_Format Format)
421 {
422 #ifdef WORDS_BIGENDIAN
423  bool bBigEndian = true;
424 #else
425  bool bBigEndian = false;
426 #endif
427 
428  CSG_String FileName(_FileName);
429 
430  bool bBinary;
431 
432  if( Format == GRID_FILE_FORMAT_ASCII )
433  {
434  bBinary = false;
435  }
436  else if( Format == GRID_FILE_FORMAT_Binary_old )
437  {
438  bBinary = true; SG_File_Set_Extension(FileName, "sgrd");
439  }
440  else
441  {
442  bBinary = true; SG_File_Set_Extension(FileName, "sg-grd");
443  }
444 
445  CSG_Grid_File_Info Info(*this);
446 
447  if( Info.Save(FileName, bBinary) )
448  {
449  CSG_File Stream(SG_File_Make_Path("", FileName, "sdat"), SG_FILE_W, true);
450 
451  if( bBinary ? _Save_Binary(Stream, m_Type, false, bBigEndian) : _Save_ASCII (Stream) )
452  {
453  Save_MetaData(FileName);
454 
455  Get_Projection().Save(SG_File_Make_Path("", FileName, "prj"));
456 
457  Info.Save_AUX_XML(SG_File_Make_Path("", FileName, "sdat"));
458 
459  return( true );
460  }
461  }
462 
463  return( false );
464 }
465 
466 
468 // //
469 // Compressed //
470 // //
472 
473 //---------------------------------------------------------
474 bool CSG_Grid::_Load_Compressed(const CSG_String &_FileName, bool bCached, bool bLoadData)
475 {
476  Set_File_Name(_FileName, true);
477 
478  CSG_Archive Stream(_FileName, SG_FILE_R);
479 
480  if( !Stream.is_Reading() )
481  {
482  return( false );
483  }
484 
485  //-----------------------------------------------------
486  CSG_String FileName(SG_File_Get_Name(_FileName, false) + ".");
487 
488  if( !Stream.Get_File(FileName + "sgrd" )
489  && !Stream.Get_File(FileName + "sg-grd") )
490  {
491  FileName.Clear();
492 
493  for(size_t i=0; i<Stream.Get_File_Count(); i++)
494  {
495  if( SG_File_Cmp_Extension(Stream.Get_File_Name(i), "sgrd" )
496  || SG_File_Cmp_Extension(Stream.Get_File_Name(i), "sg-grd") )
497  {
498  FileName = SG_File_Get_Name(Stream.Get_File_Name(i), false) + ".";
499  Stream.Get_File(Stream.Get_File_Name(i));
500  break;
501  }
502  }
503 
504  if( FileName.is_Empty() )
505  {
506  return( false );
507  }
508  }
509 
510  //-----------------------------------------------------
511  CSG_Grid_File_Info Info;
512 
513  if( !Info.Create(Stream) )
514  {
515  return( false );
516  }
517 
518  Set_Name (Info.m_Name);
520  Set_Unit (Info.m_Unit);
521 
522  Set_NoData_Value_Range(Info.m_NoData[0], Info.m_NoData[1]);
523 
524  m_System = Info.m_System;
525  m_Type = Info.m_Type;
526  m_zScale = Info.m_zScale;
527  m_zOffset = Info.m_zOffset;
528 
529  m_nBytes_Value = SG_Data_Type_Get_Size(m_Type);
530  m_nBytes_Line = m_Type == SG_DATATYPE_Bit ? 1 + Get_NX() / 8 : Get_NX() * m_nBytes_Value;
531 
532  if( Stream.Get_File(FileName + "prj") )
533  {
534  Get_Projection().Load(Stream);
535  }
536 
537  if( !bLoadData )
538  {
539  return( _Memory_Create(bCached) );
540  }
541 
542  if( Stream.Get_File(FileName + "mgrd") )
543  {
544  Load_MetaData(Stream);
545  }
546 
547  //-----------------------------------------------------
548  if( _Cache_Check() )
549  {
550  bCached = true;
551  }
552 
553  return( Stream.Get_File(FileName + "sdat") && _Memory_Create(bCached)
554  && _Load_Binary(Stream, m_Type, Info.m_bFlip, Info.m_bSwapBytes)
555  );
556 }
557 
558 //---------------------------------------------------------
559 bool CSG_Grid::_Save_Compressed(const CSG_String &_FileName)
560 {
561 #ifdef WORDS_BIGENDIAN
562  bool bBigEndian = true;
563 #else
564  bool bBigEndian = false;
565 #endif
566 
567  CSG_Archive Stream(_FileName, SG_FILE_W);
568 
569  if( Stream.is_Writing() )
570  {
571  CSG_String FileName(SG_File_Get_Name(_FileName, false) + ".");
572 
573  CSG_Grid_File_Info Info(*this);
574 
575  if( Stream.Add_File(FileName + "sgrd") && Info.Save(Stream, true)
576  && Stream.Add_File(FileName + "sdat") && _Save_Binary(Stream, m_Type, false, bBigEndian) )
577  {
578  Stream.Add_File(FileName + "mgrd" ); Save_MetaData(Stream);
579  Stream.Add_File(FileName + "prj" ); Get_Projection().Save(Stream);
580  Stream.Add_File(FileName + "sdat.aux.xml"); Info.Save_AUX_XML(Stream);
581 
582  return( true );
583  }
584  }
585 
586  return( false );
587 }
588 
589 
591 // //
592 // Binary //
593 // //
595 
596 //---------------------------------------------------------
597 void CSG_Grid::_Swap_Bytes(char *Bytes, int nBytes) const
598 {
599  if( nBytes == 2 )
600  {
601  uint16_t val, valSwapped;
602  memcpy(&val, Bytes, nBytes);
603  valSwapped = ntohs(val);
604  memcpy(Bytes, &valSwapped, nBytes);
605  }
606  else if( nBytes == 4 )
607  {
608  uint32_t val, valSwapped;
609  memcpy(&val, Bytes, nBytes);
610  valSwapped = ntohl(val);
611  memcpy(Bytes, &valSwapped, nBytes);
612  }
613 }
614 
615 //---------------------------------------------------------
616 bool CSG_Grid::_Load_Binary(CSG_File &Stream, TSG_Data_Type File_Type, bool bFlip, bool bSwapBytes)
617 {
618  if( !Stream.is_Open() || !is_Valid() )
619  {
620  return( false );
621  }
622 
624 
625  //-----------------------------------------------------
626  if( File_Type == SG_DATATYPE_Bit )
627  {
628  int nLineBytes = Get_NX() / 8 + 1;
629 
630  if( m_Type == File_Type && !is_Cached() )
631  {
632  for(int y=0; y<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
633  {
634  Stream.Read(m_Values[bFlip ? Get_NY() - y - 1 : y], sizeof(char), nLineBytes);
635  }
636  }
637  else
638  {
639  CSG_Array Line(1, nLineBytes);
640 
641  for(int y=0; y<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
642  {
643  Stream.Read(Line.Get_Array(), nLineBytes);
644 
645  char *pValue = (char *)Line.Get_Array();
646 
647  for(int x=0, yy=bFlip ? Get_NY()-y-1 : y; x<Get_NX(); pValue++)
648  {
649  for(int i=0; i<8 && x<Get_NX(); i++, x++)
650  {
651  Set_Value(x, yy, (*pValue & m_Bitmask[i]) == 0 ? 0.0 : 1.0);
652  }
653  }
654  }
655  }
656  }
657 
658  //-----------------------------------------------------
659  else
660  {
661  int nValueBytes = (int)SG_Data_Type_Get_Size(File_Type);
662  int nLineBytes = Get_NX() * nValueBytes;
663 
664  if( m_Type == File_Type && !is_Cached() && !bSwapBytes )
665  {
666  for(int y=0; y<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
667  {
668  Stream.Read(m_Values[bFlip ? Get_NY() - y - 1 : y], nLineBytes);
669  }
670  }
671  else
672  {
673  CSG_Array Line(1, nLineBytes);
674 
675  for(int y=0; y<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
676  {
677  Stream.Read(Line.Get_Array(), nLineBytes);
678 
679  char *pValue = (char *)Line.Get_Array();
680 
681  for(int x=0, yy=bFlip ? Get_NY()-y-1 : y; x<Get_NX(); x++, pValue+=nValueBytes)
682  {
683  if( bSwapBytes )
684  {
685  _Swap_Bytes(pValue, nValueBytes);
686  }
687 
688  switch( File_Type )
689  {
690  case SG_DATATYPE_Byte : Set_Value(x, yy, *(BYTE *)pValue, false); break;
691  case SG_DATATYPE_Char : Set_Value(x, yy, *(char *)pValue, false); break;
692  case SG_DATATYPE_Word : Set_Value(x, yy, *(WORD *)pValue, false); break;
693  case SG_DATATYPE_Short : Set_Value(x, yy, *(short *)pValue, false); break;
694  case SG_DATATYPE_DWord : Set_Value(x, yy, *(DWORD *)pValue, false); break;
695  case SG_DATATYPE_Int : Set_Value(x, yy, *(int *)pValue, false); break;
696  case SG_DATATYPE_Float : Set_Value(x, yy, *(float *)pValue, false); break;
697  case SG_DATATYPE_Double: Set_Value(x, yy, *(double *)pValue, false); break;
698  default: break;
699  }
700  }
701  }
702  }
703  }
704 
705  //-----------------------------------------------------
706  return( true );
707 }
708 
709 //---------------------------------------------------------
710 bool CSG_Grid::_Save_Binary(CSG_File &Stream, TSG_Data_Type File_Type, bool bFlip, bool bSwapBytes)
711 {
712  //-----------------------------------------------------
713  if( !Stream.is_Writing() || !is_Valid() )
714  {
715  return( false );
716  }
717 
719 
720  //-----------------------------------------------------
721  if( File_Type == SG_DATATYPE_Bit )
722  {
723  int nLineBytes = Get_NX() / 8 + 1;
724 
725  if( m_Type == File_Type && !is_Cached() )
726  {
727  for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
728  {
729  Stream.Write((char *)m_Values[bFlip ? Get_NY() - y - 1 : y], sizeof(char), nLineBytes);
730  }
731  }
732  else
733  {
734  CSG_Array Line(1, nLineBytes);
735 
736  for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
737  {
738  char *pValue = (char *)Line.Get_Array();
739 
740  for(int x=0, yy=bFlip ? Get_NY()-y-1 : y; x<Get_NX(); pValue++)
741  {
742  for(int i=0; i<8 && x<Get_NX(); i++, x++)
743  {
744  *pValue = asChar(x, yy) != 0.0 ? *pValue | m_Bitmask[i] : *pValue & (~m_Bitmask[i]);
745  }
746  }
747 
748  Stream.Write(Line.Get_Array(), nLineBytes);
749  }
750  }
751  }
752 
753  //-----------------------------------------------------
754  else
755  {
756  int nValueBytes = (int)SG_Data_Type_Get_Size(File_Type);
757  int nLineBytes = Get_NX() * nValueBytes;
758 
759  if( m_Type == File_Type && !is_Cached() && !bSwapBytes )
760  {
761  for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
762  {
763  Stream.Write((char *)m_Values[bFlip ? Get_NY() - y - 1 : y], nLineBytes);
764  }
765  }
766  else
767  {
768  CSG_Array Line(1, nLineBytes);
769 
770  for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
771  {
772  char *pValue = (char *)Line.Get_Array();
773 
774  for(int x=0, yy=bFlip ? Get_NY()-y-1 : y; x<Get_NX(); x++, pValue+=nValueBytes)
775  {
776  switch( File_Type )
777  {
778  case SG_DATATYPE_Byte : *(BYTE *)pValue = asByte (x, yy, false); break;
779  case SG_DATATYPE_Char : *(char *)pValue = asChar (x, yy, false); break;
780  case SG_DATATYPE_Word : *(WORD *)pValue = asShort (x, yy, false); break;
781  case SG_DATATYPE_Short : *(short *)pValue = asShort (x, yy, false); break;
782  case SG_DATATYPE_DWord : *(DWORD *)pValue = asInt (x, yy, false); break;
783  case SG_DATATYPE_Int : *(int *)pValue = asInt (x, yy, false); break;
784  case SG_DATATYPE_Float : *(float *)pValue = asFloat (x, yy, false); break;
785  case SG_DATATYPE_Double: *(double *)pValue = asDouble(x, yy, false); break;
786  default: break;
787  }
788 
789  if( bSwapBytes )
790  {
791  _Swap_Bytes(pValue, nValueBytes);
792  }
793  }
794 
795  Stream.Write(Line.Get_Array(), nLineBytes);
796  }
797  }
798  }
799 
800  //-----------------------------------------------------
801  return( true );
802 }
803 
804 
806 // //
807 // ASCII //
808 // //
810 
811 //---------------------------------------------------------
812 bool CSG_Grid::_Load_ASCII(CSG_File &Stream, bool bCached, bool bFlip)
813 {
814  if( !Stream.is_Reading() || !_Memory_Create(bCached) )
815  {
816  return( false );
817  }
818 
820 
821  for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
822  {
823  for(int x=0, yy=bFlip ? Get_NY()-y-1 : y; x<Get_NX(); x++)
824  {
825  Set_Value(x, yy, Stream.Scan_Double());
826  }
827  }
828 
829  return( true );
830 }
831 
832 //---------------------------------------------------------
833 bool CSG_Grid::_Save_ASCII(CSG_File &Stream, bool bFlip)
834 {
835  if( !Stream.is_Writing() || !is_Valid() )
836  {
837  return( false );
838  }
839 
841 
842  for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
843  {
844  for(int x=0, yy=bFlip ? Get_NY()-y-1 : y; x<Get_NX(); x++)
845  {
846  Stream.Printf("%lf ", asDouble(x, yy));
847  }
848 
849  Stream.Printf("\n");
850  }
851 
852  return( true );
853 }
854 
855 
857 // //
859 
860 //---------------------------------------------------------
861 bool CSG_Grid::_Load_Surfer(const CSG_String &FileName, bool bCached, bool bLoadData)
862 {
863  const float NoData = 1.70141e38f;
864 
865  if( !SG_File_Cmp_Extension(FileName, "grd") )
866  {
867  return( false );
868  }
869 
870  Set_File_Name(FileName, true);
871 
872  //-----------------------------------------------------
873  CSG_File Stream;
874 
875  if( !Stream.Open(FileName, SG_FILE_R, true) )
876  {
877  return( false );
878  }
879 
880  char Identifier[4];
881 
882  Stream.Read(Identifier, sizeof(char), 4);
883 
884  //-----------------------------------------------------
885  if( !strncmp(Identifier, "DSBB", 4) ) // Binary...
886  {
887  short nx, ny;
888  double d;
889  TSG_Rect r;
890 
891  Stream.Read(&nx , sizeof(short ));
892  Stream.Read(&ny , sizeof(short ));
893  Stream.Read(&r.xMin, sizeof(double));
894  Stream.Read(&r.xMax, sizeof(double));
895  Stream.Read(&r.yMin, sizeof(double));
896  Stream.Read(&r.yMax, sizeof(double));
897  Stream.Read(&d , sizeof(double)); // zMin
898  Stream.Read(&d , sizeof(double)); // zMax
899 
900  d = (r.xMax - r.xMin) / (nx - 1.0);
901  // d = (r.yMax - r.yMin) / (ny - 1.0); // we could proof for equal cellsize in direction of y...
902 
903  //-------------------------------------------------
904  if( !Create(SG_DATATYPE_Float, nx, ny, d, r.xMin, r.yMin, bCached) || Stream.is_EOF() )
905  {
906  return( false );
907  }
908 
909  //-------------------------------------------------
910  if( bLoadData )
911  {
912  CSG_Array Line(sizeof(float), Get_NX()); float *Values = (float *)Line.Get_Array();
913 
914  for(int y=0; y<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
915  {
916  Stream.Read(Values, sizeof(float), Get_NX());
917 
918  for(int x=0; x<Get_NX(); x++)
919  {
920  if( Values[x] == NoData )
921  {
922  Set_NoData(x, y);
923  }
924  else
925  {
926  Set_Value(x, y, Values[x]);
927  }
928  }
929  }
930  }
931 
932  Get_MetaData().Add_Child("SURFER_GRID", "Surfer Grid (Binary)");
933  }
934 
935  //-----------------------------------------------------
936  else if( !strncmp(Identifier, "DSAA", 4) ) // ASCII...
937  {
938  int nx = Stream.Scan_Int ();
939  int ny = Stream.Scan_Int ();
940  double xMin = Stream.Scan_Double();
941  double xMax = Stream.Scan_Double();
942  double yMin = Stream.Scan_Double(); Stream.Scan_Double();
943  // double yMax = Stream.Scan_Double();
944  double dx = Stream.Scan_Double(); Stream.Scan_Double();
945  // double dy = Stream.Scan_Double();
946 
947  dx = (xMax - xMin) / (nx - 1.0);
948  // dy = (yMax - yMin) / (ny - 1.0); // we could proof for equal cellsize in direction of y...
949 
950  //-------------------------------------------------
951  if( !Create(SG_DATATYPE_Float, nx, ny, dx, xMin, yMin, bCached) || Stream.is_EOF() )
952  {
953  return( false );
954  }
955 
956  //-------------------------------------------------
957  if( bLoadData )
958  {
959  for(int y=0; y<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
960  {
961  for(int x=0; x<Get_NX(); x++)
962  {
963  double Value;
964 
965  if( Stream.Scan(Value) && Value != NoData )
966  {
967  Set_Value(x, y, Value);
968  }
969  else
970  {
971  Set_NoData(x, y);
972  }
973  }
974  }
975  }
976 
977  Get_MetaData().Add_Child("SURFER_GRID", "Surfer Grid (ASCII)");
978  }
979 
980  //-------------------------------------------------
982 
983  Set_File_Name(FileName);
984  Load_MetaData(FileName);
985 
986  return( true );
987 }
988 
989 
991 // //
992 // //
993 // //
995 
996 //---------------------------------------------------------
998 {
999  _On_Construction();
1000 }
1001 
1002 void CSG_Grid_File_Info::_On_Construction(void)
1003 {
1004  m_Name .Clear();
1005  m_Description .Clear();
1006  m_Unit .Clear();
1007  m_System .Assign(0.0, 0.0, 0.0, 0, 0);
1008  m_Type = SG_DATATYPE_Float; // defaults to float
1009  m_zScale = 1.0;
1010  m_zOffset = 0;
1011  m_NoData[0] = -99999.0;
1012  m_NoData[1] = -99999.0;
1013  m_Data_File .Clear();
1014  m_bFlip = false;
1015  m_bSwapBytes = false;
1016  m_Offset = 0;
1017  m_Projection .Destroy();
1018 }
1019 
1020 //---------------------------------------------------------
1022 {
1023  Create(Info);
1024 }
1025 
1027 {
1028  m_Name = Info.m_Name;
1030  m_Unit = Info.m_Unit;
1031  m_System = Info.m_System;
1032  m_Type = Info.m_Type;
1033  m_zScale = Info.m_zScale;
1034  m_zOffset = Info.m_zOffset;
1035  m_NoData[0] = Info.m_NoData[0];
1036  m_NoData[1] = Info.m_NoData[1];
1037  m_Data_File = Info.m_Data_File;
1038  m_bFlip = Info.m_bFlip;
1039  m_bSwapBytes = Info.m_bSwapBytes;
1040  m_Offset = Info.m_Offset;
1041  m_Projection = Info.m_Projection;
1042 
1043  return( true );
1044 }
1045 
1046 //---------------------------------------------------------
1048 {
1049  Create(Grid);
1050 }
1051 
1053 {
1054  m_Name = Grid.Get_Name();
1055  m_Description = Grid.Get_Description();
1056  m_Unit = Grid.Get_Unit();
1057  m_System = Grid.Get_System();
1058  m_Type = Grid.Get_Type();
1059  m_zScale = Grid.Get_Scaling();
1060  m_zOffset = Grid.Get_Offset();
1061  m_NoData[0] = Grid.Get_NoData_Value();
1062  m_NoData[1] = Grid.Get_NoData_Value(true);
1063  m_Data_File .Clear();
1064  m_bFlip = false;
1065  m_bSwapBytes = false;
1066  m_Offset = 0;
1067  m_Projection = Grid.Get_Projection();
1068 
1069  return( true );
1070 }
1071 
1072 //---------------------------------------------------------
1074 {
1075  Create(FileName);
1076 }
1077 
1079 {
1080  if( !SG_File_Cmp_Extension(FileName, "sg-grd-z") )
1081  {
1082  if( SG_File_Cmp_Extension(FileName, "sgrd")
1083  || SG_File_Cmp_Extension(FileName, "sg-grd") )
1084  {
1085  CSG_File Stream(FileName, SG_FILE_R, false);
1086 
1087  return( Create(Stream) );
1088  }
1089 
1090  return( false );
1091  }
1092 
1093  //-----------------------------------------------------
1094  CSG_Archive Stream(FileName, SG_FILE_R);
1095 
1096  if( Stream.is_Reading() )
1097  {
1098  CSG_String File(SG_File_Get_Name(FileName, false) + ".");
1099 
1100  if( !Stream.Get_File(File + "sgrd" )
1101  && !Stream.Get_File(File + "sg-grd") )
1102  {
1103  for(size_t i=0; i<Stream.Get_File_Count(); i++)
1104  {
1105  if( SG_File_Cmp_Extension(Stream.Get_File_Name(i), "sgrd" )
1106  || SG_File_Cmp_Extension(Stream.Get_File_Name(i), "sg-grd") )
1107  {
1108  Stream.Get_File(Stream.Get_File_Name(i));
1109  break;
1110  }
1111  }
1112  }
1113 
1114  return( Create(Stream) );
1115  }
1116 
1117  //-----------------------------------------------------
1118  return( false );
1119 }
1120 
1121 //---------------------------------------------------------
1123 {
1124  Create(Stream);
1125 }
1126 
1128 {
1129  _On_Construction();
1130 
1131  //-----------------------------------------------------
1132  if( !Stream.is_Reading() )
1133  {
1134  return( false );
1135  }
1136 
1137  //-----------------------------------------------------
1138  sLong NX = 0, NY = 0;
1139  double Cellsize = 0.0, xMin = 0.0, yMin = 0.0;
1140 
1141  do
1142  {
1143  CSG_String Value;
1144 
1145  switch( _Get_Key(Stream, Value) )
1146  {
1147  case GRID_FILE_KEY_NAME : m_Name = Value; break;
1148  case GRID_FILE_KEY_DESCRIPTION : m_Description = Value; break;
1149  case GRID_FILE_KEY_UNITNAME : m_Unit = Value; break;
1150 
1151  case GRID_FILE_KEY_CELLCOUNT_X : NX = Value.asInt (); break;
1152  case GRID_FILE_KEY_CELLCOUNT_Y : NY = Value.asInt (); break;
1153  case GRID_FILE_KEY_POSITION_XMIN : xMin = Value.asDouble(); break;
1154  case GRID_FILE_KEY_POSITION_YMIN : yMin = Value.asDouble(); break;
1155  case GRID_FILE_KEY_CELLSIZE : Cellsize = Value.asDouble(); break;
1156 
1157  case GRID_FILE_KEY_Z_FACTOR : m_zScale = Value.asDouble(); break;
1158  case GRID_FILE_KEY_Z_OFFSET : m_zOffset = Value.asDouble(); break;
1159  case GRID_FILE_KEY_NODATA_VALUE : m_NoData[0] = Value.asDouble();
1160  Value = Value.AfterFirst(';'); m_NoData[1] = Value.is_Empty() ? m_NoData[0] : Value.asDouble(); break;
1161 
1162  case GRID_FILE_KEY_DATAFILE_OFFSET: m_Offset = Value.asInt (); break;
1164  case GRID_FILE_KEY_TOPTOBOTTOM : m_bFlip = Value.Find(GRID_FILE_KEY_TRUE) >= 0; break;
1165 
1167  if( SG_File_Get_Path(Value).Length() > 0 )
1168  {
1169  m_Data_File = Value;
1170  }
1171  else
1172  {
1174  }
1175  break;
1176 
1178  {
1179  for(int i=0; i<SG_DATATYPE_Undefined; i++)
1180  {
1181  if( Value.Find(gSG_Data_Type_Identifier[i]) >= 0 )
1182  {
1183  m_Type = (TSG_Data_Type)i;
1184 
1185  break;
1186  }
1187  }
1188  }
1189  break;
1190  }
1191  }
1192  while( !Stream.is_EOF() );
1193 
1194  //-----------------------------------------------------
1195  return( m_System.Assign(Cellsize, xMin, yMin, (int)NX, (int)NY) );
1196 }
1197 
1198 //---------------------------------------------------------
1199 int CSG_Grid_File_Info::_Get_Key(CSG_File &Stream, CSG_String &Value)
1200 {
1201  int i;
1202  CSG_String sLine;
1203 
1204  if( Stream.Read_Line(sLine) && (i = sLine.Find('=')) > 0 )
1205  {
1206  Value = sLine.AfterFirst('=');
1207  Value.Trim();
1208 
1209  sLine.Remove(i);
1210 
1211  for(i=0; i<GRID_FILE_KEY_Count; i++)
1212  {
1214 
1215  if( s.Find(sLine.Left(s.Length())) >= 0 )
1216  {
1217  return( i );
1218  }
1219  }
1220  }
1221 
1222  return( -1 );
1223 }
1224 
1225 
1227 // //
1229 
1230 //---------------------------------------------------------
1231 bool CSG_Grid_File_Info::Save(const CSG_String &FileName, bool bBinary)
1232 {
1233  return( Save(CSG_File(FileName, SG_FILE_W, false), bBinary) );
1234 }
1235 
1236 //---------------------------------------------------------
1237 bool CSG_Grid_File_Info::Save(const CSG_File &Stream, bool bBinary)
1238 {
1239  if( !Stream.is_Writing() )
1240  {
1241  return( false );
1242  }
1243 
1244 #define GRID_FILE_PRINT(Key, Val) { CSG_String s(gSG_Grid_File_Key_Names[Key]); s += "\t= " + Val + "\n"; Stream.Write(s); }
1245 
1251 #ifdef WORDS_BIGENDIAN
1253 #else
1255 #endif
1265 
1266  return( true );
1267 }
1268 
1269 //---------------------------------------------------------
1270 bool CSG_Grid_File_Info::Save(const CSG_String &FileName, const CSG_Grid &Grid, bool bBinary)
1271 {
1272  CSG_Grid_File_Info Info(Grid);
1273 
1274  return( Info.Save(FileName, bBinary) );
1275 }
1276 
1277 //---------------------------------------------------------
1278 bool CSG_Grid_File_Info::Save(const CSG_File &Stream, const CSG_Grid &Grid, bool bBinary)
1279 {
1280  CSG_Grid_File_Info Info(Grid);
1281 
1282  return( Info.Save(Stream, bBinary) );
1283 }
1284 
1285 
1287 // //
1289 
1290 //---------------------------------------------------------
1292 {
1293  CSG_File Stream;
1294 
1295  return( m_Projection.is_Okay() && Stream.Open(FileName + ".aux.xml", SG_FILE_W, false) && Save_AUX_XML(Stream) );
1296 }
1297 
1298 //---------------------------------------------------------
1300 {
1301  if( m_Projection.is_Okay() && Stream.is_Writing() ) // store srs information that is recognized by ArcGIS
1302  {
1303  Stream.Write("<PAMDataset>\n<SRS>");
1304  Stream.Write(m_Projection.Get_WKT());
1305  Stream.Write("</SRS>\n</PAMDataset>\n");
1306 
1307  return( true );
1308  }
1309 
1310  return( false );
1311 }
1312 
1313 
1315 // //
1316 // //
1317 // //
1319 
1320 //---------------------------------------------------------
CSG_Grid::Get_Type
TSG_Data_Type Get_Type(void) const
Definition: grid.h:521
CSG_Grid_File_Info::m_Offset
sLong m_Offset
Definition: grid.h:441
CSG_String::BeforeFirst
CSG_String BeforeFirst(char Character) const
Definition: api_string.cpp:690
SG_DATATYPE_Int
@ SG_DATATYPE_Int
Definition: api_core.h:1001
SG_File_Get_Path
SAGA_API_DLL_EXPORT CSG_String SG_File_Get_Path(const CSG_String &full_Path)
Definition: api_file.cpp:1030
SG_DATATYPE_Undefined
@ SG_DATATYPE_Undefined
Definition: api_core.h:1010
CSG_Grid_File_Info::Save_AUX_XML
bool Save_AUX_XML(const CSG_String &File)
Definition: grid_io.cpp:1291
CSG_Projection::Save
bool Save(const CSG_String &File, ESG_CRS_Format Format=ESG_CRS_Format::WKT) const
Definition: projections.cpp:261
SG_T
#define SG_T(s)
Definition: api_core.h:537
CSG_Grid_System::Get_Precision
static int Get_Precision(void)
Definition: grid_system.cpp:88
CSG_Grid_System::Get_Cellsize
double Get_Cellsize(void) const
Definition: grid.h:231
GRID_FILE_KEY_DESCRIPTION
@ GRID_FILE_KEY_DESCRIPTION
Definition: grid.h:103
_TL
#define _TL(s)
Definition: api_core.h:1507
SG_DATATYPE_DWord
@ SG_DATATYPE_DWord
Definition: api_core.h:1000
CSG_Grid_File_Info::m_zOffset
double m_zOffset
Definition: grid.h:443
CSG_Data_Object::Set_File_Name
void Set_File_Name(const CSG_String &FileName)
Definition: dataobject.cpp:366
CSG_Data_Object::Get_Description
const SG_Char * Get_Description(void) const
Definition: dataobject.cpp:360
CSG_Data_Collection::Count
size_t Count(void) const
Definition: data_manager.h:94
GRID_FILE_KEY_Z_FACTOR
@ GRID_FILE_KEY_Z_FACTOR
Definition: grid.h:114
CSG_String::Remove
CSG_String & Remove(size_t pos)
Definition: api_string.cpp:593
CSG_Grid_System::Get_XMin
double Get_XMin(bool bCells=false) const
Definition: grid.h:240
data_manager.h
CSG_Data_Object::Get_NoData_Value
double Get_NoData_Value(bool bUpper=false) const
Definition: dataobject.h:253
GRID_FILE_FORMAT_Compressed
@ GRID_FILE_FORMAT_Compressed
Definition: grid.h:94
CSG_Grid_File_Info::m_bSwapBytes
bool m_bSwapBytes
Definition: grid.h:439
SG_UI_MSG_STYLE_SUCCESS
@ SG_UI_MSG_STYLE_SUCCESS
Definition: api_core.h:1523
CSG_File::Seek
bool Seek(sLong Offset, int Origin=SG_FILE_START) const
Definition: api_file.cpp:241
CSG_Grid_File_Info::CSG_Grid_File_Info
CSG_Grid_File_Info(void)
Definition: grid_io.cpp:997
GRID_FILE_FORMAT_Undefined
@ GRID_FILE_FORMAT_Undefined
Definition: grid.h:90
GRID_FILE_KEY_BYTEORDER_BIG
@ GRID_FILE_KEY_BYTEORDER_BIG
Definition: grid.h:108
CSG_String::asInt
int asInt(void) const
Definition: api_string.cpp:746
CSG_Grid::Create
bool Create(const CSG_Grid &Grid)
Definition: grid.cpp:235
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:1091
GRID_FILE_KEY_DATAFORMAT
@ GRID_FILE_KEY_DATAFORMAT
Definition: grid.h:107
GRID_FILE_FORMAT_GeoTIFF
@ GRID_FILE_FORMAT_GeoTIFF
Definition: grid.h:95
CSG_Data_Object::Save_MetaData
bool Save_MetaData(const CSG_String &FileName)
Definition: dataobject.cpp:681
GRID_FILE_KEY_TRUE
#define GRID_FILE_KEY_TRUE
Definition: grid.h:144
SG_Data_Type_Get_Size
size_t SG_Data_Type_Get_Size(TSG_Data_Type Type)
Definition: api_core.h:1061
GRID_FILE_KEY_POSITION_YMIN
@ GRID_FILE_KEY_POSITION_YMIN
Definition: grid.h:110
SG_DATATYPE_Byte
@ SG_DATATYPE_Byte
Definition: api_core.h:996
CSG_Archive
Definition: api_core.h:1200
CSG_Projection::is_Okay
bool is_Okay(void) const
Definition: geo_tools.h:863
CSG_Tool
Definition: tool.h:151
CSG_File::Scan
bool Scan(int &Value) const
Definition: api_file.cpp:490
CSG_Grid_File_Info::m_NoData
double m_NoData[2]
Definition: grid.h:443
grid.h
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_Rect::xMax
double xMax
Definition: geo_tools.h:468
CSG_Grid_File_Info::m_System
CSG_Grid_System m_System
Definition: grid.h:449
CSG_File::Scan_Int
int Scan_Int(void) const
Definition: api_file.cpp:552
SG_RUN_TOOL
#define SG_RUN_TOOL(bRetVal, LIBRARY, TOOL, CONDITION)
Definition: tool_library.h:260
CSG_Grid_File_Info::Save
bool Save(const CSG_String &File, bool bBinary=true)
Definition: grid_io.cpp:1231
SG_File_Delete
SAGA_API_DLL_EXPORT bool SG_File_Delete(const CSG_String &FileName)
Definition: api_file.cpp:995
GRID_FILE_KEY_CELLSIZE
@ GRID_FILE_KEY_CELLSIZE
Definition: grid.h:113
GRID_FILE_KEY_NODATA_VALUE
@ GRID_FILE_KEY_NODATA_VALUE
Definition: grid.h:116
SG_FILE_R
@ SG_FILE_R
Definition: api_core.h:1111
SG_Grid_Get_File_Extension_Default
CSG_String SG_Grid_Get_File_Extension_Default(void)
Definition: grid_io.cpp:129
CSG_Projection::Get_WKT
const CSG_String & Get_WKT(void) const
Definition: geo_tools.h:887
TSG_Grid_File_Format
TSG_Grid_File_Format
Definition: grid.h:89
CSG_File::Read
size_t Read(void *Buffer, size_t Size, size_t Count=1) const
Definition: api_file.cpp:337
CSG_Projection::Destroy
void Destroy(void)
Definition: projections.cpp:235
CSG_Tool_Library_Manager::Delete_Tool
bool Delete_Tool(CSG_Tool *pTool) const
Definition: tool_library.cpp:865
CSG_Grid::Get_System
const CSG_Grid_System & Get_System(void) const
Definition: grid.h:533
CSG_File
Definition: api_core.h:1126
CSG_String::Cmp
int Cmp(const CSG_String &String) const
Definition: api_string.cpp:515
SSG_Rect::xMin
double xMin
Definition: geo_tools.h:468
SSG_Rect
Definition: geo_tools.h:467
CSG_Archive::Get_File_Name
virtual CSG_String Get_File_Name(size_t Index)
Definition: api_file.cpp:777
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:1524
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:1017
CSG_Grid::Get_Scaling
double Get_Scaling(void) const
Definition: grid.cpp:422
SG_TOOL_PARAMLIST_ADD
#define SG_TOOL_PARAMLIST_ADD(IDENTIFIER, VALUE)
Definition: tool_library.h:356
SG_TOOL_PARAMETER_SET
#define SG_TOOL_PARAMETER_SET(IDENTIFIER, VALUE)
Definition: tool_library.h:354
CSG_Grid::On_Delete
virtual bool On_Delete(void)
Definition: grid_io.cpp:80
GRID_FILE_KEY_NAME
@ GRID_FILE_KEY_NAME
Definition: grid.h:102
gSG_Grid_File_Key_Names
const SG_Char gSG_Grid_File_Key_Names[GRID_FILE_KEY_Count][32]
Definition: grid.h:123
CSG_String::Trim
int Trim(bool fromRight=false)
Definition: api_string.cpp:614
CSG_Grid_File_Info::Create
bool Create(const CSG_Grid_File_Info &Info)
Definition: grid_io.cpp:1026
CSG_Grid::is_Valid
virtual bool is_Valid(void) const
Definition: grid.cpp:441
CSG_Grid_File_Info::m_Unit
CSG_String m_Unit
Definition: grid.h:447
GRID_FILE_KEY_FALSE
#define GRID_FILE_KEY_FALSE
Definition: grid.h:145
GRID_FILE_KEY_DATAFILE_NAME
@ GRID_FILE_KEY_DATAFILE_NAME
Definition: grid.h:105
CSG_File::is_Writing
bool is_Writing(void) const
Definition: api_core.h:1147
SG_UI_Msg_Lock
int SG_UI_Msg_Lock(bool bOn)
Definition: api_callback.cpp:471
CSG_File::Scan_Double
double Scan_Double(void) const
Definition: api_file.cpp:557
CSG_Grid::Set_Value
virtual void Set_Value(sLong i, double Value, bool bScaled=true)
Definition: grid.h:817
sLong
signed long long sLong
Definition: api_core.h:158
SG_Grid_Set_File_Format_Default
bool SG_Grid_Set_File_Format_Default(int Format)
Definition: grid_io.cpp:106
SG_Get_Tool_Library_Manager
CSG_Tool_Library_Manager & SG_Get_Tool_Library_Manager(void)
Definition: tool_library.cpp:286
SG_Data_Type_is_Numeric
bool SG_Data_Type_is_Numeric(TSG_Data_Type Type)
Definition: api_core.cpp:198
CSG_Grid_File_Info::m_Type
TSG_Data_Type m_Type
Definition: grid.h:445
CSG_Grid::Get_Unit
const CSG_String & Get_Unit(void) const
Definition: grid.h:527
GRID_FILE_KEY_TOPTOBOTTOM
@ GRID_FILE_KEY_TOPTOBOTTOM
Definition: grid.h:117
CSG_File::Open
virtual bool Open(const SG_Char *FileName, int Mode=SG_FILE_R, bool bBinary=true, int Encoding=SG_FILE_ENCODING_ANSI)
Definition: api_file.cpp:112
CSG_Grid::Get_NY
int Get_NY(void) const
Definition: grid.h:538
SG_DATATYPE_Float
@ SG_DATATYPE_Float
Definition: api_core.h:1004
CSG_Grid_System::Assign
bool Assign(const CSG_Grid_System &System)
Definition: grid_system.cpp:240
CSG_Grid::Get_Offset
double Get_Offset(void) const
Definition: grid.cpp:428
CSG_Data_Object::Set_File_Type
void Set_File_Type(int Type)
Definition: dataobject.h:275
GRID_FILE_FORMAT_Binary_old
@ GRID_FILE_FORMAT_Binary_old
Definition: grid.h:91
CSG_Data_Object::Get_File_Name
const SG_Char * Get_File_Name(bool bNative=true) const
Definition: dataobject.cpp:390
CSG_Grid_File_Info::m_Projection
CSG_Projection m_Projection
Definition: grid.h:451
CSG_Archive::Get_File
bool Get_File(const SG_Char *Name)
Definition: api_file.cpp:760
CSG_Grid_File_Info::m_Name
CSG_String m_Name
Definition: grid.h:447
CSG_Grid::asShort
virtual short asShort(int x, int y, bool bScaled=true) const
Definition: grid.h:757
CSG_Grid::On_Reload
virtual bool On_Reload(void)
Definition: grid_io.cpp:74
SG_FILE_W
@ SG_FILE_W
Definition: api_core.h:1112
SSG_Rect::yMax
double yMax
Definition: geo_tools.h:468
CSG_Projection::Load
bool Load(const CSG_String &File)
Definition: projections.cpp:253
CSG_File::is_Open
bool is_Open(void) const
Definition: api_core.h:1145
CSG_Grid_File_Info::m_zScale
double m_zScale
Definition: grid.h:443
SG_DATATYPE_Word
@ SG_DATATYPE_Word
Definition: api_core.h:998
CSG_Grid_System::Get_NY
int Get_NY(void) const
Definition: grid.h:235
CSG_Data_Object::Set_Name
void Set_Name(const CSG_String &Name)
Definition: dataobject.cpp:300
CSG_Archive::Get_File_Count
size_t Get_File_Count(void)
Definition: api_core.h:1220
CSG_String::Format
static CSG_String Format(const char *Format,...)
Definition: api_string.cpp:270
CSG_String::Find
int Find(char Character, bool fromEnd=false) const
Definition: api_string.cpp:640
gSG_Data_Type_Identifier
const char gSG_Data_Type_Identifier[][32]
Definition: api_core.h:1040
CSG_Tool_Library_Manager::Create_Tool
CSG_Tool * Create_Tool(const CSG_String &Library, int Index, bool bWithGUI=false, bool bWithCMD=true) const
Definition: tool_library.cpp:836
gSG_Grid_File_Format_Default
static TSG_Grid_File_Format gSG_Grid_File_Format_Default
Definition: grid_io.cpp:103
CSG_Grid::Set_NoData
virtual void Set_NoData(int x, int y)
Definition: grid.h:704
SG_File_Set_Extension
SAGA_API_DLL_EXPORT bool SG_File_Set_Extension(CSG_String &FileName, const CSG_String &Extension)
Definition: api_file.cpp:1097
CSG_String::Left
CSG_String Left(size_t count) const
Definition: api_string.cpp:729
CSG_String::AfterFirst
CSG_String AfterFirst(char Character) const
Definition: api_string.cpp:668
CSG_String::Clear
void Clear(void)
Definition: api_string.cpp:259
SG_Grid_Get_File_Format_Default
TSG_Grid_File_Format SG_Grid_Get_File_Format_Default(void)
Definition: grid_io.cpp:123
CSG_Grid::Save
virtual bool Save(const char *File, int Format=0)
Definition: grid.h:509
CSG_Array
Definition: api_core.h:308
CSG_String
Definition: api_core.h:563
CSG_Grid_File_Info::m_Description
CSG_String m_Description
Definition: grid.h:447
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:767
CSG_Data_Manager
Definition: data_manager.h:129
CSG_Data_Object::Set_Description
void Set_Description(const CSG_String &Description)
Definition: dataobject.cpp:355
CSG_Grid::Get_NX
int Get_NX(void) const
Definition: grid.h:537
CSG_Grid_File_Info::m_Data_File
CSG_String m_Data_File
Definition: grid.h:447
GRID_FILE_KEY_UNITNAME
@ GRID_FILE_KEY_UNITNAME
Definition: grid.h:104
CSG_Grid::asFloat
virtual float asFloat(int x, int y, bool bScaled=true) const
Definition: grid.h:763
CSG_Tool::Settings_Push
bool Settings_Push(class CSG_Data_Manager *pManager=NULL)
Definition: tool.cpp:621
CSG_File::Printf
int Printf(const char *Format,...)
Definition: api_file.cpp:286
CSG_String::is_Empty
bool is_Empty(void) const
Definition: api_string.cpp:178
SG_UI_Process_Set_Progress
bool SG_UI_Process_Set_Progress(int Position, int Range)
Definition: api_callback.cpp:255
CSG_Data_Object::Get_MetaData
CSG_MetaData & Get_MetaData(void) const
Definition: dataobject.h:234
CSG_File::Read_Line
bool Read_Line(CSG_String &Line) const
Definition: api_file.cpp:394
SSG_Rect::yMin
double yMin
Definition: geo_tools.h:468
SG_DATATYPE_Short
@ SG_DATATYPE_Short
Definition: api_core.h:999
CSG_Data_Object::Load_MetaData
bool Load_MetaData(const CSG_String &FileName)
Definition: dataobject.cpp:654
GRID_FILE_KEY_CELLCOUNT_X
@ GRID_FILE_KEY_CELLCOUNT_X
Definition: grid.h:111
GRID_FILE_PRINT
#define GRID_FILE_PRINT(Key, Val)
GRID_FILE_KEY_Z_OFFSET
@ GRID_FILE_KEY_Z_OFFSET
Definition: grid.h:115
CSG_Grid::is_Cached
bool is_Cached(void) const
Definition: grid.h:607
CSG_Grid
Definition: grid.h:475
SG_DATATYPE_Bit
@ SG_DATATYPE_Bit
Definition: api_core.h:995
CSG_Grid::asByte
virtual BYTE asByte(int x, int y, bool bScaled=true) const
Definition: grid.h:753
CSG_Grid_System::Get_NX
int Get_NX(void) const
Definition: grid.h:234
CSG_String::asDouble
double asDouble(void) const
Definition: api_string.cpp:784
CSG_Tool::On_Before_Execution
virtual bool On_Before_Execution(void)
Definition: tool.h:245
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:1058
SG_UI_ProgressAndMsg_Lock
void SG_UI_ProgressAndMsg_Lock(bool bOn)
Definition: api_callback.cpp:589
CSG_String::c_str
const SG_Char * c_str(void) const
Definition: api_string.cpp:236
tool_library.h
CSG_File::Write
size_t Write(void *Buffer, size_t Size, size_t Count=1) const
Definition: api_file.cpp:369
CSG_Grid::asChar
virtual char asChar(int x, int y, bool bScaled=true) const
Definition: grid.h:755
SG_UI_Process_Set_Ready
bool SG_UI_Process_Set_Ready(void)
Definition: api_callback.cpp:305
TSG_Data_Type
TSG_Data_Type
Definition: api_core.h:994
CSG_MetaData::Add_Child
CSG_MetaData * Add_Child(void)
Definition: metadata.cpp:166
GRID_FILE_KEY_CELLCOUNT_Y
@ GRID_FILE_KEY_CELLCOUNT_Y
Definition: grid.h:112
GRID_FILE_FORMAT_Binary
@ GRID_FILE_FORMAT_Binary
Definition: grid.h:92
CSG_Grid::Set_Unit
void Set_Unit(const CSG_String &Unit)
Definition: grid.cpp:400
CSG_Data_Manager::Grid
CSG_Data_Collection & Grid(void) const
Definition: data_manager.h:138
GRID_FILE_KEY_Count
@ GRID_FILE_KEY_Count
Definition: grid.h:118
GRID_FILE_KEY_POSITION_XMIN
@ GRID_FILE_KEY_POSITION_XMIN
Definition: grid.h:109
CSG_Grid_File_Info::m_bFlip
bool m_bFlip
Definition: grid.h:439
CSG_File::is_EOF
bool is_EOF(void) const
Definition: api_file.cpp:235
GRID_FILE_FORMAT_ASCII
@ GRID_FILE_FORMAT_ASCII
Definition: grid.h:93
GRID_FILE_KEY_DATAFILE_OFFSET
@ GRID_FILE_KEY_DATAFILE_OFFSET
Definition: grid.h:106
CSG_Grid_System::Get_YMin
double Get_YMin(bool bCells=false) const
Definition: grid.h:244
CSG_Data_Object::Set_NoData_Value_Range
virtual bool Set_NoData_Value_Range(double Lower, double Upper)
Definition: dataobject.cpp:578
SG_DATATYPE_Char
@ SG_DATATYPE_Char
Definition: api_core.h:997
CSG_Data_Object::Get_Projection
CSG_Projection & Get_Projection(void)
Definition: dataobject.cpp:637
CSG_File::is_Reading
bool is_Reading(void) const
Definition: api_core.h:1146
CSG_Grid::asInt
virtual int asInt(int x, int y, bool bScaled=true) const
Definition: grid.h:759
CSG_File::Get_File_Name
virtual const CSG_String & Get_File_Name(void) const
Definition: api_core.h:1137
CSG_Grid_File_Info
Definition: grid.h:410
SG_UI_Msg_Add
void SG_UI_Msg_Add(const char *Message, bool bNewLine, TSG_UI_MSG_STYLE Style)
Definition: api_callback.cpp:502
CSG_Grid::Set_Modified
virtual void Set_Modified(bool bModified=true)
Definition: grid.h:638
SG_DATATYPE_Double
@ SG_DATATYPE_Double
Definition: api_core.h:1005