Пример #1
0
//---------------------------------------------------------
bool CSRTM30_Import::On_Execute(void)
{
	char	x_sTile[9][5]	= {	"W180", "W140", "W100", "W060", "W020", "E020", "E060", "E100", "E140"	},
			y_sTile[3][4]	= {	"S10", "N40", "N90"	};

	double	dSize			= 30.0 / (60.0 * 60.0);

	//-----------------------------------------------------
	int			xTile, yTile;
	double		xMin, xMax, yMin, yMax;
	TSG_Rect	rOut, rTile;
	CSG_String	sTile;
	CSG_Grid	*pOut;

	//-----------------------------------------------------
	xMin		= Parameters("XMIN")->asInt();
	xMax		= Parameters("XMAX")->asInt();
	yMin		= Parameters("YMIN")->asInt();
	yMax		= Parameters("YMAX")->asInt();

	rOut.xMin	= (180 + xMin) / 40.0 * X_WIDTH;
	rOut.xMax	= rOut.xMin + (int)((xMax - xMin) / dSize);
	rOut.yMin	= ( 60 + yMin) / 50.0 * Y_WIDTH;
	rOut.yMax	= rOut.yMin + (int)((yMax - yMin) / dSize);

	//-----------------------------------------------------
	pOut		= SG_Create_Grid(SG_DATATYPE_Short,
					(int)(rOut.xMax - rOut.xMin),
					(int)(rOut.yMax - rOut.yMin),
					dSize,
					xMin + 0.5 * dSize,
					yMin + 0.5 * dSize
				);

	pOut->Set_NoData_Value(-9999);
	pOut->Assign_NoData();
	pOut->Set_Name(SG_T("SRTM30"));
	pOut->Get_Projection().Create(SG_T("GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]"));

	//-----------------------------------------------------
	for(yTile=0, rTile.yMin=0, rTile.yMax=Y_WIDTH; yTile<3; yTile++, rTile.yMin+=Y_WIDTH, rTile.yMax+=Y_WIDTH)
	{
		for(xTile=0, rTile.xMin=0, rTile.xMax=X_WIDTH; xTile<9; xTile++, rTile.xMin+=X_WIDTH, rTile.xMax+=X_WIDTH)
		{
			sTile.Printf(SG_T("Tile: %s%s"), x_sTile[xTile], y_sTile[yTile]);
			Process_Set_Text(sTile);

			sTile.Printf(SG_T("%s%s%s.dem"), Parameters("PATH")->asString(), x_sTile[xTile], y_sTile[yTile]);
			Tile_Load(sTile, rTile, pOut, rOut);
		}
	}

	//-----------------------------------------------------
	Parameters("GRID")->Set_Value(pOut);

	return( true );
}
Пример #2
0
//---------------------------------------------------------
bool CCRS_Transform_Grid::Transform(CSG_Parameter_Grid_List *pSources, CSG_Parameter_Grid_List *pTargets, const CSG_Grid_System &Target_System)
{
	if( !m_Projector.Set_Inverse(true) || !pTargets || !pSources || pSources->Get_Count() < 1 )
	{
		return( false );
	}

	//-----------------------------------------------------
	CSG_Grid	*pX, *pY;

	if( !Parameters("CREATE_XY")->asBool() )
	{
		pX	= pY	= NULL;
	}
	else
	{
		Parameters("OUT_X")->Set_Value(pX	= SG_Create_Grid(Target_System, SG_DATATYPE_Float));
		pX->Assign_NoData();
		pX->Set_Name(_TL("X-Coordinate"));
		pX->Get_Projection().Create(m_Projector.Get_Target());

		Parameters("OUT_Y")->Set_Value(pY	= SG_Create_Grid(Target_System, SG_DATATYPE_Float));
		pY->Assign_NoData();
		pY->Set_Name(_TL("Y-Coordinate"));
		pY->Get_Projection().Create(m_Projector.Get_Target());
	}

	//-----------------------------------------------------
	bool	bGeogCS_Adjust	= m_Projector.Get_Source().Get_Type() == SG_PROJ_TYPE_CS_Geographic && pSources->asGrid(0)->Get_System().Get_XMax() > 180.0;

	Set_Target_Area(pSources->asGrid(0)->Get_System(), Target_System);

	//-----------------------------------------------------
	int	i, n	= pTargets->Get_Count();

	for(i=0; i<pSources->Get_Count(); i++)
	{
		CSG_Grid	*pSource	= pSources->asGrid(i);
		CSG_Grid	*pTarget	= SG_Create_Grid(Target_System, m_Interpolation == 0 ? pSource->Get_Type() : SG_DATATYPE_Float);

		if( pTarget )
		{
			pTarget->Set_NoData_Value_Range	(pSource->Get_NoData_Value(), pSource->Get_NoData_hiValue());
			pTarget->Set_ZFactor			(pSource->Get_ZFactor());
			pTarget->Set_Name				(CSG_String::Format(SG_T("%s"), pSource->Get_Name()));
			pTarget->Set_Unit				(pSource->Get_Unit());
			pTarget->Assign_NoData();
			pTarget->Get_Projection().Create(m_Projector.Get_Target());

			pTargets->Add_Item(pTarget);
		}
	}

	//-------------------------------------------------
	for(int y=0; y<Target_System.Get_NY() && Set_Progress(y, Target_System.Get_NY()); y++)
	{
		double	yTarget	= Target_System.Get_YMin() + y * Target_System.Get_Cellsize();

		#pragma omp parallel for private(i)
		for(int x=0; x<Target_System.Get_NX(); x++)
		{
			double	z, ySource, xSource	= Target_System.Get_XMin() + x * Target_System.Get_Cellsize();

			if( is_In_Target_Area(x, y) && m_Projector.Get_Projection(xSource, ySource = yTarget) )
			{
				if( pX )	pX->Set_Value(x, y, xSource);
				if( pY )	pY->Set_Value(x, y, ySource);

				if( bGeogCS_Adjust && xSource < 0.0 )
				{
					xSource	+= 360.0;
				}

				for(i=0; i<pTargets->Get_Count(); i++)
				{
					if( pSources->asGrid(i)->Get_Value(xSource, ySource, z, m_Interpolation) )
					{
						pTargets->asGrid(n + i)->Set_Value(x, y, z);
					}
				}
			}
		}
	}

	//-----------------------------------------------------
	m_Target_Area.Destroy();

	return( true );
}
Пример #3
0
//---------------------------------------------------------
bool CPoint_Zonal_Multi_Grid_Regression::On_Execute(void)
{
	//-----------------------------------------------------
	CSG_Shapes	*pPoints		= Parameters("POINTS"    )->asShapes();
	CSG_Shapes	*pZones			= Parameters("ZONES"     )->asShapes();
	CSG_Grid	*pRegression	= Parameters("REGRESSION")->asGrid  ();

	pRegression->Assign_NoData();

	CSG_Grid	Regression(*Get_System(), SG_DATATYPE_Float);

	SG_UI_Progress_Lock(true);	// suppress dialogs from popping up

	for(int i=0; i<pZones->Get_Count() && Process_Get_Okay(); i++)
	{
		CSG_Shape_Polygon	*pZone	= (CSG_Shape_Polygon *)pZones->Get_Shape(i);

		//-------------------------------------------------
		// select all points located in current zone polygon

		bool	bResult;

		CSG_Shapes Zone(SHAPE_TYPE_Polygon);	Zone.Add_Shape(pZone);

		SG_RUN_TOOL(bResult, "shapes_tools", 5,	// select points by location
			   SG_TOOL_PARAMETER_SET("LOCATIONS", &Zone)
			&& SG_TOOL_PARAMETER_SET("SHAPES"   , pPoints)
		);

		if( !bResult )
		{
			SG_UI_Process_Set_Okay();	// don't stop overall work flow, if tool execution failed for current zone
		}
		else if( pPoints->Get_Selection_Count() > 0 )
		{
			//---------------------------------------------
			// copy selected points to a new (temporary) points layer

			CSG_Shapes	Selection;

			SG_RUN_TOOL(bResult, "shapes_tools", 6,	// copy selected points to a new layer
				   SG_TOOL_PARAMETER_SET("INPUT" , pPoints)
				&& SG_TOOL_PARAMETER_SET("OUTPUT", &Selection)
			);

			pPoints->asShapes()->Select();	// unselect everything from original points layer

			//---------------------------------------------
			// perform the regression analysis, regression grid for zone is temporary

			SG_RUN_TOOL(bResult, "statistics_regression", 1,	// multiple linear regression for points and predictor grids
				   SG_TOOL_PARAMETER_SET("PREDICTORS", Parameters("PREDICTORS"))
				&& SG_TOOL_PARAMETER_SET("REGRESSION", &Regression             )
				&& SG_TOOL_PARAMETER_SET("POINTS"    , &Selection              )
				&& SG_TOOL_PARAMETER_SET("ATTRIBUTE" , Parameters("ATTRIBUTE" ))
				&& SG_TOOL_PARAMETER_SET("RESAMPLING", Parameters("RESAMPLING"))
				&& SG_TOOL_PARAMETER_SET("COORD_X"   , Parameters("COORD_X"   ))
				&& SG_TOOL_PARAMETER_SET("COORD_Y"   , Parameters("COORD_Y"   ))
				&& SG_TOOL_PARAMETER_SET("INTERCEPT" , Parameters("INTERCEPT" ))
				&& SG_TOOL_PARAMETER_SET("METHOD"    , Parameters("METHOD"    ))
				&& SG_TOOL_PARAMETER_SET("P_VALUE"   , Parameters("P_VALUE"   ))
			);

			//---------------------------------------------
			// use zone polygon as mask for copying zonal regression result to final regression grid

			if( !bResult )
			{
				SG_UI_Process_Set_Okay();	// don't stop overall work flow, if tool execution failed for current zone
			}
			else
			{
				#pragma omp parallel for	// speed up using multiple processors
				for(int y=0; y<Get_NY(); y++)
				{
					for(int x=0; x<Get_NX(); x++)
					{
						if( !Regression.is_NoData(x, y) && pZone->Contains(Get_System()->Get_Grid_to_World(x, y)) )
						{
							pRegression->Set_Value(x, y, Regression.asDouble(x, y));
						}
					}
				}
			}
		}
	}

	//-----------------------------------------------------
	SG_UI_Progress_Lock(false);

	//-----------------------------------------------------
	Set_Residuals(pPoints, pRegression);

	//-----------------------------------------------------
	return( true );
}
Пример #4
0
//---------------------------------------------------------
bool CCRS_Transform_Grid::Transform(CSG_Parameter_Grid_List *pSources, CSG_Parameter_Grid_List *pTargets, const CSG_Grid_System &Target_System)
{
	if( !m_Projector.Set_Inverse(true) || !pTargets || !pSources || pSources->Get_Count() < 1 )
	{
		return( false );
	}

	//-----------------------------------------------------
	CSG_Grid	*pX, *pY;

	if( (pX = m_Grid_Target.Get_Grid("OUT_X")) != NULL )
	{
		pX->Assign_NoData();
		pX->Set_Name(_TL("X Coordinates"));
		pX->Get_Projection().Create(m_Projector.Get_Target());
	}

	if( (pY = m_Grid_Target.Get_Grid("OUT_Y")) != NULL )
	{
		pY->Assign_NoData();
		pY->Set_Name(_TL("Y Coordinates"));
		pY->Get_Projection().Create(m_Projector.Get_Target());
	}

	//-----------------------------------------------------
	bool	bGeogCS_Adjust	= m_Projector.Get_Source().Get_Type() == SG_PROJ_TYPE_CS_Geographic && pSources->asGrid(0)->Get_System().Get_XMax() > 180.0;

	Set_Target_Area(pSources->asGrid(0)->Get_System(), Target_System);

	bool	bKeepType	= m_Resampling == GRID_RESAMPLING_NearestNeighbour || Parameters("KEEP_TYPE")->asBool();

	//-----------------------------------------------------
	int	i, n	= pTargets->Get_Count();

	for(i=0; i<pSources->Get_Count(); i++)
	{
		CSG_Grid	*pSource	= pSources->asGrid(i);
		CSG_Grid	*pTarget	= SG_Create_Grid(Target_System, bKeepType ? pSource->Get_Type() : SG_DATATYPE_Float);

		if( pTarget )
		{
			pTargets->Add_Item(pTarget);

			pTarget->Set_NoData_Value_Range (pSource->Get_NoData_Value(), pSource->Get_NoData_hiValue());
			pTarget->Set_Scaling            (pSource->Get_Scaling(), pSource->Get_Offset());
			pTarget->Set_Name               (pSource->Get_Name());
			pTarget->Set_Unit               (pSource->Get_Unit());
			pTarget->Get_Projection().Create(m_Projector.Get_Target());
			pTarget->Assign_NoData();

			CSG_Parameters Parms; if( DataObject_Get_Parameters(pSource, Parms) ) { DataObject_Add(pTarget); DataObject_Set_Parameters(pTarget, Parms); }
		}
	}

	//-------------------------------------------------
	for(int y=0; y<Target_System.Get_NY() && Set_Progress(y, Target_System.Get_NY()); y++)
	{
		double	yTarget	= Target_System.Get_YMin() + y * Target_System.Get_Cellsize();

	//	#pragma omp parallel for private(i)
		for(int x=0; x<Target_System.Get_NX(); x++)
		{
			double	z, ySource, xSource	= Target_System.Get_XMin() + x * Target_System.Get_Cellsize();

			if( is_In_Target_Area(x, y) && m_Projector.Get_Projection(xSource, ySource = yTarget) )
			{
				if( bGeogCS_Adjust )
				{
					if( xSource < 0.0 )
					{
						xSource	+= 360.0;
					}
					else if( xSource >= 360.0 )
					{
						xSource	-= 360.0;
					}
				}

				if( pX ) pX->Set_Value(x, y, xSource);
				if( pY ) pY->Set_Value(x, y, ySource);

				for(i=0; i<pSources->Get_Count(); i++)
				{
					if( pSources->asGrid(i)->Get_Value(xSource, ySource, z, m_Resampling, false, true) )
					{
						pTargets->asGrid(n + i)->Set_Value(x, y, z);
					}
				}
			}
		}
	}

	//-----------------------------------------------------
	m_Target_Area.Destroy();

	return( true );
}
Пример #5
0
//---------------------------------------------------------
bool CFlow_Parallel::Set_Flow(void)
{
	//-----------------------------------------------------
	if( !m_pDTM->Set_Index() )
	{
		return( false );
	}

	//-----------------------------------------------------
	int Method	= Parameters("METHOD")->asInt();

	if( Method == 2 )
	{
		BRM_Init();
	}

	//-----------------------------------------------------
	double	dLinear	= Parameters("LINEAR_DO")->asBool() ? Parameters("LINEAR_MIN")->asDouble() : -1.0;

	CSG_Grid	*pLinear_Val	= Parameters("LINEAR_VAL")->asGrid();
	CSG_Grid	*pLinear_Dir	= Parameters("LINEAR_DIR")->asGrid();

	//-----------------------------------------------------
	bool	bNoNegatives	= m_pWeights ? Parameters("NO_NEGATIVES")->asBool() : false;

	CSG_Grid	*pLoss	= Parameters("WEIGHT_LOSS")->asGrid();

	if( bNoNegatives && pLoss )
	{
		pLoss->Assign_NoData();
	}

	//-----------------------------------------------------
	for(sLong n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
	{
		int		x, y;

		if( m_pDTM->Get_Sorted(n, x, y) )
		{
			if( bNoNegatives && m_pFlow->asDouble(x, y) < 0.0 )
			{
				if( pLoss )
				{
					pLoss->Set_Value(x, y, fabs(m_pFlow->asDouble(x, y)));
				}

				m_pFlow->Set_Value(x, y, 0.0);
			}

			if( pLinear_Dir && !pLinear_Dir->is_NoData(x, y) )
			{
				Set_D8(x, y, pLinear_Dir->asInt(x, y));
			}
			else if( dLinear > 0.0 && dLinear <= (pLinear_Val && !pLinear_Val->is_NoData(x, y) ? pLinear_Val->asDouble(x, y) : m_pFlow->asDouble(x, y)) )
			{
				Set_D8(x, y, pLinear_Dir && !pLinear_Dir->is_NoData(x, y) ? pLinear_Dir->asInt(x, y) : -1);
			}
			else switch( Method )
			{
			case 0:	Set_D8    (x, y);	break;
			case 1:	Set_Rho8  (x, y);	break;
			case 2:	Set_BRM   (x, y);	break;
			case 3:	Set_DInf  (x, y);	break;
			case 4:	Set_MFD   (x, y);	break;
			case 5:	Set_MDInf (x, y);	break;
			case 6:	Set_MMDGFD(x, y);	break;
			}
		}
	}

	//-----------------------------------------------------
	if( m_pRoute )
	{
		for(sLong n=0; n<Get_NCells() && Set_Progress_NCells(n); n++)
		{
			int		x, y;

			if( m_pDTM->Get_Sorted(n, x, y, false) )
			{
				Check_Route(x, y);
			}
		}
	}

	//-----------------------------------------------------
	return( true );
}