コード例 #1
0
ファイル: Points_From_Table.cpp プロジェクト: am2222/SAGA-GIS
bool CPoints_From_Table::On_Execute(void)
{
	int				iRecord, iXField, iYField;
	double			dX, dY;
	CSG_Table			*pTable;
	CSG_Table_Record	*pRecord;
	CSG_Shapes			*pShapes;
	CSG_Shape			*pShape;

	pTable	= Parameters("TABLE")	->asTable();
	pShapes	= Parameters("POINTS")	->asShapes();

	iXField	= Parameters("X")		->asInt();
	iYField	= Parameters("Y")		->asInt();

	pShapes->Create(SHAPE_TYPE_Point, pTable->Get_Name(), pTable);

	if( pTable->Get_Field_Count() > 1 && pTable->Get_Record_Count() > 0 )
	{
		for(iRecord=0; iRecord<pTable->Get_Record_Count() && Set_Progress(iRecord, pTable->Get_Record_Count()); iRecord++)
		{
			pRecord	= pTable->Get_Record(iRecord);

			dX		= pRecord->asDouble(iXField);
			dY		= pRecord->asDouble(iYField);

			pShape	= pShapes->Add_Shape(pRecord, SHAPE_COPY_ATTR);
			pShape->Add_Point(dX, dY);
		}//for

		return( true );
	}//if

	return( false );
}//method
コード例 #2
0
//---------------------------------------------------------
bool CErosion_LS_Fields::Get_Statistics(void)
{
	CSG_Shapes	*pFields		= Parameters("FIELDS"    )->asShapes();
	CSG_Shapes	*pStatistics	= Parameters("STATISTICS")->asShapes();

	//-----------------------------------------------------
	if( !pStatistics || !pFields || m_nFields <= 0 || pFields->Get_Count() != m_nFields )
	{
		return( false );
	}

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

	CSG_Simple_Statistics	*Statistics	= new CSG_Simple_Statistics[m_nFields];

	//-----------------------------------------------------
	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		for(int x=0; x<Get_NX(); x++)
		{
			if( !m_pLS->is_NoData(x, y) && (i = m_Fields.asInt(x, y)) >= 0 && i < m_nFields )
			{
				Statistics[i]	+= m_pLS->asDouble(x, y);
			}
		}
	}

	//-----------------------------------------------------
	pStatistics->Create(SHAPE_TYPE_Polygon, CSG_String::Format(SG_T("%s [%s]"), pFields->Get_Name(), _TL("LS")));

	pStatistics->Add_Field("NCELLS", SG_DATATYPE_Int   );
	pStatistics->Add_Field("MEAN"  , SG_DATATYPE_Double);
	pStatistics->Add_Field("MIN"   , SG_DATATYPE_Double);
	pStatistics->Add_Field("MAX"   , SG_DATATYPE_Double);
	pStatistics->Add_Field("STDDEV", SG_DATATYPE_Double);

	for(i=0; i<pFields->Get_Count() && Set_Progress(i, pFields->Get_Count()); i++)
	{
		CSG_Shape	*pField	= pStatistics->Add_Shape(pFields->Get_Shape(i));

		if( Statistics[i].Get_Count() > 0 )
		{
			pField->Set_Value(0, Statistics[i].Get_Count  ());
			pField->Set_Value(1, Statistics[i].Get_Mean   ());
			pField->Set_Value(2, Statistics[i].Get_Minimum());
			pField->Set_Value(3, Statistics[i].Get_Maximum());
			pField->Set_Value(4, Statistics[i].Get_StdDev ());
		}
		else for(int j=0; j<pFields->Get_Field_Count(); j++)
		{
			pField->Set_NoData(j);
		}
	}

	//-------------------------------------------------
	delete[](Statistics);

	return( true );
}
コード例 #3
0
ファイル: _kriging_base.cpp プロジェクト: am2222/SAGA-GIS
//---------------------------------------------------------
bool C_Kriging_Base::_Get_Points(void)
{
	int		iShape, iPart, iPoint;
	CSG_Shape	*pShape , *pPoint;
	CSG_Shapes	*pPoints;

	m_pShapes	= Parameters("SHAPES")	->asShapes();
	m_zField	= Parameters("FIELD")	->asInt();

	if( m_pShapes->Get_Type() != SHAPE_TYPE_Point )
	{
		pPoints	= SG_Create_Shapes(SHAPE_TYPE_Point, SG_T(""), m_pShapes);

		for(iShape=0; iShape<m_pShapes->Get_Count() && Set_Progress(iShape, m_pShapes->Get_Count()); iShape++)
		{
			pShape	= m_pShapes->Get_Shape(iShape);

			if( !pShape->is_NoData(m_zField) )
			{
				for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
				{
					for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
					{
						pPoint	= pPoints->Add_Shape(pShape, SHAPE_COPY_ATTR);
						pPoint->Add_Point(pShape->Get_Point(iPoint, iPart));
					}
				}
			}
		}

		m_pShapes	= pPoints;
	}

	return( m_pShapes->Get_Count() > 1 );
}
コード例 #4
0
//---------------------------------------------------------
bool CCollect_Points::On_Execute_Finish(void)
{
	CSG_Shapes	*pTarget	= Parameters("REF_TARGET")->asShapes();

	if( pTarget != NULL )
	{
		pTarget->Create(SHAPE_TYPE_Point, _TL("Reference Points (Projection)"));

		pTarget->Add_Field("X_SRC", SG_DATATYPE_Double);
		pTarget->Add_Field("Y_SRC", SG_DATATYPE_Double);
		pTarget->Add_Field("X_MAP", SG_DATATYPE_Double);
		pTarget->Add_Field("Y_MAP", SG_DATATYPE_Double);
		pTarget->Add_Field("RESID", SG_DATATYPE_Double);

		for(int iPoint=0; iPoint<m_pPoints->Get_Count(); iPoint++)
		{
			CSG_Shape	*pPoint	= pTarget->Add_Shape(m_pPoints->Get_Shape(iPoint), SHAPE_COPY_ATTR);

			pPoint->Add_Point(
				pPoint->asDouble(2),
				pPoint->asDouble(3)
			);
		}
	}

	m_Engine.Destroy();

	return( true );
}
コード例 #5
0
ファイル: CreatePointGrid.cpp プロジェクト: am2222/SAGA-GIS
bool CCreatePointGrid::On_Execute(void){

	CSG_Shape *pShape;
	
	double dXMin	= ((CSG_Parameter_Range *) Parameters("X_EXTENT")->Get_Data())->Get_LoVal();
	double dYMin	= ((CSG_Parameter_Range *) Parameters("Y_EXTENT")->Get_Data())->Get_LoVal();
	double dXMax	= ((CSG_Parameter_Range *) Parameters("X_EXTENT")->Get_Data())->Get_HiVal();
	double dYMax	= ((CSG_Parameter_Range *) Parameters("Y_EXTENT")->Get_Data())->Get_HiVal();

	double dDistance = Parameters("DIST")->asDouble();
	if (dDistance<=0){
		return false;
	}//if

	CSG_Shapes *pShapes = Parameters("POINTS")->asShapes();
	pShapes->Create(SHAPE_TYPE_Point, _TL("Point Grid"));

	pShapes->Add_Field("X", SG_DATATYPE_Double);
	pShapes->Add_Field("Y", SG_DATATYPE_Double);
	
	for (double x=dXMin; x<dXMax; x=x+dDistance){
		for (double y=dYMin; y<dYMax; y=y+dDistance){ 
			pShape = pShapes->Add_Shape();
			pShape->Add_Point(x,y);
			pShape->Set_Value(0, x);
			pShape->Set_Value(1, y);
		}//for
	}//for

	return true;

}//method
コード例 #6
0
//---------------------------------------------------------
bool CPoint_Zonal_Multi_Grid_Regression::Set_Residuals(CSG_Shapes *pPoints, CSG_Grid *pRegression)
{
	CSG_Shapes	*pResiduals	= Parameters("RESIDUALS")->asShapes();
	int			iAttribute	= Parameters("ATTRIBUTE")->asInt   ();

	if( !pRegression || !pResiduals )
	{
		return( false );
	}

	//-----------------------------------------------------
	pResiduals->Create(SHAPE_TYPE_Point, CSG_String::Format(SG_T("%s [%s]"), Parameters("ATTRIBUTE")->asString(), _TL("Residuals")));
	pResiduals->Add_Field(pPoints->Get_Field_Name(iAttribute), SG_DATATYPE_Double);
	pResiduals->Add_Field("TREND"	, SG_DATATYPE_Double);
	pResiduals->Add_Field("RESIDUAL", SG_DATATYPE_Double);

	TSG_Grid_Resampling	Resampling;

	switch( Parameters("RESAMPLING")->asInt() )
	{
	default:	Resampling	= GRID_RESAMPLING_NearestNeighbour;	break;
	case  1:	Resampling	= GRID_RESAMPLING_Bilinear;			break;
	case  2:	Resampling	= GRID_RESAMPLING_BicubicSpline;	break;
	case  3:	Resampling	= GRID_RESAMPLING_BSpline;			break;
	}

	//-----------------------------------------------------
	for(int iShape=0; iShape<pPoints->Get_Count() && Set_Progress(iShape, pPoints->Get_Count()); iShape++)
	{
		CSG_Shape	*pShape	= pPoints->Get_Shape(iShape);

		if( !pShape->is_NoData(iAttribute) )
		{
			double	zShape	= pShape->asDouble(iAttribute);

			for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
			{
				for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
				{
					double		zGrid;
					TSG_Point	Point	= pShape->Get_Point(iPoint, iPart);

					if( pRegression->Get_Value(Point, zGrid, Resampling) )
					{
						CSG_Shape	*pResidual	= pResiduals->Add_Shape();

						pResidual->Add_Point(Point);
						pResidual->Set_Value(0, zShape);
						pResidual->Set_Value(1, zGrid);
						pResidual->Set_Value(2, zShape - zGrid);
					}
				}
			}
		}
	}

	//-----------------------------------------------------
	return( true );
}
コード例 #7
0
//---------------------------------------------------------
void CGrid_Cross_Profiles::Make_Report(const SG_Char *FileName, CSG_Grid *pDEM, CSG_Shapes *pLines, CSG_Shapes *pProfiles, double Distance)
{
	if( FileName )
	{
		int				iProfile, iPoint, nSamples, iBox;
		CSG_Rect		r;
		CSG_Shape			*pProfile, *pLine;
		CSG_Shapes			Profile;
		CSG_Doc_PDF	pdf;

		pdf.Open(PDF_PAGE_SIZE_A4, PDF_PAGE_ORIENTATION_PORTRAIT, _TL("Cross Profiles"));
		pdf.Layout_Add_Box(5,  5, 95, 20);
		pdf.Layout_Add_Box(5, 25, 95, 45);
		pdf.Layout_Add_Box(5, 50, 95, 70);
		pdf.Layout_Add_Box(5, 75, 95, 90);

		nSamples	= pProfiles->Get_Field_Count() - OFFSET;
		Distance	= Distance / (nSamples - 1);
		iBox		= 0;

		for(iProfile=0; iProfile<pProfiles->Get_Count() && Set_Progress(iProfile, pProfiles->Get_Count()); iProfile++)
		{
			pProfile	= pProfiles->Get_Shape(iProfile);

			Profile.Create(SHAPE_TYPE_Line);
			pLine		= Profile.Add_Shape();

			for(iPoint=0; iPoint<nSamples; iPoint++)
			{
				if( !pProfile->is_NoData(OFFSET + iPoint) )
				{
					pLine->Add_Point(
						(iPoint - nSamples / 2) * Distance,
						pProfile->asDouble(OFFSET + iPoint)
					);
				}
			}

			if( pLine->Get_Point_Count(0) > 1 )
			{
				if( iBox >= NBOXES )
				{
					pdf.Add_Page();
					iBox	= 0;
				}

//				pdf.Draw_Graticule	(pdf.Layout_Get_Box(iBox),  Profile.Get_Extent(), 20);
//				pdf.Draw_Shapes		(pdf.Layout_Get_Box(iBox), &Profile);
				r	= pLine->Get_Extent();	r.Inflate(10);
				pdf.Draw_Graticule	(pdf.Layout_Get_Box(iBox), r, 15);
				pdf.Draw_Shape		(pdf.Layout_Get_Box(iBox), pLine, PDF_STYLE_POLYGON_FILLSTROKE, SG_COLOR_GREEN, SG_COLOR_BLACK, 1, &r);

				iBox++;
			}
		}

		pdf.Save(Parameters("DOCUMENT")->asString());
	}
}
コード例 #8
0
ファイル: ogr_driver.cpp プロジェクト: am2222/SAGA-GIS
//---------------------------------------------------------
CSG_Shapes * COGR_DataSource::Read_Shapes(int iLayer)
{
	OGRLayer	*pLayer	= Get_Layer(iLayer);

	//-----------------------------------------------------
	if( pLayer && Get_Type(iLayer) != SHAPE_TYPE_Undefined )
	{
		int				iField;
		OGRFeature		*pFeature;
		OGRFeatureDefn	*pDef		= pLayer->GetLayerDefn();
		CSG_Shapes		*pShapes	= SG_Create_Shapes(Get_Type(iLayer), CSG_String(pDef->GetName()));

		for(iField=0; iField<pDef->GetFieldCount(); iField++)
		{
			OGRFieldDefn	*pDefField	= pDef->GetFieldDefn(iField);

			pShapes->Add_Field(pDefField->GetNameRef(), COGR_Driver::Get_Type(pDefField->GetType()));
		}

		pLayer->ResetReading();

		//-------------------------------------------------
		while( (pFeature = pLayer->GetNextFeature()) != NULL && SG_UI_Process_Get_Okay(false) )
		{
			OGRGeometry	*pGeometry	= pFeature->GetGeometryRef();

			if( pGeometry != NULL )
			{
				CSG_Shape	*pShape	= pShapes->Add_Shape();

				for(iField=0; iField<pDef->GetFieldCount(); iField++)
				{
					OGRFieldDefn	*pDefField	= pDef->GetFieldDefn(iField);

					switch( pDefField->GetType() )
					{
					default:			pShape->Set_Value(iField, SG_STR_MBTOSG(pFeature->GetFieldAsString (iField)));	break;
					case OFTString:		pShape->Set_Value(iField, SG_STR_MBTOSG(pFeature->GetFieldAsString (iField)));	break;
					case OFTInteger:	pShape->Set_Value(iField, pFeature->GetFieldAsInteger(iField));	break;
					case OFTReal:		pShape->Set_Value(iField, pFeature->GetFieldAsDouble (iField));	break;
					}
				}

				//-----------------------------------------
				if( _Read_Geometry(pShape, pGeometry) == false )
				{
					pShapes->Del_Shape(pShape);
				}
			}

			OGRFeature::DestroyFeature(pFeature);
		}

		return( pShapes );
	}

	//-----------------------------------------------------
	return( NULL );
}
コード例 #9
0
ファイル: TIN_Gradient.cpp プロジェクト: johanvdw/saga-debian
//---------------------------------------------------------
bool CTIN_Gradient::On_Execute(void)
{
	bool			bDegree;
	int				iTriangle, zField;
	double			a, b;
	CSG_TIN_Triangle	*pTriangle;
	CSG_TIN			*pTIN;
	CSG_Shape			*pShape;
	CSG_Shapes			*pShapes;

	//-----------------------------------------------------
	pTIN		= Parameters("TIN")			->asTIN();
	zField		= Parameters("ZFIELD")		->asInt();
	pShapes		= Parameters("GRADIENT")	->asShapes();
	bDegree		= Parameters("DEGREE")		->asInt() == 1;

	//-----------------------------------------------------
	pShapes->Create(SHAPE_TYPE_Polygon, CSG_String::Format(SG_T("%s [%s], %s [%s]"), _TL("TIN_Gradient"), pTIN->Get_Field_Name(zField), _TL("TIN"), pTIN->Get_Name()));

	pShapes->Add_Field(_TL("ID")		, SG_DATATYPE_Int);
	pShapes->Add_Field(_TL("AREA")	, SG_DATATYPE_Double);
	pShapes->Add_Field(_TL("DECLINE"), SG_DATATYPE_Double);
	pShapes->Add_Field(_TL("AZIMUTH"), SG_DATATYPE_Double);

	//-----------------------------------------------------
	for(iTriangle=0; iTriangle<pTIN->Get_Triangle_Count() && Set_Progress(iTriangle, pTIN->Get_Triangle_Count()); iTriangle++)
	{
		pTriangle	= pTIN->Get_Triangle(iTriangle);

		if( pTriangle->Get_Gradient(zField, a, b) )
		{
			if( bDegree )
			{
				a	*= M_RAD_TO_DEG;
				b	*= M_RAD_TO_DEG;
			}

			pShape		= pShapes->Add_Shape();
			pShape->Add_Point(pTriangle->Get_Node(0)->Get_Point());
			pShape->Add_Point(pTriangle->Get_Node(1)->Get_Point());
			pShape->Add_Point(pTriangle->Get_Node(2)->Get_Point());

			pShape->Set_Value(0, iTriangle + 1);
			pShape->Set_Value(1, pTriangle->Get_Area());
			pShape->Set_Value(2, a);
			pShape->Set_Value(3, b);
		}
	}

	return( true );
}
コード例 #10
0
ファイル: xyz.cpp プロジェクト: johanvdw/SAGA-GIS-git-mirror
//---------------------------------------------------------
bool CXYZ_Import::On_Execute(void)
{
	CSG_File	Stream;

	if( !Stream.Open(Parameters("FILENAME")->asString(), SG_FILE_R) )
	{
		Error_Set(_TL("file could not be opened"));

		return( false );
	}

	//-----------------------------------------------------
	CSG_Shapes	*pPoints	= Parameters("POINTS")->asShapes();

	pPoints->Create(SHAPE_TYPE_Point, SG_File_Get_Name(Parameters("FILENAME")->asString(), false));

	pPoints->Add_Field("Z", SG_DATATYPE_Double);

	//-----------------------------------------------------
	if( Parameters("HEADLINE")->asBool() )
	{
		CSG_String	sLine;

		if( !Stream.Read_Line(sLine) )
		{
			Error_Set(_TL("could not read headline"));

			return( false );
		}
	}

	//-----------------------------------------------------
	sLong	Length	= Stream.Length();

	double	x, y, z;

	while( Stream.Scan(x) && Stream.Scan(y) && Stream.Scan(z) && Set_Progress((double)Stream.Tell(), (double)Length) )
	{
		CSG_Shape	*pPoint	= pPoints->Add_Shape();

		pPoint->Add_Point(x, y);

		pPoint->Set_Value(0, z);
	}

	return( pPoints->Get_Count() > 0 );
}
コード例 #11
0
//---------------------------------------------------------
bool CGW_Regression_Grid::Set_Residuals(void)
{
	CSG_Shapes	*pResiduals	= Parameters("RESIDUALS")->asShapes();

	if( !pResiduals || !m_pPoints || !m_pRegression )
	{
		return( false );
	}

	//-----------------------------------------------------
	pResiduals->Create(SHAPE_TYPE_Point, CSG_String::Format(SG_T("%s [%s]"), m_pPoints->Get_Name(), _TL("Residuals")));
	pResiduals->Add_Field(m_pPoints->Get_Field_Name(m_iDependent), SG_DATATYPE_Double);
	pResiduals->Add_Field("TREND"	, SG_DATATYPE_Double);
	pResiduals->Add_Field("RESIDUAL", SG_DATATYPE_Double);

	//-------------------------------------------------
	for(int iShape=0; iShape<m_pPoints->Get_Count() && Set_Progress(iShape, m_pPoints->Get_Count()); iShape++)
	{
		CSG_Shape	*pShape	= m_pPoints->Get_Shape(iShape);
		double		 zShape	= pShape->asDouble(m_iDependent);

		for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
		{
			for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
			{
				double	zRegression;

				TSG_Point	Point	= pShape->Get_Point(iPoint, iPart);

				if( m_pRegression->Get_Value(Point, zRegression) )
				{
					CSG_Shape	*pResidual	= pResiduals->Add_Shape();

					pResidual->Add_Point(Point);
					pResidual->Set_Value(0, zShape);
					pResidual->Set_Value(1, zRegression);
					pResidual->Set_Value(2, zShape - zRegression);
				}
			}
		}
	}

	//-----------------------------------------------------
	return( true );
}
コード例 #12
0
//---------------------------------------------------------
bool CGrid_To_Points_Random::On_Execute(void)
{
	int		x, y, n;
	double	frequency;
	CSG_Grid	*pGrid;
	CSG_Shape	*pShape;
	CSG_Shapes	*pShapes;

	pGrid		= Parameters("GRID")->asGrid();
	frequency	= 1.0 / Parameters("FREQ")->asDouble();
	pShapes		= Parameters("POINTS")->asShapes();

	pShapes->Create(SHAPE_TYPE_Point, pGrid->Get_Name());
	pShapes->Add_Field("ID"		, SG_DATATYPE_Int);
	pShapes->Add_Field("VALUE"	, SG_DATATYPE_Double);

	srand((unsigned)time(NULL));

	for(n=0, y=0; y<Get_NY() && Set_Progress(y); y++)
	{
		for(x=0; x<Get_NX(); x++)
		{
			if( (double)rand() / (double)RAND_MAX <= frequency )
			{
				pShape	= pShapes->Add_Shape();

				pShape->Add_Point(
					pGrid->Get_XMin() + x * Get_Cellsize(),
					pGrid->Get_YMin() + y * Get_Cellsize()
				);

				pShape->Set_Value(0, ++n);
				pShape->Set_Value(1, pGrid->asDouble(x, y));
			}
		}
	}

	return( true );
}
コード例 #13
0
//---------------------------------------------------------
CSG_Shapes * CInterpolation::Get_Points(bool bOnlyNonPoints)
{
	m_pShapes	= Parameters("SHAPES")	->asShapes();

	if( !bOnlyNonPoints || m_pShapes->Get_Type() != SHAPE_TYPE_Point )
	{
		CSG_Shapes	*pPoints	= SG_Create_Shapes(SHAPE_TYPE_Point);

		pPoints->Set_NoData_Value_Range(m_pShapes->Get_NoData_Value(), m_pShapes->Get_NoData_hiValue());
		pPoints->Add_Field(SG_T("Z"), SG_DATATYPE_Double);

		for(int iShape=0; iShape<m_pShapes->Get_Count() && Set_Progress(iShape, m_pShapes->Get_Count()); iShape++)
		{
			CSG_Shape	*pShape	= m_pShapes->Get_Shape(iShape);

			if( !pShape->is_NoData(m_zField) )
			{
				for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
				{
					for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
					{
						CSG_Shape	*pPoint	= pPoints->Add_Shape();

						pPoint->Add_Point(pShape->Get_Point(iPoint, iPart));

						pPoint->Set_Value(0, pShape->asDouble(m_zField));
					}
				}
			}
		}

		m_zField	= 0;
		m_pShapes	= pPoints;
	}

	return( m_pShapes );
}
コード例 #14
0
//---------------------------------------------------------
bool CPoints_From_MultiPoints::On_Execute(void)
{
	//-----------------------------------------------------
	CSG_Shapes	*pMultipoints	= Parameters("MULTIPOINTS")	->asShapes();
	CSG_Shapes	*pPoints		= Parameters("POINTS")		->asShapes();

	pPoints->Create(SHAPE_TYPE_Point, pMultipoints->Get_Name(), pMultipoints, pMultipoints->Get_Vertex_Type());

	//-----------------------------------------------------
	for(int iMultipoint=0; iMultipoint<pMultipoints->Get_Count() && Set_Progress(iMultipoint, pMultipoints->Get_Count()); iMultipoint++)
	{
		CSG_Shape	*pMultipoint	= pMultipoints->Get_Shape(iMultipoint);

		for(int iPart=0; iPart<pMultipoint->Get_Part_Count(); iPart++)
		{
			for(int iPoint=0; iPoint<pMultipoint->Get_Point_Count(iPart); iPoint++)
			{
				CSG_Shape	*pPoint	= pPoints->Add_Shape(pMultipoint, SHAPE_COPY_ATTR);

				pPoint->Add_Point(pMultipoint->Get_Point(iPoint, iPart));

				if( pMultipoints->Get_Vertex_Type() != SG_VERTEX_TYPE_XY )
				{
					pPoint->Set_Z(pMultipoint->Get_Z(iPoint, iPart), 0);

					if( pMultipoints->Get_Vertex_Type() == SG_VERTEX_TYPE_XYZM )
					{
						pPoint->Set_M(pMultipoint->Get_M(iPoint, iPart), 0);
					}
				}
			}
		}
	}

	return( true );
}
コード例 #15
0
//---------------------------------------------------------
bool CGCS_Graticule::Get_Graticule(const CSG_Rect &Extent)
{
	double		x, y, Interval;
	CSG_Rect	r;

	if( !Get_Extent(Extent, r) || (Interval = Get_Interval(r)) <= 0.0 )
	{
		return( false );
	}

	//-----------------------------------------------------
	r.m_rect.xMin	= Interval * floor(r.Get_XMin() / Interval);
	r.m_rect.xMax	= Interval * ceil (r.Get_XMax() / Interval);
	r.m_rect.yMin	= Interval * floor(r.Get_YMin() / Interval);
	r.m_rect.yMax	= Interval * ceil (r.Get_YMax() / Interval);

	r.Inflate(Interval, false);

	if( r.Get_XMin() < -180.0 )	r.m_rect.xMin	= -180.0;
	if( r.Get_XMax() >  180.0 )	r.m_rect.xMax	=  180.0;
	if( r.Get_YMin() <  -90.0 )	r.m_rect.yMin	=  -90.0;
	if( r.Get_YMax() >   90.0 )	r.m_rect.yMax	=   90.0;

	//-----------------------------------------------------
	double	Resolution	= Parameters("RESOLUTION")->asDouble();	if( Resolution <= 0.0 )	Resolution	= Interval;

	if( Interval > Resolution )
	{
		Resolution	= Interval / ceil(Interval / Resolution);
	}

	//-----------------------------------------------------
	CSG_Shapes	*pGraticule	= Parameters("GRATICULE")->asShapes();

	pGraticule->Create(SHAPE_TYPE_Line);
	pGraticule->Set_Name(_TL("Graticule"));

	pGraticule->Add_Field("TYPE"  , SG_DATATYPE_String);
	pGraticule->Add_Field("LABEL" , SG_DATATYPE_String);
	pGraticule->Add_Field("DEGREE", SG_DATATYPE_Double);

	//-----------------------------------------------------
	CSG_Shapes	*pCoordinates	= Parameters("COORDS")->asShapes();

	if( pCoordinates )
	{
		pCoordinates->Create(SHAPE_TYPE_Point);
		pCoordinates->Set_Name(_TL("Coordinates"));

		pCoordinates->Add_Field("TYPE" , SG_DATATYPE_String);
		pCoordinates->Add_Field("LABEL", SG_DATATYPE_String);
	}

	//-----------------------------------------------------
	CSG_Shapes	Clip(SHAPE_TYPE_Polygon);
	CSG_Shape	*pClip	= Clip.Add_Shape();

	pClip->Add_Point(Extent.Get_XMin(), Extent.Get_YMin());
	pClip->Add_Point(Extent.Get_XMin(), Extent.Get_YMax());
	pClip->Add_Point(Extent.Get_XMax(), Extent.Get_YMax());
	pClip->Add_Point(Extent.Get_XMax(), Extent.Get_YMin());
	pClip->Add_Point(Extent.Get_XMin(), Extent.Get_YMin());

	//-----------------------------------------------------
	for(y=r.Get_YMin(); y<=r.Get_YMax(); y+=Interval)
	{
		CSG_Shape	*pLine	= pGraticule->Add_Shape();

		pLine->Set_Value(0, "LAT");
		pLine->Set_Value(1, Get_Degree(y, DEG_PREC_DEG));
		pLine->Set_Value(2, y);

		for(x=r.Get_XMin(); x<=r.Get_XMax(); x+=Interval)
		{
			CSG_Point	p(x, y);	m_Projector.Get_Projection(p);	pLine->Add_Point(p);

			if( Resolution < Interval && x < r.Get_XMax() )
			{
				for(double i=x+Resolution; i<x+Interval; i+=Resolution)
				{
					CSG_Point	p(i, y);	m_Projector.Get_Projection(p);	pLine->Add_Point(p);
				}
			}
		}

		Get_Coordinate(Extent, pCoordinates, pLine, AXIS_LEFT);
		Get_Coordinate(Extent, pCoordinates, pLine, AXIS_RIGHT);

		if( !SG_Polygon_Intersection(pLine, pClip) )
		{
			pGraticule->Del_Shape(pLine);
		}
	}

	//-----------------------------------------------------
	for(x=r.Get_XMin(); x<=r.Get_XMax(); x+=Interval)
	{
		CSG_Shape	*pLine	= pGraticule->Add_Shape();

		pLine->Set_Value(0, "LON");
		pLine->Set_Value(1, Get_Degree(x, DEG_PREC_DEG));
		pLine->Set_Value(2, x);

		for(y=r.Get_YMin(); y<=r.Get_YMax(); y+=Interval)
		{
			CSG_Point	p(x, y);	m_Projector.Get_Projection(p);	pLine->Add_Point(p);

			if( Resolution < Interval && y < r.Get_YMax() )
			{
				for(double i=y+Resolution; i<y+Interval; i+=Resolution)
				{
					CSG_Point	p(x, i);	m_Projector.Get_Projection(p);	pLine->Add_Point(p);
				}
			}
		}

		Get_Coordinate(Extent, pCoordinates, pLine, AXIS_BOTTOM);
		Get_Coordinate(Extent, pCoordinates, pLine, AXIS_TOP);

		if( !SG_Polygon_Intersection(pLine, pClip) )
		{
			pGraticule->Del_Shape(pLine);
		}
	}

	//-----------------------------------------------------
	return( true );
}
コード例 #16
0
//---------------------------------------------------------
bool CWaterRetentionCapacity::On_Execute(void)
{
	CSG_Shapes	*pInput		= Parameters("SHAPES")->asShapes();
	CSG_Shapes	*pOutput	= Parameters("OUTPUT")->asShapes();

	if( pInput->Get_Field_Count() < 5 )
	{
		Error_Set(_TL("Plot hole data has to provide at the very least five attributes (horizon depth, TF, L, Ar, Mo)."));

		return( false );
	}

	pOutput->Create(SHAPE_TYPE_Point, _TL("Water Retention Capacity"));

	pOutput->Add_Field("CCC"                     , SG_DATATYPE_Double);
	pOutput->Add_Field("CIL"                     , SG_DATATYPE_Double);
	pOutput->Add_Field("Permeability"            , SG_DATATYPE_Double);
	pOutput->Add_Field("Equivalent Moisture"     , SG_DATATYPE_Double);
	pOutput->Add_Field("Water Retention Capacity", SG_DATATYPE_Double);

	//-----------------------------------------------------
	CSG_Grid	*pDEM	= Parameters("DEM")->asGrid();

	CSG_Matrix	Data(5, pInput->Get_Field_Count() / 5);

	for(int iPoint=0; iPoint<pInput->Get_Count(); iPoint++)
	{
		CSG_Shape	*pPoint	= pInput->Get_Shape(iPoint);

		for(int iHorizon=0, n=0; iHorizon<Data.Get_NRows(); iHorizon++, n+=5)
		{
			for(int i=0; i<5; i++)
			{
				Data[iHorizon][i]	= pPoint->asDouble(n + i);
			}
		}

		double	Slope, Aspect;

		if( !pDEM->Get_Gradient(pPoint->Get_Point(0), Slope, Aspect, GRID_RESAMPLING_BSpline) )
		{
			Slope	= 0.0;
		}

		Get_WaterRetention(Data, 1. - tan(Slope), pOutput->Add_Shape(pPoint, SHAPE_COPY_GEOM));
	}

	//-----------------------------------------------------
	CSG_Grid	*pRetention	= Parameters("RETENTION")->asGrid();

	if( pRetention )
	{
		switch( Parameters("INTERPOL")->asInt() )
		{
		default:	// Multlevel B-Spline Interpolation
			SG_RUN_TOOL_ExitOnError("grid_spline", 4,
					SG_TOOL_PARAMETER_SET("SHAPES"           , pOutput)
				&&  SG_TOOL_PARAMETER_SET("FIELD"            , pOutput->Get_Field_Count() - 1)
				&&  SG_TOOL_PARAMETER_SET("TARGET_DEFINITION", 1)	// grid or grid system
				&&  SG_TOOL_PARAMETER_SET("TARGET_OUT_GRID"  , pRetention)
			);
			break;

		case  1:	// Inverse Distance Weighted
			SG_RUN_TOOL_ExitOnError("grid_gridding", 1,
					SG_TOOL_PARAMETER_SET("SHAPES"           , pOutput)
				&&  SG_TOOL_PARAMETER_SET("FIELD"            , pOutput->Get_Field_Count() - 1)
				&&  SG_TOOL_PARAMETER_SET("TARGET_DEFINITION", 1)	// grid or grid system
				&&  SG_TOOL_PARAMETER_SET("TARGET_OUT_GRID"  , pRetention)
				&&  SG_TOOL_PARAMETER_SET("SEARCH_RANGE"     , 1)	// global
				&&  SG_TOOL_PARAMETER_SET("SEARCH_POINTS_ALL", 1)	// all points within search distance
			);
			break;
		}

		if( Parameters("SLOPECORR")->asBool() )
		{
			#pragma omp parallel for
			for(int y=0; y<Get_NY(); y++)
			{
				for(int x=0; x<Get_NX(); x++)
				{
					if( !pRetention->is_NoData(x, y) )
					{
						double	Slope, Aspect;

						if( !pDEM->Get_Gradient(x, y, Slope, Aspect) )
						{
							Slope	= 0.0;
						}

						pRetention->Mul_Value(x, y, 1. - tan(Slope));
					}
				}
			}
		}
	}

	//-----------------------------------------------------
	return( true );
}
コード例 #17
0
ファイル: GraticuleBuilder.cpp プロジェクト: am2222/SAGA-GIS
bool CGraticuleBuilder::On_Execute(void){
	
	CSG_Shape *pShape;
	CSG_Shapes *pLimit;
	double x,y;
	double dXMin;
	double dYMin;
	double dXMax;
	double dYMax;
	
	pLimit = Parameters("LIMIT_SHAPES")->asShapes();
	
	if (pLimit == NULL){
		dXMin	= ((CSG_Parameter_Range *) Parameters("X_EXTENT")->Get_Data())->Get_LoVal();
		dYMin	= ((CSG_Parameter_Range *) Parameters("Y_EXTENT")->Get_Data())->Get_LoVal();
		dXMax	= ((CSG_Parameter_Range *) Parameters("X_EXTENT")->Get_Data())->Get_HiVal();
		dYMax	= ((CSG_Parameter_Range *) Parameters("Y_EXTENT")->Get_Data())->Get_HiVal();
	}//if
	else{
		dXMin = pLimit->Get_Extent().Get_XMin();
		dXMax = pLimit->Get_Extent().Get_XMax();
		dYMin = pLimit->Get_Extent().Get_YMin();
		dYMax = pLimit->Get_Extent().Get_YMax();
	}//else

	int iElement = 0;
	int iType = Parameters("TYPE")->asInt();

	double dDistanceX = Parameters("DISTX")->asDouble();
	double dDistanceY = Parameters("DISTY")->asDouble();
	
	if (dDistanceX<=0 || dDistanceY<=0){
		return false;
	}//if

	CSG_Shapes *pGraticule = Parameters("LINES")->asShapes();
	
	if (iType == 0)
	{
		pGraticule->Create(SHAPE_TYPE_Line, _TL("Graticule"));
		pGraticule->Add_Field("ID", SG_DATATYPE_Int);

		for (x=dXMin; x<=dXMax; x=x+dDistanceX)
		{
			pShape = pGraticule->Add_Shape();
			pShape->Set_Value(0,iElement++);

			for (y=dYMin; y<=dYMax; y=y+dDistanceY)
			{
				pShape->Add_Point(x,y);
				pShape->Add_Point(x,y);
			}
		}//for

		for (y=dYMin; y<=dYMax; y=y+dDistanceY)
		{
			pShape = pGraticule->Add_Shape();
			pShape->Set_Value(0,iElement++);

			for (x=dXMin; x<=dXMax; x=x+dDistanceX)
			{
				pShape->Add_Point(x,y);
				pShape->Add_Point(x,y);
			}
		}//for
	}//if
	else
	{
		pGraticule->Create(SHAPE_TYPE_Polygon, _TL("Graticule"));
		pGraticule->Add_Field("ID", SG_DATATYPE_Int);

		for (x=dXMin; x<=dXMax-dDistanceX; x=x+dDistanceX)
		{
			for (y=dYMin; y<=dYMax-dDistanceY; y=y+dDistanceY)
			{
				pShape = pGraticule->Add_Shape();
				pShape->Set_Value(0,iElement++);

				pShape->Add_Point(x,y);
				pShape->Add_Point(x,y+dDistanceY);		
				pShape->Add_Point(x+dDistanceX,y+dDistanceY);
				pShape->Add_Point(x+dDistanceX,y);		
			}//for
		}//for		
	}//else

	return true;

}//method
コード例 #18
0
//---------------------------------------------------------
bool CLine_Crossings::On_Execute(void)
{
	CSG_Shapes	*pLines_A	= Parameters("LINES_A"  )->asShapes();
	CSG_Shapes	*pLines_B	= Parameters("LINES_B"  )->asShapes();
	CSG_Shapes	*pCrossings	= Parameters("CROSSINGS")->asShapes();

	if(	!pLines_A->is_Valid() || !pLines_B->is_Valid() || pLines_A->Get_Extent().Intersects(pLines_B->Get_Extent()) == INTERSECTION_None )
	{
		Error_Set(_TL("no intersection"));

		return( false );
	}

	//--------------------------------------------------------
	int	Attributes	= Parameters("ATTRIBUTES")->asInt();

	pCrossings->Create(SHAPE_TYPE_Point, CSG_String::Format("%s [%s - %s]", _TL("Crossings"), pLines_A->Get_Name(), pLines_B->Get_Name()));

	if( Attributes == 0 || Attributes == 2 )
	{
		pCrossings->Add_Field("ID_A", SG_DATATYPE_Int);
		pCrossings->Add_Field("ID_B", SG_DATATYPE_Int);
	}

	if( Attributes == 1 || Attributes == 2 )
	{
		Add_Attributes(pCrossings, pLines_A);
		Add_Attributes(pCrossings, pLines_B);
	}

	//--------------------------------------------------------
	for(int aLine=0, iPair=0, nPairs=pLines_A->Get_Count()*pLines_B->Get_Count() && Process_Get_Okay(); aLine<pLines_A->Get_Count(); aLine++)
	{
		CSG_Shape_Line	*pA	= (CSG_Shape_Line *)pLines_A->Get_Shape(aLine);

		for(int bLine=0; bLine<pLines_B->Get_Count() && Set_Progress(iPair++, nPairs); bLine++)
		{
			CSG_Shape_Line	*pB	= (CSG_Shape_Line *)pLines_B->Get_Shape(bLine);

			if( pA->Intersects(pB) )
			{
				for(int aPart=0; aPart<pA->Get_Part_Count(); aPart++)
				{
					TSG_Point	A[2];	A[1]	= pA->Get_Point(0, aPart);

					for(int aPoint=1; aPoint<pA->Get_Point_Count(aPart); aPoint++)
					{
						A[0]	= A[1];	A[1]	= pA->Get_Point(aPoint, aPart);

						for(int bPart=0; bPart<pB->Get_Part_Count(); bPart++)
						{
							TSG_Point	B[2], C;	B[1]	= pB->Get_Point(0, bPart);

							for(int bPoint=1; bPoint<pB->Get_Point_Count(bPart); bPoint++)
							{
								B[0]	= B[1];	B[1]	= pB->Get_Point(bPoint, bPart);

								if( SG_Get_Crossing(C, A[0], A[1], B[0], B[1]) )
								{
									Set_Crossing(C, pA, pB, pCrossings->Add_Shape(), Attributes);
								}
							}
						}
					}
				}
			}
		}
	}

	//--------------------------------------------------------
	return( pCrossings->Get_Count() > 0 );
}
コード例 #19
0
//---------------------------------------------------------
bool CShape_Index::On_Execute(void)
{
	//-----------------------------------------------------
	CSG_Shapes	*pPolygons = Parameters("SHAPES")->asShapes();

	if( !pPolygons->is_Valid() )
	{
		Error_Set(_TL("invalid polygons layer"));

		return( false );
	}

	//-----------------------------------------------------
	if( Parameters("INDEX")->asShapes() && Parameters("INDEX")->asShapes() != pPolygons )
	{
		CSG_Shapes	*pTarget   = Parameters("INDEX")->asShapes();

		pTarget->Create(SHAPE_TYPE_Polygon, CSG_String::Format("%s [%s]", pPolygons->Get_Name(), _TL("Shape Indices")));

		pTarget->Add_Field("ID", SG_DATATYPE_Int);

		for(int iPolygon=0; iPolygon<pPolygons->Get_Count() && Set_Progress(iPolygon, pPolygons->Get_Count()); iPolygon++)
		{
			pTarget->Add_Shape(pPolygons->Get_Shape(iPolygon), SHAPE_COPY)->Set_Value(0, iPolygon);
		}

		pPolygons	= pTarget;
	}

	//-----------------------------------------------------
	int	offIndices	= pPolygons->Get_Field_Count();

	pPolygons->Add_Field(_TL("A"           ), SG_DATATYPE_Double);	//  0
	pPolygons->Add_Field(_TL("P"           ), SG_DATATYPE_Double);	//  1
	pPolygons->Add_Field(_TL("P/A"         ), SG_DATATYPE_Double);	//  2
	pPolygons->Add_Field(_TL("P/sqrt(A)"   ), SG_DATATYPE_Double);	//  3
	pPolygons->Add_Field(_TL("Depqc"       ), SG_DATATYPE_Double);	//  4
	pPolygons->Add_Field(_TL("Sphericity"  ), SG_DATATYPE_Double);	//  5
	pPolygons->Add_Field(_TL("Shape Index" ), SG_DATATYPE_Double);	//  6
	pPolygons->Add_Field(_TL("Dmax"        ), SG_DATATYPE_Double);	//  7
	pPolygons->Add_Field(_TL("DmaxDir"     ), SG_DATATYPE_Double);	//  8
	pPolygons->Add_Field(_TL("Dmax/A"      ), SG_DATATYPE_Double);	//  9
	pPolygons->Add_Field(_TL("Dmax/sqrt(A)"), SG_DATATYPE_Double);	// 10

	bool	bGyros	= Parameters("GYROS")->asBool();

	if( bGyros )
	{
		pPolygons->Add_Field(_TL("Dgyros"  ), SG_DATATYPE_Double);	// 11
	}

	int	offFeret	= pPolygons->Get_Field_Count();

	double	dFeret	= 0.0;

	if( Parameters("FERET")->asBool() )
	{
		dFeret	= M_DEG_TO_RAD * (180. / (1. + Parameters("FERET_DIRS")->asInt()));

		pPolygons->Add_Field(_TL("Fmax"    ), SG_DATATYPE_Double);	//  0
		pPolygons->Add_Field(_TL("FmaxDir" ), SG_DATATYPE_Double);	//  1
		pPolygons->Add_Field(_TL("Fmin"    ), SG_DATATYPE_Double);	//  2
		pPolygons->Add_Field(_TL("FminDir" ), SG_DATATYPE_Double);	//  3
		pPolygons->Add_Field(_TL("Fmean"   ), SG_DATATYPE_Double);	//  4
		pPolygons->Add_Field(_TL("Fmax90"  ), SG_DATATYPE_Double);	//  5
		pPolygons->Add_Field(_TL("Fmin90"  ), SG_DATATYPE_Double);	//  6
		pPolygons->Add_Field(_TL("Fvol"    ), SG_DATATYPE_Double);	//  7
	}

	//-----------------------------------------------------
	CSG_Shapes	*pDmax	= Parameters("DMAX")->asShapes();

	if( pDmax )
	{
		pDmax->Create(SHAPE_TYPE_Line, CSG_String::Format("%s [%s]", pPolygons->Get_Name(), _TL("Maximum Diameter")));

		pDmax->Add_Field("ID", SG_DATATYPE_Int   );
		pDmax->Add_Field("D" , SG_DATATYPE_Double);
	}

	//-----------------------------------------------------
	for(int iPolygon=0; iPolygon<pPolygons->Get_Count() && Set_Progress(iPolygon, pPolygons->Get_Count()); iPolygon++)
	{
		CSG_Shape_Polygon	*pPolygon	= (CSG_Shape_Polygon *)pPolygons->Get_Shape(iPolygon);

		double	A	= pPolygon->Get_Area     ();
		double	P	= pPolygon->Get_Perimeter();

		if( A > 0.0 && P > 0.0 )
		{
			pPolygon->Set_Value(offIndices + 0, A);
			pPolygon->Set_Value(offIndices + 1, P);
			pPolygon->Set_Value(offIndices + 2, P / A);
			pPolygon->Set_Value(offIndices + 3, P / sqrt(A));
			pPolygon->Set_Value(offIndices + 4, 2 * sqrt(A / M_PI));
			pPolygon->Set_Value(offIndices + 5, (2 * sqrt(A * M_PI)) / P);
			pPolygon->Set_Value(offIndices + 6, P / (2 * sqrt(A * M_PI)));

			double	Dmax;	TSG_Point	Pmax[2];

			if( Get_Diameter_Max(pPolygon, Dmax, Pmax) )
			{
				double	DmaxDir	= SG_Get_Angle_Of_Direction(Pmax[0], Pmax[1]); if( DmaxDir > M_PI_180 ) DmaxDir -= M_PI_180;

				pPolygon->Set_Value(offIndices +  7, Dmax);
				pPolygon->Set_Value(offIndices +  8, DmaxDir * M_RAD_TO_DEG);
				pPolygon->Set_Value(offIndices +  9, Dmax / A);
				pPolygon->Set_Value(offIndices + 10, Dmax / sqrt(A));

				if( pDmax )
				{
					CSG_Shape	*pLine	= pDmax->Add_Shape();

					pLine->Add_Point(Pmax[0]);
					pLine->Add_Point(Pmax[1]);

					pLine->Set_Value(0, iPolygon);
					pLine->Set_Value(1, Dmax);
				}

				if( bGyros )
				{
					Get_Diameter_Gyros(pPolygon, offIndices + 11);
				}

				if( dFeret > 0.0 )
				{
					Get_Diameters_Feret(pPolygon, offFeret, dFeret);
				}
			}
			else
			{
				for(int iField=offIndices+7; iField<pPolygons->Get_Field_Count(); iField++)
				{
					pPolygon->Set_NoData(iField);
				}
			}
		}
		else
		{
			for(int iField=offIndices; iField<pPolygons->Get_Field_Count(); iField++)
			{
				pPolygon->Set_NoData(iField);
			}
		}
	}

	//-----------------------------------------------------
	if( pPolygons == Parameters("SHAPES")->asShapes() )
	{	// output is always updated automatically - but if input has been modified, this needs a manual update!
		DataObject_Update(pPolygons);
	}

	return( pPolygons->is_Valid() );
}
コード例 #20
0
//---------------------------------------------------------
bool CTIN_From_Grid_Specific_Points::On_Execute(void)
{
	bool					bResult;
	int						x, y, i;
	CSG_TIN					*pTIN;
	CSG_Grid					*pGrid, Grid;
	CSG_Parameter_Grid_List	*pValues;
	CSG_Shape					*pPoint;
	CSG_Shapes					Points;

	//-----------------------------------------------------
	pGrid	= Parameters("GRID")->asGrid();
	Grid.Create(pGrid, SG_DATATYPE_Byte);

	//-----------------------------------------------------
	switch( Parameters("METHOD")->asInt() )
	{
	default:
		bResult	= false;
		break;

	case 0:
		bResult	= Get_MarkHighestNB	(&Grid, pGrid);
		break;

	case 1:
		bResult	= Get_OppositeNB	(&Grid, pGrid, Parameters("HIGH")->asInt());
		break;

	case 2:
		bResult	= Get_FlowDirection	(&Grid, pGrid,
			(int)Parameters("FLOW")->asRange()->Get_LoVal(),
			(int)Parameters("FLOW")->asRange()->Get_HiVal()
		);
		break;

	case 3:
		bResult	= Get_FlowDirection2(&Grid, pGrid,
			(int)Parameters("FLOW")->asRange()->Get_HiVal()
		);
		break;

	case 4:
		bResult	= Get_Peucker		(&Grid, pGrid, Parameters("PEUCKER")->asDouble());
		break;
	}

	//-----------------------------------------------------
	if( bResult )
	{
		pValues	= Parameters("VALUES")->asGridList();

		Points.Create(SHAPE_TYPE_Point);
		Points.Add_Field(_TL("VALUE"), SG_DATATYPE_Double);

		for(i=0; i<pValues->Get_Count(); i++)
		{
			Points.Add_Field(pValues->asGrid(i)->Get_Name(), SG_DATATYPE_Double);
		}

		for(y=0; y<Get_NY() && Set_Progress(y, Get_NY()); y++)
		{
			for(x=0; x<Get_NX(); x++)
			{
				if( Grid.asInt(x, y) != 0 )
				{
					pPoint	= Points.Add_Shape();

					pPoint->Add_Point(
						Get_XMin() + Get_Cellsize() * x,
						Get_YMin() + Get_Cellsize() * y
					);

					pPoint->Set_Value(0, pGrid->asDouble(x, y));

					for(i=0; i<pValues->Get_Count(); i++)
					{
						pPoint->Set_Value(1 + i, pValues->asGrid(i)->asDouble(x, y));
					}
				}
			}
		}

		//-------------------------------------------------
		if( Points.Get_Count() >= 3 )
		{
			pTIN	= Parameters("TIN")->asTIN();
			pTIN->Create(&Points);
			pTIN->Set_Name(pGrid->Get_Name());
		}
	}

	return( bResult );
}
コード例 #21
0
//---------------------------------------------------------
bool CDirect_Georeferencing_WorldFile::On_Execute(void)
{
	//-----------------------------------------------------
	int	nx	= Parameters("NX")->asInt();
	int	ny	= Parameters("NY")->asInt();

	if( !m_Georeferencer.Set_Transformation(Parameters, nx, ny) )
	{
		return( false );
	}

	//-----------------------------------------------------
	CSG_String	File	= Parameters("FILE")->asString();

	if( File.is_Empty() )
	{
		return( false );
	}

	//-----------------------------------------------------
	CSG_File	Stream;

	if( !Stream.Open(File, SG_FILE_W, false) )
	{
		return( false );
	}

	//-----------------------------------------------------
	CSG_Matrix	R(m_Georeferencer.Get_Transformation());

	R	*= 0.001 * Parameters("Z")->asDouble() / Parameters("CFL")->asDouble() * Parameters("PXSIZE")->asDouble();

	TSG_Point	p	= m_Georeferencer.Image_to_World(0, ny);

	Stream.Printf(SG_T("%.10f\n%.10f\n%.10f\n%.10f\n%.10f\n%.10f\n"),
		 R[0][0],	// A: pixel size in the x-direction in map units/pixel
		 R[1][0],	// D: rotation about y-axis
		-R[0][1],	// B: rotation about x-axis
		-R[1][1],	// E: pixel size in the y-direction in map units, almost always negative
		     p.x,	// X: top left pixel center
		     p.y	// Y: top left pixel center
	);

	//-----------------------------------------------------
	CSG_Shapes	*pExtents	= Parameters("EXTENT")->asShapes();

	if( pExtents )
	{
		pExtents->Create(SHAPE_TYPE_Polygon, SG_File_Get_Name(File, false));
		pExtents->Add_Field(_TL("NAME"), SG_DATATYPE_String);

		CSG_Shape	*pExtent	= pExtents->Add_Shape();

		p	= m_Georeferencer.Image_to_World( 0,  0);	pExtent->Add_Point(p.x, p.y);
		p	= m_Georeferencer.Image_to_World( 0, ny);	pExtent->Add_Point(p.x, p.y);
		p	= m_Georeferencer.Image_to_World(nx, ny);	pExtent->Add_Point(p.x, p.y);
		p	= m_Georeferencer.Image_to_World(nx,  0);	pExtent->Add_Point(p.x, p.y);

		pExtent->Set_Value(0, SG_File_Get_Name(File, false));
	}

	//-----------------------------------------------------
	return( true );
}
コード例 #22
0
//---------------------------------------------------------
bool CDirect_Georeferencing::On_Execute(void)
{
	//-----------------------------------------------------
	if( !m_Georeferencer.Set_Transformation(Parameters, Get_NX(), Get_NY()) )
	{
		return( false );
	}

	//-----------------------------------------------------
	CSG_Grid	*pDEM	= Parameters("DEM"      )->asGrid();
	double		zRef	= Parameters("ZREF"     )->asDouble();
	bool		bFlip	= Parameters("ROW_ORDER")->asInt() == 1;

	//-----------------------------------------------------
	TSG_Grid_Resampling	Resampling;

	switch( Parameters("RESAMPLING")->asInt() )
	{
	default:	Resampling	= GRID_RESAMPLING_NearestNeighbour;	break;
	case  1:	Resampling	= GRID_RESAMPLING_Bilinear;			break;
	case  2:	Resampling	= GRID_RESAMPLING_BicubicSpline;	break;
	case  3:	Resampling	= GRID_RESAMPLING_BSpline;			break;
	}

	//-----------------------------------------------------
	TSG_Point	p[4];

	p[0]	= m_Georeferencer.Image_to_World(       0,        0, zRef);
	p[1]	= m_Georeferencer.Image_to_World(Get_NX(),        0, zRef);
	p[2]	= m_Georeferencer.Image_to_World(Get_NX(), Get_NY(), zRef);
	p[3]	= m_Georeferencer.Image_to_World(       0, Get_NY(), zRef);

	CSG_Rect	r(p[0], p[1]);	r.Union(p[2]);	r.Union(p[3]);

	//-----------------------------------------------------
	CSG_Shapes	*pShapes	= Parameters("EXTENT")->asShapes();

	if( pShapes )
	{
		pShapes->Create(SHAPE_TYPE_Polygon, _TL("Extent"));
		pShapes->Add_Field(_TL("OID"), SG_DATATYPE_Int);

		CSG_Shape	*pExtent	= pShapes->Add_Shape();

		pExtent->Add_Point(p[0]);
		pExtent->Add_Point(p[1]);
		pExtent->Add_Point(p[2]);
		pExtent->Add_Point(p[3]);
	}

	//-----------------------------------------------------
	double	Cellsize	= SG_Get_Distance(p[0], p[1]) / Get_NX();

	CSG_Grid_System	System(Cellsize, r);

	m_Grid_Target.Set_User_Defined(Get_Parameters("TARGET"), r, Get_NX());

	if( !Dlg_Parameters("TARGET") )
	{
		return( false );
	}

	System	= m_Grid_Target.Get_System();

	if( !System.is_Valid() )
	{
		return( false );
	}

	//-----------------------------------------------------
	CSG_Parameter_Grid_List	*pInput		= Parameters("INPUT" )->asGridList();
	CSG_Parameter_Grid_List	*pOutput	= Parameters("OUTPUT")->asGridList();

	pOutput->Del_Items();

	if( pInput->Get_Count() <= 0 )
	{
		return( false );
	}
	else
	{
		TSG_Data_Type	Type;

		switch( Parameters("DATA_TYPE")->asInt() )
		{
		case 0:		Type	= SG_DATATYPE_Byte;			break;
		case 1:		Type	= SG_DATATYPE_Char;			break;
		case 2:		Type	= SG_DATATYPE_Word;			break;
		case 3:		Type	= SG_DATATYPE_Short;		break;
		case 4:		Type	= SG_DATATYPE_DWord;		break;
		case 5:		Type	= SG_DATATYPE_Int;			break;
		case 6: 	Type	= SG_DATATYPE_Float;		break;
		case 7:		Type	= SG_DATATYPE_Double;		break;
		default:	Type	= SG_DATATYPE_Undefined;	break;
		}

		for(int i=0; i<pInput->Get_Count(); i++)
		{
			CSG_Grid	*pGrid	= SG_Create_Grid(System, Type != SG_DATATYPE_Undefined ? Type : pInput->asGrid(i)->Get_Type());

			if( !pGrid || !pGrid->is_Valid() )
			{
				if( pGrid )
				{
					delete(pGrid);
				}

				return( false );
			}

			pOutput->Add_Item(pGrid);

			pGrid->Set_Name(pInput->asGrid(i)->Get_Name());
		}
	}

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

		#pragma omp parallel for
		for(int x=0; x<System.Get_NX(); x++)
		{
			double	pz, px	= System.Get_XMin() + x * System.Get_Cellsize();

			if( !pDEM || !pDEM->Get_Value(px, py, pz) )
			{
				pz	= zRef;
			}

			TSG_Point	p	= m_Georeferencer.World_to_Image(px, py, pz);

			if( bFlip )
			{
				p.y	= (Get_NY() - 1) - p.y;
			}

			for(int i=0; i<pInput->Get_Count(); i++)
			{
				if( pInput->asGrid(i)->Get_Value(p.x, p.y, pz, Resampling) )
				{
					pOutput->asGrid(i)->Set_Value(x, y, pz);
				}
				else
				{
					pOutput->asGrid(i)->Set_NoData(x, y);
				}
			}
		}
	}

	//-----------------------------------------------------
	return( true );
}
コード例 #23
0
//---------------------------------------------------------
bool CPointCloud_Create_Tileshape_From_SPCVF::On_Execute(void)
{
	CSG_String		sFileName;
	CSG_Shapes		*pShapes;

	CSG_MetaData	SPCVF;
	CSG_String		sPathSPCVF, sFilePath;
	int				iPoints;
	double			dBBoxXMin, dBBoxYMin, dBBoxXMax, dBBoxYMax;


	//-----------------------------------------------------
	sFileName	= Parameters("FILENAME")->asString();
	pShapes		= Parameters("TILE_SHP")->asShapes();
	

	//-----------------------------------------------------
	if( !SPCVF.Create(sFileName) || SPCVF.Get_Name().CmpNoCase(SG_T("SPCVFDataset")) )
	{
		SG_UI_Msg_Add_Error(_TL("Please provide a valid *.scpvf file!"));
		return( false );
	}


	//-----------------------------------------------------
	CSG_String	sMethodPaths;
	SPCVF.Get_Property(SG_T("Paths"), sMethodPaths);

	if( !sMethodPaths.CmpNoCase(SG_T("absolute")) )
	{
		sPathSPCVF = SG_T("");
	}
	else if( !sMethodPaths.CmpNoCase(SG_T("relative")) )
	{
		sPathSPCVF = SG_File_Get_Path(sFileName);
		sPathSPCVF.Replace(SG_T("\\"), SG_T("/"));
	}
	else
	{
		SG_UI_Msg_Add_Error(_TL("Encountered invalid path description in *.spcvf file!"));
		return( false );
	}


	//-----------------------------------------------------
	pShapes->Destroy();

	pShapes->Add_Field(_TL("ID"),		SG_DATATYPE_Int);
	pShapes->Add_Field(_TL("Filepath"),	SG_DATATYPE_String);
	pShapes->Add_Field(_TL("File"),		SG_DATATYPE_String);
	pShapes->Add_Field(_TL("Points"),	SG_DATATYPE_Int);

	pShapes->Set_Name(CSG_String::Format(_TL("Tileshape_%s"), SG_File_Get_Name(sFileName, false).c_str()));


	//-----------------------------------------------------
	CSG_MetaData	*pDatasets = SPCVF.Get_Child(SG_T("Datasets"));

	for(int i=0; i<pDatasets->Get_Children_Count(); i++)
	{
		CSG_MetaData	*pDataset	= pDatasets->Get_Child(i);
		CSG_MetaData	*pBBox		= pDataset->Get_Child(SG_T("BBox"));

		pDataset->Get_Property(SG_T("File"), sFilePath);

		pDataset->Get_Property(SG_T("Points"), iPoints);

		pBBox->Get_Property(SG_T("XMin"), dBBoxXMin);
		pBBox->Get_Property(SG_T("YMin"), dBBoxYMin);
		pBBox->Get_Property(SG_T("XMax"), dBBoxXMax);
		pBBox->Get_Property(SG_T("YMax"), dBBoxYMax);

		//-----------------------------------------------------
		CSG_Shape	*pShape = pShapes->Add_Shape();

		pShape->Add_Point(dBBoxXMin, dBBoxYMin);
		pShape->Add_Point(dBBoxXMin, dBBoxYMax);
		pShape->Add_Point(dBBoxXMax, dBBoxYMax);
		pShape->Add_Point(dBBoxXMax, dBBoxYMin);

		pShape->Set_Value(0, i + 1);

		if( sPathSPCVF.Length() == 0 )	// absolute paths
		{
			pShape->Set_Value(1, sFilePath.BeforeLast('/'));
			pShape->Set_Value(2, sFilePath.AfterLast('/'));
		}
		else							// relative paths
		{
			pShape->Set_Value(1, sPathSPCVF);
			pShape->Set_Value(2, sFilePath);
		}

		pShape->Set_Value(3, iPoints);
	}


	//-----------------------------------------------------
	return( true );
}
コード例 #24
0
//---------------------------------------------------------
bool CLine_Dissolve::On_Execute(void)
{
	CSG_Shapes	*pLines	= Parameters("LINES")->asShapes();

	if(	!pLines->is_Valid() || pLines->Get_Count() < 2 )
	{
		Error_Set(_TL("invalid or empty lines layer"));

		return( false );
	}

	//-----------------------------------------------------
	CSG_Shapes	*pDissolved	= Parameters("DISSOLVED")->asShapes();

	pDissolved->Create(SHAPE_TYPE_Line);

	CSG_Parameter_Table_Fields	&Fields	= *Parameters("FIELDS")->asTableFields();

	CSG_Table	Dissolve;

	//-----------------------------------------------------
	if( Fields.Get_Count() == 0 )
	{
		pDissolved->Fmt_Name("%s [%s]", pLines->Get_Name(), _TL("Dissolved"));
	}
	else
	{
		Dissolve.Add_Field("INDEX", SG_DATATYPE_Int   );
		Dissolve.Add_Field("VALUE", SG_DATATYPE_String);

		Dissolve.Set_Record_Count(pLines->Get_Count());

		for(int i=0; i<pLines->Get_Count() && Set_Progress(i, pLines->Get_Count()); i++)
		{
			CSG_Shape	*pLine	= pLines->Get_Shape(i);

			CSG_String	Value;

			for(int iField=0; iField<Fields.Get_Count(); iField++)
			{
				Value	+= pLine->asString(Fields.Get_Index(iField));
			}

			Dissolve[i].Set_Value(0, i);
			Dissolve[i].Set_Value(1, Value);
		}

		Dissolve.Set_Index(1, TABLE_INDEX_Ascending);

		//-------------------------------------------------
		CSG_String	Name;

		for(int iField=0; iField<Fields.Get_Count(); iField++)
		{
			if( iField > 0 )
			{
				Name	+= "; ";
			}

			Name	+= pLines->Get_Field_Name(Fields.Get_Index(iField));

			pDissolved->Add_Field(
				pLines->Get_Field_Name(Fields.Get_Index(iField)),
				pLines->Get_Field_Type(Fields.Get_Index(iField))
			);
		}

		pDissolved->Fmt_Name("%s [%s: %s]", pLines->Get_Name(), _TL("Dissolved"), Name.c_str());
	}

	//-----------------------------------------------------
	Statistics_Initialize(pDissolved, pLines);

	//-----------------------------------------------------
	CSG_String	Value;	CSG_Shape	*pDissolve	= NULL;

	for(int i=0; i<pLines->Get_Count() && Set_Progress(i, pLines->Get_Count()); i++)
	{
		CSG_Shape	*pLine	= pLines->Get_Shape(!Dissolve.Get_Count() ? i : Dissolve[i].asInt(0));

		if( !pDissolve || (Dissolve.Get_Count() && Value.Cmp(Dissolve[i].asString(1))) )
		{
			if( Dissolve.Get_Count() )
			{
				Value	= Dissolve[i].asString(1);
			}

			pDissolve	= pDissolved->Add_Shape(pLine, SHAPE_COPY_GEOM);

			for(int iField=0; iField<Fields.Get_Count(); iField++)
			{
				*pDissolve->Get_Value(iField)	= *pLine->Get_Value(Fields.Get_Index(iField));
			}

			Statistics_Add(pDissolve, pLine, true);
		}
		else
		{
			Add_Line(pDissolve, pLine);

			Statistics_Add(pDissolve, pLine, false);
		}
	}

	//-----------------------------------------------------
	return( pDissolved->is_Valid() );
}
コード例 #25
0
ファイル: stl.cpp プロジェクト: am2222/SAGA-GIS
//---------------------------------------------------------
bool CSTL_Import::On_Execute(void)
{
	int			Method;
	DWORD		iFacette, nFacettes;
	TSTL_Point	p[3];
	CSG_String	sFile, sHeader;
	CSG_File	Stream;

	//-----------------------------------------------------
	sFile		= Parameters("FILE")		->asString();
	Method		= Parameters("METHOD")		->asInt();

	r_sin_x	= sin(Parameters("ROT_X")->asDouble() * M_DEG_TO_RAD);
	r_sin_y	= sin(Parameters("ROT_Y")->asDouble() * M_DEG_TO_RAD);
	r_sin_z	= sin(Parameters("ROT_Z")->asDouble() * M_DEG_TO_RAD);
	r_cos_x	= cos(Parameters("ROT_X")->asDouble() * M_DEG_TO_RAD);
	r_cos_y	= cos(Parameters("ROT_Y")->asDouble() * M_DEG_TO_RAD);
	r_cos_z	= cos(Parameters("ROT_Z")->asDouble() * M_DEG_TO_RAD);

	//-----------------------------------------------------
	if( !Stream.Open(sFile) )
	{
		return( false );
	}

	if( !Stream.Read(sHeader, 80) )
	{
		return( false );
	}

	Message_Add(sHeader);

	if( !Stream.Read(&nFacettes, sizeof(nFacettes)) )
	{
		return( false );
	}

	Message_Add(CSG_String::Format(SG_T("%s: %d"), _TL("Number of Facettes"), nFacettes));

	//-----------------------------------------------------
	switch( Method )
	{

	//-----------------------------------------------------
	case 0:	{	// Point Cloud
		CSG_Rect	Extent;

		if( Get_Extent(Stream, Extent, nFacettes) )
		{
			CSG_PRQuadTree	Points(Extent);
			CSG_PointCloud	*pPoints	= SG_Create_PointCloud();
			Parameters("POINTS")->Set_Value(pPoints);
			pPoints->Set_Name(SG_File_Get_Name(sFile, false));
			pPoints->Add_Field((const char *)NULL, SG_DATATYPE_Undefined);

			for(iFacette=0; iFacette<nFacettes && !Stream.is_EOF() && Set_Progress(iFacette, nFacettes); iFacette++)
			{
				if( Read_Facette(Stream, p) )
				{
					for(int i=0; i<3; i++)
					{
						if( Points.Add_Point(p[i].x, p[i].y, p[i].z) )
						{
							pPoints->Add_Point(p[i].x, p[i].y, p[i].z);
						}
					}
				}
			}
		}

	break;	}

	//-----------------------------------------------------
	case 1:	{	// Point Cloud (centered)
		CSG_PointCloud	*pPoints	= SG_Create_PointCloud();
		Parameters("POINTS")->Set_Value(pPoints);
		pPoints->Set_Name(SG_File_Get_Name(sFile, false));
		pPoints->Add_Field((const char *)NULL, SG_DATATYPE_Undefined);

		for(iFacette=0; iFacette<nFacettes && !Stream.is_EOF() && Set_Progress(iFacette, nFacettes); iFacette++)
		{
			if( Read_Facette(Stream, p) )
			{
				pPoints->Add_Point(
					(p[0].x + p[1].x + p[2].x) / 3.0,
					(p[0].y + p[1].y + p[2].y) / 3.0,
					(p[0].z + p[1].z + p[2].z) / 3.0
				);
			}
		}

	break;	}

	//-----------------------------------------------------
	case 2:	{	// Points
		CSG_Shapes	*pPoints	= SG_Create_Shapes(SHAPE_TYPE_Point, SG_File_Get_Name(sFile, false));
		pPoints->Add_Field(SG_T("Z"), SG_DATATYPE_Float);
		Parameters("SHAPES")->Set_Value(pPoints);

		for(iFacette=0; iFacette<nFacettes && !Stream.is_EOF() && Set_Progress(iFacette, nFacettes); iFacette++)
		{
			if( Read_Facette(Stream, p) )
			{
				CSG_Shape	*pPoint	= pPoints->Add_Shape();

				pPoint->Add_Point(
					(p[0].x + p[1].x + p[2].x) / 3.0,
					(p[0].y + p[1].y + p[2].y) / 3.0
				);

				pPoint->Set_Value(0,
					(p[0].z + p[1].z + p[2].z) / 3.0
				);
			}
		}

	break;	}

	//-----------------------------------------------------
	case 3:	{	// Raster
		CSG_Rect	Extent;

		if( Get_Extent(Stream, Extent, nFacettes) )
		{
			int		nx, ny;
			double	d;

			nx		= Parameters("GRID_RES")->asInt();
			d		= Extent.Get_XRange() / nx;
			ny		= 1 + (int)(Extent.Get_YRange() / d);

			m_pGrid	= SG_Create_Grid(SG_DATATYPE_Float, nx, ny, d, Extent.Get_XMin(), Extent.Get_YMin());
			m_pGrid->Set_Name(SG_File_Get_Name(sFile, false));
			m_pGrid->Set_NoData_Value(-99999);
			m_pGrid->Assign_NoData();

			Parameters("GRID")->Set_Value(m_pGrid);

			//---------------------------------------------
			for(iFacette=0; iFacette<nFacettes && !Stream.is_EOF() && Set_Progress(iFacette, nFacettes); iFacette++)
			{
				if( Read_Facette(Stream, p) )
				{
					TSG_Point_Z	Point[3];

					for(int i=0; i<3; i++)
					{
						Point[i].x	= (p[i].x - m_pGrid->Get_XMin()) / m_pGrid->Get_Cellsize();
						Point[i].y	= (p[i].y - m_pGrid->Get_YMin()) / m_pGrid->Get_Cellsize();
						Point[i].z	=  p[i].z;
					}

					Set_Triangle(Point);
				}
			}
		}

	break;	}
	}

	//-----------------------------------------------------
	return( true );
}
コード例 #26
0
ファイル: wasp_map.cpp プロジェクト: am2222/SAGA-GIS
//---------------------------------------------------------
bool CWASP_MAP_Import::On_Execute(void)
{
	int			n, Method, nLength;
	double		z, dz, zMin, rLeft, rRight;
	FILE		*Stream;
	TSG_Point	p, pu[2], pm[2];
	CSG_String	fName, sLine;
	CSG_Shape	*pLine;
	CSG_Shapes	*pLines;

	//-----------------------------------------------------
	pLines	= Parameters("SHAPES")		->asShapes();
	fName	= Parameters("FILE")		->asString();
	Method	= Parameters("METHOD")		->asInt();

	//-----------------------------------------------------
	if( (Stream = fopen(fName.b_str(), "r")) != NULL )
	{
		fseek(Stream, 0, SEEK_END);
		nLength	= ftell(Stream);
		fseek(Stream, 0, SEEK_SET);

		pLines->Create(SHAPE_TYPE_Line, SG_File_Get_Name(fName, false));

		switch( Method )
		{
		case 0:	// elevation
			pLines->Add_Field("Z"		, SG_DATATYPE_Double);
			break;

		case 1:	// roughness
			pLines->Add_Field("RLEFT"	, SG_DATATYPE_Double);
			pLines->Add_Field("RRIGHT"	, SG_DATATYPE_Double);
			break;

		case 2:	// elevation and roughness
			pLines->Add_Field("Z"		, SG_DATATYPE_Double);
			pLines->Add_Field("RLEFT"	, SG_DATATYPE_Double);
			pLines->Add_Field("RRIGHT"	, SG_DATATYPE_Double);
			break;
		}


		// 1)	Text string identifying the terrain map: + ...

		SG_Read_Line(Stream, sLine);


		// 2)	Fixed point #1 in user and metric [m] coordinates:
		//			X1(user) Y1(user) X1(metric) Y1(metric)

		fscanf(Stream, "%lf %lf %lf %lf", &pu[0].x, &pu[0].y, &pm[0].x, &pm[0].y);


		// 3)	Fixed point #2 in user and metric [m] coordinates:
		//			X2(user) Y2(user) X2(metric) Y2(metric)

		fscanf(Stream, "%lf %lf %lf %lf", &pu[1].x, &pu[1].y, &pm[1].x, &pm[1].y);


		// 4)	Scaling factor and offset for height scale (Z):
		//			Zmetric = {scaling factor}(Zuser + {offset})

		fscanf(Stream, "%lf %lf", &dz, &zMin);


		while( !feof(Stream) && Set_Progress(ftell(Stream), nLength) )
		{
			pLine	= NULL;

			switch( Method )
			{
			case 0:	// elevation
				// 5a)	Height contour: elevation (Z) and number of points (n) in line:
				//			Z n

				fscanf(Stream, "%lf %d", &z, &n);

				if( !feof(Stream) && n > 1 )
				{
					pLine	= pLines->Add_Shape();
					pLine->Set_Value(0, zMin + dz * z);
				}
				break;

			case 1:	// roughness
				// 5b)	Roughness change line:
				//			roughness lengths to the left (z0l) and right (z0r) side of the line,
				//			respectively, and number of points:
				//				z0l z0r n

				fscanf(Stream, "%lf %lf %d", &rLeft, &rRight, &n);

				if( !feof(Stream) && n > 1 )
				{
					pLine	= pLines->Add_Shape();
					pLine->Set_Value(0, rLeft);
					pLine->Set_Value(1, rRight);
				}
				break;

			case 2:	// elevation and roughness
				// 5c)	Roughness and contour line:
				//			roughness lengths to the left and right of the line,
				//			respectively, elevation and number of points:
				//				z0l z0r Z n

				fscanf(Stream, "%lf %lf %lf %d", &rLeft, &rRight, &z, &n);

				if( !feof(Stream) && n > 1 )
				{
					pLine	= pLines->Add_Shape();
					pLine->Set_Value(0, zMin + dz * z);
					pLine->Set_Value(1, rLeft);
					pLine->Set_Value(2, rRight);
				}
				break;
			}


			// 6–)	Cartesian coordinates (X, Y) of line described in 5a, 5b or 5c:
			//			X1 Y1 [... Xn Yn]
			//			Xn+1 Yn+1
			//			... where [] embrace optional numbers and n is > 0

			for(int i=0; i<n && !feof(Stream) && Process_Get_Okay(false); i++)
			{
				fscanf(Stream, "%lf %lf", &p.x, &p.y);

				pLine->Add_Point(p);
			}
		}

		fclose(Stream);

		return( true );
	}

	return( false );
}
コード例 #27
0
//---------------------------------------------------------
bool CGraticuleBuilder::On_Execute(void)
{
	//-----------------------------------------------------
	TSG_Rect	Extent;
	
	if( Parameters("EXTENT")->asShapes() )
	{
		Extent		= Parameters("EXTENT")->asShapes()->Get_Extent();
	}
	else
	{
		Extent.xMin	= Parameters("EXTENT_X")->asRange()->Get_LoVal();
		Extent.yMin	= Parameters("EXTENT_Y")->asRange()->Get_LoVal();
		Extent.xMax	= Parameters("EXTENT_X")->asRange()->Get_HiVal();
		Extent.yMax	= Parameters("EXTENT_Y")->asRange()->Get_HiVal();
	}

	if( Extent.xMin >= Extent.xMax || Extent.yMin >= Extent.yMax )
	{
		Error_Set(_TL("invalid extent"));

		return( false );
	}

	//-----------------------------------------------------
	double	dx	= Parameters("DIVISION_X")->asDouble();
	double	dy	= Parameters("DIVISION_Y")->asDouble();

	if( dx <= 0.0 || dy <= 0.0 )
	{
		Error_Set(_TL("invalid division size"));

		return( false );
	}

	//-----------------------------------------------------
	int	nx	= (int)ceil((Extent.xMax - Extent.xMin) / dx);
	int	ny	= (int)ceil((Extent.yMax - Extent.yMin) / dy);

	switch( Parameters("ALIGNMENT")->asInt() )
	{
	default:	// bottom-left
	//	Extent.xMax	= Extent.xMin + nx * dx;
	//	Extent.yMax	= Extent.yMin + ny * dy;
		break;

	case  1:	// top-left
	//	Extent.xMax	= Extent.xMin + nx * dx;
		Extent.yMin	= Extent.yMax - ny * dy;
		break;

	case  2:	// bottom-right
		Extent.xMin	= Extent.xMax - nx * dx;
	//	Extent.yMax	= Extent.yMin + ny * dy;
		break;

	case  3:	// top-right
		Extent.xMin	= Extent.xMax - nx * dx;
		Extent.yMin	= Extent.yMax - ny * dy;
		break;

	case  4:	// centered
		{
			double	cx	= Extent.xMin + (Extent.xMax - Extent.xMin) / 2.0;
			double	cy	= Extent.yMin + (Extent.yMax - Extent.yMin) / 2.0;

			Extent.xMin	= cx - nx * dx / 2.0;
			Extent.yMin	= cy - ny * dy / 2.0;
		//	Extent.xMax	= cx + nx * dx / 2.0;
		//	Extent.yMax	= cy + ny * dy / 2.0;
		}
		break;
	}

	//-----------------------------------------------------
	CSG_Shapes	*pGraticule	= Parameters("TYPE")->asInt() == 0
		? Parameters("GRATICULE_LINE")->asShapes()
		: Parameters("GRATICULE_RECT")->asShapes();

	int			x, y;
	TSG_Point	p;

	switch( Parameters("TYPE")->asInt() )
	{
	//-----------------------------------------------------
	case 0:	// Lines
		{
			pGraticule->Create(SHAPE_TYPE_Line, _TL("Graticule"));

			pGraticule->Add_Field("ID", SG_DATATYPE_Int);

			for(x=0, p.x=Extent.xMin; x<=nx; x++, p.x+=dx)
			{
				CSG_Shape	*pLine	= pGraticule->Add_Shape();

				pLine->Set_Value(0, pGraticule->Get_Count());

				for(y=0, p.y=Extent.yMin; y<=ny; y++, p.y+=dy)
				{
					pLine->Add_Point(p.x, p.y);
				}
			}

			for(y=0, p.y=Extent.yMin; y<=ny; y++, p.y+=dy)
			{
				CSG_Shape	*pLine	= pGraticule->Add_Shape();

				pLine->Set_Value(0, pGraticule->Get_Count());

				for(x=0, p.x=Extent.xMin; x<=nx; x++, p.x+=dx)
				{
					pLine->Add_Point(p.x, p.y);
				}
			}
		}
		break;

	//-----------------------------------------------------
	case 1:	// Rectangles
		{
			pGraticule->Create(SHAPE_TYPE_Polygon, _TL("Graticule"));

			pGraticule->Add_Field("ID" , SG_DATATYPE_Int);
			pGraticule->Add_Field("ROW", SG_DATATYPE_Int);
			pGraticule->Add_Field("COL", SG_DATATYPE_Int);

			for(y=0, p.y=Extent.yMin; y<ny; y++, p.y+=dy)
			{
				p.x	= Extent.xMin;

				for(x=0, p.x=Extent.xMin; x<nx; x++, p.x+=dx)
				{
					CSG_Shape	*pRect	= pGraticule->Add_Shape();

					pRect->Set_Value(0, pGraticule->Get_Count());
					pRect->Set_Value(1, 1 + y);
					pRect->Set_Value(2, 1 + x);

					pRect->Add_Point(p.x     , p.y     );
					pRect->Add_Point(p.x     , p.y + dy);
					pRect->Add_Point(p.x + dx, p.y + dy);
					pRect->Add_Point(p.x + dx, p.y     );
					pRect->Add_Point(p.x     , p.y     );
				}
			}
		}
		break;

	//-----------------------------------------------------
	}

	return( true );
}
コード例 #28
0
//---------------------------------------------------------
void CD8_Flow_Analysis::Get_Nodes(void)
{
	Process_Set_Text(_TL("Junctions"));

	CSG_Shapes	*pNodes	= Parameters("NODES")->asShapes();

	if( pNodes )
	{
		pNodes	->Create(SHAPE_TYPE_Point, _TL("Junctions"), NULL, SG_VERTEX_TYPE_XYZ);
		pNodes	->Add_Field(_TL("NODE_ID")		, SG_DATATYPE_Int);
		pNodes	->Add_Field(_TL("TYPE")			, SG_DATATYPE_String);
	}

	m_Nodes.Create(*Get_System(), SG_DATATYPE_Int);

	m_pBasins->Set_NoData_Value(0);
	m_pBasins->Assign_NoData();

	for(int y=0, nNodes=0, nBasins=0; y<Get_NY() && Set_Progress(y); y++)
	{
		for(int x=0; x<Get_NX(); x++)
		{
			int	i, Order	= m_pOrder->asInt(x, y);

			if( Order >= m_Threshold )
			{
				if( (i = m_pDir->asInt(x, y)) >= 0 )
				{
					int	ix	= Get_xTo(i, x);
					int	iy	= Get_yTo(i, y);

					if( !m_Nodes.asInt(ix, iy) && m_pOrder->asInt(ix, iy) > Order && m_pDir->asInt(ix, iy) >= 0 )
					{
						Set_Node(ix, iy, ++nNodes, NODE_JUNCTION, pNodes ? pNodes->Add_Shape() : NULL);
					}

					if( Order == m_Threshold )
					{
						bool	bSpring	= true;

						for(i=0; i<8 && bSpring; i++)
						{
							if( Get_System()->Get_Neighbor_Pos(i + 4, x, y, ix, iy) && m_pDir->asInt(ix, iy) == i )
							{
								bSpring	= m_pOrder->asInt(ix, iy) < m_Threshold;
							}
						}

						if( bSpring )
						{
							Set_Node(x, y, ++nNodes, NODE_SPRING, pNodes ? pNodes->Add_Shape() : NULL);
						}
					}
				}
				else
				{
					Set_Node(x, y, ++nNodes, NODE_OUTLET, pNodes ? pNodes->Add_Shape() : NULL);

					m_pBasins->Set_Value(x, y, ++nBasins);
				}
			}
		}
	}
}
コード例 #29
0
//---------------------------------------------------------
bool CPolygon_Dissolve::On_Execute(void)
{
	//-----------------------------------------------------
	CSG_Shapes	*pPolygons	= Parameters("POLYGONS")->asShapes();

	if(	!pPolygons->is_Valid() || pPolygons->Get_Count() < 2 )
	{
		Error_Set(_TL("invalid or empty polygons layer"));

		return( false );
	}

	//-----------------------------------------------------
	CSG_Shapes	*pUnions	= Parameters("DISSOLVED")->asShapes();

	pUnions->Create(SHAPE_TYPE_Polygon);

	int	Field_1	= Parameters("FIELD_1")->asInt();
	int	Field_2	= Parameters("FIELD_2")->asInt();	if( Field_1 < 0 )	Field_2	= -1;
	int	Field_3	= Parameters("FIELD_3")->asInt();	if( Field_2 < 0 )	Field_3	= -1;

	if( Field_1 >= 0 )
	{
		CSG_String	s	= pPolygons->Get_Field_Name(Field_1);
		pUnions->Add_Field(pPolygons->Get_Field_Name(Field_1), pPolygons->Get_Field_Type(Field_1));

		if( Field_2 >= 0 )
		{
			s	+= CSG_String(" | ") + pPolygons->Get_Field_Name(Field_2);
			pUnions->Add_Field(pPolygons->Get_Field_Name(Field_2), pPolygons->Get_Field_Type(Field_2));

			if( Field_3 >= 0 )
			{
				s	+= CSG_String(" | ") + pPolygons->Get_Field_Name(Field_3);
				pUnions->Add_Field(pPolygons->Get_Field_Name(Field_3), pPolygons->Get_Field_Type(Field_3));
			}
		}

		pPolygons->Set_Index(Field_1, TABLE_INDEX_Ascending, Field_2, TABLE_INDEX_Ascending, Field_3, TABLE_INDEX_Ascending);

		pUnions->Set_Name(CSG_String::Format(SG_T("%s [%s: %s]"), pPolygons->Get_Name(), _TL("Dissolved"), s.c_str()));
	}
	else // if( Field_1 < 0 )
	{
		pUnions->Set_Name(CSG_String::Format(SG_T("%s [%s: %s]"), pPolygons->Get_Name(), _TL("Dissolved"), _TL("All")));
	}

	Init_Statistics(pUnions, pPolygons);

	//-----------------------------------------------------
	CSG_String	Value;

	CSG_Shape	*pUnion		= NULL;

	bool		bDissolve	= Parameters("BND_KEEP")->asBool() == false;

	//-----------------------------------------------------
	for(int iPolygon=0; iPolygon<pPolygons->Get_Count() && Set_Progress(iPolygon, pPolygons->Get_Count()); iPolygon++)
	{
		CSG_Shape	*pPolygon	= pPolygons->Get_Shape(pPolygons->Get_Record_byIndex(iPolygon)->Get_Index());

		CSG_String	s;

		if( Field_1 >= 0 )	s	 = pPolygon->asString(Field_1);
		if( Field_2 >= 0 )	s	+= pPolygon->asString(Field_2);
		if( Field_3 >= 0 )	s	+= pPolygon->asString(Field_3);

		if( pUnion == NULL || (Field_1 >= 0 && Value.Cmp(s)) )
		{
			Set_Union(pUnion, bDissolve);

			Value	= s;
			pUnion	= pUnions->Add_Shape(pPolygon, SHAPE_COPY_GEOM);

			if( Field_1 >= 0 )	pUnion->Set_Value(0, pPolygon->asString(Field_1));
			if( Field_2 >= 0 )	pUnion->Set_Value(1, pPolygon->asString(Field_2));
			if( Field_3 >= 0 )	pUnion->Set_Value(2, pPolygon->asString(Field_3));

			Add_Statistics(pUnion, pPolygon, true);
		}
		else
		{
			for(int iPart=0; iPart<pPolygon->Get_Part_Count(); iPart++)
			{
				for(int iPoint=0, nParts=pUnion->Get_Part_Count(); iPoint<pPolygon->Get_Point_Count(iPart); iPoint++)
				{
					pUnion->Add_Point(pPolygon->Get_Point(iPoint, iPart), nParts);
				}
			}

			Add_Statistics(pUnion, pPolygon, false);
		}
	}

	Set_Union(pUnion, bDissolve);

	//-----------------------------------------------------
	if( m_Statistics )
	{
		delete[](m_Statistics);
	}

	m_List.Clear();

	return( pUnions->is_Valid() );
}
コード例 #30
0
//---------------------------------------------------------
bool CSG_Network::_Add_Line(CSG_Shape *pLine, int ID)
{
	int			iEdge, iPoint, iCrossing;
	CSG_Shape	*pEdge, *pCrossing;
	CSG_Shapes	Crossings(SHAPE_TYPE_Point);

	//-----------------------------------------------------
	// 1. find crossings

	Crossings.Add_Field(SG_T("LINE_POINT")	, SG_DATATYPE_Int);
	Crossings.Add_Field(SG_T("EDGE_ID")		, SG_DATATYPE_Int);
	Crossings.Add_Field(SG_T("EDGE_POINT")	, SG_DATATYPE_Int);
	Crossings.Add_Field(SG_T("EDGE_DIST")	, SG_DATATYPE_Double);

	for(iEdge=0; iEdge<m_Edges.Get_Count(); iEdge++)
	{
		pEdge	= m_Edges.Get_Shape(iEdge);

		if( pEdge->Intersects(pLine) )
		{
			TSG_Point	a	= pEdge->Get_Point(0);

			for(int iEdge_Point=1; iEdge_Point<pEdge->Get_Point_Count(0); iEdge_Point++)
			{
				TSG_Point	b	= a;	a	= pEdge->Get_Point(iEdge_Point);
				TSG_Point	A	= pLine->Get_Point(0);

				for(iPoint=1; iPoint<pLine->Get_Point_Count(0); iPoint++)
				{
					TSG_Point	C, B	= A;	A	= pLine->Get_Point(iPoint);

					if( SG_Get_Crossing(C, A, B, a, b) )
					{
						pCrossing	= Crossings.Add_Shape();
						pCrossing->Add_Point(C);
						pCrossing->Set_Value(0, iPoint);
						pCrossing->Set_Value(1, iEdge);
						pCrossing->Set_Value(2, iEdge_Point);
						pCrossing->Set_Value(3, SG_Get_Distance(C, b));
					}
				}
			}
		}
	}


	//-----------------------------------------------------
	// 2. add new line's vertices

	Crossings.Set_Index(0, TABLE_INDEX_Ascending);

	pEdge		= m_Edges.Add_Shape();
	pEdge		->Set_Value(3, ID);

	for(iCrossing=0, iPoint=0; iCrossing<Crossings.Get_Count(); iCrossing++)
	{
		pCrossing	= Crossings.Get_Shape_byIndex(iCrossing);

		while( iPoint < pCrossing->asInt(0) )
		{
			pEdge->Add_Point(pLine->Get_Point(iPoint++));
		}

		pEdge->Add_Point(pCrossing->Get_Point(0));

		pEdge		= m_Edges.Add_Shape();
		pEdge		->Set_Value(3, ID);
		pEdge		->Add_Point(pCrossing->Get_Point(0));
	}

	while( iPoint < pLine->Get_Point_Count(0) )
	{
		pEdge->Add_Point(pLine->Get_Point(iPoint++));
	}


	//-----------------------------------------------------
	// 3. split edges, if necessary

	Crossings.Set_Index(1, TABLE_INDEX_Descending, 2, TABLE_INDEX_Ascending, 3, TABLE_INDEX_Ascending);

	for(iCrossing=0; iCrossing<Crossings.Get_Count(); )
	{
		pCrossing	= Crossings.Get_Shape_byIndex(iCrossing);
		iEdge		= pCrossing->asInt(1);
		pLine		= m_Edges.Get_Shape(iEdge);
		ID			= pLine->asInt(0);
		iPoint		= 0;
		pEdge		= m_Edges.Add_Shape();
		pEdge		->Set_Value(3, pLine->asInt(3));

		while( 1 )
		{
			while( iPoint < pCrossing->asInt(2) )
			{
				pEdge->Add_Point(pLine->Get_Point(iPoint++));
			}

			pEdge->Add_Point(pCrossing->Get_Point(0));

			if( ++iCrossing < Crossings.Get_Count() && iEdge == Crossings.Get_Shape_byIndex(iCrossing)->asInt(1) )
			{
				pEdge		= m_Edges.Add_Shape();
				pEdge		->Set_Value(3, pLine->asInt(3));

				pEdge->Add_Point(pCrossing->Get_Point(0));

				pCrossing	= Crossings.Get_Shape_byIndex(iCrossing);
			}
			else
			{
				if( iPoint < pLine->Get_Point_Count() )
				{
					pEdge		= m_Edges.Add_Shape();
					pEdge		->Set_Value(3, pLine->asInt(3));
		
					pEdge->Add_Point(pCrossing->Get_Point(0));

					while( iPoint < pLine->Get_Point_Count() )
					{
						pEdge->Add_Point(pLine->Get_Point(iPoint++));
					}
				}

				break;
			}
		}

		m_Edges.Del_Shape(iEdge);
	}

	return( true );
}