📄 grid.h
字号:
///////////////////////////////////////////////////////////
// //
// SAGA //
// //
// System for Automated Geoscientific Analyses //
// //
// Application Programming Interface //
// //
// Library: SAGA_API //
// //
//-------------------------------------------------------//
// //
// grid.h //
// //
// Copyright (C) 2005 by Olaf Conrad //
// //
//-------------------------------------------------------//
// //
// This file is part of 'SAGA - System for Automated //
// Geoscientific Analyses'. //
// //
// This library is free software; you can redistribute //
// it and/or modify it under the terms of the GNU Lesser //
// General Public License as published by the Free //
// Software Foundation, version 2.1 of the License. //
// //
// This library is distributed in the hope that it will //
// be useful, but WITHOUT ANY WARRANTY; without even the //
// implied warranty of MERCHANTABILITY or FITNESS FOR A //
// PARTICULAR PURPOSE. See the GNU Lesser General Public //
// License for more details. //
// //
// You should have received a copy of the GNU Lesser //
// General Public License along with this program; if //
// not, write to the Free Software Foundation, Inc., //
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, //
// USA. //
// //
//-------------------------------------------------------//
// //
// contact: Olaf Conrad //
// Institute of Geography //
// University of Goettingen //
// Goldschmidtstr. 5 //
// 37077 Goettingen //
// Germany //
// //
// e-mail: oconrad@saga-gis.org //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#ifndef HEADER_INCLUDED__SAGA_API__grid_H
#define HEADER_INCLUDED__SAGA_API__grid_H
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#include "dataobject.h"
///////////////////////////////////////////////////////////
// //
// Data Types //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
typedef enum ESG_Grid_Type
{
GRID_TYPE_Undefined = 0,
GRID_TYPE_Byte,
GRID_TYPE_Char,
GRID_TYPE_Word,
GRID_TYPE_Short,
GRID_TYPE_DWord,
GRID_TYPE_Int,
GRID_TYPE_Float,
GRID_TYPE_Double,
GRID_TYPE_Bit,
GRID_TYPE_Count
}
TSG_Grid_Type;
//---------------------------------------------------------
const SG_Char gSG_Grid_Type_Names[GRID_TYPE_Count][32] =
{
SG_T("ASCII"),
SG_T("BYTE_UNSIGNED"),
SG_T("BYTE"),
SG_T("SHORTINT_UNSIGNED"),
SG_T("SHORTINT"),
SG_T("INTEGER_UNSIGNED"),
SG_T("INTEGER"),
SG_T("FLOAT"),
SG_T("DOUBLE"),
SG_T("BIT")
};
//---------------------------------------------------------
const SG_Char gSG_Grid_Type_Sizes[GRID_TYPE_Count] =
{
0,
1,
1,
2,
2,
4,
4,
4,
8,
-1
};
///////////////////////////////////////////////////////////
// //
// Memory Handling //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
typedef enum ESG_Grid_Memory_Type
{
GRID_MEMORY_Normal = 0,
GRID_MEMORY_Cache,
GRID_MEMORY_Compression
}
TSG_Grid_Memory_Type;
///////////////////////////////////////////////////////////
// //
// Grid File //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
typedef enum ESG_Grid_File_Format
{
GRID_FILE_FORMAT_Undefined = 0,
GRID_FILE_FORMAT_Binary,
GRID_FILE_FORMAT_ASCII
}
TSG_Grid_File_Format;
//---------------------------------------------------------
typedef enum ESG_Grid_File_Key
{
GRID_FILE_KEY_NAME = 0,
GRID_FILE_KEY_DESCRIPTION,
GRID_FILE_KEY_UNITNAME,
GRID_FILE_KEY_DATAFILE_NAME,
GRID_FILE_KEY_DATAFILE_OFFSET,
GRID_FILE_KEY_DATAFORMAT,
GRID_FILE_KEY_BYTEORDER_BIG,
GRID_FILE_KEY_POSITION_XMIN,
GRID_FILE_KEY_POSITION_YMIN,
GRID_FILE_KEY_CELLCOUNT_X,
GRID_FILE_KEY_CELLCOUNT_Y,
GRID_FILE_KEY_CELLSIZE,
GRID_FILE_KEY_Z_FACTOR,
GRID_FILE_KEY_NODATA_VALUE,
GRID_FILE_KEY_TOPTOBOTTOM,
GRID_FILE_KEY_Count
}
TSG_Grid_File_Key;
//---------------------------------------------------------
const SG_Char gSG_Grid_File_Key_Names[GRID_FILE_KEY_Count][32] =
{
SG_T("NAME"),
SG_T("DESCRIPTION"),
SG_T("UNIT"),
SG_T("DATAFILE_NAME"),
SG_T("DATAFILE_OFFSET"),
SG_T("DATAFORMAT"),
SG_T("BYTEORDER_BIG"),
SG_T("POSITION_XMIN"),
SG_T("POSITION_YMIN"),
SG_T("CELLCOUNT_X"),
SG_T("CELLCOUNT_Y"),
SG_T("CELLSIZE"),
SG_T("Z_FACTOR"),
SG_T("NODATA_VALUE"),
SG_T("TOPTOBOTTOM")
};
//---------------------------------------------------------
#define GRID_FILE_KEY_TRUE SG_T("TRUE")
#define GRID_FILE_KEY_FALSE SG_T("FALSE")
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
typedef enum ESG_Grid_Interpolation
{
GRID_INTERPOLATION_NearestNeighbour = 0,
GRID_INTERPOLATION_Bilinear,
GRID_INTERPOLATION_InverseDistance,
GRID_INTERPOLATION_BicubicSpline,
GRID_INTERPOLATION_BSpline,
GRID_INTERPOLATION_Undefined
}
TSG_Grid_Interpolation;
//---------------------------------------------------------
typedef enum ESG_Grid_Operation
{
GRID_OPERATION_Addition = 0,
GRID_OPERATION_Subtraction,
GRID_OPERATION_Multiplication,
GRID_OPERATION_Division
}
TSG_Grid_Operation;
///////////////////////////////////////////////////////////
// //
// CSG_Grid_System //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
/**
* CSG_Grid_System is used by the CSG_Grid class to provide
* information about the number of rows and columns, the
* cell size and the georeference, which define the grid.
* It offers various functions, which help when working
* with grids.
* @see CSG_Grid
*/
//---------------------------------------------------------
class SAGA_API_DLL_EXPORT CSG_Grid_System
{
public:
CSG_Grid_System(void);
CSG_Grid_System(const CSG_Grid_System &System);
CSG_Grid_System(double Cellsize, const CSG_Rect &Extent);
CSG_Grid_System(double Cellsize, double xMin, double yMin, double xMax, double yMax);
CSG_Grid_System(double Cellsize, double xMin, double yMin, int NX, int NY);
~CSG_Grid_System(void);
//-----------------------------------------------------
bool is_Valid (void) const;
const SG_Char * Get_Name (bool bShort = true);
double Get_Cellsize (void) const { return( m_Cellsize ); }
double Get_Cellarea (void) const { return( m_Cellarea ); }
const CSG_Rect & Get_Extent (void) const { return( m_Extent ); }
int Get_NX (void) const { return( m_NX ); }
int Get_NY (void) const { return( m_NY ); }
long Get_NCells (void) const { return( m_NCells ); }
double Get_XMin (void) const { return( m_Extent.m_rect.xMin ); }
double Get_XMax (void) const { return( m_Extent.m_rect.xMax ); }
double Get_XRange (void) const { return( m_Extent.Get_XRange() ); }
double Get_YMin (void) const { return( m_Extent.m_rect.yMin ); }
double Get_YMax (void) const { return( m_Extent.m_rect.yMax ); }
double Get_YRange (void) const { return( m_Extent.Get_YRange() ); }
//-----------------------------------------------------
bool operator == (const CSG_Grid_System &System) const;
void operator = (const CSG_Grid_System &System);
bool Assign (const CSG_Grid_System &System);
bool Assign (double Cellsize, const CSG_Rect &Extent);
bool Assign (double Cellsize, double xMin, double yMin, double xMax, double yMax);
bool Assign (double Cellsize, double xMin, double yMin, int NX, int NY);
bool is_Equal (const CSG_Grid_System &System) const;
bool is_Equal (double Cellsize, const TSG_Rect &Extent) const;
//-----------------------------------------------------
/// Aligns the world coordinate x to the rows of the grid system and returns it.
double Fit_xto_Grid_System (double x) const { return( Get_XMin() + m_Cellsize * (int)(0.5 + (x - Get_XMin()) / m_Cellsize) ); }
/// Aligns the world coordinate y to the columns of the grid system and returns it.
double Fit_yto_Grid_System (double y) const { return( Get_YMin() + m_Cellsize * (int)(0.5 + (y - Get_YMin()) / m_Cellsize) ); }
/// Aligns the world coordinate ptWorld to the rows and columns of the grid system and returns it.
TSG_Point Fit_to_Grid_System (TSG_Point ptWorld) const
{
ptWorld.x = Fit_xto_Grid_System(ptWorld.x);
ptWorld.y = Fit_yto_Grid_System(ptWorld.y);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -