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