|
SAGA API
v9.6
|
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 DBName(s.BeforeFirst(
':'));
301 s = s.AfterFirst(
':');
CSG_String Table (s.BeforeFirst(
':'));
302 s = s.AfterFirst(
':');
CSG_String rid (s.BeforeFirst(
':').AfterFirst(
'='));
317 for(
int i=0; !bResult && i<Connections.
Get_Count(); i++)
319 if( !Connection.Cmp(Connections[i].asString(0)) )
357 bool CSG_Grid::_Load_Native(
const CSG_String &FileName,
bool bCached,
bool bLoadData)
361 if( !Info.
Create(FileName) )
386 return( _Memory_Create(bCached) );
402 return( _Load_ASCII(Stream, bCached, Info.
m_bFlip) );
409 if( bCached || _Cache_Check() )
424 if( _Memory_Create(bCached) )
443 #ifdef WORDS_BIGENDIAN
444 bool bBigEndian =
true;
446 bool bBigEndian =
false;
468 if( Info.
Save(FileName, bBinary) )
472 if( bBinary ? _Save_Binary(Stream, m_Type,
false, bBigEndian) : _Save_ASCII (Stream) )
495 bool CSG_Grid::_Load_Compressed(
const CSG_String &_FileName,
bool bCached,
bool bLoadData)
509 if( !Stream.Get_File(FileName +
"sgrd" )
510 && !Stream.Get_File(FileName +
"sg-grd") )
514 for(
size_t i=0; i<Stream.Get_File_Count(); i++)
534 if( !Info.
Create(Stream) )
553 if( Stream.Get_File(FileName +
"prj") )
560 return( _Memory_Create(bCached) );
563 if( Stream.Get_File(FileName +
"mgrd") )
574 return( Stream.Get_File(FileName +
"sdat") && _Memory_Create(bCached)
580 bool CSG_Grid::_Save_Compressed(
const CSG_String &_FileName)
582 #ifdef WORDS_BIGENDIAN
583 bool bBigEndian =
true;
585 bool bBigEndian =
false;
596 if( Stream.Add_File(FileName +
"sgrd") && Info.
Save(Stream,
true)
597 && Stream.Add_File(FileName +
"sdat") && _Save_Binary(Stream, m_Type,
false, bBigEndian) )
601 Stream.Add_File(FileName +
"sdat.aux.xml"); Info.
Save_AUX_XML(Stream);
618 void CSG_Grid::_Swap_Bytes(
char *Bytes,
int nBytes)
const
622 uint16_t val, valSwapped;
623 memcpy(&val, Bytes, nBytes);
624 valSwapped = ntohs(val);
625 memcpy(Bytes, &valSwapped, nBytes);
627 else if( nBytes == 4 )
629 uint32_t val, valSwapped;
630 memcpy(&val, Bytes, nBytes);
631 valSwapped = ntohl(val);
632 memcpy(Bytes, &valSwapped, nBytes);
649 int nLineBytes =
Get_NX() / 8 + 1;
651 if( m_Type == File_Type && !
is_Cached() )
655 Stream.
Read(m_Values[bFlip ?
Get_NY() - y - 1 : y],
sizeof(char), nLineBytes);
664 Stream.
Read(Line.Get_Array(), nLineBytes);
666 char *pValue = (
char *)Line.Get_Array();
668 for(
int x=0, yy=bFlip ?
Get_NY()-y-1 : y; x<
Get_NX(); pValue++)
670 for(
int i=0; i<8 && x<
Get_NX(); i++, x++)
672 Set_Value(x, yy, (*pValue & m_Bitmask[i]) == 0 ? 0.0 : 1.0);
683 int nLineBytes =
Get_NX() * nValueBytes;
685 if( m_Type == File_Type && !
is_Cached() && !bSwapBytes )
689 Stream.
Read(m_Values[bFlip ?
Get_NY() - y - 1 : y], nLineBytes);
698 Stream.
Read(Line.Get_Array(), nLineBytes);
700 char *pValue = (
char *)Line.Get_Array();
702 for(
int x=0, yy=bFlip ?
Get_NY()-y-1 : y; x<
Get_NX(); x++, pValue+=nValueBytes)
706 _Swap_Bytes(pValue, nValueBytes);
744 int nLineBytes =
Get_NX() / 8 + 1;
746 if( m_Type == File_Type && !
is_Cached() )
750 Stream.
Write((
char *)m_Values[bFlip ?
Get_NY() - y - 1 : y],
sizeof(char), nLineBytes);
759 char *pValue = (
char *)Line.Get_Array();
761 for(
int x=0, yy=bFlip ?
Get_NY()-y-1 : y; x<
Get_NX(); pValue++)
763 for(
int i=0; i<8 && x<
Get_NX(); i++, x++)
765 *pValue =
asChar(x, yy) != 0.0 ? *pValue | m_Bitmask[i] : *pValue & (~m_Bitmask[i]);
769 Stream.
Write(Line.Get_Array(), nLineBytes);
778 int nLineBytes =
Get_NX() * nValueBytes;
780 if( m_Type == File_Type && !
is_Cached() && !bSwapBytes )
784 Stream.
Write((
char *)m_Values[bFlip ?
Get_NY() - y - 1 : y], nLineBytes);
793 char *pValue = (
char *)Line.Get_Array();
795 for(
int x=0, yy=bFlip ?
Get_NY()-y-1 : y; x<
Get_NX(); x++, pValue+=nValueBytes)
812 _Swap_Bytes(pValue, nValueBytes);
816 Stream.
Write(Line.Get_Array(), nLineBytes);
833 bool CSG_Grid::_Load_ASCII(
CSG_File &Stream,
bool bCached,
bool bFlip)
835 if( !Stream.
is_Reading() || !_Memory_Create(bCached) )
844 for(
int x=0, yy=bFlip ?
Get_NY()-y-1 : y; x<
Get_NX(); x++)
854 bool CSG_Grid::_Save_ASCII(
CSG_File &Stream,
bool bFlip)
865 for(
int x=0, yy=bFlip ?
Get_NY()-y-1 : y; x<
Get_NX(); x++)
882 bool CSG_Grid::_Load_Surfer(
const CSG_String &FileName,
bool bCached,
bool bLoadData)
884 const float NoData = 1.70141e38f;
903 Stream.
Read(Identifier,
sizeof(
char), 4);
906 if( !strncmp(Identifier,
"DSBB", 4) )
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));
919 Stream.
Read(&d ,
sizeof(
double));
933 CSG_Array Line(
sizeof(
float),
Get_NX());
float *Values = (
float *)Line.Get_Array();
939 for(
int x=0; x<
Get_NX(); x++)
941 if( Values[x] == NoData )
957 else if( !strncmp(Identifier,
"DSAA", 4) )
968 dx = (xMax - xMin) / (nx - 1.0);
982 for(
int x=0; x<
Get_NX(); x++)
986 if( Stream.
Scan(Value) && Value != NoData )
1023 void CSG_Grid_File_Info::_On_Construction(
void)
1108 return(
Create(Stream) );
1121 if( !Stream.
Get_File(File +
"sgrd" )
1122 && !Stream.
Get_File(File +
"sg-grd") )
1135 return(
Create(Stream) );
1159 sLong NX = 0, NY = 0;
1160 double Cellsize = 0.0, xMin = 0.0, yMin = 0.0;
1166 switch( _Get_Key(Stream, Value) )
1213 while( !Stream.
is_EOF() );
1216 return(
m_System.
Assign(Cellsize, xMin, yMin, (
int)NX, (
int)NY) );
1236 if( s.Find(sLine.
Left(s.Length())) >= 0 )
1265 #define GRID_FILE_PRINT(Key, Val) { CSG_String s(gSG_Grid_File_Key_Names[Key]); s += "\t= " + Val + "\n"; Stream.Write(s); }
1272 #ifdef WORDS_BIGENDIAN
1295 return( Info.
Save(FileName, bBinary) );
1303 return( Info.
Save(Stream, bBinary) );
1324 Stream.
Write(
"<PAMDataset>\n<SRS>");
1326 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)
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
@ 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 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)
bool Load(const CSG_String &File)
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
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)