 |
SAGA API
v9.7
|
Go to the documentation of this file.
56 #include <arpa/inet.h>
57 #include <netinet/in.h>
163 bool bResult =
false;
172 bResult = _Save_Compressed(FileName);
213 bool CSG_Grid::_Load_External(
const CSG_String &FileName,
bool bCached,
bool bLoadData)
253 if( bResult && Manager.
Grid().
Count() && Manager.
Grid(0).is_Valid() )
267 m_System = pGrid->m_System;
268 m_Type = pGrid->m_Type;
269 m_Values = pGrid->m_Values; pGrid->m_Values = NULL;
271 m_zOffset = pGrid->m_zOffset;
272 m_zScale = pGrid->m_zScale;
273 m_Unit = pGrid->m_Unit;
275 m_nBytes_Value = pGrid->m_nBytes_Value;
276 m_nBytes_Line = pGrid->m_nBytes_Line;
290 bool CSG_Grid::_Load_PGSQL(
const CSG_String &FileName,
bool bCached,
bool bLoadData)
292 bool bResult =
false;
298 s = s.AfterFirst(
':');
CSG_String Host (s.BeforeFirst(
':'));
299 s = s.AfterFirst(
':');
CSG_String Port (s.BeforeFirst(
':'));
300 s = s.AfterFirst(
':');
CSG_String DBase(s.BeforeFirst(
':'));
301 s = s.AfterFirst(
':');
CSG_String Table(s.BeforeFirst(
':'));
302 s = s.AfterFirst(
':');
CSG_String rid (s.BeforeFirst(
':').AfterFirst(
'='));
310 CSG_String Connection(DBase +
" [" + Host +
":" + Port +
"]");
336 bool CSG_Grid::_Load_Native(
const CSG_String &FileName,
bool bCached,
bool bLoadData)
340 if( !Info.
Create(FileName) )
365 return( _Memory_Create(bCached) );
381 return( _Load_ASCII(Stream, bCached, Info.
m_bFlip) );
388 if( bCached || _Cache_Check() )
403 if( _Memory_Create(bCached) )
422 #ifdef WORDS_BIGENDIAN
423 bool bBigEndian =
true;
425 bool bBigEndian =
false;
447 if( Info.
Save(FileName, bBinary) )
451 if( bBinary ? _Save_Binary(Stream, m_Type,
false, bBigEndian) : _Save_ASCII (Stream) )
474 bool CSG_Grid::_Load_Compressed(
const CSG_String &_FileName,
bool bCached,
bool bLoadData)
488 if( !Stream.Get_File(FileName +
"sgrd" )
489 && !Stream.Get_File(FileName +
"sg-grd") )
493 for(
size_t i=0; i<Stream.Get_File_Count(); i++)
513 if( !Info.
Create(Stream) )
532 if( Stream.Get_File(FileName +
"prj") )
539 return( _Memory_Create(bCached) );
542 if( Stream.Get_File(FileName +
"mgrd") )
553 return( Stream.Get_File(FileName +
"sdat") && _Memory_Create(bCached)
559 bool CSG_Grid::_Save_Compressed(
const CSG_String &_FileName)
561 #ifdef WORDS_BIGENDIAN
562 bool bBigEndian =
true;
564 bool bBigEndian =
false;
575 if( Stream.Add_File(FileName +
"sgrd") && Info.
Save(Stream,
true)
576 && Stream.Add_File(FileName +
"sdat") && _Save_Binary(Stream, m_Type,
false, bBigEndian) )
580 Stream.Add_File(FileName +
"sdat.aux.xml"); Info.
Save_AUX_XML(Stream);
597 void CSG_Grid::_Swap_Bytes(
char *Bytes,
int nBytes)
const
601 uint16_t val, valSwapped;
602 memcpy(&val, Bytes, nBytes);
603 valSwapped = ntohs(val);
604 memcpy(Bytes, &valSwapped, nBytes);
606 else if( nBytes == 4 )
608 uint32_t val, valSwapped;
609 memcpy(&val, Bytes, nBytes);
610 valSwapped = ntohl(val);
611 memcpy(Bytes, &valSwapped, nBytes);
628 int nLineBytes =
Get_NX() / 8 + 1;
630 if( m_Type == File_Type && !
is_Cached() )
634 Stream.
Read(m_Values[bFlip ?
Get_NY() - y - 1 : y],
sizeof(char), nLineBytes);
643 Stream.
Read(Line.Get_Array(), nLineBytes);
645 char *pValue = (
char *)Line.Get_Array();
647 for(
int x=0, yy=bFlip ?
Get_NY()-y-1 : y; x<
Get_NX(); pValue++)
649 for(
int i=0; i<8 && x<
Get_NX(); i++, x++)
651 Set_Value(x, yy, (*pValue & m_Bitmask[i]) == 0 ? 0.0 : 1.0);
662 int nLineBytes =
Get_NX() * nValueBytes;
664 if( m_Type == File_Type && !
is_Cached() && !bSwapBytes )
668 Stream.
Read(m_Values[bFlip ?
Get_NY() - y - 1 : y], nLineBytes);
677 Stream.
Read(Line.Get_Array(), nLineBytes);
679 char *pValue = (
char *)Line.Get_Array();
681 for(
int x=0, yy=bFlip ?
Get_NY()-y-1 : y; x<
Get_NX(); x++, pValue+=nValueBytes)
685 _Swap_Bytes(pValue, nValueBytes);
723 int nLineBytes =
Get_NX() / 8 + 1;
725 if( m_Type == File_Type && !
is_Cached() )
729 Stream.
Write((
char *)m_Values[bFlip ?
Get_NY() - y - 1 : y],
sizeof(char), nLineBytes);
738 char *pValue = (
char *)Line.Get_Array();
740 for(
int x=0, yy=bFlip ?
Get_NY()-y-1 : y; x<
Get_NX(); pValue++)
742 for(
int i=0; i<8 && x<
Get_NX(); i++, x++)
744 *pValue =
asChar(x, yy) != 0.0 ? *pValue | m_Bitmask[i] : *pValue & (~m_Bitmask[i]);
748 Stream.
Write(Line.Get_Array(), nLineBytes);
757 int nLineBytes =
Get_NX() * nValueBytes;
759 if( m_Type == File_Type && !
is_Cached() && !bSwapBytes )
763 Stream.
Write((
char *)m_Values[bFlip ?
Get_NY() - y - 1 : y], nLineBytes);
772 char *pValue = (
char *)Line.Get_Array();
774 for(
int x=0, yy=bFlip ?
Get_NY()-y-1 : y; x<
Get_NX(); x++, pValue+=nValueBytes)
791 _Swap_Bytes(pValue, nValueBytes);
795 Stream.
Write(Line.Get_Array(), nLineBytes);
812 bool CSG_Grid::_Load_ASCII(
CSG_File &Stream,
bool bCached,
bool bFlip)
814 if( !Stream.
is_Reading() || !_Memory_Create(bCached) )
823 for(
int x=0, yy=bFlip ?
Get_NY()-y-1 : y; x<
Get_NX(); x++)
833 bool CSG_Grid::_Save_ASCII(
CSG_File &Stream,
bool bFlip)
844 for(
int x=0, yy=bFlip ?
Get_NY()-y-1 : y; x<
Get_NX(); x++)
861 bool CSG_Grid::_Load_Surfer(
const CSG_String &FileName,
bool bCached,
bool bLoadData)
863 const float NoData = 1.70141e38f;
882 Stream.
Read(Identifier,
sizeof(
char), 4);
885 if( !strncmp(Identifier,
"DSBB", 4) )
891 Stream.
Read(&nx ,
sizeof(
short ));
892 Stream.
Read(&ny ,
sizeof(
short ));
893 Stream.
Read(&r.
xMin,
sizeof(
double));
894 Stream.
Read(&r.
xMax,
sizeof(
double));
895 Stream.
Read(&r.
yMin,
sizeof(
double));
896 Stream.
Read(&r.
yMax,
sizeof(
double));
897 Stream.
Read(&d ,
sizeof(
double));
898 Stream.
Read(&d ,
sizeof(
double));
912 CSG_Array Line(
sizeof(
float),
Get_NX());
float *Values = (
float *)Line.Get_Array();
918 for(
int x=0; x<
Get_NX(); x++)
920 if( Values[x] == NoData )
936 else if( !strncmp(Identifier,
"DSAA", 4) )
947 dx = (xMax - xMin) / (nx - 1.0);
961 for(
int x=0; x<
Get_NX(); x++)
965 if( Stream.
Scan(Value) && Value != NoData )
1002 void CSG_Grid_File_Info::_On_Construction(
void)
1087 return(
Create(Stream) );
1100 if( !Stream.
Get_File(File +
"sgrd" )
1101 && !Stream.
Get_File(File +
"sg-grd") )
1114 return(
Create(Stream) );
1138 sLong NX = 0, NY = 0;
1139 double Cellsize = 0.0, xMin = 0.0, yMin = 0.0;
1145 switch( _Get_Key(Stream, Value) )
1192 while( !Stream.
is_EOF() );
1195 return(
m_System.
Assign(Cellsize, xMin, yMin, (
int)NX, (
int)NY) );
1215 if( s.Find(sLine.
Left(s.Length())) >= 0 )
1244 #define GRID_FILE_PRINT(Key, Val) { CSG_String s(gSG_Grid_File_Key_Names[Key]); s += "\t= " + Val + "\n"; Stream.Write(s); }
1251 #ifdef WORDS_BIGENDIAN
1274 return( Info.
Save(FileName, bBinary) );
1282 return( Info.
Save(Stream, bBinary) );
1303 Stream.
Write(
"<PAMDataset>\n<SRS>");
1305 Stream.
Write(
"</SRS>\n</PAMDataset>\n");
TSG_Data_Type Get_Type(void) const
CSG_String BeforeFirst(char Character) const
SAGA_API_DLL_EXPORT CSG_String SG_File_Get_Path(const CSG_String &full_Path)
bool Save_AUX_XML(const CSG_String &File)
bool Save(const CSG_String &File, ESG_CRS_Format Format=ESG_CRS_Format::WKT) const
static int Get_Precision(void)
double Get_Cellsize(void) const
@ GRID_FILE_KEY_DESCRIPTION
void Set_File_Name(const CSG_String &FileName)
const SG_Char * Get_Description(void) const
CSG_String & Remove(size_t pos)
double Get_XMin(bool bCells=false) const
double Get_NoData_Value(bool bUpper=false) const
@ GRID_FILE_FORMAT_Compressed
@ SG_UI_MSG_STYLE_SUCCESS
bool Seek(sLong Offset, int Origin=SG_FILE_START) const
@ GRID_FILE_FORMAT_Undefined
@ GRID_FILE_KEY_BYTEORDER_BIG
bool Create(const CSG_Grid &Grid)
SAGA_API_DLL_EXPORT bool SG_File_Cmp_Extension(const CSG_String &FileName, const CSG_String &Extension)
@ GRID_FILE_KEY_DATAFORMAT
@ GRID_FILE_FORMAT_GeoTIFF
bool Save_MetaData(const CSG_String &FileName)
#define GRID_FILE_KEY_TRUE
size_t SG_Data_Type_Get_Size(TSG_Data_Type Type)
@ GRID_FILE_KEY_POSITION_YMIN
bool Scan(int &Value) const
const SG_Char * Get_Name(void) const
bool Save(const CSG_String &File, bool bBinary=true)
SAGA_API_DLL_EXPORT bool SG_File_Delete(const CSG_String &FileName)
@ GRID_FILE_KEY_NODATA_VALUE
CSG_String SG_Grid_Get_File_Extension_Default(void)
const CSG_String & Get_WKT(void) const
size_t Read(void *Buffer, size_t Size, size_t Count=1) const
const CSG_Grid_System & Get_System(void) const
int Cmp(const CSG_String &String) const
virtual CSG_String Get_File_Name(size_t Index)
@ SG_UI_MSG_STYLE_FAILURE
SAGA_API_DLL_EXPORT CSG_String SG_File_Get_Name(const CSG_String &full_Path, bool bExtension)
double Get_Scaling(void) const
virtual bool On_Delete(void)
const SG_Char gSG_Grid_File_Key_Names[GRID_FILE_KEY_Count][32]
int Trim(bool fromRight=false)
bool Create(const CSG_Grid_File_Info &Info)
virtual bool is_Valid(void) const
#define GRID_FILE_KEY_FALSE
@ GRID_FILE_KEY_DATAFILE_NAME
bool is_Writing(void) const
int SG_UI_Msg_Lock(bool bOn)
double Scan_Double(void) const
virtual void Set_Value(sLong i, double Value, bool bScaled=true)
bool SG_Grid_Set_File_Format_Default(int Format)
bool SG_Data_Type_is_Numeric(TSG_Data_Type Type)
const CSG_String & Get_Unit(void) const
@ GRID_FILE_KEY_TOPTOBOTTOM
virtual bool Open(const SG_Char *FileName, int Mode=SG_FILE_R, bool bBinary=true, int Encoding=SG_FILE_ENCODING_ANSI)
bool Assign(const CSG_Grid_System &System)
double Get_Offset(void) const
void Set_File_Type(int Type)
@ GRID_FILE_FORMAT_Binary_old
const SG_Char * Get_File_Name(bool bNative=true) const
CSG_Projection m_Projection
bool Get_File(const SG_Char *Name)
virtual short asShort(int x, int y, bool bScaled=true) const
virtual bool On_Reload(void)
bool Load(const CSG_String &File)
void Set_Name(const CSG_String &Name)
size_t Get_File_Count(void)
static CSG_String Format(const char *Format,...)
int Find(char Character, bool fromEnd=false) const
const char gSG_Data_Type_Identifier[][32]
static TSG_Grid_File_Format gSG_Grid_File_Format_Default
virtual void Set_NoData(int x, int y)
SAGA_API_DLL_EXPORT bool SG_File_Set_Extension(CSG_String &FileName, const CSG_String &Extension)
CSG_String Left(size_t count) const
CSG_String AfterFirst(char Character) const
TSG_Grid_File_Format SG_Grid_Get_File_Format_Default(void)
virtual bool Save(const char *File, int Format=0)
virtual double asDouble(sLong i, bool bScaled=true) const
void Set_Description(const CSG_String &Description)
virtual float asFloat(int x, int y, bool bScaled=true) const
int Printf(const char *Format,...)
bool is_Empty(void) const
bool SG_UI_Process_Set_Progress(int Position, int Range)
CSG_MetaData & Get_MetaData(void) const
bool Read_Line(CSG_String &Line) const
bool Load_MetaData(const CSG_String &FileName)
@ GRID_FILE_KEY_CELLCOUNT_X
#define GRID_FILE_PRINT(Key, Val)
bool is_Cached(void) const
virtual BYTE asByte(int x, int y, bool bScaled=true) const
double asDouble(void) const
SAGA_API_DLL_EXPORT CSG_String SG_File_Make_Path(const CSG_String &Directory, const CSG_String &Name)
void SG_UI_ProgressAndMsg_Lock(bool bOn)
const SG_Char * c_str(void) const
size_t Write(void *Buffer, size_t Size, size_t Count=1) const
virtual char asChar(int x, int y, bool bScaled=true) const
bool SG_UI_Process_Set_Ready(void)
@ GRID_FILE_KEY_CELLCOUNT_Y
@ GRID_FILE_FORMAT_Binary
void Set_Unit(const CSG_String &Unit)
CSG_Data_Collection & Grid(void) const
@ GRID_FILE_KEY_POSITION_XMIN
@ GRID_FILE_KEY_DATAFILE_OFFSET
double Get_YMin(bool bCells=false) const
virtual bool Set_NoData_Value_Range(double Lower, double Upper)
CSG_Projection & Get_Projection(void)
bool is_Reading(void) const
virtual int asInt(int x, int y, bool bScaled=true) const
virtual const CSG_String & Get_File_Name(void) const
void SG_UI_Msg_Add(const char *Message, bool bNewLine, TSG_UI_MSG_STYLE Style)
virtual void Set_Modified(bool bModified=true)