//---------------------------------------------------------
bool CGW_Regression_Grid::On_Execute(void)
{
	//-----------------------------------------------------
	m_pPredictor	= Parameters("PREDICTOR" )->asGrid  ();
	m_pRegression	= Parameters("REGRESSION")->asGrid  ();
	m_pQuality		= Parameters("QUALITY"   )->asGrid  ();
	m_pIntercept	= Parameters("INTERCEPT" )->asGrid  ();
	m_pSlope		= Parameters("SLOPE"     )->asGrid  ();
	m_pPoints		= Parameters("POINTS"    )->asShapes();
	m_iDependent	= Parameters("DEPENDENT" )->asInt   ();

	m_nPoints_Min	= Parameters("SEARCH_POINTS_MIN")->asInt   ();
	m_nPoints_Max	= Parameters("SEARCH_POINTS_ALL")->asInt   () == 0
					? Parameters("SEARCH_POINTS_MAX")->asInt   () : 0;
	m_Radius		= Parameters("SEARCH_RANGE"     )->asInt   () == 0
					? Parameters("SEARCH_RADIUS"    )->asDouble() : 0.0;
	m_Direction		= Parameters("SEARCH_DIRECTION" )->asInt   () == 0 ? -1 : 4;

	m_Weighting.Set_Parameters(Parameters("WEIGHTING")->asParameters());

	//-----------------------------------------------------
	if( (m_nPoints_Max > 0 || m_Radius > 0.0) && !m_Search.Create(m_pPoints, -1) )
	{
		return( false );
	}

	//-----------------------------------------------------
	GRID_INIT(m_pRegression, _TL("GWR Regression"));
	GRID_INIT(m_pQuality   , _TL("GWR Quality"));
	GRID_INIT(m_pIntercept , _TL("GWR Intercept"));
	GRID_INIT(m_pSlope     , _TL("GWR Slope"));

	//-----------------------------------------------------
	int	nPoints_Max	= m_nPoints_Max > 0 ? m_nPoints_Max : m_pPoints->Get_Count();

	m_y.Create(nPoints_Max);
	m_z.Create(nPoints_Max);
	m_w.Create(nPoints_Max);

	//-----------------------------------------------------
	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		for(int x=0; x<Get_NX(); x++)
		{
			if( m_pPredictor->is_NoData(x, y) || !Get_Regression(x, y) )
			{
				GRID_SET_NODATA(m_pRegression , x, y);
				GRID_SET_NODATA(m_pIntercept  , x, y);
				GRID_SET_NODATA(m_pSlope      , x, y);
				GRID_SET_NODATA(m_pQuality    , x, y);
			}
		}
	}

	//-----------------------------------------------------
	Set_Residuals();

	m_y.Destroy();
	m_z.Destroy();
	m_w.Destroy();

	m_Search.Destroy();

	DataObject_Update(m_pIntercept);
	DataObject_Update(m_pSlope);
	DataObject_Update(m_pQuality);

	return( true );
}
//---------------------------------------------------------
bool CPoint_Trend_Surface::On_Execute(void)
{
	int			iAttribute;
	CSG_Shapes	*pPoints, *pResiduals;
	CSG_Grid	*pRegression;

	//-----------------------------------------------------
	pPoints		= Parameters("POINTS")		->asShapes();
	pResiduals	= Parameters("RESIDUALS")	->asShapes();
	iAttribute	= Parameters("ATTRIBUTE")	->asInt();

	switch( Parameters("POLYNOM")->asInt() )
	{
	case 0:	m_xOrder = 1; m_yOrder = 1; m_tOrder = 1;	break;	// simple planar surface	// a + bx + cy
	case 1:	m_xOrder = 1; m_yOrder = 1; m_tOrder = 2;	break;	// bi-linear saddle"),		// a + bx + cy + dxy
	case 2:	m_xOrder = 2; m_yOrder = 2; m_tOrder = 2;	break;	// quadratic surface"),		// a + bx + cy + dxy + ex2 + fy2
	case 3:	m_xOrder = 3; m_yOrder = 3; m_tOrder = 3;	break;	// cubic surface"),			// a + bx + cy + dxy + ex2 + fy2 + gx2y + hxy2 + ix3 + iy3
	case 4:
		m_xOrder	= Parameters("XORDER")->asInt();
		m_yOrder	= Parameters("YORDER")->asInt();
		m_tOrder	= Parameters("TORDER")->asInt();
		break;
	}

	//-----------------------------------------------------
	if( !Get_Regression(pPoints, iAttribute) )
	{
		return( false );
	}

	Set_Message();

	//-----------------------------------------------------
	pRegression		= NULL;

	switch( Parameters("TARGET")->asInt() )
	{
	case 0:	// user defined...
		if( m_Grid_Target.Init_User(pPoints->Get_Extent()) && Dlg_Parameters("USER") )
		{
			pRegression	= m_Grid_Target.Get_User();
		}
		break;

	case 1:	// grid...
		if( Dlg_Parameters("GRID") )
		{
			pRegression	= m_Grid_Target.Get_Grid();
		}
		break;
	}

	if( pRegression == NULL )
	{
		return( false );
	}

	//-----------------------------------------------------
	pRegression->Set_Name(CSG_String::Format(SG_T("%s [%s]"), Parameters("ATTRIBUTE")->asString(), _TL("Trend Surface")));

	Set_Regression(pRegression);

	Set_Residuals(pPoints, iAttribute, pResiduals, pRegression);

	m_Coefficients.Destroy();

	return( true );
}
Exemple #3
0
//---------------------------------------------------------
bool CGW_Regression::On_Execute(void)
{
	//-----------------------------------------------------
	m_pPoints		= Parameters("POINTS")		->asShapes();
	m_iDependent	= Parameters("DEPENDENT")	->asInt();
	m_iPredictor	= Parameters("PREDICTOR")	->asInt();
	m_Radius		= Parameters("RANGE")		->asInt() == 0 ? Parameters("RADIUS")   ->asDouble() : 0.0;
	m_Mode			= Parameters("MODE")		->asInt();
	m_nPoints_Max	= Parameters("NPOINTS")		->asInt() == 0 ? Parameters("MAXPOINTS")->asInt()    : 0;
	m_nPoints_Min	= Parameters("MINPOINTS")	->asInt();

	m_Weighting.Set_Parameters(Parameters("WEIGHTING")->asParameters());

	//-----------------------------------------------------
	if( (m_nPoints_Max > 0 || m_Radius > 0.0) && !m_Search.Create(m_pPoints, -1) )
	{
		return( false );
	}

	//-----------------------------------------------------
	m_pIntercept	= NULL;
	m_pSlope		= NULL;
	m_pQuality		= NULL;

	switch( Parameters("TARGET")->asInt() )
	{
	case 0:	// user defined...
		if( m_Grid_Target.Init_User(m_pPoints->Get_Extent()) && Dlg_Parameters("USER") )
		{
			m_pIntercept	= m_Grid_Target.Get_User(SG_T("INTERCEPT"));
			m_pSlope		= m_Grid_Target.Get_User(SG_T("SLOPE"));
			m_pQuality		= m_Grid_Target.Get_User(SG_T("QUALITY"));
		}
		break;

	case 1:	// grid...
		if( Dlg_Parameters("GRID") )
		{
			m_pIntercept	= m_Grid_Target.Get_Grid(SG_T("INTERCEPT"));
			m_pSlope		= m_Grid_Target.Get_Grid(SG_T("SLOPE"));
			m_pQuality		= m_Grid_Target.Get_Grid(SG_T("QUALITY"));
		}
		break;
	}

	if( m_pIntercept == NULL )
	{
		m_Search.Destroy();

		return( false );
	}

	m_pIntercept->Set_Name(CSG_String::Format(SG_T("%s (%s)"), m_pPoints->Get_Name(), _TL("GWR Intercept")));
	m_pSlope    ->Set_Name(CSG_String::Format(SG_T("%s (%s)"), m_pPoints->Get_Name(), _TL("GWR Slope")));
	m_pQuality  ->Set_Name(CSG_String::Format(SG_T("%s (%s)"), m_pPoints->Get_Name(), _TL("GWR Quality")));

	//-----------------------------------------------------
	int	nPoints_Max	= m_nPoints_Max > 0 ? m_nPoints_Max : m_pPoints->Get_Count();

	m_y.Create(nPoints_Max);
	m_z.Create(nPoints_Max);
	m_w.Create(nPoints_Max);

	//-----------------------------------------------------
	for(int y=0; y<m_pIntercept->Get_NY() && Set_Progress(y, m_pIntercept->Get_NY()); y++)
	{
		for(int x=0; x<m_pIntercept->Get_NX(); x++)
		{
			if( !Get_Regression(x, y) )
			{
				m_pIntercept->Set_NoData(x, y);
				m_pSlope    ->Set_NoData(x, y);
				m_pQuality  ->Set_NoData(x, y);
			}
		}
	}

	//-----------------------------------------------------
	m_y.Destroy();
	m_z.Destroy();
	m_w.Destroy();

	m_Search.Destroy();

	DataObject_Update(m_pIntercept);
	DataObject_Update(m_pSlope);
	DataObject_Update(m_pQuality);

	return( true );
}
//---------------------------------------------------------
bool CGW_Multi_Regression::On_Execute(void)
{
	int		i;

	//-----------------------------------------------------
	m_pPoints		= Parameters("POINTS")		->asShapes();
	m_iDependent	= Parameters("DEPENDENT")	->asInt();
	m_Radius		= Parameters("RANGE")		->asInt() == 0 ? Parameters("RADIUS")   ->asDouble() : 0.0;
	m_Mode			= Parameters("MODE")		->asInt();
	m_nPoints_Max	= Parameters("NPOINTS")		->asInt() == 0 ? Parameters("MAXPOINTS")->asInt()    : 0;
	m_nPoints_Min	= Parameters("MINPOINTS")	->asInt();

	m_Weighting.Set_Parameters(Parameters("WEIGHTING")->asParameters());

	//-----------------------------------------------------
	if( !Get_Predictors() )
	{
		Finalize();

		return( false );
	}

	if( (m_nPoints_Max > 0 || m_Radius > 0.0) && !m_Search.Create(m_pPoints, -1) )
	{
		Finalize();

		return( false );
	}

	//-----------------------------------------------------
	m_pQuality		= NULL;
	m_pIntercept	= NULL;
	m_pSlopes		= (CSG_Grid **)SG_Calloc(m_nPredictors, sizeof(CSG_Grid *));

	switch( Parameters("TARGET")->asInt() )
	{
	case 0:	// user defined...
		if( m_Grid_Target.Init_User(m_pPoints->Get_Extent()) && Dlg_Parameters("USER") )
		{
			m_pQuality		= m_Grid_Target.Get_User(SG_T("QUALITY"  ));
			m_pIntercept	= m_Grid_Target.Get_User(SG_T("INTERCEPT"));

			for(i=0; i<m_nPredictors; i++)
			{
				m_pSlopes[i]	= m_Grid_Target.Get_User(SG_Get_String(i, 0));
			}
		}
		break;

	case 1:	// grid...
		if( Dlg_Parameters("GRID") )
		{
			m_pQuality		= m_Grid_Target.Get_Grid(SG_T("QUALITY"  ));
			m_pIntercept	= m_Grid_Target.Get_Grid(SG_T("INTERCEPT"));

			for(i=0; i<m_nPredictors; i++)
			{
				m_pSlopes[i]	= m_Grid_Target.Get_Grid(SG_Get_String(i, 0));
			}
		}
		break;
	}

	if( m_pQuality == NULL )
	{
		Finalize();

		return( false );
	}

	m_pQuality  ->Set_Name(CSG_String::Format(SG_T("%s (%s)"), m_pPoints->Get_Name(), _TL("GWR Quality")));
	m_pIntercept->Set_Name(CSG_String::Format(SG_T("%s (%s)"), m_pPoints->Get_Name(), _TL("GWR Intercept")));

	for(i=0; i<m_nPredictors; i++)
	{
		m_pSlopes[i]->Set_Name(CSG_String::Format(SG_T("%s (%s)"), m_pPoints->Get_Name(), m_pPoints->Get_Field_Name(m_iPredictor[i])));
	}

	//-----------------------------------------------------
	int	nPoints_Max	= m_nPoints_Max > 0 ? m_nPoints_Max : m_pPoints->Get_Count();

	m_y.Create(1 + m_nPredictors, nPoints_Max);
	m_z.Create(nPoints_Max);
	m_w.Create(nPoints_Max);

	//-----------------------------------------------------
	for(int y=0; y<m_pIntercept->Get_NY() && Set_Progress(y, m_pIntercept->Get_NY()); y++)
	{
		for(int x=0; x<m_pIntercept->Get_NX(); x++)
		{
			if( !Get_Regression(x, y) )
			{
				m_pQuality  ->Set_NoData(x, y);
				m_pIntercept->Set_NoData(x, y);

				for(i=0; i<m_nPredictors; i++)
				{
					m_pSlopes[i]->Set_NoData(x, y);
				}
			}
		}
	}

	//-----------------------------------------------------
	Finalize();

	return( true );
}