⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tin_from_grid_specific_points.cpp

📁 这是一个GPS相关的程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:

///////////////////////////////////////////////////////////
//                                                       //
//                         SAGA                          //
//                                                       //
//      System for Automated Geoscientific Analyses      //
//                                                       //
//                    Module Library:                    //
//                       TIN_Tools                       //
//                                                       //
//-------------------------------------------------------//
//                                                       //
//            TIN_From_Grid_Specific_Points.cpp          //
//                                                       //
//                 Copyright (C) 2003 by                 //
//                      Olaf Conrad                      //
//                                                       //
//-------------------------------------------------------//
//                                                       //
// This file is part of 'SAGA - System for Automated     //
// Geoscientific Analyses'. SAGA is free software; you   //
// can redistribute it and/or modify it under the terms  //
// of the GNU General Public License as published by the //
// Free Software Foundation; version 2 of the License.   //
//                                                       //
// SAGA 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 General Public        //
// License for more details.                             //
//                                                       //
// You should have received a copy of the GNU 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.                                                  //
//                                                       //
//-------------------------------------------------------//
//                                                       //
//    e-mail:     oconrad@saga-gis.org                   //
//                                                       //
//    contact:    Olaf Conrad                            //
//                Institute of Geography                 //
//                University of Goettingen               //
//                Goldschmidtstr. 5                      //
//                37077 Goettingen                       //
//                Germany                                //
//                                                       //
///////////////////////////////////////////////////////////

//---------------------------------------------------------


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
#include "TIN_From_Grid_Specific_Points.h"


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
CTIN_From_Grid_Specific_Points::CTIN_From_Grid_Specific_Points(void)
{
	CSG_Parameter	*pNode;

	//-----------------------------------------------------
	Set_Name(_TL("Grid to TIN (Surface Specific Points)"));

	Set_Author(_TL("Copyrights (c) 2004 by Olaf Conrad"));

	Set_Description(
		_TL("Creates a TIN by identifying (surface) specific points of a grid.\n\n")
	);


	//-----------------------------------------------------
	Parameters.Add_Grid(
		NULL	, "GRID"		, _TL("Grid"),
		_TL(""),
		PARAMETER_INPUT
	);

	Parameters.Add_Grid_List(
		NULL	, "VALUES"		, _TL("Values"),
		_TL(""),
		PARAMETER_INPUT_OPTIONAL
	);

	Parameters.Add_TIN(
		NULL	, "TIN"			, _TL("TIN"),
		_TL(""),
		PARAMETER_OUTPUT
	);

	Parameters.Add_Choice(
		NULL	, "METHOD"		, _TL("Method"),
		_TL("The method used to identify surface specific points."),

		CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"),
			_TL("Mark Highest Neighbour"),
			_TL("Opposite Neighbours"),
			_TL("Flow Direction"),
			_TL("Flow Direction (up and down)"),
			_TL("Peucker & Douglas")
		), 1
	);

	pNode	= Parameters.Add_Node(NULL, "THRESHOLDS", _TL("Thresholds"), _TL(""));

	Parameters.Add_Value(
		pNode	, "HIGH"		, _TL("Mark Highest Neighbour"),
		_TL(""),
		PARAMETER_TYPE_Int		, 4, 1, true, 4, true
	);

	Parameters.Add_Range(
		pNode	, "FLOW"		, _TL("Flow Direction"),
		_TL(""),
		0, 3, 0, true, 8, true
	);

	Parameters.Add_Value(
		pNode	, "PEUCKER"		, _TL("Peucker & Douglas"),
		_TL(""),
		PARAMETER_TYPE_Double	, 2
	);
}

//---------------------------------------------------------
CTIN_From_Grid_Specific_Points::~CTIN_From_Grid_Specific_Points(void)
{}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
bool CTIN_From_Grid_Specific_Points::On_Execute(void)
{
	bool					bResult;
	int						x, y, i;
	CSG_TIN					*pTIN;
	CSG_Grid					*pGrid, Grid;
	CSG_Parameter_Grid_List	*pValues;
	CSG_Shape					*pPoint;
	CSG_Shapes					Points;

	//-----------------------------------------------------
	pGrid	= Parameters("GRID")->asGrid();
	Grid.Create(pGrid, GRID_TYPE_Byte);

	//-----------------------------------------------------
	switch( Parameters("METHOD")->asInt() )
	{
	default:
		bResult	= false;
		break;

	case 0:
		bResult	= Get_MarkHighestNB	(&Grid, pGrid);
		break;

	case 1:
		bResult	= Get_OppositeNB	(&Grid, pGrid, Parameters("HIGH")->asInt());
		break;

	case 2:
		bResult	= Get_FlowDirection	(&Grid, pGrid,
			(int)Parameters("FLOW")->asRange()->Get_LoVal(),
			(int)Parameters("FLOW")->asRange()->Get_HiVal()
		);
		break;

	case 3:
		bResult	= Get_FlowDirection2(&Grid, pGrid,
			(int)Parameters("FLOW")->asRange()->Get_HiVal()
		);
		break;

	case 4:
		bResult	= Get_Peucker		(&Grid, pGrid, Parameters("PEUCKER")->asDouble());
		break;
	}

	//-----------------------------------------------------
	if( bResult )
	{
		pValues	= Parameters("VALUES")->asGridList();

		Points.Create(SHAPE_TYPE_Point);
		Points.Get_Table().Add_Field(_TL("VALUE"), TABLE_FIELDTYPE_Double);

		for(i=0; i<pValues->Get_Count(); i++)
		{
			Points.Get_Table().Add_Field(pValues->asGrid(i)->Get_Name(), TABLE_FIELDTYPE_Double);
		}

		for(y=0; y<Get_NY() && Set_Progress(y, Get_NY()); y++)
		{
			for(x=0; x<Get_NX(); x++)
			{
				if( Grid.asInt(x, y) != 0 )
				{
					pPoint	= Points.Add_Shape();

					pPoint->Add_Point(
						Get_XMin() + Get_Cellsize() * x,
						Get_YMin() + Get_Cellsize() * y
					);

					pPoint->Get_Record()->Set_Value(0, pGrid->asDouble(x, y));

					for(i=0; i<pValues->Get_Count(); i++)
					{
						pPoint->Get_Record()->Set_Value(1 + i, pValues->asGrid(i)->asDouble(x, y));
					}
				}
			}
		}

		//-------------------------------------------------
		if( Points.Get_Count() >= 3 )
		{
			pTIN	= Parameters("TIN")->asTIN();
			bResult	= pTIN->Create(&Points);
		}
	}

	return( bResult );
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
bool CTIN_From_Grid_Specific_Points::Get_MarkHighestNB(CSG_Grid *pResult, CSG_Grid *pGrid)	// Band & Lammers...
{
	int		i, x, y, ix, iy, xlo, ylo, xhi, yhi;
	double	lo, hi, z;
	CSG_Grid	*clo, *chi;

	clo		= SG_Create_Grid(pGrid, GRID_TYPE_Char);
	chi		= SG_Create_Grid(pGrid, GRID_TYPE_Char);

	// Pass 1: Auszaehlen...
	for(y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		for(x=0; x<Get_NX()-1; x++)
        {
			lo	= hi	= pGrid->asDouble(x,y);
			xhi	= xlo	= x;
			yhi	= ylo	= y;

			for(i=0; i<4; i++)
			{
				ix	= Get_xTo(i,x);
				iy	= Get_yTo(i,y);
  
				if( is_InGrid(ix,iy) )
				{
					z	= pGrid->asDouble(ix,iy);

					if( z > hi )
					{
						hi	= z;
						xhi	= ix;
						yhi	= iy;
					}
					else if( z < lo )
					{
						lo	= z;
						xlo	= ix;
						ylo	= iy;
					}
				}
			}

			clo->Add_Value(xlo,ylo,1);
			chi->Add_Value(xhi,yhi,1);
		}
	}

	// Pass 2: Setzen...
	for(y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		for(x=0; x<Get_NX()-1; x++)
		{
			if( !chi->asChar(x,y) )
			{
				if( !clo->asChar(x,y) )
					pResult->Set_Value(x,y, 2);	// Sattel
				else
					pResult->Set_Value(x,y, 1);	// Tiefenlinie
			}
			else if( !clo->asChar(x,y) )
				pResult->Set_Value(x,y, -1);	// Wasserscheide

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -