コード例 #1
0
//---------------------------------------------------------
bool CHillslope_Evolution_FTCS::On_Execute(void)
{
	//-----------------------------------------------------
	CSG_Grid	DEM(Get_System());

	m_pDEM_Old	= &DEM;

	m_pDEM		= Parameters("MODEL")->asGrid();

	m_pDEM->Assign(Parameters("DEM")->asGrid());

	DataObject_Set_Colors(Parameters("DIFF")->asGrid(), 10, SG_COLORS_RED_GREY_BLUE, true);

	//-----------------------------------------------------
	double	k, dTime, nTime;

	k		= Parameters("KAPPA"   )->asDouble();
	nTime	= Parameters("DURATION")->asDouble();

	if( Parameters("TIMESTEP")->asInt() == 0 )
	{
		dTime	= Parameters("DTIME")->asDouble();
	}
	else
	{
		dTime	= 0.5 * Get_Cellarea() / (2.0 * k);

		if( Parameters("NEIGHBOURS")->asInt() == 1 )
		{
			dTime	/= sqrt(2.0);
		}
	}

	if( dTime > nTime )
	{
		Message_Fmt("\n%s: %s [%f]", _TL("Warning"), _TL("Time step exceeds duration"), dTime);

		dTime	= nTime;
	}

	Message_Fmt("\n%s: %f", _TL("Time Step"), dTime);
	Message_Fmt("\n%s: %d", _TL("Steps"), (int)(nTime / dTime));

	//-----------------------------------------------------
	for(double iTime=dTime; iTime<=nTime && Set_Progress(iTime, nTime); iTime+=dTime)
	{
		Process_Set_Text("%s: %.2f [%.2f]", _TL("Simulation Time"), iTime, nTime);

		SG_UI_Progress_Lock(true);

		Set_Diffusion(dTime * k / Get_Cellarea());

		Set_Difference();

		SG_UI_Progress_Lock(false);
	}

	//-----------------------------------------------------
	return( true );
}
コード例 #2
0
//---------------------------------------------------------
bool CWKSP_Map_Graticule::Get_Graticule(const CSG_Rect &Extent)
{
	bool	bResult	= false;

	m_Graticule  .Create(SHAPE_TYPE_Line );
	m_Coordinates.Create(SHAPE_TYPE_Point);

	CSG_Tool	*pTool	= SG_Get_Tool_Library_Manager().Get_Tool("pj_proj4", 14);

	if(	pTool && Get_Map()->Get_Projection().is_Okay() )
	{
		SG_UI_Msg_Lock     (true);
		SG_UI_Progress_Lock(true);

		pTool->Settings_Push();

		if( pTool->Set_Parameter("XMIN"      , Extent.Get_XMin())
		&&  pTool->Set_Parameter("XMAX"      , Extent.Get_XMax())
		&&  pTool->Set_Parameter("YMIN"      , Extent.Get_YMin())
		&&  pTool->Set_Parameter("YMAX"      , Extent.Get_YMax())
		&&  pTool->Set_Parameter("INTERVAL"  , m_Parameters("INTERVAL"))
		&&  pTool->Set_Parameter("FIXED"     , m_Parameters("FIXED"))
		&&  pTool->Set_Parameter("FITTED"    , m_Parameters("FITTED"))
		&&  pTool->Set_Parameter("RESOLUTION", m_Parameters("RESOLUTION"))
		&&  pTool->Set_Parameter("GRATICULE" , &m_Graticule)
		&&  pTool->Set_Parameter("COORDS"    , &m_Coordinates)
		&&  pTool->Set_Parameter("CRS_PROJ4" , Get_Map()->Get_Projection().Get_Proj4())
		&&  pTool->On_Before_Execution() && pTool->Execute() )
		{
			bResult	= true;
		}

		pTool->Settings_Pop();

		SG_UI_Msg_Lock     (false);
		SG_UI_Progress_Lock(false);
	}

	return( bResult );
}
コード例 #3
0
//---------------------------------------------------------
bool CWator::On_Execute(void)
{
	//-----------------------------------------------------
	m_pWator	= m_Grid_Target.Get_Grid("GRID", SG_DATATYPE_Byte);

	if( !m_pWator )
	{
		Error_Set(_TL("could not create target grid"));

		return( false );
	}

	//-----------------------------------------------------
	m_pWator->Set_Name(_TL("Wa-Tor"));
	m_pWator->Set_NoData_Value(-1);

	CSG_Colors	Colors(3);

	Colors.Set_Color(0, SG_COLOR_BLACK);
	Colors.Set_Color(1, SG_COLOR_GREEN);
	Colors.Set_Color(2, SG_COLOR_RED  );

	DataObject_Add       (m_pWator);
	DataObject_Set_Colors(m_pWator, Colors);
	DataObject_Update    (m_pWator, 0, 2, SG_UI_DATAOBJECT_SHOW);

	//-----------------------------------------------------
	if( Parameters("REFRESH")->asBool() )
	{
		double	Fish_perc	= Parameters("INIT_FISH" )->asDouble();
		double	Shark_perc	= Parameters("INIT_SHARK")->asDouble() + Fish_perc;

		#pragma omp parallel for
		for(int y=0; y<m_pWator->Get_NY(); y++)
		{
			for(int x=0; x<m_pWator->Get_NX(); x++)
			{
				double	perc	= CSG_Random::Get_Uniform(0, 100);

				if( perc <= Fish_perc )
				{
					m_pWator->Set_Value(x, y, FISH);
				}
				else if( perc <= Shark_perc )
				{
					m_pWator->Set_Value(x, y, SHARK);
				}
				else
				{
					m_pWator->Set_Value(x, y, 0);
				}
			}
		}
	}

	//-----------------------------------------------------
	CSG_Table	*pTable	= Parameters("TABLE")->asTable();

	pTable->Destroy();
	pTable->Set_Name(_TL("Wa-Tor"));

	pTable->Add_Field("Cycle" , SG_DATATYPE_Int);
	pTable->Add_Field("Fishes", SG_DATATYPE_Int);
	pTable->Add_Field("Sharks", SG_DATATYPE_Int);

	//-----------------------------------------------------
	m_Fish_Birth	= Parameters("FISH_BIRTH"  )->asInt();
	m_Shark_Birth	= Parameters("SHARK_BIRTH" )->asInt();
	m_Shark_Starve	= Parameters("SHARK_STARVE")->asInt();

	m_Next  .Create(m_pWator, SG_DATATYPE_Byte);
	m_Age   .Create(m_pWator, SG_DATATYPE_Byte);
	m_Starve.Create(m_pWator, SG_DATATYPE_Byte);

	#pragma omp parallel for
	for(int y=0; y<m_pWator->Get_NY(); y++)
	{
		for(int x=0; x<m_pWator->Get_NX(); x++)
		{
			switch( m_pWator->asByte(x, y) )
			{
			case FISH:
				m_Age   .Set_Value(x, y, CSG_Random::Get_Uniform(0.0, m_Fish_Birth  ));
				break;

			case SHARK:
				m_Age   .Set_Value(x, y, CSG_Random::Get_Uniform(0.0, m_Shark_Birth ));
				m_Starve.Set_Value(x, y, CSG_Random::Get_Uniform(0.0, m_Shark_Starve));
				break;
			}
		}
	}

	//-----------------------------------------------------
	int		i;

	SG_UI_Progress_Lock(true);

	for(i=1; Process_Get_Okay(true) && Next_Cycle(); i++)
	{
		Process_Set_Text("%s: %d", _TL("Life Cycle"), i);

		CSG_Table_Record	*pRecord	= pTable->Add_Record();

		pRecord->Set_Value(0, i);
		pRecord->Set_Value(1, m_nFishes);
		pRecord->Set_Value(2, m_nSharks);

		DataObject_Update(m_pWator, 0, 2);
		DataObject_Update(pTable);
	}

	SG_UI_Progress_Lock(false);

	//-----------------------------------------------------
	m_Next  .Destroy();
	m_Age   .Destroy();
	m_Starve.Destroy();

	if( is_Progress() )
	{
		Message_Fmt("\n%s %d %s", _TL("Dead after"), i, _TL("Life Cycles"));
	}

	return( true );
}
コード例 #4
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 );
}
コード例 #5
0
//---------------------------------------------------------
CSG_Shape * CSG_PointCloud::_Set_Shape(int iPoint)
{
    SG_UI_Progress_Lock(true);

    CSG_Shape	*pShape	= m_Shapes.Get_Shape(0);

    if( pShape->is_Modified() && m_Shapes_Index >= 0 && m_Shapes_Index < Get_Count() )
    {
        m_Cursor	= m_Points[m_Shapes_Index];

        for(int i=0; i<Get_Field_Count(); i++)
        {
            switch( Get_Field_Type(i) )
            {
            default:
                Set_Value(i, pShape->asDouble(i));
                break;

            case SG_DATATYPE_Date:
            case SG_DATATYPE_String:
                Set_Value(i, pShape->asString(i));
                break;
            }
        }

        Set_Value(0, pShape->Get_Point(0).x);
        Set_Value(1, pShape->Get_Point(0).y);
        Set_Value(2, pShape->Get_Z    (0)  );
    }

    if( iPoint >= 0 && iPoint < Get_Count() )
    {
        if(1|| iPoint != m_Shapes_Index )
        {
            m_Cursor	= m_Points[iPoint];

            pShape->Set_Point(Get_X(), Get_Y(), 0, 0);
            pShape->Set_Z    (Get_Z()         , 0, 0);

            for(int i=0; i<Get_Field_Count(); i++)
            {
                switch( Get_Field_Type(i) )
                {
                default:
                    pShape->Set_Value(i, Get_Value(i));
                    break;

                case SG_DATATYPE_Date:
                case SG_DATATYPE_String:
                {
                    CSG_String	s;

                    Get_Value(i, s);

                    pShape->Set_Value(i, s);
                }
                break;
                }
            }

            m_Shapes_Index	= iPoint;
            pShape->m_Index	= iPoint;
            pShape->Set_Selected(is_Selected(iPoint));
        }

        m_Shapes.Set_Modified(false);

        SG_UI_Progress_Lock(false);

        return( pShape );
    }

    m_Shapes_Index	= -1;

    SG_UI_Progress_Lock(false);

    return( NULL );
}
コード例 #6
0
//---------------------------------------------------------
inline void CVIEW_Map_Control::_Set_StatusBar(CSG_Point ptWorld)
{
	static bool	bBuisy	= false;

	if( bBuisy == false )
	{
		bBuisy	= true;

		CSG_Tool	*pProjector	= NULL;

		if( m_pMap->Get_Parameter("GCS_POSITION")->asBool() && m_pMap->Get_Projection().is_Okay() && (pProjector = SG_Get_Tool_Library_Manager().Get_Tool("pj_proj4", 2)) != NULL )	// Coordinate Transformation (Shapes)
		{
			if( pProjector->is_Executing() )
			{
				pProjector	= NULL;
			}
			else
			{
				SG_UI_Progress_Lock(true);
				SG_UI_Msg_Lock     (true);

				CSG_Shapes	prj(SHAPE_TYPE_Point), gcs(SHAPE_TYPE_Point); prj.Add_Shape()->Add_Point(ptWorld); prj.Get_Projection().Assign(m_pMap->Get_Projection());

				pProjector->Settings_Push(NULL);

				if( pProjector->Set_Parameter("CRS_PROJ4", SG_T("+proj=longlat +ellps=WGS84 +datum=WGS84"))
				&&  pProjector->Set_Parameter("SOURCE"   , &prj)
				&&  pProjector->Set_Parameter("TARGET"   , &gcs)
				&&  pProjector->Execute() )
				{
					CSG_Point ptWorld_gcs	= gcs.Get_Shape(0)->Get_Point(0);

					STATUSBAR_Set_Text(wxString::Format("X %s", SG_Double_To_Degree(ptWorld_gcs.Get_X()).c_str()), STATUSBAR_VIEW_X);
					STATUSBAR_Set_Text(wxString::Format("Y %s", SG_Double_To_Degree(ptWorld_gcs.Get_Y()).c_str()), STATUSBAR_VIEW_Y);

					pProjector->Settings_Pop();
				}
				else
				{
					pProjector->Settings_Pop();		pProjector	= NULL;
				}

				SG_UI_Progress_Lock(false);
				SG_UI_Msg_Lock     (false);
			}
		}

		if( !pProjector )
		{
			STATUSBAR_Set_Text(wxString::Format("X %f", ptWorld.Get_X()), STATUSBAR_VIEW_X);
			STATUSBAR_Set_Text(wxString::Format("Y %f", ptWorld.Get_Y()), STATUSBAR_VIEW_Y);
		}

		if( m_Mode == MAP_MODE_DISTANCE )
		{
			STATUSBAR_Set_Text(wxString::Format("D %f", m_Distance + m_Distance_Move), STATUSBAR_VIEW_Z);
		}
		else if( Get_Active_Layer() )
		{
			STATUSBAR_Set_Text(wxString::Format("Z %s", Get_Active_Layer()->Get_Value(ptWorld, _Get_World(2.0)).c_str()), STATUSBAR_VIEW_Z);
		}
		else
		{
			STATUSBAR_Set_Text("Z", STATUSBAR_VIEW_Z);
		}

		bBuisy	= false;
	}
}