コード例 #1
0
//---------------------------------------------------------
bool CWKSP_Shapes::_Edit_Split(void)
{
    if( Get_Shapes()->Get_Type() == SHAPE_TYPE_Polygon
            ||  Get_Shapes()->Get_Type() == SHAPE_TYPE_Line )
    {
        switch( m_Edit_Mode )
        {
        default:
            break;

        //-------------------------------------------------
        case EDIT_SHAPE_MODE_Normal:
            m_Edit_Mode	= EDIT_SHAPE_MODE_Split;

            if( m_Edit_Shapes.Get_Count() == 0 )
            {
                m_Edit_Shapes.Add_Shape(Get_Shapes()->Get_Selection());
            }

            if( m_Edit_Shapes.Get_Count() > 1 )
            {
                m_Edit_Shapes.Get_Shape(1)->Del_Parts();
            }
            else
            {
                m_Edit_Shapes.Add_Shape();
            }

            return( true );

        //-------------------------------------------------
        case EDIT_SHAPE_MODE_Split:
            m_Edit_Mode	= EDIT_SHAPE_MODE_Normal;

            CSG_Tool	*pTool	= Get_Shapes()->Get_Type() == SHAPE_TYPE_Polygon
                                  ?	SG_Get_Tool_Library_Manager().Get_Tool(SG_T("shapes_polygons"), 8)	// Polygon-Line Intersection
                                  :	SG_Get_Tool_Library_Manager().Get_Tool(SG_T("shapes_lines"   ), 6); // Split Lines with Lines

            if(	pTool )
            {
                CSG_Shapes	Line(SHAPE_TYPE_Line), Split(Get_Shapes()->Get_Type());

                Line.Add_Shape();

                for(int i=0; i<m_Edit_Shapes.Get_Shape(1)->Get_Point_Count(); i++)
                {
                    Line.Get_Shape(0)->Add_Point(m_Edit_Shapes.Get_Shape(1)->Get_Point(i));
                }

                m_Edit_Shapes.Del_Shape(1);

                //-----------------------------------------
                bool	bResult;

                CSG_Parameters	P;
                P.Assign(pTool->Get_Parameters());

                pTool->Set_Manager(NULL);

                if( Get_Shapes()->Get_Type() == SHAPE_TYPE_Polygon )
                {
                    bResult	= pTool->Get_Parameters()->Set_Parameter("POLYGONS" , &m_Edit_Shapes)
                              &&    pTool->Get_Parameters()->Set_Parameter("LINES"    , &Line)
                              &&    pTool->Get_Parameters()->Set_Parameter("INTERSECT", &Split)
                              &&    pTool->Execute();
                }
                else //	if( Get_Shapes()->Get_Type() == SHAPE_TYPE_Line )
                {
                    bResult	= pTool->Get_Parameters()->Set_Parameter("LINES"    , &m_Edit_Shapes)
                              &&    pTool->Get_Parameters()->Set_Parameter("SPLIT"    , &Line)
                              &&    pTool->Get_Parameters()->Set_Parameter("INTERSECT", &Split)
                              &&    pTool->Execute();
                }

                //-----------------------------------------
                if( bResult )
                {
                    if( m_Edit_pShape )
                    {
                        m_Edit_pShape->Assign(Split.Get_Shape(0), false);

                        for(int iSplit=1; iSplit<Split.Get_Count(); iSplit++)
                        {
                            CSG_Shape	*pSplit	= Split.Get_Shape(iSplit);

                            for(int iPart=0; iPart<pSplit->Get_Part_Count(); iPart++)
                            {
                                for(int iPoint=0, jPart=m_Edit_pShape->Get_Part_Count(); iPoint<pSplit->Get_Point_Count(iPart); iPoint++)
                                {
                                    m_Edit_pShape->Add_Point(pSplit->Get_Point(iPoint, iPart), jPart);
                                }
                            }
                        }
                    }
                    else if( Get_Shapes()->Get_Selection_Count() == 1 ) // if( !m_Edit_pShape )
                    {
                        CSG_Shape	*pSelection	= Get_Shapes()->Get_Selection();

                        pSelection->Assign(Split.Get_Shape(0), false);

                        for(int iSplit=1; iSplit<Split.Get_Count(); iSplit++)
                        {
                            CSG_Shape	*pSplit	= Get_Shapes()->Add_Shape(Split.Get_Shape(iSplit));

                            ((CSG_Table_Record *)pSplit)->Assign(pSelection);

                            Get_Shapes()->Select(pSplit, true);
                        }

                        m_Edit_Shapes.Del_Shapes();
                    }
                }

                pTool->Get_Parameters()->Assign_Values(&P);
                pTool->Set_Manager(P.Get_Manager());
            }

            Update_Views(false);

            return( true );
        }
    }

    return( false );
}
コード例 #2
0
//---------------------------------------------------------
bool CKriging_Regression::On_Execute(void)
{
	//-----------------------------------------------------
	CSG_Shapes	Points(SHAPE_TYPE_Point);

	CSG_Grid	*pPrediction	= Parameters("PREDICTION")->asGrid();
	CSG_Grid	*pRegression	= Parameters("REGRESSION")->asGrid();
	CSG_Grid	*pResiduals		= Parameters("RESIDUALS" )->asGrid();
	CSG_Grid	*pVariance		= Parameters("VARIANCE"  )->asGrid();

	//-----------------------------------------------------
	if( !pResiduals )
	{
		pResiduals	= pPrediction;
	}

	//-----------------------------------------------------
	SG_RUN_TOOL_ExitOnError("statistics_regression", 1,	// Multiple Regression Analysis (Points and Predictor Grids)
			SG_TOOL_PARAMETER_SET("PREDICTORS", Parameters("PREDICTORS"))
		&&	SG_TOOL_PARAMETER_SET("POINTS"    , Parameters("POINTS"    ))
		&&	SG_TOOL_PARAMETER_SET("ATTRIBUTE" , Parameters("FIELD"     ))
		&&	SG_TOOL_PARAMETER_SET("INFO_COEFF", Parameters("INFO_COEFF"))
		&&	SG_TOOL_PARAMETER_SET("INFO_MODEL", Parameters("INFO_MODEL"))
		&&	SG_TOOL_PARAMETER_SET("INFO_STEPS", Parameters("INFO_STEPS"))
		&&	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"   ))
		&&	SG_TOOL_PARAMETER_SET("REGRESSION", pRegression)
		&&	SG_TOOL_PARAMETER_SET("RESIDUALS" , &Points )
	);

	//-----------------------------------------------------
	CSG_Tool	*pK	= Parameters("KRIGING")->asInt() == 0 ? (CSG_Tool *)&m_SK : (CSG_Tool *)&m_OK;

	Process_Set_Text(pK->Get_Name());

	pK->Set_Manager(NULL);

	if( !pK->Set_Parameter("POINTS"           , &Points)
	||  !pK->Set_Parameter("FIELD"            , 2)	// residual
	||  !pK->Set_Parameter("LOG"              , Parameters("LOG"              ))
	||  !pK->Set_Parameter("BLOCK"            , Parameters("BLOCK"            ))
	||  !pK->Set_Parameter("DBLOCK"           , Parameters("DBLOCK"           ))
	||  !pK->Set_Parameter("SEARCH_RANGE"     , Parameters("SEARCH_RANGE"     ))
	||  !pK->Set_Parameter("SEARCH_RADIUS"    , Parameters("SEARCH_RADIUS"    ))
	||  !pK->Set_Parameter("SEARCH_POINTS_ALL", Parameters("SEARCH_POINTS_ALL"))
	||  !pK->Set_Parameter("SEARCH_POINTS_MIN", Parameters("SEARCH_POINTS_MIN"))
	||  !pK->Set_Parameter("SEARCH_POINTS_MAX", Parameters("SEARCH_POINTS_MAX"))
	||  !pK->Set_Parameter("SEARCH_DIRECTION" , Parameters("SEARCH_DIRECTION" ))
	||  !pK->Set_Parameter("TARGET_DEFINITION", 1)	// grid or grid system
	||  !pK->Set_Parameter("PREDICTION"       , pResiduals)
	||  !pK->Set_Parameter("VARIANCE"         , pVariance )

	|| (!SG_UI_Get_Window_Main() && (	// saga_cmd
	    !pK->Set_Parameter("VAR_MAXDIST"      , Parameters("VAR_MAXDIST"      ))
	||  !pK->Set_Parameter("VAR_NCLASSES"     , Parameters("VAR_NCLASSES"     ))
	||  !pK->Set_Parameter("VAR_NSKIP"        , Parameters("VAR_NSKIP"        ))
	||  !pK->Set_Parameter("VAR_MODEL"        , Parameters("VAR_MODEL"        )))) )
	{
		Error_Set(CSG_String::Format("%s [%s].[%s]", _TL("could not initialize tool"), _TL("statistics_regression"), pK->Get_Name().c_str()));

		return( false );
	}

	if( !pK->Execute() )
	{
		Error_Set(CSG_String::Format("%s [%s].[%s]", _TL("could not execute tool"   ), _TL("statistics_regression"), pK->Get_Name().c_str()));

		return( false );
	}

	//-----------------------------------------------------
	#pragma omp parallel for
	for(int y=0; y<Get_NY(); y++)
	{
		for(int x=0; x<Get_NX(); x++)
		{
			if( pRegression->is_NoData(x, y) || pResiduals->is_NoData(x, y) )
			{
				pPrediction->Set_NoData(x, y);
			}
			else
			{
				pPrediction->Set_Value(x, y, pRegression->asDouble(x, y) + pResiduals->asDouble(x, y));
			}
		}
	}

	//-----------------------------------------------------
	pRegression->Fmt_Name("%s.%s [%s]", Parameters("POINTS")->asShapes()->Get_Name(), Parameters("FIELD")->asString(), _TL("Regression"));
	pPrediction->Fmt_Name("%s.%s [%s]", Parameters("POINTS")->asShapes()->Get_Name(), Parameters("FIELD")->asString(), _TL("Prediction"));

	if( Parameters("RESIDUALS")->asGrid() )
	{
		pResiduals->Fmt_Name("%s.%s [%s]", Parameters("POINTS")->asShapes()->Get_Name(), Parameters("FIELD")->asString(), _TL("Residuals"));
	}

	if( pVariance )
	{
		pVariance ->Fmt_Name("%s.%s [%s]", Parameters("POINTS")->asShapes()->Get_Name(), Parameters("FIELD")->asString(), _TL("Quality"));
	}

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