52#ifndef HEADER_INCLUDED__SAGA_API__grids_H
53#define HEADER_INCLUDED__SAGA_API__grids_H
100#define SG_GRIDS_NAME_OWNER 0x01
101#define SG_GRIDS_NAME_INDEX 0x02
102#define SG_GRIDS_NAME_VALUE 0x04
103#define SG_GRIDS_NAME_GRID 0x08
133 CSG_Grids (
const char *FileName,
bool bLoadData =
true);
134 virtual bool Create (
const char *FileName,
bool bLoadData =
true);
135 CSG_Grids (
const wchar_t *FileName,
bool bLoadData =
true);
136 virtual bool Create (
const wchar_t *FileName,
bool bLoadData =
true);
156 virtual bool Load (
const CSG_String &File,
bool bLoadData =
true);
160 virtual bool Save (
const wchar_t *File,
int Format = 0) {
return(
Save(
CSG_String(File), Format) ); }
190 int Get_NZ (
void)
const {
return( (
int)m_Attributes.Get_Count() ); }
192 sLong Get_Data_Count (
void);
193 sLong Get_NoData_Count (
void);
208 double Get_ZMin (
bool bCells =
false)
const {
return( m_Attributes.Get_Minimum(m_Z_Attribute) ); }
209 double Get_ZMax (
bool bCells =
false)
const {
return( m_Attributes.Get_Maximum(m_Z_Attribute) ); }
210 double Get_ZRange (
bool bCells =
false)
const {
return( m_Attributes.Get_Range (m_Z_Attribute) ); }
216 bool Set_Z_Attribute (
int Field,
bool bSetNameField =
false);
219 bool Set_Z_Name_Field (
int Field);
220 int Get_Z_Name_Field (
void)
const;
224 bool Add_Attribute (
const char *Name,
TSG_Data_Type Type,
int Insert = -1);
225 bool Add_Attribute (
const wchar_t *Name,
TSG_Data_Type Type,
int Insert = -1);
227 bool Del_Attribute (
int Field);
234 bool Set_Attribute (
int i,
int Field,
const CSG_String &Value);
236 bool Set_Attribute (
int i,
const wchar_t *Field,
const wchar_t *Value);
237 bool Set_Attribute (
int i,
const char *Field,
const char *Value);
239 bool Set_Attribute (
int i,
int Field,
double Value);
240 bool Set_Attribute (
int i,
const CSG_String &Field,
double Value);
241 bool Set_Attribute (
int i,
const wchar_t *Field,
double Value);
242 bool Set_Attribute (
int i,
const char *Field,
double Value);
244 bool Set_Z (
int i,
double Value);
245 double Get_Z (
int i)
const {
return( m_Attributes[i].
asDouble(m_Z_Attribute) ); }
247 bool Update_Z_Order (
void);
253 bool Set_Grid_Count (
int Count);
256 bool Add_Grid (
double Z);
257 bool Add_Grid (
double Z,
CSG_Grid *pGrid,
bool bAttach =
false);
261 bool Del_Grid (
int i,
bool bDetach =
false);
262 bool Del_Grids (
bool bDetach =
false);
266 CSG_String Get_Grid_Name (
int i,
int Style = 0)
const;
274 void Set_Scaling (
double Scale = 1.,
double Offset = 0.);
279 double Get_Mean (
void);
280 double Get_Min (
void);
281 double Get_Max (
void);
282 double Get_Range (
void);
283 double Get_StdDev (
void);
284 double Get_Variance (
void);
285 double Get_Quantile (
double Quantile,
bool bFromHistogram =
true);
286 double Get_Percentile (
double Percentile,
bool bFromHistogram =
true);
306 bool is_Compatible (
CSG_Grid *pGrid )
const;
307 bool is_Compatible (
CSG_Grids *pGrids)
const;
309 bool is_Compatible (
int NX,
int NY,
double Cellsize,
double xMin,
double yMin)
const;
323 m_Attributes.Set_Modified(bModified);
340 void Assign_NoData (
void);
342 virtual bool Assign (
double Value = 0.);
351 virtual CSG_Grids & operator = (
double Value );
353 virtual CSG_Grids & operator += (
double Value );
356 virtual CSG_Grids & operator -= (
double Value );
357 virtual CSG_Grids & Subtract (
double Value );
359 virtual CSG_Grids & operator *= (
double Value );
360 virtual CSG_Grids & Multiply (
double Value );
362 virtual CSG_Grids & operator /= (
double Value );
363 virtual CSG_Grids & Divide (
double Value );
365 virtual double operator () (
int x,
int y,
int z)
const {
return(
asDouble(x, y, z) ); }
367 virtual CSG_Grid & operator [] (
int i) {
return( *m_pGrids[i] ); }
400 virtual float asFloat (
int x,
int y,
int z,
bool bScaled =
true)
const {
return( (
float) (
asDouble(x, y, z, bScaled)) ); }
411 virtual double asDouble(
int x,
int y,
int z,
bool bScaled =
true)
const
413 return( m_pGrids[z]->
asDouble(x, y, bScaled) );
431 m_pGrids[z]->Set_Value((
sLong)(i % m_pGrids[0]->
Get_NCells()), Value, bScaled);
434 virtual void Set_Value(
int x,
int y,
int z,
double Value,
bool bScaled =
true)
436 m_pGrids[z]->Set_Value(x, y, Value, bScaled);
452 return( _Get_Index() );
457 if( Position >= 0 && Position <
Get_NCells() && _Get_Index() )
459 Position = m_Index[bDown ?
Get_NCells() - Position - 1 : Position];
461 if( !bCheckNoData || !
is_NoData(Position) )
472 return( (i =
Get_Sorted(Position, bDown, bCheckNoData)) >= 0 );
475 bool Get_Sorted (
sLong Position,
int &x,
int &y,
int &z,
bool bDown =
true,
bool bCheckNoData =
true)
477 if( (Position =
Get_Sorted(Position, bDown, bCheckNoData)) >= 0 )
479 z = (int)(Position / m_pGrids[0]->
Get_NCells());
481 Position = Position % m_pGrids[0]->Get_NCells();
483 x = (int)(Position %
Get_NX());
484 y = (int)(Position /
Get_NX());
504 int m_Z_Attribute, m_Z_Name;
520 void _On_Construction (
void);
522 void _Synchronize (
CSG_Grid *pGrid);
525 bool _Get_Z (
double Value,
int &iz,
double &dz)
const;
528 bool _Set_Index (
void);
529 bool _Get_Index (
void)
536 return( m_Index || _Set_Index() );
540 bool _Load_External (
const CSG_String &FileName);
541 bool _Load_PGSQL (
const CSG_String &FileName);
543 bool _Load_Normal (
const CSG_String &FileName);
544 bool _Save_Normal (
const CSG_String &FileName);
546 bool _Load_Compressed (
const CSG_String &FileName);
547 bool _Save_Compressed (
const CSG_String &FileName);
549 bool _Load_Header (CSG_File &Stream);
550 bool _Save_Header (CSG_File &Stream);
552 bool _Load_Attributes (CSG_File &Stream);
553 bool _Save_Attributes (CSG_File &Stream);
555 bool _Load_Data (CSG_File &Stream, CSG_Grid *pGrid);
556 bool _Save_Data (CSG_File &Stream, CSG_Grid *pGrid);
560 bool _Assign_MeanValue (CSG_Grids *pSource,
bool bVolumeProportional);
561 bool _Assign_ExtremeValue (CSG_Grids *pSource,
bool bMaximum);
562 bool _Assign_Majority (CSG_Grids *pSource);
565 CSG_Grids & _Operation_Arithmetic (
const CSG_Grids &Grids,
TSG_Grid_Operation Operation);
578#define SG_GRIDS_PTR_SAFE_SET_NODATA(g, x, y, z) { if( g && g->is_InGrid(x, y, z, false) ) { g->Set_NoData(x, y, z ); } }
579#define SG_GRIDS_PTR_SAFE_SET_VALUE(g, x, y, z, v) { if( g && g->is_InGrid(x, y, z, false) ) { g->Set_Value (x, y, z, v); } }
#define SAGA_API_DLL_EXPORT
#define SG_FREE_SAFE(PTR)
virtual bool is_Modified(void) const
bool is_NoData_Value(double Value) const
virtual bool is_Valid(void) const =0
void Set_Update_Flag(bool bOn=true)
virtual bool Set_Max_Samples(sLong Max_Samples)
double Get_NoData_Value(bool bUpper=false) const
bool Get_Update_Flag(void)
virtual bool Set_NoData_Value_Range(double Lower, double Upper)
bool Update(bool bForce=false)
virtual bool Destroy(void)
virtual bool Save(const CSG_String &File, int Format=0)=0
virtual void Set_Modified(bool bOn=true)
virtual bool Assign(CSG_Data_Object *pObject, bool bProgress=false)
virtual bool On_Update(void)
virtual bool On_Delete(void)=0
virtual bool On_Reload(void)=0
virtual const CSG_Rect & Get_Extent(void)=0
TSG_Data_Type Get_Type(void) const
virtual void Set_NoData(int x, int y, int z)
virtual int asInt(sLong i, bool bScaled=true) const
virtual float asFloat(int x, int y, int z, bool bScaled=true) const
virtual void Mul_Value(sLong i, double Value)
double Get_ZMin(bool bCells=false) const
const CSG_Grid_System & Get_System(void) const
CSG_Table * Get_Attributes_Ptr(void)
const CSG_Grid & Get_Grid(int i) const
virtual BYTE asByte(sLong i, bool bScaled=true) const
virtual const CSG_Rect & Get_Extent(void)
virtual bool is_NoData(int x, int y, int z) const
virtual void Set_Modified(bool bModified=true)
virtual bool is_Modified(void) const
virtual void Set_NoData(sLong i)
virtual void Mul_Value(int x, int y, int z, double Value)
bool Get_Sorted(sLong Position, sLong &i, bool bDown=true, bool bCheckNoData=true)
sLong Get_NCells(void) const
double Get_Cellsize(void) const
virtual short asShort(sLong i, bool bScaled=true) const
double Get_XRange(bool bCells=false) const
virtual void Add_Value(sLong i, double Value)
double Get_YMax(bool bCells=false) const
virtual bool Create(const CSG_Grids &Grids)
virtual void Set_Value(sLong i, double Value, bool bScaled=true)
sLong Get_Sorted(sLong Position, bool bDown=true, bool bCheckNoData=true)
virtual bool is_NoData(sLong i) const
TSG_Intersection is_Intersecting(const CSG_Rect &Extent) const
TSG_Data_Type Get_Z_Type(void) const
sLong Get_Memory_Size(void) const
const SG_Char * Get_Unit(void) const
double Get_Cellarea(void) const
bool is_InGrid_byPos(double x, double y, double z, bool bCheckNoData=true) const
double Get_XMin(bool bCells=false) const
double Get_ZMax(bool bCells=false) const
double Get_Offset(void) const
double Get_Scaling(void) const
double Get_Z(int i) const
virtual bool Save(const wchar_t *File, int Format=0)
bool is_InGrid_byPos(const TSG_Point_3D &p, bool bCheckNoData=true) const
int Get_Grid_Count(void) const
int Get_Z_Attribute(void) const
bool Get_Sorted(sLong Position, int &x, int &y, int &z, bool bDown=true, bool bCheckNoData=true)
virtual short asShort(int x, int y, int z, bool bScaled=true) const
CSG_Grid * Get_Grid_Ptr(int i) const
virtual sLong asLong(sLong i, bool bScaled=true) const
virtual char asChar(sLong i, bool bScaled=true) const
double Get_YMin(bool bCells=false) const
virtual int asInt(int x, int y, int z, bool bScaled=true) const
bool Set_Index(bool bOn=true)
double Get_YRange(bool bCells=false) const
virtual void Add_Value(int x, int y, int z, double Value)
virtual bool Load(const CSG_String &File, bool bLoadData=true)
virtual char asChar(int x, int y, int z, bool bScaled=true) const
virtual sLong asLong(int x, int y, int z, bool bScaled=true) const
const CSG_Rect & Get_Extent(bool bCells=false) const
const CSG_Table & Get_Attributes(void) const
double Get_XMax(bool bCells=false) const
TSG_Intersection is_Intersecting(const TSG_Rect &Extent) const
bool is_InGrid(int x, int y, int z, bool bCheckNoData=true) const
virtual TSG_Data_Object_Type Get_ObjectType(void) const
virtual double asDouble(sLong i, bool bScaled=true) const
virtual bool Save(const char *File, int Format=0)
virtual float asFloat(sLong i, bool bScaled=true) const
virtual BYTE asByte(int x, int y, int z, bool bScaled=true) const
CSG_Table_Record & Get_Attributes(int i) const
double Get_ZRange(bool bCells=false) const
virtual double asDouble(int x, int y, int z, bool bScaled=true) const
int Get_nValueBytes(void) const
bool is_Scaled(void) const
TSG_Intersection is_Intersecting(double xMin, double yMin, double xMax, double yMax) const
virtual void Set_Value(int x, int y, int z, double Value, bool bScaled=true)
int Get_nLineBytes(void) const
@ SG_DATAOBJECT_TYPE_Grids
@ GRIDS_FILE_FORMAT_GeoTIFF
@ GRIDS_FILE_FORMAT_Normal
@ GRIDS_FILE_FORMAT_Compressed
@ GRIDS_FILE_FORMAT_Undefined
SAGA_API_DLL_EXPORT CSG_Grids * SG_Create_Grids(void)