SAGA API  v9.2
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;
216 
217  CSG_Data_Manager Data;
218 
219  CSG_Tool *pTool = NULL;
220 
221  SG_UI_Msg_Lock(true);
222 
223  //-----------------------------------------------------
224  // Image Import
225 
226  if( ( SG_File_Cmp_Extension(FileName, "bmp")
227  || SG_File_Cmp_Extension(FileName, "gif")
228  || SG_File_Cmp_Extension(FileName, "jpg")
229  || SG_File_Cmp_Extension(FileName, "png")
230  || SG_File_Cmp_Extension(FileName, "pcx") )
231  && !bResult && (pTool = SG_Get_Tool_Library_Manager().Create_Tool("io_grid_image", 1)) != NULL )
232  {
233  pTool->Settings_Push(&Data);
234 
235  bResult = pTool->Set_Parameter("FILE", FileName)
236  && pTool->Execute();
237 
239  }
240 
241  //-----------------------------------------------------
242  // GDAL Import
243 
244  if( !bResult && (pTool = SG_Get_Tool_Library_Manager().Create_Tool("io_gdal", 0)) != NULL )
245  {
246  pTool->Settings_Push(&Data);
247 
248  bResult = pTool->Set_Parameter("FILES" , FileName)
249  && pTool->Set_Parameter("MULTIPLE", 0 ) // output as single grid(s)
250  && pTool->Execute();
251 
253  }
254 
255  SG_UI_Msg_Lock(false);
256 
257  //-----------------------------------------------------
258  if( bResult && Data.Get_Grid_System(0) && Data.Get_Grid_System(0)->Get(0) && Data.Get_Grid_System(0)->Get(0)->is_Valid() )
259  {
260  CSG_Grid *pGrid = (CSG_Grid *)Data.Get_Grid_System(0)->Get(0);
261 
262  if( pGrid->is_Cached() )
263  {
264  return( Create(*pGrid) );
265  }
266 
267  Set_File_Name(FileName, false);
268 
269  Set_Name (pGrid->Get_Name());
270  Set_Description (pGrid->Get_Description());
271 
272  m_System = pGrid->m_System;
273  m_Type = pGrid->m_Type;
274  m_Values = pGrid->m_Values; pGrid->m_Values = NULL; // take ownership of data array
275 
276  m_zOffset = pGrid->m_zOffset;
277  m_zScale = pGrid->m_zScale;
278  m_Unit = pGrid->m_Unit;
279 
280  m_nBytes_Value = pGrid->m_nBytes_Value;
281  m_nBytes_Line = pGrid->m_nBytes_Line;
282 
283  Get_MetaData () = pGrid->Get_MetaData ();
284  Get_Projection() = pGrid->Get_Projection();
285 
287 
288  return( true );
289  }
290 
291  return( false );
292 }
293 
294 //---------------------------------------------------------
295 bool CSG_Grid::_Load_PGSQL(const CSG_String &FileName, bool bCached, bool bLoadData)
296 {
297  bool bResult = false;
298 
299  if( FileName.BeforeFirst(':').Cmp("PGSQL") == 0 ) // database source
300  {
301  CSG_String s(FileName);
302 
303  s = s.AfterFirst(':'); CSG_String Host (s.BeforeFirst(':'));
304  s = s.AfterFirst(':'); CSG_String Port (s.BeforeFirst(':'));
305  s = s.AfterFirst(':'); CSG_String DBName(s.BeforeFirst(':'));
306  s = s.AfterFirst(':'); CSG_String Table (s.BeforeFirst(':'));
307  s = s.AfterFirst(':'); CSG_String rid (s.BeforeFirst(':').AfterFirst('='));
308 
309  CSG_Tool *pTool = SG_Get_Tool_Library_Manager().Create_Tool("db_pgsql", 0, true); // CGet_Connections
310 
311  if( pTool != NULL )
312  {
314 
315  //---------------------------------------------
316  CSG_Table Connections; CSG_String Connection(DBName + " [" + Host + ":" + Port + "]");
317 
318  pTool->Set_Manager(NULL); pTool->On_Before_Execution();
319 
320  if( SG_TOOL_PARAMETER_SET("CONNECTIONS", &Connections) && pTool->Execute() ) // CGet_Connections
321  {
322  for(int i=0; !bResult && i<Connections.Get_Count(); i++)
323  {
324  if( !Connection.Cmp(Connections[i].asString(0)) )
325  {
326  bResult = true;
327  }
328  }
329  }
330 
332 
333  //---------------------------------------------
334  if( bResult && (bResult = (pTool = SG_Get_Tool_Library_Manager().Create_Tool("db_pgsql", 33, true)) != NULL) == true ) // CPGIS_Raster_Load_Band
335  {
336  pTool->Set_Manager(NULL); pTool->On_Before_Execution();
337 
338  bResult = SG_TOOL_PARAMETER_SET("CONNECTION", Connection)
339  && SG_TOOL_PARAMETER_SET("DB_TABLE" , Table )
340  && SG_TOOL_PARAMETER_SET("RID" , rid )
341  && SG_TOOL_PARAMETER_SET("GRID" , this )
342  && pTool->Execute();
343 
345  }
346 
348  }
349  }
350 
351  return( bResult );
352 }
353 
354 
356 // //
357 // Native //
358 // //
360 
361 //---------------------------------------------------------
362 bool CSG_Grid::_Load_Native(const CSG_String &FileName, bool bCached, bool bLoadData)
363 {
364  CSG_Grid_File_Info Info;
365 
366  if( !Info.Create(FileName) )
367  {
368  return( false );
369  }
370 
371  Set_File_Name(FileName, true);
372 
373  Set_Name (Info.m_Name);
375  Set_Unit (Info.m_Unit);
376 
377  Set_NoData_Value_Range(Info.m_NoData[0], Info.m_NoData[1]);
378 
379  m_System = Info.m_System;
380  m_Type = Info.m_Type;
381  m_zScale = Info.m_zScale;
382  m_zOffset = Info.m_zOffset;
383 
384  m_nBytes_Value = SG_Data_Type_Get_Size(m_Type);
385  m_nBytes_Line = m_Type == SG_DATATYPE_Bit ? 1 + Get_NX() / 8 : Get_NX() * m_nBytes_Value;
386 
387  Get_Projection().Load(SG_File_Make_Path("", FileName, "prj"), SG_PROJ_FMT_WKT);
388 
389  if( !bLoadData )
390  {
391  return( _Memory_Create(bCached) );
392  }
393 
394  Load_MetaData(FileName);
395 
396  //-----------------------------------------------------
397  CSG_File Stream;
398 
399  if( !SG_Data_Type_is_Numeric(m_Type) ) // ASCII...
400  {
401  if( Stream.Open(Info.m_Data_File , SG_FILE_R, false)
402  || Stream.Open(SG_File_Make_Path("", FileName, "dat"), SG_FILE_R, false)
403  || Stream.Open(SG_File_Make_Path("", FileName, "sdat"), SG_FILE_R, false) )
404  {
405  Stream.Seek(Info.m_Offset);
406 
407  return( _Load_ASCII(Stream, bCached, Info.m_bFlip) );
408  }
409  }
410 
411  //-----------------------------------------------------
412  else // Binary...
413  {
414  if( bCached || _Cache_Check() )
415  {
416  if( _Cache_Create(Info.m_Data_File , m_Type, Info.m_Offset, Info.m_bSwapBytes, Info.m_bFlip)
417  || _Cache_Create(SG_File_Make_Path("", FileName, "dat"), m_Type, Info.m_Offset, Info.m_bSwapBytes, Info.m_bFlip)
418  || _Cache_Create(SG_File_Make_Path("", FileName, "sdat"), m_Type, Info.m_Offset, Info.m_bSwapBytes, Info.m_bFlip) )
419  {
420  return( true );
421  }
422  }
423 
424  m_Cache_File = Info.m_Data_File;
425  m_Cache_Offset = Info.m_Offset;
426  m_Cache_bSwap = Info.m_bSwapBytes;
427  m_Cache_bFlip = Info.m_bFlip;
428 
429  if( _Memory_Create(bCached) )
430  {
431  if( Stream.Open(Info.m_Data_File , SG_FILE_R, true)
432  || Stream.Open(SG_File_Make_Path("", FileName, "dat"), SG_FILE_R, true)
433  || Stream.Open(SG_File_Make_Path("", FileName, "sdat"), SG_FILE_R, true) )
434  {
435  Stream.Seek(Info.m_Offset);
436 
437  return( _Load_Binary(Stream, m_Type, Info.m_bFlip, Info.m_bSwapBytes) );
438  }
439  }
440  }
441 
442  return( false );
443 }
444 
445 //---------------------------------------------------------
446 bool CSG_Grid::_Save_Native(const CSG_String &_FileName, TSG_Grid_File_Format Format)
447 {
448 #ifdef WORDS_BIGENDIAN
449  bool bBigEndian = true;
450 #else
451  bool bBigEndian = false;
452 #endif
453 
454  CSG_String FileName(_FileName);
455 
456  bool bBinary;
457 
458  if( Format == GRID_FILE_FORMAT_ASCII )
459  {
460  bBinary = false;
461  }
462  else if( Format == GRID_FILE_FORMAT_Binary_old )
463  {
464  bBinary = true; SG_File_Set_Extension(FileName, "sgrd");
465  }
466  else
467  {
468  bBinary = true; SG_File_Set_Extension(FileName, "sg-grd");
469  }
470 
471  CSG_Grid_File_Info Info(*this);
472 
473  if( Info.Save(FileName, bBinary) )
474  {
475  CSG_File Stream(SG_File_Make_Path("", FileName, "sdat"), SG_FILE_W, true);
476 
477  if( bBinary ? _Save_Binary(Stream, m_Type, false, bBigEndian) : _Save_ASCII (Stream) )
478  {
479  Save_MetaData(FileName);
480 
481  Get_Projection().Save(SG_File_Make_Path("", FileName, "prj"), SG_PROJ_FMT_WKT);
482 
483  Info.Save_AUX_XML(SG_File_Make_Path("", FileName, "sdat"));
484 
485  return( true );
486  }
487  }
488 
489  return( false );
490 }
491 
492 
494 // //
495 // Compressed //
496 // //
498 
499 //---------------------------------------------------------
500 bool CSG_Grid::_Load_Compressed(const CSG_String &_FileName, bool bCached, bool bLoadData)
501 {
502  Set_File_Name(_FileName, true);
503 
504  CSG_File_Zip Stream(_FileName, SG_FILE_R);
505 
506  if( !Stream.is_Reading() )
507  {
508  return( false );
509  }
510 
511  //-----------------------------------------------------
512  CSG_String FileName(SG_File_Get_Name(_FileName, false) + ".");
513 
514  if( !Stream.Get_File(FileName + "sgrd" )
515  && !Stream.Get_File(FileName + "sg-grd") )
516  {
517  FileName.Clear();
518 
519  for(size_t i=0; i<Stream.Get_File_Count(); i++)
520  {
521  if( SG_File_Cmp_Extension(Stream.Get_File_Name(i), "sgrd" )
522  || SG_File_Cmp_Extension(Stream.Get_File_Name(i), "sg-grd") )
523  {
524  FileName = SG_File_Get_Name(Stream.Get_File_Name(i), false) + ".";
525  Stream.Get_File(Stream.Get_File_Name(i));
526  break;
527  }
528  }
529 
530  if( FileName.is_Empty() )
531  {
532  return( false );
533  }
534  }
535 
536  //-----------------------------------------------------
537  CSG_Grid_File_Info Info;
538 
539  if( !Info.Create(Stream) )
540  {
541  return( false );
542  }
543 
544  Set_Name (Info.m_Name);
546  Set_Unit (Info.m_Unit);
547 
548  Set_NoData_Value_Range(Info.m_NoData[0], Info.m_NoData[1]);
549 
550  m_System = Info.m_System;
551  m_Type = Info.m_Type;
552  m_zScale = Info.m_zScale;
553  m_zOffset = Info.m_zOffset;
554 
555  m_nBytes_Value = SG_Data_Type_Get_Size(m_Type);
556  m_nBytes_Line = m_Type == SG_DATATYPE_Bit ? 1 + Get_NX() / 8 : Get_NX() * m_nBytes_Value;
557 
558  if( Stream.Get_File(FileName + "prj") )
559  {
561  }
562 
563  if( !bLoadData )
564  {
565  return( _Memory_Create(bCached) );
566  }
567 
568  if( Stream.Get_File(FileName + "mgrd") )
569  {
570  Load_MetaData(Stream);
571  }
572 
573  //-----------------------------------------------------
574  if( _Cache_Check() )
575  {
576  bCached = true;
577  }
578 
579  return( Stream.Get_File(FileName + "sdat") && _Memory_Create(bCached)
580  && _Load_Binary(Stream, m_Type, Info.m_bFlip, Info.m_bSwapBytes)
581  );
582 }
583 
584 //---------------------------------------------------------
585 bool CSG_Grid::_Save_Compressed(const CSG_String &_FileName)
586 {
587 #ifdef WORDS_BIGENDIAN
588  bool bBigEndian = true;
589 #else
590  bool bBigEndian = false;
591 #endif
592 
593  CSG_File_Zip Stream(_FileName, SG_FILE_W);
594 
595  if( Stream.is_Writing() )
596  {
597  CSG_String FileName(SG_File_Get_Name(_FileName, false) + ".");
598 
599  CSG_Grid_File_Info Info(*this);
600 
601  if( Stream.Add_File(FileName + "sgrd") && Info.Save(Stream, true)
602  && Stream.Add_File(FileName + "sdat") && _Save_Binary(Stream, m_Type, false, bBigEndian) )
603  {
604  Stream.Add_File(FileName + "mgrd" ); Save_MetaData(Stream);
605  Stream.Add_File(FileName + "prj" ); Get_Projection().Save(Stream, SG_PROJ_FMT_WKT);
606  Stream.Add_File(FileName + "sdat.aux.xml"); Info.Save_AUX_XML(Stream);
607 
608  return( true );
609  }
610  }
611 
612  return( false );
613 }
614 
615 
617 // //
618 // Binary //
619 // //
621 
622 //---------------------------------------------------------
623 void CSG_Grid::_Swap_Bytes(char *Bytes, int nBytes) const
624 {
625  if( nBytes == 2 )
626  {
627  uint16_t val, valSwapped;
628  memcpy(&val, Bytes, nBytes);
629  valSwapped = ntohs(val);
630  memcpy(Bytes, &valSwapped, nBytes);
631  }
632  else if( nBytes == 4 )
633  {
634  uint32_t val, valSwapped;
635  memcpy(&val, Bytes, nBytes);
636  valSwapped = ntohl(val);
637  memcpy(Bytes, &valSwapped, nBytes);
638  }
639 }
640 
641 //---------------------------------------------------------
642 bool CSG_Grid::_Load_Binary(CSG_File &Stream, TSG_Data_Type File_Type, bool bFlip, bool bSwapBytes)
643 {
644  if( !Stream.is_Open() || !is_Valid() )
645  {
646  return( false );
647  }
648 
650 
651  //-----------------------------------------------------
652  if( File_Type == SG_DATATYPE_Bit )
653  {
654  int nLineBytes = Get_NX() / 8 + 1;
655 
656  if( m_Type == File_Type && !is_Cached() )
657  {
658  for(int y=0; y<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
659  {
660  Stream.Read(m_Values[bFlip ? Get_NY() - y - 1 : y], sizeof(char), nLineBytes);
661  }
662  }
663  else
664  {
665  CSG_Array Line(1, nLineBytes);
666 
667  for(int y=0; y<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
668  {
669  Stream.Read(Line.Get_Array(), nLineBytes);
670 
671  char *pValue = (char *)Line.Get_Array();
672 
673  for(int x=0, yy=bFlip ? Get_NY()-y-1 : y; x<Get_NX(); pValue++)
674  {
675  for(int i=0; i<8 && x<Get_NX(); i++, x++)
676  {
677  Set_Value(x, yy, (*pValue & m_Bitmask[i]) == 0 ? 0.0 : 1.0);
678  }
679  }
680  }
681  }
682  }
683 
684  //-----------------------------------------------------
685  else
686  {
687  int nValueBytes = (int)SG_Data_Type_Get_Size(File_Type);
688  int nLineBytes = Get_NX() * nValueBytes;
689 
690  if( m_Type == File_Type && !is_Cached() && !bSwapBytes )
691  {
692  for(int y=0; y<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
693  {
694  Stream.Read(m_Values[bFlip ? Get_NY() - y - 1 : y], nLineBytes);
695  }
696  }
697  else
698  {
699  CSG_Array Line(1, nLineBytes);
700 
701  for(int y=0; y<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
702  {
703  Stream.Read(Line.Get_Array(), nLineBytes);
704 
705  char *pValue = (char *)Line.Get_Array();
706 
707  for(int x=0, yy=bFlip ? Get_NY()-y-1 : y; x<Get_NX(); x++, pValue+=nValueBytes)
708  {
709  if( bSwapBytes )
710  {
711  _Swap_Bytes(pValue, nValueBytes);
712  }
713 
714  switch( File_Type )
715  {
716  case SG_DATATYPE_Byte : Set_Value(x, yy, *(BYTE *)pValue, false); break;
717  case SG_DATATYPE_Char : Set_Value(x, yy, *(char *)pValue, false); break;
718  case SG_DATATYPE_Word : Set_Value(x, yy, *(WORD *)pValue, false); break;
719  case SG_DATATYPE_Short : Set_Value(x, yy, *(short *)pValue, false); break;
720  case SG_DATATYPE_DWord : Set_Value(x, yy, *(DWORD *)pValue, false); break;
721  case SG_DATATYPE_Int : Set_Value(x, yy, *(int *)pValue, false); break;
722  case SG_DATATYPE_Float : Set_Value(x, yy, *(float *)pValue, false); break;
723  case SG_DATATYPE_Double: Set_Value(x, yy, *(double *)pValue, false); break;
724  default: break;
725  }
726  }
727  }
728  }
729  }
730 
731  //-----------------------------------------------------
732  return( true );
733 }
734 
735 //---------------------------------------------------------
736 bool CSG_Grid::_Save_Binary(CSG_File &Stream, TSG_Data_Type File_Type, bool bFlip, bool bSwapBytes)
737 {
738  //-----------------------------------------------------
739  if( !Stream.is_Writing() || !is_Valid() )
740  {
741  return( false );
742  }
743 
745 
746  //-----------------------------------------------------
747  if( File_Type == SG_DATATYPE_Bit )
748  {
749  int nLineBytes = Get_NX() / 8 + 1;
750 
751  if( m_Type == File_Type && !is_Cached() )
752  {
753  for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
754  {
755  Stream.Write((char *)m_Values[bFlip ? Get_NY() - y - 1 : y], sizeof(char), nLineBytes);
756  }
757  }
758  else
759  {
760  CSG_Array Line(1, nLineBytes);
761 
762  for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
763  {
764  char *pValue = (char *)Line.Get_Array();
765 
766  for(int x=0, yy=bFlip ? Get_NY()-y-1 : y; x<Get_NX(); pValue++)
767  {
768  for(int i=0; i<8 && x<Get_NX(); i++, x++)
769  {
770  *pValue = asChar(x, yy) != 0.0 ? *pValue | m_Bitmask[i] : *pValue & (~m_Bitmask[i]);
771  }
772  }
773 
774  Stream.Write(Line.Get_Array(), nLineBytes);
775  }
776  }
777  }
778 
779  //-----------------------------------------------------
780  else
781  {
782  int nValueBytes = (int)SG_Data_Type_Get_Size(File_Type);
783  int nLineBytes = Get_NX() * nValueBytes;
784 
785  if( m_Type == File_Type && !is_Cached() && !bSwapBytes )
786  {
787  for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
788  {
789  Stream.Write((char *)m_Values[bFlip ? Get_NY() - y - 1 : y], nLineBytes);
790  }
791  }
792  else
793  {
794  CSG_Array Line(1, nLineBytes);
795 
796  for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
797  {
798  char *pValue = (char *)Line.Get_Array();
799 
800  for(int x=0, yy=bFlip ? Get_NY()-y-1 : y; x<Get_NX(); x++, pValue+=nValueBytes)
801  {
802  switch( File_Type )
803  {
804  case SG_DATATYPE_Byte : *(BYTE *)pValue = asByte (x, yy, false); break;
805  case SG_DATATYPE_Char : *(char *)pValue = asChar (x, yy, false); break;
806  case SG_DATATYPE_Word : *(WORD *)pValue = asShort (x, yy, false); break;
807  case SG_DATATYPE_Short : *(short *)pValue = asShort (x, yy, false); break;
808  case SG_DATATYPE_DWord : *(DWORD *)pValue = asInt (x, yy, false); break;
809  case SG_DATATYPE_Int : *(int *)pValue = asInt (x, yy, false); break;
810  case SG_DATATYPE_Float : *(float *)pValue = asFloat (x, yy, false); break;
811  case SG_DATATYPE_Double: *(double *)pValue = asDouble(x, yy, false); break;
812  default: break;
813  }
814 
815  if( bSwapBytes )
816  {
817  _Swap_Bytes(pValue, nValueBytes);
818  }
819  }
820 
821  Stream.Write(Line.Get_Array(), nLineBytes);
822  }
823  }
824  }
825 
826  //-----------------------------------------------------
827  return( true );
828 }
829 
830 
832 // //
833 // ASCII //
834 // //
836 
837 //---------------------------------------------------------
838 bool CSG_Grid::_Load_ASCII(CSG_File &Stream, bool bCached, bool bFlip)
839 {
840  if( !Stream.is_Reading() || !_Memory_Create(bCached) )
841  {
842  return( false );
843  }
844 
846 
847  for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
848  {
849  for(int x=0, yy=bFlip ? Get_NY()-y-1 : y; x<Get_NX(); x++)
850  {
851  Set_Value(x, yy, Stream.Scan_Double());
852  }
853  }
854 
855  return( true );
856 }
857 
858 //---------------------------------------------------------
859 bool CSG_Grid::_Save_ASCII(CSG_File &Stream, bool bFlip)
860 {
861  if( !Stream.is_Writing() || !is_Valid() )
862  {
863  return( false );
864  }
865 
867 
868  for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
869  {
870  for(int x=0, yy=bFlip ? Get_NY()-y-1 : y; x<Get_NX(); x++)
871  {
872  Stream.Printf("%lf ", asDouble(x, yy));
873  }
874 
875  Stream.Printf("\n");
876  }
877 
878  return( true );
879 }
880 
881 
883 // //
885 
886 //---------------------------------------------------------
887 bool CSG_Grid::_Load_Surfer(const CSG_String &FileName, bool bCached, bool bLoadData)
888 {
889  const float NoData = 1.70141e38f;
890 
891  if( !SG_File_Cmp_Extension(FileName, "grd") )
892  {
893  return( false );
894  }
895 
896  Set_File_Name(FileName, true);
897 
898  //-----------------------------------------------------
899  CSG_File Stream;
900 
901  if( !Stream.Open(FileName, SG_FILE_R, true) )
902  {
903  return( false );
904  }
905 
906  char Identifier[4];
907 
908  Stream.Read(Identifier, sizeof(char), 4);
909 
910  //-----------------------------------------------------
911  if( !strncmp(Identifier, "DSBB", 4) ) // Binary...
912  {
913  short nx, ny;
914  double d;
915  TSG_Rect r;
916 
917  Stream.Read(&nx , sizeof(short ));
918  Stream.Read(&ny , sizeof(short ));
919  Stream.Read(&r.xMin, sizeof(double));
920  Stream.Read(&r.xMax, sizeof(double));
921  Stream.Read(&r.yMin, sizeof(double));
922  Stream.Read(&r.yMax, sizeof(double));
923  Stream.Read(&d , sizeof(double)); // zMin
924  Stream.Read(&d , sizeof(double)); // zMax
925 
926  d = (r.xMax - r.xMin) / (nx - 1.0);
927  // d = (r.yMax - r.yMin) / (ny - 1.0); // we could proof for equal cellsize in direction of y...
928 
929  //-------------------------------------------------
930  if( !Create(SG_DATATYPE_Float, nx, ny, d, r.xMin, r.yMin, bCached) || Stream.is_EOF() )
931  {
932  return( false );
933  }
934 
935  //-------------------------------------------------
936  if( bLoadData )
937  {
938  CSG_Array Line(sizeof(float), Get_NX()); float *Values = (float *)Line.Get_Array();
939 
940  for(int y=0; y<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
941  {
942  Stream.Read(Values, sizeof(float), Get_NX());
943 
944  for(int x=0; x<Get_NX(); x++)
945  {
946  if( Values[x] == NoData )
947  {
948  Set_NoData(x, y);
949  }
950  else
951  {
952  Set_Value(x, y, Values[x]);
953  }
954  }
955  }
956  }
957 
958  Get_MetaData().Add_Child("SURFER_GRID", "Surfer Grid (Binary)");
959  }
960 
961  //-----------------------------------------------------
962  else if( !strncmp(Identifier, "DSAA", 4) ) // ASCII...
963  {
964  int nx = Stream.Scan_Int ();
965  int ny = Stream.Scan_Int ();
966  double xMin = Stream.Scan_Double();
967  double xMax = Stream.Scan_Double();
968  double yMin = Stream.Scan_Double(); Stream.Scan_Double();
969  // double yMax = Stream.Scan_Double();
970  double dx = Stream.Scan_Double(); Stream.Scan_Double();
971  // double dy = Stream.Scan_Double();
972 
973  dx = (xMax - xMin) / (nx - 1.0);
974  // dy = (yMax - yMin) / (ny - 1.0); // we could proof for equal cellsize in direction of y...
975 
976  //-------------------------------------------------
977  if( !Create(SG_DATATYPE_Float, nx, ny, dx, xMin, yMin, bCached) || Stream.is_EOF() )
978  {
979  return( false );
980  }
981 
982  //-------------------------------------------------
983  if( bLoadData )
984  {
985  for(int y=0; y<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
986  {
987  for(int x=0; x<Get_NX(); x++)
988  {
989  double Value;
990 
991  if( Stream.Scan(Value) && Value != NoData )
992  {
993  Set_Value(x, y, Value);
994  }
995  else
996  {
997  Set_NoData(x, y);
998  }
999  }
1000  }
1001  }
1002 
1003  Get_MetaData().Add_Child("SURFER_GRID", "Surfer Grid (ASCII)");
1004  }
1005 
1006  //-------------------------------------------------
1008 
1009  Set_File_Name(FileName);
1010  Load_MetaData(FileName);
1011 
1012  return( true );
1013 }
1014 
1015 
1017 // //
1018 // //
1019 // //
1021 
1022 //---------------------------------------------------------
1024 {
1025  _On_Construction();
1026 }
1027 
1028 void CSG_Grid_File_Info::_On_Construction(void)
1029 {
1030  m_Name .Clear();
1031  m_Description .Clear();
1032  m_Unit .Clear();
1033  m_System .Assign(0.0, 0.0, 0.0, 0, 0);
1034  m_Type = SG_DATATYPE_Float; // defaults to float
1035  m_zScale = 1.0;
1036  m_zOffset = 0;
1037  m_NoData[0] = -99999.0;
1038  m_NoData[1] = -99999.0;
1039  m_Data_File .Clear();
1040  m_bFlip = false;
1041  m_bSwapBytes = false;
1042  m_Offset = 0;
1043  m_Projection .Destroy();
1044 }
1045 
1046 //---------------------------------------------------------
1048 {
1049  Create(Info);
1050 }
1051 
1053 {
1054  m_Name = Info.m_Name;
1056  m_Unit = Info.m_Unit;
1057  m_System = Info.m_System;
1058  m_Type = Info.m_Type;
1059  m_zScale = Info.m_zScale;
1060  m_zOffset = Info.m_zOffset;
1061  m_NoData[0] = Info.m_NoData[0];
1062  m_NoData[1] = Info.m_NoData[1];
1063  m_Data_File = Info.m_Data_File;
1064  m_bFlip = Info.m_bFlip;
1065  m_bSwapBytes = Info.m_bSwapBytes;
1066  m_Offset = Info.m_Offset;
1067  m_Projection = Info.m_Projection;
1068 
1069  return( true );
1070 }
1071 
1072 //---------------------------------------------------------
1074 {
1075  Create(Grid);
1076 }
1077 
1079 {
1080  m_Name = Grid.Get_Name();
1081  m_Description = Grid.Get_Description();
1082  m_Unit = Grid.Get_Unit();
1083  m_System = Grid.Get_System();
1084  m_Type = Grid.Get_Type();
1085  m_zScale = Grid.Get_Scaling();
1086  m_zOffset = Grid.Get_Offset();
1087  m_NoData[0] = Grid.Get_NoData_Value();
1088  m_NoData[1] = Grid.Get_NoData_Value(true);
1089  m_Data_File .Clear();
1090  m_bFlip = false;
1091  m_bSwapBytes = false;
1092  m_Offset = 0;
1093  m_Projection = Grid.Get_Projection();
1094 
1095  return( true );
1096 }
1097 
1098 //---------------------------------------------------------
1100 {
1101  Create(FileName);
1102 }
1103 
1105 {
1106  if( !SG_File_Cmp_Extension(FileName, "sg-grd-z") )
1107  {
1108  if( SG_File_Cmp_Extension(FileName, "sgrd")
1109  || SG_File_Cmp_Extension(FileName, "sg-grd") )
1110  {
1111  CSG_File Stream(FileName, SG_FILE_R, false);
1112 
1113  return( Create(Stream) );
1114  }
1115 
1116  return( false );
1117  }
1118 
1119  //-----------------------------------------------------
1120  CSG_File_Zip Stream(FileName, SG_FILE_R);
1121 
1122  if( Stream.is_Reading() )
1123  {
1124  CSG_String File(SG_File_Get_Name(FileName, false) + ".");
1125 
1126  if( !Stream.Get_File(File + "sgrd" )
1127  && !Stream.Get_File(File + "sg-grd") )
1128  {
1129  for(size_t i=0; i<Stream.Get_File_Count(); i++)
1130  {
1131  if( SG_File_Cmp_Extension(Stream.Get_File_Name(i), "sgrd" )
1132  || SG_File_Cmp_Extension(Stream.Get_File_Name(i), "sg-grd") )
1133  {
1134  Stream.Get_File(Stream.Get_File_Name(i));
1135  break;
1136  }
1137  }
1138  }
1139 
1140  return( Create(Stream) );
1141  }
1142 
1143  //-----------------------------------------------------
1144  return( false );
1145 }
1146 
1147 //---------------------------------------------------------
1149 {
1150  Create(Stream);
1151 }
1152 
1154 {
1155  _On_Construction();
1156 
1157  //-----------------------------------------------------
1158  if( !Stream.is_Reading() )
1159  {
1160  return( false );
1161  }
1162 
1163  //-----------------------------------------------------
1164  sLong NX = 0, NY = 0;
1165  double Cellsize = 0.0, xMin = 0.0, yMin = 0.0;
1166 
1167  do
1168  {
1169  CSG_String Value;
1170 
1171  switch( _Get_Key(Stream, Value) )
1172  {
1173  case GRID_FILE_KEY_NAME : m_Name = Value; break;
1174  case GRID_FILE_KEY_DESCRIPTION : m_Description = Value; break;
1175  case GRID_FILE_KEY_UNITNAME : m_Unit = Value; break;
1176 
1177  case GRID_FILE_KEY_CELLCOUNT_X : NX = Value.asInt (); break;
1178  case GRID_FILE_KEY_CELLCOUNT_Y : NY = Value.asInt (); break;
1179  case GRID_FILE_KEY_POSITION_XMIN : xMin = Value.asDouble(); break;
1180  case GRID_FILE_KEY_POSITION_YMIN : yMin = Value.asDouble(); break;
1181  case GRID_FILE_KEY_CELLSIZE : Cellsize = Value.asDouble(); break;
1182 
1183  case GRID_FILE_KEY_Z_FACTOR : m_zScale = Value.asDouble(); break;
1184  case GRID_FILE_KEY_Z_OFFSET : m_zOffset = Value.asDouble(); break;
1185  case GRID_FILE_KEY_NODATA_VALUE : m_NoData[0] = Value.asDouble();
1186  Value = Value.AfterFirst(';'); m_NoData[1] = Value.is_Empty() ? m_NoData[0] : Value.asDouble(); break;
1187 
1188  case GRID_FILE_KEY_DATAFILE_OFFSET: m_Offset = Value.asInt (); break;
1190  case GRID_FILE_KEY_TOPTOBOTTOM : m_bFlip = Value.Find(GRID_FILE_KEY_TRUE) >= 0; break;
1191 
1193  if( SG_File_Get_Path(Value).Length() > 0 )
1194  {
1195  m_Data_File = Value;
1196  }
1197  else
1198  {
1200  }
1201  break;
1202 
1204  {
1205  for(int i=0; i<SG_DATATYPE_Undefined; i++)
1206  {
1207  if( Value.Find(gSG_Data_Type_Identifier[i]) >= 0 )
1208  {
1209  m_Type = (TSG_Data_Type)i;
1210 
1211  break;
1212  }
1213  }
1214  }
1215  break;
1216  }
1217  }
1218  while( !Stream.is_EOF() );
1219 
1220  //-----------------------------------------------------
1221  return( m_System.Assign(Cellsize, xMin, yMin, (int)NX, (int)NY) );
1222 }
1223 
1224 //---------------------------------------------------------
1225 int CSG_Grid_File_Info::_Get_Key(CSG_File &Stream, CSG_String &Value)
1226 {
1227  int i;
1228  CSG_String sLine;
1229 
1230  if( Stream.Read_Line(sLine) && (i = sLine.Find('=')) > 0 )
1231  {
1232  Value = sLine.AfterFirst('=');
1233  Value.Trim();
1234 
1235  sLine.Remove(i);
1236 
1237  for(i=0; i<GRID_FILE_KEY_Count; i++)
1238  {
1240 
1241  if( s.Find(sLine.Left(s.Length())) >= 0 )
1242  {
1243  return( i );
1244  }
1245  }
1246  }
1247 
1248  return( -1 );
1249 }
1250 
1251 
1253 // //
1255 
1256 //---------------------------------------------------------
1257 bool CSG_Grid_File_Info::Save(const CSG_String &FileName, bool bBinary)
1258 {
1259  return( Save(CSG_File(FileName, SG_FILE_W, false), bBinary) );
1260 }
1261 
1262 //---------------------------------------------------------
1263 bool CSG_Grid_File_Info::Save(const CSG_File &Stream, bool bBinary)
1264 {
1265  if( !Stream.is_Writing() )
1266  {
1267  return( false );
1268  }
1269 
1270 #define GRID_FILE_PRINT(Key, Val) { CSG_String s(gSG_Grid_File_Key_Names[Key]); s += "\t= " + Val + "\n"; Stream.Write(s); }
1271 
1277 #ifdef WORDS_BIGENDIAN
1279 #else
1281 #endif
1291 
1292  return( true );
1293 }
1294 
1295 //---------------------------------------------------------
1296 bool CSG_Grid_File_Info::Save(const CSG_String &FileName, const CSG_Grid &Grid, bool bBinary)
1297 {
1298  CSG_Grid_File_Info Info(Grid);
1299 
1300  return( Info.Save(FileName, bBinary) );
1301 }
1302 
1303 //---------------------------------------------------------
1304 bool CSG_Grid_File_Info::Save(const CSG_File &Stream, const CSG_Grid &Grid, bool bBinary)
1305 {
1306  CSG_Grid_File_Info Info(Grid);
1307 
1308  return( Info.Save(Stream, bBinary) );
1309 }
1310 
1311 
1313 // //
1315 
1316 //---------------------------------------------------------
1318 {
1319  CSG_File Stream;
1320 
1321  return( m_Projection.is_Okay() && Stream.Open(FileName + ".aux.xml", SG_FILE_W, false) && Save_AUX_XML(Stream) );
1322 }
1323 
1324 //---------------------------------------------------------
1326 {
1327  if( m_Projection.is_Okay() && Stream.is_Writing() ) // store srs information that is recognized by ArcGIS
1328  {
1329  Stream.Write("<PAMDataset>\n<SRS>");
1330  Stream.Write(m_Projection.Get_WKT());
1331  Stream.Write("</SRS>\n</PAMDataset>\n");
1332 
1333  return( true );
1334  }
1335 
1336  return( false );
1337 }
1338 
1339 
1341 // //
1342 // //
1343 // //
1345 
1346 //---------------------------------------------------------
CSG_Grid::Get_Type
TSG_Data_Type Get_Type(void) const
Definition: grid.h:519
CSG_Grid_File_Info::m_Offset
sLong m_Offset
Definition: grid.h:439
CSG_String::BeforeFirst
CSG_String BeforeFirst(char Character) const
Definition: api_string.cpp:666
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
SG_File_Get_Path
SAGA_API_DLL_EXPORT CSG_String SG_File_Get_Path(const CSG_String &full_Path)
Definition: api_file.cpp:875
SG_DATATYPE_Undefined
@ SG_DATATYPE_Undefined
Definition: api_core.h:1001
CSG_File_Zip::Get_File
bool Get_File(const CSG_String &Name)
Definition: api_file.cpp:690
CSG_Grid_File_Info::Save_AUX_XML
bool Save_AUX_XML(const CSG_String &File)
Definition: grid_io.cpp:1317
SG_T
#define SG_T(s)
Definition: api_core.h:531
CSG_Grid_System::Get_Precision
static int Get_Precision(void)
Definition: grid_system.cpp:77
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:1480
SG_DATATYPE_DWord
@ SG_DATATYPE_DWord
Definition: api_core.h:991
CSG_Data_Collection::Get
CSG_Data_Object * Get(size_t i) const
Definition: data_manager.h:96
CSG_Grid_File_Info::m_zOffset
double m_zOffset
Definition: grid.h:441
CSG_Data_Object::Set_File_Name
void Set_File_Name(const CSG_String &FileName)
Definition: dataobject.cpp:307
CSG_Data_Object::Get_Description
const SG_Char * Get_Description(void) const
Definition: dataobject.cpp:301
SG_PROJ_FMT_WKT
@ SG_PROJ_FMT_WKT
Definition: geo_tools.h:771
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:569
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:244
GRID_FILE_FORMAT_Compressed
@ GRID_FILE_FORMAT_Compressed
Definition: grid.h:94
CSG_Grid_File_Info::m_bSwapBytes
bool m_bSwapBytes
Definition: grid.h:437
SG_UI_MSG_STYLE_SUCCESS
@ SG_UI_MSG_STYLE_SUCCESS
Definition: api_core.h:1496
CSG_File::Seek
bool Seek(sLong Offset, int Origin=SG_FILE_START) const
Definition: api_file.cpp:232
CSG_Grid_File_Info::CSG_Grid_File_Info
CSG_Grid_File_Info(void)
Definition: grid_io.cpp:1023
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:722
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
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:618
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:1052
GRID_FILE_KEY_POSITION_YMIN
@ GRID_FILE_KEY_POSITION_YMIN
Definition: grid.h:110
SG_DATATYPE_Byte
@ SG_DATATYPE_Byte
Definition: api_core.h:987
CSG_Projection::is_Okay
bool is_Okay(void) const
Definition: geo_tools.h:861
CSG_Tool
Definition: tool.h:149
CSG_File::Scan
bool Scan(int &Value) const
Definition: api_file.cpp:475
CSG_Grid_File_Info::m_NoData
double m_NoData[2]
Definition: grid.h:441
grid.h
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_Rect::xMax
double xMax
Definition: geo_tools.h:465
CSG_Grid_File_Info::m_System
CSG_Grid_System m_System
Definition: grid.h:447
CSG_File::Scan_Int
int Scan_Int(void) const
Definition: api_file.cpp:537
SG_RUN_TOOL
#define SG_RUN_TOOL(bRetVal, LIBRARY, TOOL, CONDITION)
Definition: tool_library.h:257
CSG_Grid_File_Info::Save
bool Save(const CSG_String &File, bool bBinary=true)
Definition: grid_io.cpp:1257
SG_File_Delete
SAGA_API_DLL_EXPORT bool SG_File_Delete(const CSG_String &FileName)
Definition: api_file.cpp:840
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:1101
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:879
TSG_Grid_File_Format
TSG_Grid_File_Format
Definition: grid.h:89
CSG_Data_Manager::Get_Grid_System
CSG_Grid_Collection * Get_Grid_System(size_t i) const
Definition: data_manager.h:175
CSG_File::Read
size_t Read(void *Buffer, size_t Size, size_t Count=1) const
Definition: api_file.cpp:322
CSG_Projection::Destroy
void Destroy(void)
Definition: projections.cpp:394
CSG_Tool_Library_Manager::Delete_Tool
bool Delete_Tool(CSG_Tool *pTool) const
Definition: tool_library.cpp:726
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
SSG_Rect::xMin
double xMin
Definition: geo_tools.h:465
SSG_Rect
Definition: geo_tools.h:464
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
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_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
SG_TOOL_PARAMETER_SET
#define SG_TOOL_PARAMETER_SET(IDENTIFIER, VALUE)
Definition: tool_library.h:351
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:590
CSG_Grid_File_Info::Create
bool Create(const CSG_Grid_File_Info &Info)
Definition: grid_io.cpp:1052
CSG_Grid::is_Valid
virtual bool is_Valid(void) const
Definition: grid.cpp:449
CSG_Grid_File_Info::m_Unit
CSG_String m_Unit
Definition: grid.h:445
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::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
CSG_File::is_Writing
bool is_Writing(void) const
Definition: api_core.h:1137
SG_UI_Msg_Lock
int SG_UI_Msg_Lock(bool bOn)
Definition: api_callback.cpp:465
CSG_File_Zip::Get_File_Count
size_t Get_File_Count(void)
Definition: api_core.h:1204
CSG_File::Scan_Double
double Scan_Double(void) const
Definition: api_file.cpp:542
CSG_Grid::Set_Value
virtual void Set_Value(sLong i, double Value, bool bScaled=true)
Definition: grid.h:815
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:197
CSG_Grid_File_Info::m_Type
TSG_Data_Type m_Type
Definition: grid.h:443
CSG_Grid::Get_Unit
const CSG_String & Get_Unit(void) const
Definition: grid.h:525
GRID_FILE_KEY_TOPTOBOTTOM
@ GRID_FILE_KEY_TOPTOBOTTOM
Definition: grid.h:117
CSG_Grid::Get_NY
int Get_NY(void) const
Definition: grid.h:536
CSG_Table::Get_Count
sLong Get_Count(void) const
Definition: table.h:385
SG_DATATYPE_Float
@ SG_DATATYPE_Float
Definition: api_core.h:995
CSG_Grid_System::Assign
bool Assign(const CSG_Grid_System &System)
Definition: grid_system.cpp:225
CSG_Grid::Get_Offset
double Get_Offset(void) const
Definition: grid.cpp:436
CSG_Data_Object::Set_File_Type
void Set_File_Type(int Type)
Definition: dataobject.h:263
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:331
CSG_Grid_File_Info::m_Projection
CSG_Projection m_Projection
Definition: grid.h:449
CSG_Grid_File_Info::m_Name
CSG_String m_Name
Definition: grid.h:445
CSG_Grid::asShort
virtual short asShort(int x, int y, bool bScaled=true) const
Definition: grid.h:755
CSG_Grid::On_Reload
virtual bool On_Reload(void)
Definition: grid_io.cpp:74
SG_FILE_W
@ SG_FILE_W
Definition: api_core.h:1102
SSG_Rect::yMax
double yMax
Definition: geo_tools.h:465
CSG_File::is_Open
bool is_Open(void) const
Definition: api_core.h:1135
CSG_Grid_File_Info::m_zScale
double m_zScale
Definition: grid.h:441
SG_DATATYPE_Word
@ SG_DATATYPE_Word
Definition: api_core.h:989
CSG_Grid_System::Get_NY
int Get_NY(void) const
Definition: grid.h:235
CSG_Data_Object::Set_Name
void Set_Name(const CSG_String &Name)
Definition: dataobject.cpp:235
CSG_File_Zip::Get_File_Name
virtual CSG_String Get_File_Name(size_t Index)
Definition: api_file.cpp:707
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:616
gSG_Data_Type_Identifier
const char gSG_Data_Type_Identifier[][32]
Definition: api_core.h:1031
CSG_Table
Definition: table.h:283
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:702
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_String::Left
CSG_String Left(size_t count) const
Definition: api_string.cpp:705
CSG_String::AfterFirst
CSG_String AfterFirst(char Character) const
Definition: api_string.cpp:644
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:507
CSG_Array
Definition: api_core.h:308
CSG_String
Definition: api_core.h:557
CSG_Grid_File_Info::m_Description
CSG_String m_Description
Definition: grid.h:445
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_Data_Object::Set_Description
void Set_Description(const CSG_String &Description)
Definition: dataobject.cpp:296
CSG_Grid::Get_NX
int Get_NX(void) const
Definition: grid.h:535
CSG_Grid_File_Info::m_Data_File
CSG_String m_Data_File
Definition: grid.h:445
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:761
CSG_Tool::Settings_Push
bool Settings_Push(class CSG_Data_Manager *pManager=NULL)
Definition: tool.cpp:600
CSG_File::Printf
int Printf(const char *Format,...)
Definition: api_file.cpp:271
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:249
CSG_Data_Object::Get_MetaData
CSG_MetaData & Get_MetaData(void) const
Definition: dataobject.h:225
SSG_Rect::yMin
double yMin
Definition: geo_tools.h:465
SG_DATATYPE_Short
@ SG_DATATYPE_Short
Definition: api_core.h:990
CSG_Data_Object::Load_MetaData
bool Load_MetaData(const CSG_String &FileName)
Definition: dataobject.cpp:595
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:605
CSG_Grid
Definition: grid.h:473
SG_DATATYPE_Bit
@ SG_DATATYPE_Bit
Definition: api_core.h:986
CSG_Projection::Save
bool Save(const CSG_String &FileName, TSG_Projection_Format Format=SG_PROJ_FMT_WKT) const
Definition: projections.cpp:421
CSG_Grid::asByte
virtual BYTE asByte(int x, int y, bool bScaled=true) const
Definition: grid.h:751
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:760
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
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_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
SG_UI_Process_Set_Ready
bool SG_UI_Process_Set_Ready(void)
Definition: api_callback.cpp:299
TSG_Data_Type
TSG_Data_Type
Definition: api_core.h:985
CSG_MetaData::Add_Child
CSG_MetaData * Add_Child(void)
Definition: metadata.cpp:174
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:408
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:437
CSG_File::is_EOF
bool is_EOF(void) const
Definition: api_file.cpp:226
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: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_File::is_Reading
bool is_Reading(void) const
Definition: api_core.h:1136
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_Data_Object::is_Valid
virtual bool is_Valid(void) const =0
CSG_File::Get_File_Name
virtual const CSG_String & Get_File_Name(void) const
Definition: api_core.h:1127
CSG_Grid_File_Info
Definition: grid.h:408
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_Grid::Set_Modified
virtual void Set_Modified(bool bModified=true)
Definition: grid.h:636
SG_DATATYPE_Double
@ SG_DATATYPE_Double
Definition: api_core.h:996