Example #1
0
bool CCreateChartLayer::GetExtraParameters(){

	int i;
	CSG_Shapes *pInput;
	CSG_Parameter *pParam;
	CSG_String sName;
	bool bIsValidSelection = false;

	pInput = Parameters("INPUT")->asShapes();

	m_pExtraParameters->Create(this, _TL("Fields for diagram"), _TL(""), SG_T("EXTRA"));

	m_bIncludeParam = new bool [pInput->Get_Field_Count() ];

	for (i = 0; i < pInput->Get_Field_Count(); i++)
	{
		switch( pInput->Get_Field_Type(i) )
		{
		default:
			break;

		case SG_DATATYPE_Byte:
		case SG_DATATYPE_Char:
		case SG_DATATYPE_Word:
		case SG_DATATYPE_Short:
		case SG_DATATYPE_DWord:
		case SG_DATATYPE_Int:
		case SG_DATATYPE_ULong:
		case SG_DATATYPE_Long:
		case SG_DATATYPE_Float:
		case SG_DATATYPE_Double:	// is numeric field
			m_pExtraParameters->Add_Value(
				NULL, SG_Get_String(i,0).c_str(), pInput->Get_Field_Name(i), _TL(""), PARAMETER_TYPE_Bool, false
			);
			break;
		}
	}//for

	if(Dlg_Parameters("EXTRA")){
		for (i = 0; i < pInput->Get_Field_Count(); i++){
			sName = SG_Get_String(i,0);
			if (pParam = Get_Parameters("EXTRA")->Get_Parameter(sName.c_str())){
				m_bIncludeParam[i] = pParam->asBool();
				bIsValidSelection = true;
			}//try
			else{
				m_bIncludeParam[i] = false;
			}//else
		}//for

		m_pExtraParameters->Destroy();

		return bIsValidSelection;
	}//if

	m_pExtraParameters->Destroy();

	return false;

}//method
Example #2
0
void CSG_Doc_SVG::Draw_Polygon(CSG_Points &Points, 
							  int Fill_Color, 
							  int Line_Color, 
							  double Line_Width)
{
	if( Points.Get_Count() > 2 )
	{
		int i;
		CSG_String sPoints;
		CSG_String sWidth;
		
		for (i = 0; i < Points.Get_Count(); i++)
		{
			sPoints.Append(SG_Get_String(Points.Get_X(i),2));
			sPoints.Append(SG_T(","));
			sPoints.Append(SG_Get_String(Points.Get_Y(i),2));
			sPoints.Append(SG_T(" "));
		}
		m_sSVGCode.Append(SG_T("<polygon "));
		_AddAttribute(SG_T("points"), sPoints);
		sWidth.Append(SG_Get_String(Line_Width,2));
		sWidth.Append(g_Unit);
		_AddAttribute(SG_T("stroke-width"), sWidth);				
		_AddAttribute(SG_T("stroke"), _Get_SVGColor(Line_Color));
		_AddAttribute(SG_T("fill"), _Get_SVGColor(Fill_Color));
		m_sSVGCode.Append(SG_T("/>\n"));
	}
}
Example #3
0
void CSG_Doc_SVG::Draw_LinkedPolygon(CSG_Points &Points, 
							  const SG_Char* Link,
							  int Fill_Color, 
							  int Line_Color, 
							  double Line_Width)
{
	if( Points.Get_Count() > 2 )
	{
		int i;
		CSG_String sPoints;
		CSG_String sWidth;
		CSG_String sLink;
		
		for (i = 0; i < Points.Get_Count(); i++)
		{
			sPoints.Append(SG_Get_String(Points.Get_X(i),2));
			sPoints.Append(SG_T(","));
			sPoints.Append(SG_Get_String(Points.Get_Y(i),2));
			sPoints.Append(SG_T(" "));
		}
		m_sSVGCode.Append(SG_T("<polygon "));
		_AddAttribute(SG_T("points"), sPoints);
		sWidth.Append(SG_Get_String(Line_Width,2));
		sWidth.Append(g_Unit);
		_AddAttribute(SG_T("stroke-width"), sWidth);				
		_AddAttribute(SG_T("stroke"), _Get_SVGColor(Line_Color));
		_AddAttribute(SG_T("fill"), _Get_SVGColor(Fill_Color));
		sLink = SG_T("window.open('");
		sLink.Append(Link);
		sLink.Append(SG_T("')"));
		_AddAttribute(SG_T("onclick"), sLink);
		m_sSVGCode.Append(SG_T("/>\n"));
	}
}
//---------------------------------------------------------
void CActive_Attributes_Control::On_Field_Del(wxCommandEvent &event)
{
	if( !g_pActive->Get_Active_Data_Item() || g_pActive->Get_Active_Data_Item()->Get_Type() != WKSP_ITEM_Grids )	{	return;	}

	CSG_Grids	*pGrids	= ((CWKSP_Grids *)g_pActive->Get_Active_Data_Item())->Get_Grids();

	//-----------------------------------------------------
	int				i;
	CSG_Parameters	P;

	//-----------------------------------------------------
	P.Set_Name(_TL("Delete Fields"));

	for(i=0; i<m_pTable->Get_Field_Count(); i++)
	{
		P.Add_Value(NULL, SG_Get_String(i), m_pTable->Get_Field_Name(i), _TL(""), PARAMETER_TYPE_Bool, false);
	}

	//-----------------------------------------------------
	if( DLG_Parameters(&P) )
	{
		for(i=m_pTable->Get_Field_Count()-1; i>=0; i--)
		{
			if( P(SG_Get_String(i))->asBool() )
			{
				pGrids->Get_Attributes_Ptr()->Del_Field(i);

				DeleteCols(i);
			}
		}

		g_pData->Update(pGrids, NULL);
	}
}
Example #5
0
void CSG_Doc_SVG::Draw_Line(CSG_Points &Points, 
						   double Width, 
						   int Color)
{
	int i;
	CSG_String sPoints;
	CSG_String sWidth;
	
	for (i = 0; i < Points.Get_Count(); i++)
	{
		sPoints.Append(SG_Get_String(Points.Get_X(i),2));
		sPoints.Append(SG_T(","));
		sPoints.Append(SG_Get_String(Points.Get_Y(i),2));
		sPoints.Append(SG_T(" "));
	}
	m_sSVGCode.Append(SG_T("<polyline "));
	_AddAttribute(SG_T("points"), sPoints);	
	sWidth.Append(SG_Get_String(Width,2));
	sWidth.Append(g_Unit);
	_AddAttribute(SG_T("stroke-width"), sWidth);
	_AddAttribute(SG_T("stroke"), _Get_SVGColor(Color));
	_AddAttribute(SG_T("fill"), SG_T("none"));
	m_sSVGCode.Append(SG_T("/>\n"));

}
//---------------------------------------------------------
void CVIEW_Table_Control::On_Field_Del(wxCommandEvent &event)
{
	int				i;
	CSG_Parameters	P;

	//-----------------------------------------------------
	P.Set_Name(_TL("Delete Fields"));

	for(i=0; i<m_pTable->Get_Field_Count(); i++)
	{
		P.Add_Value(NULL, SG_Get_String(i, 0), m_pTable->Get_Field_Name(i), _TL(""), PARAMETER_TYPE_Bool, false);
	}

	//-----------------------------------------------------
	if( DLG_Parameters(&P) )
	{
		for(i=m_pTable->Get_Field_Count()-1; i>=0; i--)
		{
			if( P(SG_Get_String(i, 0))->asBool() )
			{
				m_pTable->Del_Field(i);

				DeleteCols(i);
			}
		}

		g_pData->Update(m_pTable, NULL);
	}
}
Example #7
0
void CSG_Doc_SVG::Open(int iWidth, int iHeight)
{

	m_sSVGCode.Append(SVG_CODE_OPENING_1);
	m_sSVGCode.Append(SG_Get_String(iWidth,0));
	m_sSVGCode.Append(SG_T("\" height=\""));
	m_sSVGCode.Append(SG_Get_String(iHeight,0));
	m_sSVGCode.Append(SVG_CODE_OPENING_2);

	m_iWidth = iWidth;
	m_iHeight = iHeight;

}
Example #8
0
void CSG_Doc_SVG::Draw_LinkedCircle(double x, 
								 double y, 
								 double Radius, 
								 const SG_Char *Link,
								 int Fill_Color, 
								 int Line_Color, 
								 double Line_Width)
{
	
	CSG_String sWidth;
	CSG_String sLink;

	m_sSVGCode.Append(SG_T("<circle "));
	_AddAttribute(SG_T("cx"), x);
	_AddAttribute(SG_T("cy"), y);
	_AddAttribute(SG_T("r"), Radius);
	sWidth.Append(SG_Get_String(Line_Width,2));
	sWidth.Append(g_Unit);
	_AddAttribute(SG_T("stroke-width"), sWidth);
	_AddAttribute(SG_T("stroke"), _Get_SVGColor(Line_Color));
	_AddAttribute(SG_T("fill"), _Get_SVGColor(Fill_Color));
	sLink = SG_T("window.open('");
	sLink.Append(Link);
	sLink.Append(SG_T("')"));
	_AddAttribute(SG_T("onclick"), sLink);
	m_sSVGCode.Append(SG_T("/>\n"));

}
Example #9
0
void CSG_Doc_SVG::_AddAttribute(const SG_Char *Attribute, 
							   double dValue)
{

	_AddAttribute(Attribute, SG_Get_String(dValue, 2));

}
//---------------------------------------------------------
void CActive_Attributes_Control::On_Field_Rename(wxCommandEvent &event)
{
	if( !g_pActive->Get_Active_Data_Item() || g_pActive->Get_Active_Data_Item()->Get_Type() != WKSP_ITEM_Grids )	{	return;	}

	CSG_Grids	*pGrids	= ((CWKSP_Grids *)g_pActive->Get_Active_Data_Item())->Get_Grids();

	//-----------------------------------------------------
	int				i;
	CSG_Parameters	P;

	P.Set_Name(_TL("Rename Fields"));

	for(i=0; i<m_pTable->Get_Field_Count(); i++)
	{
		P.Add_String(NULL, SG_Get_String(i), m_pTable->Get_Field_Name(i), _TL(""), m_pTable->Get_Field_Name(i));
	}

	//-----------------------------------------------------
	if( DLG_Parameters(&P) )
	{
		for(i=0; i<m_pTable->Get_Field_Count(); i++)
		{
			CSG_String	s(P(i)->asString());

			if( s.Length() > 0 && s.Cmp(m_pTable->Get_Field_Name(i)) )
			{
				pGrids->Get_Attributes_Ptr()->Set_Field_Name(i, s);

				SetColLabelValue(i, s.c_str());
			}
		}

		g_pData->Update(pGrids, NULL);
	}
}
Example #11
0
void CSG_Doc_SVG::Draw_Text(double x, 
						 double y, 
						 const SG_Char *Text, 
						 int Color, 
						 const SG_Char* Font, 
						 double dSize,
						 TSG_SVG_Alignment iAlignment)
{

	CSG_String sAlignments[] = {SG_T(""), SG_T("middle"), SG_T("end")};
	CSG_String sSize;
	
	sSize.Append(SG_Get_String(dSize,2));
	sSize.Append(g_Unit);
	
	m_sSVGCode.Append(SG_T("<text "));
	_AddAttribute(SG_T("x"), x);	
	_AddAttribute(SG_T("y"), y);
	_AddAttribute(SG_T("font-family"), Font);
	_AddAttribute(SG_T("fill"), _Get_SVGColor(Color));
	_AddAttribute(SG_T("font-size"), sSize);
	_AddAttribute(SG_T("text-anchor"), sAlignments[iAlignment]);
	m_sSVGCode.Append(SG_T(">\n"));
	m_sSVGCode.Append(Text);
	m_sSVGCode.Append(SG_T("</text>"));

}
Example #12
0
//---------------------------------------------------------
bool CGW_Multi_Regression::Get_Predictors(void)
{
	int				i;
	CSG_Shapes		*pPoints		= Parameters("POINTS")		->asShapes();
	CSG_Parameters	*pAttributes	= Parameters("PREDICTORS")	->asParameters();

	m_nPredictors	= 0;
	m_iPredictor	= new int[pPoints->Get_Field_Count()];

	for(i=0; i<pAttributes->Get_Count(); i++)
	{
		if( pAttributes->Get_Parameter(i)->asBool() )
		{
			m_iPredictor[m_nPredictors++]	= CSG_String(pAttributes->Get_Parameter(i)->Get_Identifier()).asInt();
		}
	}

	CSG_Parameters	*pGrids	= Get_Parameters("GRID"), Tmp;

	Tmp.Assign(pGrids);

	pGrids->Create(this, Tmp.Get_Name(), Tmp.Get_Description(), Tmp.Get_Identifier(), false);
	m_Grid_Target.Add_Grid_Parameter(SG_T("QUALITY")   , _TL("Quality")  , false);
	m_Grid_Target.Add_Grid_Parameter(SG_T("INTERCEPT") , _TL("Intercept"), false);

	pGrids->Get_Parameter("QUALITY")->Get_Parent()->asGrid_System()->Assign(*Tmp("QUALITY")->Get_Parent()->asGrid_System());
	pGrids->Get_Parameter("QUALITY")  ->Set_Value(Tmp("QUALITY")  ->asGrid());
	pGrids->Get_Parameter("INTERCEPT")->Set_Value(Tmp("INTERCEPT")->asGrid());

	for(i=0; i<m_nPredictors; i++)
	{
		m_Grid_Target.Add_Grid_Parameter(SG_Get_String(i, 0),
			CSG_String::Format(SG_T("%s [%s]"), _TL("Slope"), pPoints->Get_Field_Name(m_iPredictor[i])), false
		);

		if( Tmp(SG_Get_String(i, 0)) )
		{
			pGrids->Get_Parameter(SG_Get_String(i, 0))->Set_Value(Tmp(SG_Get_String(i, 0))->asGrid());
		}
	}

	return( m_nPredictors > 0 );
}
Example #13
0
CSG_String CSG_Doc_SVG::_Get_SVGColor(int iColor)
{

	CSG_String s;

	if (iColor == SG_COLOR_NONE)
	{
		return SG_T("none");
	}
	else if (iColor == SG_COLOR_RANDOM)
	{
		s.Append(SG_T("rgb("));
		s.Append(SG_Get_String((int)(255.0 * (double)rand() / (double)RAND_MAX),0));
		s.Append(SG_T(","));
		s.Append(SG_Get_String((int)(255.0 * (double)rand() / (double)RAND_MAX),0));
		s.Append(SG_T(","));
		s.Append(SG_Get_String((int)(255.0 * (double)rand() / (double)RAND_MAX),0));
		s.Append(SG_T(")"));

		return s;
	}
	else
	{
		s.Append(SG_T("rgb("));
		s.Append(SG_Get_String(SG_GET_R(iColor),0));
		s.Append(SG_T(","));
		s.Append(SG_Get_String(SG_GET_G(iColor),0));
		s.Append(SG_T(","));
		s.Append(SG_Get_String(SG_GET_B(iColor),0));
		s.Append(SG_T(")"));

		return s;
	}

}
Example #14
0
//---------------------------------------------------------
bool		DLG_Table_Fields(const wxString &Caption, CSG_Parameter_Table_Fields *pFields)
{
	CSG_Table	*pTable	= pFields->Get_Table();

	if( pTable )
	{
		int				i;
		CSG_Parameters	P;

		for(i=0; i<pTable->Get_Field_Count(); i++)
		{
			P.Add_Value(NULL, SG_Get_String(i), pTable->Get_Field_Name(i), _TL(""), PARAMETER_TYPE_Bool, false);
		}

		for(i=0; i<pFields->Get_Count(); i++)
		{
			CSG_Parameter	*pParameter	= P(pFields->Get_Index(i));

			if( pParameter )
			{
				pParameter->Set_Value(true);
			}
		}

		if( DLG_Parameters(&P) )
		{
			CSG_String	s;

			for(i=0; i<pTable->Get_Field_Count(); i++)
			{
				if( P(i)->asBool() )
				{
					s	+= CSG_String::Format(s.Length() ? SG_T(",%d") : SG_T("%d"), i);
				}
			}

			pFields->Set_Value(s);

			return( true );
		}
	}

	return( false );
}
Example #15
0
//---------------------------------------------------------
int CGW_Multi_Regression::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
{
	if( m_Grid_Target.On_User_Changed(pParameters, pParameter) )
	{
		return( true );
	}

	if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("POINTS")) )
	{
		CSG_Shapes		*pPoints		= pParameters->Get_Parameter("POINTS")		->asShapes();
		CSG_Parameters	*pAttributes	= pParameters->Get_Parameter("PREDICTORS")	->asParameters();

		pAttributes->Destroy();
		pAttributes->Set_Name(_TL("Predictors"));

		for(int i=0; pPoints && i<pPoints->Get_Field_Count(); i++)
		{
			switch( pPoints->Get_Field_Type(i) )
			{
			default:	// not numeric
				break;

			case SG_DATATYPE_Byte:
			case SG_DATATYPE_Char:
			case SG_DATATYPE_Word:
			case SG_DATATYPE_Short:
			case SG_DATATYPE_DWord:
			case SG_DATATYPE_Int:
			case SG_DATATYPE_ULong:
			case SG_DATATYPE_Long:
			case SG_DATATYPE_Float:
			case SG_DATATYPE_Double:
				pAttributes->Add_Value(
					NULL, SG_Get_String(i, 0), pPoints->Get_Field_Name(i), _TL(""), PARAMETER_TYPE_Bool, false
				);
				break;
			}
		}

		return( true );
	}

	return( false );
}
Example #16
0
//---------------------------------------------------------
CSG_String CGCS_Graticule::Get_Degree(double Value, int Precision)
{
	if( Precision == DEG_PREC_DEG )
	{
		return( SG_Get_String(Value, -12) + "\xb0" );
	}

	SG_Char		c;
	int			d, h;
	double		s;
	CSG_String	String;

	if( Value < 0.0 )
	{
		Value	= -Value;
		c		= SG_T('-');
	}
	else
	{
		c		= SG_T('+');
	}

	Value	= fmod(Value, 360.0);
	d		= (int)Value;
	Value	= 60.0 * (Value - d);
	h		= (int)Value;
	Value	= 60.0 * (Value - h);
	s		= Value;

	if( s > 0.0 || Precision == DEG_PREC_FULL )
	{
		String.Printf(SG_T("%c%d\xb0%02d'%02.*f''"), c, d, h, SG_Get_Significant_Decimals(s), s);
	}
	else if( h > 0 || Precision == DEG_PREC_MIN )
	{
		String.Printf(SG_T("%c%d\xb0%02d'"        ), c, d, h);
	}
	else
	{
		String.Printf(SG_T("%c%d\xb0"             ), c, d);
	}

	return( String );
}
Example #17
0
void CSG_Doc_SVG::Draw_Line(double xa, 
						   double ya, 
						   double xb, 
						   double yb, 
						   double Width, 
						   int Color)
{

	CSG_String sWidth;

	m_sSVGCode.Append(SG_T("<line "));
	_AddAttribute(SG_T("x1"), xa);
	_AddAttribute(SG_T("x2"), xb);
	_AddAttribute(SG_T("y1"), ya);
	_AddAttribute(SG_T("y2"), yb);
	sWidth.Append(SG_Get_String(Width,2));
	sWidth.Append(g_Unit);
	_AddAttribute(SG_T("stroke-width"), sWidth);	_AddAttribute(SG_T("stroke"), _Get_SVGColor(Color));
	m_sSVGCode.Append(SG_T("/>\n"));

}
Example #18
0
void CSG_Doc_SVG::Draw_Circle(double x, 
							 double y, 
							 double Radius, 
							 int Fill_Color, 
							 int Line_Color, 
							 double Line_Width)
{
	
	CSG_String sWidth;

	m_sSVGCode.Append(SG_T("<circle "));
	_AddAttribute(SG_T("cx"), x);
	_AddAttribute(SG_T("cy"), y);
	_AddAttribute(SG_T("r"), Radius);
	sWidth.Append(SG_Get_String(Line_Width,2));
	sWidth.Append(g_Unit);
	_AddAttribute(SG_T("stroke-width"), sWidth);
	_AddAttribute(SG_T("stroke"), _Get_SVGColor(Line_Color));
	_AddAttribute(SG_T("fill"), _Get_SVGColor(Fill_Color));
	m_sSVGCode.Append(SG_T("/>\n"));

}
Example #19
0
//---------------------------------------------------------
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 );
}
//---------------------------------------------------------
bool CPointcloud_To_Text_File::On_Execute(void)
{
	CSG_PointCloud			*pPoints;
	CSG_String				fileName;
	CSG_File				*pTabStream = NULL;
	bool					bWriteHeader;
	CSG_String				fieldSep;

	CSG_Parameters			P;
	CSG_Parameter			*pNode;
	CSG_String				s;
	std::vector<int>		vCol, vPrecision;


	//-----------------------------------------------------
	pPoints			= Parameters("POINTS")		->asPointCloud();
	fileName		= Parameters("FILE")		->asString();
	bWriteHeader	= Parameters("WRITE_HEADER")->asBool();


	switch (Parameters("FIELDSEP")->asInt())
    {
	default:
    case 0:		fieldSep = "\t";	break;
    case 1:		fieldSep = " ";		break;
    case 2:		fieldSep = ",";		break;
    }


	if( fileName.Length() == 0 )
	{
		SG_UI_Msg_Add_Error(_TL("Please provide an output file name!"));
		return( false );
	}


	if (SG_UI_Get_Window_Main())
	{
		P.Set_Name(_TL("Check the fields to export"));

		for(int iField=0; iField<pPoints->Get_Field_Count(); iField++)
		{
			s.Printf(SG_T("NODE_%03d") , iField + 1);
			pNode	= P.Add_Node(NULL, s, CSG_String::Format(_TL("%d. %s"), iField + 1, _TL("Field")), _TL(""));

			s.Printf(SG_T("FIELD_%03d"), iField);
			P.Add_Value(pNode, s, CSG_String::Format(SG_T("%s"), pPoints->Get_Field_Name(iField)), _TL(""), PARAMETER_TYPE_Bool, false);

			s.Printf(SG_T("PRECISION_%03d"), iField);
			P.Add_Value(pNode, s, _TL("Decimal Precision"), _TL(""), PARAMETER_TYPE_Int, 2.0, 0.0, true);
		}


		//-----------------------------------------------------
		if( Dlg_Parameters(&P, _TL("Field Properties")) )
		{
			vCol.clear();
			vPrecision.clear();

			for(int iField=0; iField<pPoints->Get_Field_Count(); iField++)
			{
				if( P(CSG_String::Format(SG_T("FIELD_%03d" ), iField).c_str())->asBool() )
				{
					vCol.push_back(iField);
					vPrecision.push_back(P(CSG_String::Format(SG_T("PRECISION_%03d" ), iField).c_str())->asInt());
				}
			}
		}
		else
			return( false );
	}
	else // CMD
	{
		CSG_String		sFields, sPrecision;
		CSG_String		token;
		int				iValue;


		sFields		= Parameters("FIELDS")->asString();
		sPrecision	= Parameters("PRECISIONS")->asString();

		CSG_String_Tokenizer   tkz_fields(sFields, ";", SG_TOKEN_STRTOK);

		while( tkz_fields.Has_More_Tokens() )
		{
			token	= tkz_fields.Get_Next_Token();

			if( token.Length() == 0 )
				break;

			if( !token.asInt(iValue) )
			{
				SG_UI_Msg_Add_Error(_TL("Error parsing attribute fields: can't convert to number"));
				return( false );
			}

			iValue	-= 1;

			if( iValue < 0 || iValue > pPoints->Get_Field_Count() - 1 )
			{
				SG_UI_Msg_Add_Error(_TL("Error parsing attribute fields: field index out of range"));
				return( false );
			}
			else
				vCol.push_back(iValue);
		}

		CSG_String_Tokenizer   tkz_precisons(sPrecision.c_str(), ";", SG_TOKEN_STRTOK);

		while( tkz_precisons.Has_More_Tokens() )
		{
			token	= tkz_precisons.Get_Next_Token();

			if( token.Length() == 0 )
				break;

			if( !token.asInt(iValue) )
			{
				SG_UI_Msg_Add_Error(_TL("Error parsing attribute fields: can't convert to number"));
				return( false );
			}

			vPrecision.push_back(iValue);
		}
	}


	if( vCol.size() == 0 )
	{
		SG_UI_Msg_Add_Error(_TL("Please provide at least one column to export!"));
		return( false );
	}

	if( vCol.size() != vPrecision.size() )
	{
		SG_UI_Msg_Add_Error(_TL("Number of fields and precisions must be equal!"));
		return( false );
	}

	//-----------------------------------------------------
	pTabStream = new CSG_File();

	if( !pTabStream->Open(fileName, SG_FILE_W, false) )
	{
		SG_UI_Msg_Add_Error(CSG_String::Format(_TL("Unable to open output file %s!"), fileName.c_str()));
		delete (pTabStream);
		return (false);
	}


	if( bWriteHeader )
	{
	    CSG_String  sHeader;

		for(size_t i=0; i<vCol.size(); i++)
		{
		    sHeader += CSG_String::Format(SG_T("%s"), pPoints->Get_Field_Name(vCol.at(i)));

		    if( i < vCol.size()-1 )
                sHeader += fieldSep.c_str();
		}

		sHeader += SG_T("\n");

		pTabStream->Write(sHeader);
	}


	for(int iPoint=0; iPoint<pPoints->Get_Count() && Set_Progress(iPoint, pPoints->Get_Count()); iPoint++)
	{
		CSG_String	sLine;

		for(size_t i=0; i<vCol.size(); i++)
		{
			switch (pPoints->Get_Field_Type(vCol.at(i)))
			{
			case SG_DATATYPE_Double:
			case SG_DATATYPE_Float:
				sLine += SG_Get_String(pPoints->Get_Value(iPoint, vCol.at(i)), vPrecision.at(i), false);
				break;
			default:
				sLine += CSG_String::Format(SG_T("%d"), (int)pPoints->Get_Value(iPoint, vCol.at(i)));
				break;
			}

            if( i < vCol.size()-1 )
                sLine += fieldSep.c_str();
		}

		sLine += SG_T("\n");

		pTabStream->Write(sLine);
	}


	pTabStream->Close();
	delete (pTabStream);

	return( true );
}
Example #21
0
CSG_MetaData * CSG_MetaData::Ins_Child(const CSG_String &Name, double Content, int Position)
{
	return( Ins_Child(Name, SG_Get_String(Content, -16), Position) );
}
Example #22
0
void CSG_Doc_SVG::_AddAttribute(const SG_Char *Attribute, 
							   int iValue)
{

	_AddAttribute(Attribute, SG_Get_String(iValue, 0));
}
//---------------------------------------------------------
void CActive_Attributes_Control::On_Field_Type(wxCommandEvent &event)
{
	if( !g_pActive->Get_Active_Data_Item() || g_pActive->Get_Active_Data_Item()->Get_Type() != WKSP_ITEM_Grids )	{	return;	}

	CSG_Grids	*pGrids	= ((CWKSP_Grids *)g_pActive->Get_Active_Data_Item())->Get_Grids();

	//-----------------------------------------------------
	int				i, *Types	= new int[m_pTable->Get_Field_Count()];
	CSG_Parameters	P;

	P.Set_Name(_TL("Change Field Type"));

	for(i=0; i<m_pTable->Get_Field_Count(); i++)
	{
		switch( m_pTable->Get_Field_Type(i) )
		{
		default:
		case SG_DATATYPE_String:	Types[i]	=  0;	break;
		case SG_DATATYPE_Date  :	Types[i]	=  1;	break;
		case SG_DATATYPE_Color :	Types[i]	=  2;	break;
		case SG_DATATYPE_Byte  :	Types[i]	=  3;	break;
		case SG_DATATYPE_Char  :	Types[i]	=  4;	break;
		case SG_DATATYPE_Word  :	Types[i]	=  5;	break;
		case SG_DATATYPE_Short :	Types[i]	=  6;	break;
		case SG_DATATYPE_DWord :	Types[i]	=  7;	break;
		case SG_DATATYPE_Int   :	Types[i]	=  8;	break;
		case SG_DATATYPE_ULong :	Types[i]	=  9;	break;
		case SG_DATATYPE_Long  :	Types[i]	= 10;	break;
		case SG_DATATYPE_Float :	Types[i]	= 11;	break;
		case SG_DATATYPE_Double:	Types[i]	= 12;	break;
		case SG_DATATYPE_Binary:	Types[i]	= 13;	break;
		}

		P.Add_Choice("", SG_Get_String(i), m_pTable->Get_Field_Name(i), _TL(""),
			CSG_String::Format("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|",
			SG_Data_Type_Get_Name(SG_DATATYPE_String).c_str(),
			SG_Data_Type_Get_Name(SG_DATATYPE_Date  ).c_str(),
			SG_Data_Type_Get_Name(SG_DATATYPE_Color ).c_str(),
			SG_Data_Type_Get_Name(SG_DATATYPE_Byte  ).c_str(),
			SG_Data_Type_Get_Name(SG_DATATYPE_Char  ).c_str(),
			SG_Data_Type_Get_Name(SG_DATATYPE_Word  ).c_str(),
			SG_Data_Type_Get_Name(SG_DATATYPE_Short ).c_str(),
			SG_Data_Type_Get_Name(SG_DATATYPE_DWord ).c_str(),
			SG_Data_Type_Get_Name(SG_DATATYPE_Int   ).c_str(),
			SG_Data_Type_Get_Name(SG_DATATYPE_ULong ).c_str(),
			SG_Data_Type_Get_Name(SG_DATATYPE_Long  ).c_str(),
			SG_Data_Type_Get_Name(SG_DATATYPE_Float ).c_str(),
			SG_Data_Type_Get_Name(SG_DATATYPE_Double).c_str(),
			SG_Data_Type_Get_Name(SG_DATATYPE_Binary).c_str()
			), Types[i]
		);
	}

	//-----------------------------------------------------
	if( DLG_Parameters(&P) )
	{
		bool	bChanged	= false;

		for(i=0; i<m_pTable->Get_Field_Count(); i++)
		{
			TSG_Data_Type	Type;

			switch( P(i)->asInt() )
			{
			default:	Type	= SG_DATATYPE_String;	break;
			case  1:	Type	= SG_DATATYPE_Date  ;	break;
			case  2:	Type	= SG_DATATYPE_Color ;	break;
			case  3:	Type	= SG_DATATYPE_Byte  ;	break;
			case  4:	Type	= SG_DATATYPE_Char  ;	break;
			case  5:	Type	= SG_DATATYPE_Word  ;	break;
			case  6:	Type	= SG_DATATYPE_Short ;	break;
			case  7:	Type	= SG_DATATYPE_DWord ;	break;
			case  8:	Type	= SG_DATATYPE_Int   ;	break;
			case  9:	Type	= SG_DATATYPE_ULong ;	break;
			case 10:	Type	= SG_DATATYPE_Long  ;	break;
			case 11:	Type	= SG_DATATYPE_Float ;	break;
			case 12:	Type	= SG_DATATYPE_Double;	break;
			case 13:	Type	= SG_DATATYPE_Binary;	break;
			}

			if( Type != m_pTable->Get_Field_Type(i) )
			{
				pGrids->Get_Attributes_Ptr()->Set_Field_Type(i, Type);

				bChanged	= true;
			}
		}

		if( bChanged )
		{
			Update_Table();

			g_pData->Update(pGrids, NULL);
		}
	}
}
Example #24
0
//---------------------------------------------------------
bool CResection::On_Execute(void)
{

	CSG_PointCloud			*pPoints;									// Input Point Cloud
	CSG_String				fileName;
	CSG_File				*pTabStream = NULL;
	int n					= 6;										// Number of unknowns
	CSG_Vector center(3);
	CSG_Vector target(3);

	double c			= Parameters("F")			->asDouble();		// Focal Length (mm)
	double pixWmm		= Parameters("W")			->asDouble() / 1000;// Pixel Width (mm)
	double ppOffsetX	= Parameters("ppX")			->asDouble();		// Principal Point Offset X (pixels)
	double ppOffsetY	= Parameters("ppY")			->asDouble();		// Principal Point Offset Y (pixels)
	pPoints				= Parameters("POINTS")		->asPointCloud();
	fileName			= Parameters("OUTPUT FILE")	->asString();
	center[0]			= Parameters("Xc")			->asDouble();
	center[1]			= Parameters("Yc")			->asDouble();
	center[2]			= Parameters("Zc")			->asDouble();
	target[0]			= Parameters("Xt")			->asDouble();
	target[1]			= Parameters("Yt")			->asDouble();
	target[2]			= Parameters("Zt")			->asDouble();

	int pointCount = pPoints->Get_Point_Count();

	bool estPPOffsets = false;

	if ( Parameters("EST_OFFSETS")->asBool() ) {

		estPPOffsets = true;
		n = 8;															// Increase number of unknowns by 2
	}

	bool applyDistortions = false;
	CSG_Vector K(3);

	if ( Parameters("GIVE_DISTORTIONS")->asBool() ) {

		applyDistortions = true;
		K[0]			= Parameters("K1")			->asDouble();
		K[1]			= Parameters("K2")			->asDouble();
		K[2]			= Parameters("K3")			->asDouble();

	}

	double dxapp = center [0] - target [0];
	double dyapp = center [1] - target [1];
	double dzapp = center [2] - target [2];
	double h_d	= sqrt (dxapp * dxapp + dyapp * dyapp + dzapp * dzapp);	// Distance between Proj. Center & Target (m)
	double h_dmm = h_d * 1000;											// Convert to mm

	if( fileName.Length() == 0 )
	{
		SG_UI_Msg_Add_Error(_TL("Please provide an output file name!"));
		return( false );
	}

	pTabStream = new CSG_File();

	if( !pTabStream->Open(fileName, SG_FILE_W, false) )
	{
		SG_UI_Msg_Add_Error(CSG_String::Format(_TL("Unable to open output file %s!"), fileName.c_str()));
		delete (pTabStream);
		return (false);
	}


	CSG_Vector rotns = methods::calcRotations(center,target);			// Approx. rotations omega, kappa, alpha

	CSG_String msg = "********* Initial Approximate Values *********";
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);

	msg = SG_T("Rotation Angles:");
	pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);

	msg = SG_T("Omega:\t") + SG_Get_String(rotns[0],6,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);
	msg = SG_T("Kappa:\t") + SG_Get_String(rotns[1],6,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);
	msg = SG_T("Alpha:\t") + SG_Get_String(rotns[2],6,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);

	msg = SG_T("Projection Center:");
	pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);

	msg = SG_T("Xc:\t") + SG_Get_String(center[0],4,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);
	msg = SG_T("Yc:\t") + SG_Get_String(center[1],4,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);
	msg = SG_T("Zc:\t") + SG_Get_String(center[2],4,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);
	
	if (estPPOffsets) {

		msg = SG_T("Principal Point Offsets:");
		pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);

		msg = SG_T("ppX:\t") + SG_Get_String(ppOffsetX,5,false);
		pTabStream->Write(msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);
		msg = SG_T("ppY:\t") + SG_Get_String(ppOffsetY,5,false);
		pTabStream->Write(msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);

	}

	double itrNo = 0;
	CSG_Matrix invN;
	
	while (true) {													// Begin Iterations

		itrNo++;
		
		double omega = rotns[0];
		double kappa = rotns[1];
		double alpha = rotns[2];

		CSG_Matrix R = methods::calcRotnMatrix(rotns);				// Rotation Matrix from approximate values
		CSG_Matrix E(3,3);											// [w1;w2;w3] = E * [dw;dk;da]

		E[0][0] = -1;
		E[0][1] = E[1][0] = E[2][0] = 0;
		E[0][2] = sin(kappa);
		E[1][1] = -cos(omega);
		E[1][2] = -sin(omega) * cos(kappa);
		E[2][1] = sin(omega);
		E[2][2] = -cos(omega) * cos(kappa);

		CSG_Matrix N(n,n);											// Transpose(Design Matrix) * I * Design Matrix
		CSG_Vector ATL(n);											// Transpose(Design Matrix) * I * Shortened obs. vector

		double SS = 0;
		double sigma_naught = 0;
		
		for (int i = 0; i < pointCount; i++) {
			
			CSG_Vector pqs(3);										// Approx. pi, qi, si

			for (int j = 0; j < 3; j++) {
				pqs[j] = R[j][0] * (pPoints->Get_X(i) - center[0]) +
						 R[j][1] * (pPoints->Get_Y(i) - center[1]) +
						 R[j][2] * (pPoints->Get_Z(i) - center[2]);
			}

			double p_i = pqs[0];
			double q_i = pqs[1];
			double s_i = pqs[2];

			double dR =  0;
			
			// Undistorted
			double x_u = c * p_i / q_i;
			double y_u = c * s_i / q_i;
			
			double c_hat = c;
			
			if (applyDistortions) {
				double r2 = x_u * x_u + y_u * y_u;
				dR =  K[0] * r2 + K[1] * r2 * r2 + K[2] * r2 * r2 * r2;
				c_hat = c * (1 - dR);
			}

			// Approx. image coordinates (with distortions)
			double x_i = (1 - dR) * x_u + ppOffsetX * pixWmm;
			double z_i = (1 - dR) * y_u + ppOffsetY * pixWmm;

			// Shortened obervation vector: dxi & dzi
			double dx_i = pPoints->Get_Attribute(i,0) * pixWmm - x_i;
			double dz_i = pPoints->Get_Attribute(i,1) * pixWmm - z_i;
			SS += pow(dx_i,2) + pow(dz_i,2);

			/*
				x_i, z_i in [mm]
				p_i,q_i,s_i in [m]
				h_d in [m]
				c, c_hat in [mm]
				h_dmm in [mm]
			*/
			CSG_Matrix L(3,2);										// CSG_Matrix takes columns first and rows second
			CSG_Matrix V(3,3);
			CSG_Matrix LR(3,2);
			CSG_Matrix LVE(3,2);

			L[0][0] = L[1][2] = c_hat / (1000 * q_i);
			L[0][2] = L[1][0] = 0;
			L[0][1] = -x_u * (1 - dR) / (1000 * q_i);
			L[1][1] = -y_u * (1 - dR) / (1000 * q_i);

			V[0][0] = V[1][1] = V[2][2] = 0;
			V[0][1] =  s_i / h_d;
			V[0][2] = -q_i / h_d;
			V[1][0] = -s_i / h_d;
			V[1][2] =  p_i / h_d;
			V[2][0] =  q_i / h_d;
			V[2][1] = -p_i / h_d;

			LVE = ( L * V ) * E;
			LR = L * R;

			// Design Matrix (J)
			CSG_Matrix design(n,2);

			for(int j = 0; j < 2; j++) {
				for(int k = 0; k < 3; k++) {
					design[j][k] = LVE[j][k];
					design[j][k+3] = -LR[j][k];
				}
			}

			if ( estPPOffsets ) {
				design[0][6] = design[1][7] = 1.0;
			}

			// Build Normal Matrix
			for(int j = 0; j < n; j++) {
				for(int k = 0; k < n; k++) {
					N[j][k] += (design[0][j] * design[0][k] + design[1][j] * design[1][k]);
				}
			}

			// Build Tranpose (J) * I * (Shortened obs. vector)
			for (int m=0; m < n; m++) {
				ATL[m] += design[0][m] * dx_i + design[1][m] * dz_i;
			}

			L.Destroy();
			V.Destroy();
			LR.Destroy();
			LVE.Destroy();
			pqs.Destroy();
			design.Destroy();

		} // end looping over observations

		// Eigen values and Eigen Vectors
		CSG_Vector eigenVals(n);
		CSG_Matrix eigenVecs(n,n);
		SG_Matrix_Eigen_Reduction(N, eigenVecs, eigenVals, true);

		// One of the Eigen Values is 0
		if (std::any_of(eigenVals.cbegin(),
		                eigenVals.cend(),
		                [] (double i) { return i == 0; })) {
			msg = "The Normal Matrix has a rank defect. Please measure more points.";
			pTabStream->Write(msg + SG_T("\n"));
			SG_UI_Msg_Add(msg, true);
			break;
		}

		double mx = *std::max_element(eigenVals.cbegin(), eigenVals.cend());
		double mn = *std::min_element(eigenVals.cbegin(), eigenVals.cend());

		// Ratio of Smallest to the Biggest Eigen value is too small
		if ((mn / mx) < pow(10,-12.0)) {
			msg = SG_T("Condition of the Matrix of Normal Equations:\t") + CSG_String::Format(SG_T("  %13.5e"), mn/mx);
			pTabStream->Write(msg + SG_T("\n"));
			SG_UI_Msg_Add(msg, true);
			msg = "The Normal Matrix is weakly conditioned. Please measure more points.";
			pTabStream->Write(msg + SG_T("\n"));
			SG_UI_Msg_Add(msg, true);
			break;
		}

		// Calculate the adjustments
		double absMax = 0;
		invN = N.Get_Inverse();
		CSG_Vector est_param_incs = invN * ATL;

		for (int i = 0; i < n; i++) {
			if (abs(est_param_incs[i]) > absMax) {
				absMax = abs(est_param_incs[i]);
			}
		}

		if (absMax < thresh) {
			msg = "Solution has converged.";
			pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
			SG_UI_Msg_Add(msg, true);
			break;
		}

		for (int a = 0; a < 3; a++) {
			rotns[a] += est_param_incs[a] / h_dmm;								// New Approx. rotations omega, kappa, alpha
			center[a] += est_param_incs[a+3] / 1000;							// New Approx. Projection Center
		}

		if ( estPPOffsets ) {
			ppOffsetX += (est_param_incs[6] / pixWmm);							// New Approx. Principal Point
			ppOffsetY += (est_param_incs[7] / pixWmm);
		}

		sigma_naught = sqrt(SS / (2 * pointCount - n));

		// Writing To Output File & SAGA Console
		msg = "********* Iteration: " + SG_Get_String(itrNo,0,false) + " *********";
		pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);

		msg = "Sum of Squared Residuals:\t" + SG_Get_String(SS,5,false);
		pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);
		
		msg = "Sigma Naught:\t" + SG_Get_String(sigma_naught,5,false);
		pTabStream->Write(msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);
		
		msg = SG_T("Condition of the Matrix of Normal Equations:\t") + CSG_String::Format(SG_T("  %13.5e"), mn/mx);
		pTabStream->Write(msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);
		
		R.Destroy();
		E.Destroy();
		N.Destroy();
		ATL.Destroy();
		invN.Destroy();
		eigenVals.Destroy();
		eigenVecs.Destroy();
		est_param_incs.Destroy();

	} // end of iterations

	msg = "********* Final Estimated Parameters *********";
	pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);

	msg = SG_T("Rotation Angles:");
	pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);

	msg = SG_T("Omega:\t") + SG_Get_String(rotns[0],6,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);
	msg = SG_T("Kappa:\t") + SG_Get_String(rotns[1],6,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);
	msg = SG_T("Alpha:\t") + SG_Get_String(rotns[2],6,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);

	msg = SG_T("Projection Center:");
	pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);

	msg = SG_T("Xc:\t") + SG_Get_String(center[0],4,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);
	msg = SG_T("Yc:\t") + SG_Get_String(center[1],4,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);
	msg = SG_T("Zc:\t") + SG_Get_String(center[2],4,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);

	if (estPPOffsets) {

		msg = SG_T("Principal Point Offsets:");
		pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);

		msg = SG_T("ppX:\t") + SG_Get_String(ppOffsetX,5,false);
		pTabStream->Write(msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);
		msg = SG_T("ppY:\t") + SG_Get_String(ppOffsetY,5,false);
		pTabStream->Write(msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);

	}


	K.Destroy();
	rotns.Destroy();
	center.Destroy();
	target.Destroy();

	pTabStream->Close();
	
	return true;
}
Example #25
0
CSG_MetaData * CSG_MetaData::Add_Child(const CSG_String &Name, double Content)
{
	return( Ins_Child(Name, SG_Get_String(Content, -16), -1) );
}
Example #26
0
bool CAHP::On_Execute(void){

	int i,j;	
	int x,y;	
	float *pCoefs;	
	float fValue;
	float **pMatrix;
	float fSum;
	CSG_Grid *pOutputGrid;
	CSG_Grid **pGrids;
	CSG_Table_Record *pRecord;
	CSG_Table *pTable;
	CSG_Parameter_Grid_List* pGridsList;
	CSG_String sMessage;

	pTable = Parameters("TABLE")->asTable();
	pOutputGrid = Parameters("OUTPUT")->asGrid();

	if( (pGridsList = (CSG_Parameter_Grid_List *)Parameters("GRIDS")->Get_Data()) != 
			NULL && pGridsList->Get_Count() > 0 ){
		if (pTable->Get_Field_Count() != pGridsList->Get_Count() ||
				pTable->Get_Record_Count() < pGridsList->Get_Count()){
			Message_Add(_TL("Error : Wrong table. Check table dimensions"));
			return false;
		}//if
		pMatrix = new float*[pGridsList->Get_Count()];
		for (i = 0; i<pGridsList->Get_Count(); i++){
			pMatrix[i] = new float[pGridsList->Get_Count()];
			pRecord = pTable->Get_Record(i);
			for (j = 0; j<pGridsList->Get_Count(); j++){
				pMatrix[i][j] = pRecord->asFloat(j);
			}//for
		}//for

		for (i = 0; i<pGridsList->Get_Count(); i++){
			fSum = 0;
			for (j = 0; j<pGridsList->Get_Count(); j++){
				fSum += pMatrix[j][i];
			}//for
			for (j = 0; j<pGridsList->Get_Count(); j++){
				pMatrix[j][i] /= fSum;
			}//for
		}//for

		pCoefs = new float[pGridsList->Get_Count()];
		for (i = 0; i<pGridsList->Get_Count(); i++){
			fSum = 0;
			for (j = 0; j<pGridsList->Get_Count(); j++){
				fSum += pMatrix[i][j];
			}//for
			pCoefs[i] = fSum / (float) pGridsList->Get_Count();
			sMessage = _TL("Weight for grid ") + SG_Get_String(i,0) + " = " + SG_Get_String(pCoefs[i]);
			Message_Add(sMessage.c_str());
		}//for

		pGrids = new CSG_Grid* [pGridsList->Get_Count()];
		for (i = 0; i<pGridsList->Get_Count(); i++){
			pGrids[i] = pGridsList->asGrid(i); 
		}//for
		for(y=0; y<Get_NY() && Set_Progress(y); y++){
			for(x=0; x<Get_NX(); x++){
				fValue = 0;
				for (i = 0; i<pGridsList->Get_Count(); i++){
					fValue = pCoefs[i] * pGrids[i]->asFloat(x,y);
				}//for
				pOutputGrid->Set_Value(x,y,fValue);
			}//for
		}//for
	}//if

	for (i = 0; i<pGridsList->Get_Count(); i++){
		delete [] pMatrix[i];
	}//for
	delete []pMatrix;
	delete[] pCoefs;

	return true;

}//method
void CSimulateVariableWind::CreateReport(){

	CSG_String sReportFile, sFile;
	int i;

	if (Parameters("REPORTFILE")->asString() != NULL){
		
		sReportFile = Parameters("REPORTFILE")->asString();
		
		CalculateReportParameters();

		char cDate[81];
		time_t curTime;
		tm * timeinfo;
		time(&curTime);
		timeinfo = gmtime(&curTime);  

	//	std::locale spanish("esp");
	//	std::locale::global(spanish);
		strftime(cDate, 80, "%#x", timeinfo);

		sFile += "\t\t\t SIMULACIÓN realizada el ";
		sFile += cDate;
		sFile += "\n\t\t ==============================================================================";
		sFile += "\n\n\t Parámetros de entrada\n";
		sFile += "\t --------------------------------\n\n";
		sFile += "\t\t Modelos de combustible (por area) \n:  ";
		for (i = 0; i < 12; i++){
			if (m_pAreaByFuelModel[i]){
				sFile += "\t\t\t * ";
				sFile += SG_Get_String(i + 1, 0) + " : " + SG_Get_String(m_pAreaByFuelModel[i]) + " ha\n";
			}//if
		}//for		
		sFile += "\t\t Humedad de los combustibles muertos (1 h): ";
		sFile += SG_Get_String(m_fDeadFuelMoisture) + " %\n";
		sFile += "\t\t Velocidad del viento a media llama: \n" ;
		for(i = 0; i < m_iWindSpdGrids; i++){
			sFile	+= "\t\t\t * ";
			sFile	+= SG_Get_String(i * m_fInterval, 0) + " min: " 
					 + SG_Get_String(m_pMeanWindSpd[i]) + "Km/h\n";
		}//for
		sFile += "\t\t Dirección del vector viento, desde el norte geográfico: \n";
		for(i = 0; i < m_iWindDirGrids; i++){
			sFile += "\t\t\t * ";
			sFile += SG_Get_String(i * m_fInterval, 0) + " min: " 
					+ SG_Get_String(m_pMeanWindDir[i]) + "º\n";
		}//for

		sFile += "\t\t Pendiente del terreno media: ";	sFile += SG_Get_String(m_fSlope) + " %\n";       
		sFile += "\t\t Orientación del terreno: ";	sFile += SG_Get_String(m_fAspect) + "º\n";
		sFile += "\t\t Foco de partida: X = ";	sFile += SG_Get_String(Parameters("COORDX")->asDouble(), 0) + " / Y = "
				+ SG_Get_String(Parameters("COORDY")->asDouble(), 0) + "\n";
		sFile += "\t\t Tiempo de simulación: 3.0 h";

		sFile += "\n\n\t Resultado de la simulación\n";
		sFile += "\t --------------------------------\n\n";	
		sFile += "\t\t Velocidad de propagación: ";					sFile += SG_Get_String(m_fMeanSpeed) + " m/min\n";
		sFile += "\t\t Calor por unidad de area: ";					sFile += SG_Get_String(m_fHeatPerUnitArea) + " kJ/m^2\n"; //revisar unidades!!
		sFile += "\t\t Intensidad de la línea de fuego: ";			sFile += SG_Get_String(m_fIntensity) + " kCal/m\n";
		sFile += "\t\t Longitud de la llama: ";						sFile += SG_Get_String(m_fFlameHeight) + " m\n";
		sFile += "\t\t Intensidad de reacción: ";					sFile += SG_Get_String(m_fReactionIntensity) + " kCal/m2\n";
		sFile += "\t\t Velocidad efectiva del viento: ";			sFile += SG_Get_String(m_fEffectiveWind / KMH2FTMIN) + " Km/h\n";
		sFile += "\t\t Dirección de máxima propagación, desde el norte geográfico: ";	sFile += SG_Get_String(m_fMaxSpreadDir) + "º\n";
		sFile += "\t\t Area: ";										sFile += SG_Get_String(m_fArea / 10000) + " ha\n";
		sFile += "\t\t Perímetro: ";								sFile += SG_Get_String(m_fPerimeter) + "m\n";
		//Razón Longitud/Ancho:                   1.9
		sFile += "\t\t Distancia de propagación hacia delante: ";	sFile += SG_Get_String(m_fFrontDistance) + " m\n";
		sFile += "\t\t Distancia de propagación hacia atrás: ";		sFile +=  SG_Get_String(m_fRearDistance) + " m\n";

		CSG_File	file;

		if( file.Open(sReportFile, SG_FILE_W, false) )
		{
			file.Write(sFile);
		}
	}//if

}//method