 |
SAGA API
v9.2
|
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)
215 bool bResult =
false;
272 m_System = pGrid->m_System;
273 m_Type = pGrid->m_Type;
274 m_Values = pGrid->m_Values; pGrid->m_Values = NULL;
276 m_zOffset = pGrid->m_zOffset;
277 m_zScale = pGrid->m_zScale;
278 m_Unit = pGrid->m_Unit;
280 m_nBytes_Value = pGrid->m_nBytes_Value;
281 m_nBytes_Line = pGrid->m_nBytes_Line;
295 bool CSG_Grid::_Load_PGSQL(
const CSG_String &FileName,
bool bCached,
bool bLoadData)
297 bool bResult =
false;
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(
'='));
322 for(
int i=0; !bResult && i<Connections.
Get_Count(); i++)
324 if( !Connection.Cmp(Connections[i].asString(0)) )
362 bool CSG_Grid::_Load_Native(
const CSG_String &FileName,
bool bCached,
bool bLoadData)
366 if( !Info.
Create(FileName) )
391 return( _Memory_Create(bCached) );
407 return( _Load_ASCII(Stream, bCached, Info.
m_bFlip) );
414 if( bCached || _Cache_Check() )
429 if( _Memory_Create(bCached) )
448 #ifdef WORDS_BIGENDIAN
449 bool bBigEndian =
true;
451 bool bBigEndian =
false;
473 if( Info.
Save(FileName, bBinary) )
477 if( bBinary ? _Save_Binary(Stream, m_Type,
false, bBigEndian) : _Save_ASCII (Stream) )
500 bool CSG_Grid::_Load_Compressed(
const CSG_String &_FileName,
bool bCached,
bool bLoadData)
514 if( !Stream.Get_File(FileName +
"sgrd" )
515 && !Stream.Get_File(FileName +
"sg-grd") )
519 for(
size_t i=0; i<Stream.Get_File_Count(); i++)
539 if( !Info.
Create(Stream) )
558 if( Stream.Get_File(FileName +
"prj") )
565 return( _Memory_Create(bCached) );
568 if( Stream.Get_File(FileName +
"mgrd") )
579 return( Stream.Get_File(FileName +
"sdat") && _Memory_Create(bCached)
585 bool CSG_Grid::_Save_Compressed(
const CSG_String &_FileName)
587 #ifdef WORDS_BIGENDIAN
588 bool bBigEndian =
true;
590 bool bBigEndian =
false;
601 if( Stream.Add_File(FileName +
"sgrd") && Info.
Save(Stream,
true)
602 && Stream.Add_File(FileName +
"sdat") && _Save_Binary(Stream, m_Type,
false, bBigEndian) )
606 Stream.Add_File(FileName +
"sdat.aux.xml"); Info.
Save_AUX_XML(Stream);
623 void CSG_Grid::_Swap_Bytes(
char *Bytes,
int nBytes)
const
627 uint16_t val, valSwapped;
628 memcpy(&val, Bytes, nBytes);
629 valSwapped = ntohs(val);
630 memcpy(Bytes, &valSwapped, nBytes);
632 else if( nBytes == 4 )
634 uint32_t val, valSwapped;
635 memcpy(&val, Bytes, nBytes);
636 valSwapped = ntohl(val);
637 memcpy(Bytes, &valSwapped, nBytes);
654 int nLineBytes =
Get_NX() / 8 + 1;
656 if( m_Type == File_Type && !
is_Cached() )
660 Stream.
Read(m_Values[bFlip ?
Get_NY() - y - 1 : y],
sizeof(char), nLineBytes);
669 Stream.
Read(Line.Get_Array(), nLineBytes);
671 char *pValue = (
char *)Line.Get_Array();
673 for(
int x=0, yy=bFlip ?
Get_NY()-y-1 : y; x<
Get_NX(); pValue++)
675 for(
int i=0; i<8 && x<
Get_NX(); i++, x++)
677 Set_Value(x, yy, (*pValue & m_Bitmask[i]) == 0 ? 0.0 : 1.0);
688 int nLineBytes =
Get_NX() * nValueBytes;
690 if( m_Type == File_Type && !
is_Cached() && !bSwapBytes )
694 Stream.
Read(m_Values[bFlip ?
Get_NY() - y - 1 : y], nLineBytes);
703 Stream.
Read(Line.Get_Array(), nLineBytes);
705 char *pValue = (
char *)Line.Get_Array();
707 for(
int x=0, yy=bFlip ?
Get_NY()-y-1 : y; x<
Get_NX(); x++, pValue+=nValueBytes)
711 _Swap_Bytes(pValue, nValueBytes);
749 int nLineBytes =
Get_NX() / 8 + 1;
751 if( m_Type == File_Type && !
is_Cached() )
755 Stream.
Write((
char *)m_Values[bFlip ?
Get_NY() - y - 1 : y],
sizeof(char), nLineBytes);
764 char *pValue = (
char *)Line.Get_Array();
766 for(
int x=0, yy=bFlip ?
Get_NY()-y-1 : y; x<
Get_NX(); pValue++)
768 for(
int i=0; i<8 && x<
Get_NX(); i++, x++)
770 *pValue =
asChar(x, yy) != 0.0 ? *pValue | m_Bitmask[i] : *pValue & (~m_Bitmask[i]);
774 Stream.
Write(Line.Get_Array(), nLineBytes);
783 int nLineBytes =
Get_NX() * nValueBytes;
785 if( m_Type == File_Type && !
is_Cached() && !bSwapBytes )
789 Stream.
Write((
char *)m_Values[bFlip ?
Get_NY() - y - 1 : y], nLineBytes);
798 char *pValue = (
char *)Line.Get_Array();
800 for(
int x=0, yy=bFlip ?
Get_NY()-y-1 : y; x<
Get_NX(); x++, pValue+=nValueBytes)
817 _Swap_Bytes(pValue, nValueBytes);
821 Stream.
Write(Line.Get_Array(), nLineBytes);
838 bool CSG_Grid::_Load_ASCII(
CSG_File &Stream,
bool bCached,
bool bFlip)
840 if( !Stream.
is_Reading() || !_Memory_Create(bCached) )
849 for(
int x=0, yy=bFlip ?
Get_NY()-y-1 : y; x<
Get_NX(); x++)
859 bool CSG_Grid::_Save_ASCII(
CSG_File &Stream,
bool bFlip)
870 for(
int x=0, yy=bFlip ?
Get_NY()-y-1 : y; x<
Get_NX(); x++)
887 bool CSG_Grid::_Load_Surfer(
const CSG_String &FileName,
bool bCached,
bool bLoadData)
889 const float NoData = 1.70141e38f;
908 Stream.
Read(Identifier,
sizeof(
char), 4);
911 if( !strncmp(Identifier,
"DSBB", 4) )
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));
924 Stream.
Read(&d ,
sizeof(
double));
938 CSG_Array Line(
sizeof(
float),
Get_NX());
float *Values = (
float *)Line.Get_Array();
944 for(
int x=0; x<
Get_NX(); x++)
946 if( Values[x] == NoData )
962 else if( !strncmp(Identifier,
"DSAA", 4) )
973 dx = (xMax - xMin) / (nx - 1.0);
987 for(
int x=0; x<
Get_NX(); x++)
991 if( Stream.
Scan(Value) && Value != NoData )
1028 void CSG_Grid_File_Info::_On_Construction(
void)
1113 return(
Create(Stream) );
1126 if( !Stream.
Get_File(File +
"sgrd" )
1127 && !Stream.
Get_File(File +
"sg-grd") )
1140 return(
Create(Stream) );
1164 sLong NX = 0, NY = 0;
1165 double Cellsize = 0.0, xMin = 0.0, yMin = 0.0;
1171 switch( _Get_Key(Stream, Value) )
1218 while( !Stream.
is_EOF() );
1221 return(
m_System.
Assign(Cellsize, xMin, yMin, (
int)NX, (
int)NY) );
1241 if( s.Find(sLine.
Left(s.Length())) >= 0 )
1270 #define GRID_FILE_PRINT(Key, Val) { CSG_String s(gSG_Grid_File_Key_Names[Key]); s += "\t= " + Val + "\n"; Stream.Write(s); }
1277 #ifdef WORDS_BIGENDIAN
1300 return( Info.
Save(FileName, bBinary) );
1308 return( Info.
Save(Stream, bBinary) );
1329 Stream.
Write(
"<PAMDataset>\n<SRS>");
1331 Stream.
Write(
"</SRS>\n</PAMDataset>\n");
TSG_Data_Type Get_Type(void) const
CSG_String BeforeFirst(char Character) const
virtual bool Open(const CSG_String &FileName, int Mode=SG_FILE_R, bool bBinary=true, int Encoding=SG_FILE_ENCODING_ANSI)
SAGA_API_DLL_EXPORT CSG_String SG_File_Get_Path(const CSG_String &full_Path)
bool Get_File(const CSG_String &Name)
bool Save_AUX_XML(const CSG_String &File)
static int Get_Precision(void)
double Get_Cellsize(void) const
@ GRID_FILE_KEY_DESCRIPTION
CSG_Data_Object * Get(size_t i) const
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
CSG_Grid_Collection * Get_Grid_System(size_t i) 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
@ 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
bool Load(const CSG_String &FileName, TSG_Projection_Format Format=SG_PROJ_FMT_WKT)
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 Read_Line(CSG_String &sLine) const
bool is_Writing(void) const
int SG_UI_Msg_Lock(bool bOn)
size_t Get_File_Count(void)
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
sLong Get_Count(void) const
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
virtual short asShort(int x, int y, bool bScaled=true) const
virtual bool On_Reload(void)
void Set_Name(const CSG_String &Name)
virtual CSG_String Get_File_Name(size_t Index)
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 Load_MetaData(const CSG_String &FileName)
@ GRID_FILE_KEY_CELLCOUNT_X
#define GRID_FILE_PRINT(Key, Val)
bool is_Cached(void) const
bool Save(const CSG_String &FileName, TSG_Projection_Format Format=SG_PROJ_FMT_WKT) 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)
@ 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 bool is_Valid(void) const =0
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)