//---------------------------------------------------------
bool CSelect_Points::On_Execute_Position(CSG_Point ptWorld, TSG_Tool_Interactive_Mode Mode)
{
	switch( Mode )
	{
	case TOOL_INTERACTIVE_LUP:
		m_pSelection->Del_Records();

		if( m_bAddCenter )
		{
			m_pSelection->Add_Shape()->Add_Point(ptWorld);
		}

		if( m_Search.Select_Nearest_Points(ptWorld.Get_X(), ptWorld.Get_Y(), m_MaxPoints, m_Radius, m_Quadrant) )
		{
			for(int i=0; i<m_Search.Get_Selected_Count(); i++)
			{
				CSG_Shape	*pPoint	= m_pSelection->Add_Shape(m_pPoints->Get_Shape((int)m_Search.Get_Selected_Z(i)));

				pPoint->Set_Value(m_pSelection->Get_Field_Count() - 2, i + 1);
				pPoint->Set_Value(m_pSelection->Get_Field_Count() - 1, m_Search.Get_Selected_Distance(i));
			}
		}

		DataObject_Update(m_pSelection);

		break;

	default:
		break;
	}

	return( true );
}
//---------------------------------------------------------
CSG_Shape * CPolygon_Intersection::Get_Polygon(int iShape_A, int iShape_B)
{
	CSG_Shape	*pShape	= m_pShapes_AB->Add_Shape();

	if( pShape )
	{
		pShape->Set_Value(0, m_pShapes_AB->Get_Count());

		if( m_Mode == MODE_SECOND )
		{
			int		ID	= iShape_A;	iShape_A	= iShape_B;	iShape_B	= ID;
		}

		pShape->Set_Value(1, iShape_A);
		pShape->Set_Value(2, iShape_B);
		pShape->Set_Value(3, iShape_A >= 0 && iShape_B >= 0 ? 0 : iShape_A >= 0 ? -1 : 1);

		if( m_iField_A >= 0 && iShape_A >= 0 )
		{
			pShape->Set_Value(4, m_pShapes_A->Get_Shape(iShape_A)->asString(m_iField_A));
		}

		if( m_iField_B >= 0 && iShape_B >= 0 )
		{
			pShape->Set_Value(m_iField_A >= 0 ? 5 : 4, m_pShapes_B->Get_Shape(iShape_B)->asString(m_iField_B));
		}
	}

	return( pShape );
}
Beispiel #3
0
//---------------------------------------------------------
bool CLine_Properties::On_Execute(void)
{
	CSG_Shapes	*pLines	= Parameters("LINES")->asShapes();

	if(	pLines->is_Valid() && pLines->Get_Count() > 0 )
	{
		if( Parameters("OUTPUT")->asShapes() && Parameters("OUTPUT")->asShapes() != pLines )
		{
			pLines	= Parameters("OUTPUT")->asShapes();
			pLines->Create(*Parameters("LINES")->asShapes());
		}

		//-------------------------------------------------
		int		iOffset	= pLines->Get_Field_Count();

		pLines->Add_Field(SG_T("N_VERTICES"), SG_DATATYPE_Int);
		pLines->Add_Field(SG_T("LENGTH")	, SG_DATATYPE_Double);

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

			pLine->Set_Value(iOffset + 0, pLine->Get_Point_Count());
			pLine->Set_Value(iOffset + 1, ((CSG_Shape_Line *)pLine)->Get_Length());
		}

		return( true );
	}

	return( false );
}
Beispiel #4
0
//---------------------------------------------------------
bool CGPX_Import::Add_Point(CSG_MetaData *pNode, CSG_Shapes *pPoints)
{
	const SG_Char	*cString;
	TSG_Point		Point;

	if(	(cString = pNode->Get_Property(SG_T("lon"))) != NULL && CSG_String(cString).asDouble(Point.x)
	&&	(cString = pNode->Get_Property(SG_T("lat"))) != NULL && CSG_String(cString).asDouble(Point.y)
	&&	Add_Fields(pNode, pPoints) )
	{
		CSG_Shape	*pPoint	= pPoints->Add_Shape();

		pPoint->Add_Point(Point, 0);

		for(int i=0; i<pNode->Get_Children_Count(); i++)
		{
			CSG_MetaData	*pChild	= pNode->Get_Child(i);

			pPoint->Set_Value(pChild->Get_Name(), pChild->Get_Content());
		}

		if( m_bTime )
		{
			double		h	= CSG_String(pPoint->asString(SG_T("time"))).AfterFirst(SG_T('T')).asDouble();
			double		m	= CSG_String(pPoint->asString(SG_T("time"))).AfterFirst(SG_T(':')).asDouble();
			double		s	= CSG_String(pPoint->asString(SG_T("time"))).AfterLast (SG_T(':')).asDouble();

			pPoint->Set_Value(SG_T("dtime"), h + m / 60.0 + s / 3600.0);
		}

		return( true );
	}

	return( false );
}
Beispiel #5
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 );
}
Beispiel #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 );
}
Beispiel #7
0
//---------------------------------------------------------
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 );
}
//---------------------------------------------------------
bool CAddCoordinates::On_Execute(void)
{
	CSG_Shapes	*pShapes	= Parameters("OUTPUT")->asShapes();

	if( pShapes )
	{
		pShapes->Assign(Parameters("INPUT")->asShapes());
	}
	else
	{
		pShapes	= Parameters("INPUT")->asShapes();
	}

	//-----------------------------------------------------
	int	xField	= pShapes->Get_Field_Count();
	pShapes->Add_Field("X", SG_DATATYPE_Double);

	int	yField	= pShapes->Get_Field_Count();
	pShapes->Add_Field("Y", SG_DATATYPE_Double);

	int zField	= 0, mField	= 0;
	if( pShapes->Get_Vertex_Type() != SG_VERTEX_TYPE_XY )
	{
		zField	= pShapes->Get_Field_Count();
		pShapes->Add_Field("Z", SG_DATATYPE_Double);

		if( pShapes->Get_Vertex_Type() == SG_VERTEX_TYPE_XYZM )
		{
			mField	= pShapes->Get_Field_Count();
			pShapes->Add_Field("M", SG_DATATYPE_Double);
		}
	}

	//-----------------------------------------------------
	for(int i=0; i<pShapes->Get_Count(); i++)
	{
		CSG_Shape	*pShape	= pShapes->Get_Shape(i);

		pShape->Set_Value(xField, pShape->Get_Point(0).x);
		pShape->Set_Value(yField, pShape->Get_Point(0).y);

		if( pShapes->Get_Vertex_Type() != SG_VERTEX_TYPE_XY )
		{
			pShape->Set_Value(zField, pShape->Get_Z(0));

			if( pShapes->Get_Vertex_Type() == SG_VERTEX_TYPE_XYZM )
			{
				pShape->Set_Value(mField, pShape->Get_M(0));
			}
		}
	}

	DataObject_Update(pShapes);

	return( true );
}
//---------------------------------------------------------
bool CPolygon_Geometrics::On_Execute(void)
{
	//-------------------------------------------------
	int	bParts	= Parameters("BPARTS")	->asBool() ? 0 : -1;
	int	bPoints	= Parameters("BPOINTS")	->asBool() ? 0 : -1;
	int	bLength	= Parameters("BLENGTH")	->asBool() ? 0 : -1;
	int	bArea	= Parameters("BAREA")	->asBool() ? 0 : -1;

	if( bParts && bPoints && bLength && bArea )
	{
		Error_Set(_TL("no properties selected"));

		return( false );
	}

	//-------------------------------------------------
	CSG_Shapes	*pPolygons	= Parameters("POLYGONS")->asShapes();

	if(	!pPolygons->is_Valid() || pPolygons->Get_Count() <= 0 )
	{
		Error_Set(_TL("invalid lines layer"));

		return( false );
	}

	if( Parameters("OUTPUT")->asShapes() && Parameters("OUTPUT")->asShapes() != pPolygons )
	{
		pPolygons	= Parameters("OUTPUT")->asShapes();
		pPolygons->Create(*Parameters("POLYGONS")->asShapes());
	}

	//-------------------------------------------------
	if( !bParts )	{	bParts	= pPolygons->Get_Field_Count();	pPolygons->Add_Field(SG_T("NPARTS")   , SG_DATATYPE_Int   );	}
	if( !bPoints )	{	bPoints	= pPolygons->Get_Field_Count();	pPolygons->Add_Field(SG_T("NPOINTS")  , SG_DATATYPE_Int   );	}
	if( !bLength )	{	bLength	= pPolygons->Get_Field_Count();	pPolygons->Add_Field(SG_T("PERIMETER"), SG_DATATYPE_Double);	}
	if( !bArea )	{	bArea	= pPolygons->Get_Field_Count();	pPolygons->Add_Field(SG_T("AREA")     , SG_DATATYPE_Double);	}

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

		if( bParts  >= 0 )	pPolygon->Set_Value(bParts , pPolygon->Get_Part_Count());
		if( bPoints >= 0 )	pPolygon->Set_Value(bPoints, pPolygon->Get_Point_Count());
		if( bLength >= 0 )	pPolygon->Set_Value(bLength, ((CSG_Shape_Polygon *)pPolygon)->Get_Perimeter());
		if( bArea   >= 0 )	pPolygon->Set_Value(bArea  , ((CSG_Shape_Polygon *)pPolygon)->Get_Area());
	}

	//-------------------------------------------------
	if( pPolygons == Parameters("POLYGONS")->asShapes() )
	{
		DataObject_Update(pPolygons);
	}

	return( true );
}
//---------------------------------------------------------
bool CLine_Properties::On_Execute(void)
{
	//-------------------------------------------------
	int	bParts	= Parameters("BPARTS")	->asBool() ? 0 : -1;
	int	bPoints	= Parameters("BPOINTS")	->asBool() ? 0 : -1;
	int	bLength	= Parameters("BLENGTH")	->asBool() ? 0 : -1;

	if( bParts && bPoints && bLength )
	{
		Error_Set(_TL("no properties selected"));

		return( false );
	}

	//-------------------------------------------------
	CSG_Shapes	*pLines	= Parameters("LINES")->asShapes();

	if(	!pLines->is_Valid() || pLines->Get_Count() <= 0 )
	{
		Error_Set(_TL("invalid lines layer"));

		return( false );
	}

	if( Parameters("OUTPUT")->asShapes() && Parameters("OUTPUT")->asShapes() != pLines )
	{
		pLines	= Parameters("OUTPUT")->asShapes();
		pLines->Create(*Parameters("LINES")->asShapes());
	}

	//-------------------------------------------------
	if( !bParts )	{	bParts	= pLines->Get_Field_Count();	pLines->Add_Field(SG_T("NPARTS") , SG_DATATYPE_Int   );	}
	if( !bPoints )	{	bPoints	= pLines->Get_Field_Count();	pLines->Add_Field(SG_T("NPOINTS"), SG_DATATYPE_Int   );	}
	if( !bLength )	{	bLength	= pLines->Get_Field_Count();	pLines->Add_Field(SG_T("LENGTH") , SG_DATATYPE_Double);	}

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

		if( bParts  >= 0 )	pLine->Set_Value(bParts , pLine->Get_Part_Count());
		if( bPoints >= 0 )	pLine->Set_Value(bPoints, pLine->Get_Point_Count());
		if( bLength >= 0 )	pLine->Set_Value(bLength, ((CSG_Shape_Line *)pLine)->Get_Length());
	}

	//-------------------------------------------------
	if( pLines == Parameters("LINES")->asShapes() )
	{
		DataObject_Update(pLines);
	}

	return( true );
}
Beispiel #11
0
//---------------------------------------------------------
void CDXF_Import::addPoint(const DL_PointData &data)
{
	if( !Check_Layer(attributes.getLayer().c_str()) )
		return;

	CSG_Shape	*pPoint	= m_pPoints->Add_Shape();

	pPoint->Add_Point(m_Offset.x + data.x, m_Offset.y + data.y);

	pPoint->Set_Value(TBL_POINTS_LAYER	, CSG_String(attributes.getLayer().c_str()));
	pPoint->Set_Value(TBL_POINTS_Z		, m_Offset.z + data.z);
}
Beispiel #12
0
//---------------------------------------------------------
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 );
}
Beispiel #13
0
//---------------------------------------------------------
void CDXF_Import::addLine(const DL_LineData &data)
{
	if( !Check_Layer(attributes.getLayer().c_str()) )
		return;

	CSG_Shape	*pLine	= m_pLines->Add_Shape();

	pLine->Add_Point(m_Offset.x + data.x1, m_Offset.y + data.y1);
	pLine->Add_Point(m_Offset.x + data.x2, m_Offset.y + data.y2);

	pLine->Set_Value(TBL_LINES_LAYER	, CSG_String(attributes.getLayer().c_str()));
	pLine->Set_Value(TBL_LINES_Z1		, m_Offset.z + data.z1);
	pLine->Set_Value(TBL_LINES_Z2		, m_Offset.z + data.z2);
}
//---------------------------------------------------------
bool CGEOTRANS_Grid::Set_Shapes(CSG_Grid *pSource, CSG_Shapes *pTarget)
{
	int			x, y;
	TSG_Point	Pt_Source, Pt_Target;
	CSG_Shape		*pShape;

	if( pSource && pTarget )
	{
		pTarget->Create(SHAPE_TYPE_Point, pSource->Get_Name());
		pTarget->Add_Field("Z", SG_DATATYPE_Double);

		for(y=0, Pt_Source.y=pSource->Get_YMin(); y<pSource->Get_NY() && Set_Progress(y, pSource->Get_NY()); y++, Pt_Source.y+=pSource->Get_Cellsize())
		{
			for(x=0, Pt_Source.x=pSource->Get_XMin(); x<pSource->Get_NX(); x++, Pt_Source.x+=pSource->Get_Cellsize())
			{
				if( !pSource->is_NoData(x, y) )
				{
					Pt_Target	= Pt_Source;

					if( Get_Converted(Pt_Target) )
					{
						pShape		= pTarget->Add_Shape();
						pShape->Add_Point(Pt_Target);
						pShape->Set_Value(0, pSource->asDouble(x, y));
					}
				}
			}
		}

		return( true );
	}

	return( false );
}
Beispiel #15
0
//---------------------------------------------------------
bool CWatershed_Segmentation::Segment_Change(int ID, int new_ID)
{
    bool	bContinue;
    int		ax, ay, bx, by;

    //-----------------------------------------------------
    CSG_Shape	*pSeed	= m_pSeeds->Get_Shape(ID);

    pSeed->Set_Value(SEED_JOIN, new_ID);

    ax	= bx	= pSeed->asInt(SEED_X);
    ay	= by	= pSeed->asInt(SEED_Y);

    do
    {
        bContinue	= false;

        for(int x=ax; x<=bx; x++)
        {
            if( m_pSegments->asInt( x, ay) == ID )
            {
                m_pSegments->Set_Value( x, ay, new_ID);

                bContinue	= true;
            }

            if( m_pSegments->asInt( x, by) == ID )
            {
                m_pSegments->Set_Value( x, by, new_ID);

                bContinue	= true;
            }
        }

        for(int y=ay; y<=by; y++)
        {
            if( m_pSegments->asInt(ax,  y) == ID )
            {
                m_pSegments->Set_Value(ax,  y, new_ID);

                bContinue	= true;
            }

            if( m_pSegments->asInt(bx,  y) == ID )
            {
                m_pSegments->Set_Value(bx,  y, new_ID);

                bContinue	= true;
            }
        }

        if( ax > 0 )			ax--;
        if( ay > 0 )			ay--;
        if( bx < Get_NX() - 1 )	bx++;
        if( by < Get_NY() - 1 )	by++;
    }
    while( bContinue );

    return( true );
}
//---------------------------------------------------------
bool CGeoref_Grid::Set_Points(CSG_Grid *pGrid, CSG_Shapes *pReferenced)
{
	if( !pGrid || !pReferenced || pReferenced->Get_Type() != SHAPE_TYPE_Point || !m_Engine.is_Okay() )
	{
		return( false );
	}

	//-----------------------------------------------------
	pReferenced->Create(SHAPE_TYPE_Point, pGrid->Get_Name());
	pReferenced->Add_Field("Z", SG_DATATYPE_Double);

	//-----------------------------------------------------
	for(int y=0; y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++)
	{
		for(int x=0; x<pGrid->Get_NX(); x++)
		{
			if( !pGrid->is_NoData(x, y) )
			{
				TSG_Point	Point	= pGrid->Get_System().Get_Grid_to_World(x, y);

				if( m_Engine.Get_Converted(Point) )
				{
					CSG_Shape	*pPoint	= pReferenced->Add_Shape();

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

	//-----------------------------------------------------
	return( true );
}
Beispiel #17
0
//---------------------------------------------------------
bool CAddCoordinates::On_Execute(void)
{
	CSG_Shapes	*pShapes	= Parameters("OUTPUT")->asShapes();

	if( pShapes )
	{
		pShapes->Assign(Parameters("INPUT")->asShapes());
	}
	else
	{
		pShapes	= Parameters("INPUT")->asShapes();
	}

	//-----------------------------------------------------
	int	xField	= pShapes->Get_Field_Count();
	pShapes->Add_Field("X", SG_DATATYPE_Double);

	int	yField	= pShapes->Get_Field_Count();
	pShapes->Add_Field("Y", SG_DATATYPE_Double);

	//-----------------------------------------------------
	for(int i=0; i<pShapes->Get_Count(); i++)
	{
		CSG_Shape	*pShape	= pShapes->Get_Shape(i);

		pShape->Set_Value(xField, pShape->Get_Point(0).x);
		pShape->Set_Value(yField, pShape->Get_Point(0).y);
	}

	return( true );
}
Beispiel #18
0
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
Beispiel #19
0
//---------------------------------------------------------
bool Cut_Set_Extent(CSG_Rect Extent, CSG_Shapes *pExtent, bool bClear)
{
	if( pExtent )
	{
		if( bClear )
		{
			pExtent->Create(SHAPE_TYPE_Polygon, _TL("Extent [Cut]"));
			pExtent->Add_Field("ID", SG_DATATYPE_Int);
		}

		if( pExtent->Get_Type() == SHAPE_TYPE_Polygon )
		{
			CSG_Shape	*pShape	= pExtent->Add_Shape();

			pShape->Set_Value(SG_T("ID"), pExtent->Get_Count());

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

			return( true );
		}
	}

	return( false );
}
Beispiel #20
0
//---------------------------------------------------------
bool CKinWav_D8::Gauges_Initialise(void)
{
	if( m_pGauges_Flow != NULL )
	{
		if( m_pGauges == NULL )
		{
			DataObject_Add(m_pGauges = SG_Create_Shapes(SHAPE_TYPE_Point, _TL("Gauges")));

			Parameters("GAUGES")->Set_Value(m_pGauges);

			m_pGauges->Add_Field(_TL("ID"), SG_DATATYPE_Int);

			for(int y=0; y<Get_NY() && Set_Progress(y); y++)
			{
				for(int x=0; x<Get_NX(); x++)
				{
					bool	bBorder	= false;
					bool	bLowest	= true;

					for(int i=0; i<8; i++)
					{
						int	ix	= Get_xTo(i, x);
						int	iy	= Get_yTo(i, y);

						if( !m_pDEM->is_InGrid(ix, iy) )
						{
							bBorder	= true;
						}
						else if( m_pDEM->asDouble(ix, iy) < m_pDEM->asDouble(x, y) )
						{
							bLowest	= false;
						}
					}

					if( bLowest && bBorder )
					{
						CSG_Shape	*pGauge	= m_pGauges->Add_Shape();

						pGauge->Add_Point(Get_System()->Get_Grid_to_World(x, y));
						pGauge->Set_Value(0, m_pGauges->Get_Count() + 1);
					}
				}
			}
		}

		m_pGauges_Flow->Destroy();
		m_pGauges_Flow->Set_Name(_TL("Outlet Hydrographs"));
		m_pGauges_Flow->Add_Field("TIME", SG_DATATYPE_Double);

		for(int i=0; i<m_pGauges->Get_Count(); i++)
		{
			m_pGauges_Flow->Add_Field(CSG_String::Format(SG_T("GAUGE_%02d"), i + 1), SG_DATATYPE_Double);
		}

		return( true );
	}

	return( false );
}
Beispiel #21
0
//---------------------------------------------------------
bool CSG_Network::Update(void)
{
	int		iEdge;

	//-----------------------------------------------------
	for(iEdge=m_Edges.Get_Count()-1; iEdge>=0; iEdge--)
	{
		CSG_Shape	*pEdge	= m_Edges.Get_Shape(iEdge);

		if( !(((CSG_Shape_Line *)pEdge)->Get_Length() > 0.0) )
		{
			m_Edges.Del_Shape(iEdge);
		}
	}

	//-----------------------------------------------------
	for(int i=0; i<Get_Node_Count(); i++)
	{
		delete(&Get_Node(i));
	}

	m_Nodes.Set_Array(0);

	//-----------------------------------------------------
	CSG_PRQuadTree	Search(m_Edges.Get_Extent());

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

		pEdge->Set_Value(0, iEdge);

		pEdge->Set_Value(1, _Add_Node(Search, iEdge,
			pEdge->Get_Point(0),
			pEdge->Get_Point(1)
		));

		pEdge->Set_Value(2, _Add_Node(Search, iEdge,
			pEdge->Get_Point(pEdge->Get_Point_Count(0) - 1),
			pEdge->Get_Point(pEdge->Get_Point_Count(0) - 2)
		));
	}

	//-----------------------------------------------------
	return( true );
}
//---------------------------------------------------------
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 );
}
Beispiel #23
0
//---------------------------------------------------------
void CDXF_Import::add3dFace(const DL_3dFaceData &data)
{
	if( !Check_Layer(attributes.getLayer().c_str()) )
		return;

	CSG_Shape	*pTriangle	= m_pTriangles->Add_Shape();

	for(int i=0; i<3; i++)
	{
		pTriangle->Add_Point(m_Offset.x + data.x[i], m_Offset.y + data.y[i]);
	}

	pTriangle->Set_Value(TBL_TRIANGLE_LAYER	, CSG_String(attributes.getLayer().c_str()));
	pTriangle->Set_Value(TBL_TRIANGLE_THICK	, data.thickness);
	pTriangle->Set_Value(TBL_TRIANGLE_Z1	, m_Offset.z + data.z[0]);
	pTriangle->Set_Value(TBL_TRIANGLE_Z2	, m_Offset.z + data.z[1]);
	pTriangle->Set_Value(TBL_TRIANGLE_Z3	, m_Offset.z + data.z[2]);
}
Beispiel #24
0
//---------------------------------------------------------
void CQuadTree_Structure::Get_Shapes(CSG_Shapes *pShapes, CSG_PRQuadTree_Item *pItem, int Level)
{
	if( pItem )
	{
		if( pShapes->Get_Type() == SHAPE_TYPE_Line )
		{
			if( pItem->is_Node() )
			{
				CSG_Shape	*pShape	= pShapes->Add_Shape();
				pShape->Set_Value(0, Level);
				pShape->Add_Point(pItem->Get_xMin(), pItem->Get_yCenter(), 0);
				pShape->Add_Point(pItem->Get_xMax(), pItem->Get_yCenter(), 0);
				pShape->Add_Point(pItem->Get_xCenter(), pItem->Get_yMin(), 1);
				pShape->Add_Point(pItem->Get_xCenter(), pItem->Get_yMax(), 1);

				for(int i=0; i<4; i++)
				{
					Get_Shapes(pShapes, pItem->asNode()->Get_Child(i), Level + 1);
				}
			}
		}

		if( pShapes->Get_Type() == SHAPE_TYPE_Polygon )
		{
			if( pItem->is_Node() )
			{
				for(int i=0; i<4; i++)
				{
					Get_Shapes(pShapes, pItem->asNode()->Get_Child(i), Level + 1);
				}
			}
			else // if( pItem->is_Leaf() )
			{
				CSG_Shape	*pShape	= pShapes->Add_Shape();
				pShape->Set_Value(0, Level + 1);
				pShape->Set_Value(1, pItem->asLeaf()->Get_Z());
				pShape->Add_Point(pItem->Get_xMin(), pItem->Get_yMin());
				pShape->Add_Point(pItem->Get_xMin(), pItem->Get_yMax());
				pShape->Add_Point(pItem->Get_xMax(), pItem->Get_yMax());
				pShape->Add_Point(pItem->Get_xMax(), pItem->Get_yMin());
			}
		}
	}
}
//---------------------------------------------------------
bool CCRS_Transform_Grid::Transform(CSG_Parameter_Grid_List *pGrids, CSG_Shapes *pPoints)
{
	if( !pPoints || !pGrids || pGrids->Get_Count() < 1 )
	{
		return( false );
	}

	CSG_Grid	*pGrid	= pGrids->asGrid(0);

	if( !m_Projector.Set_Source(pGrid->Get_Projection()) )
	{
		return( false );
	}

	int			x, y, i;
	TSG_Point	Point;

	pPoints->Create(SHAPE_TYPE_Point, _TL("Points"));
	pPoints->Get_Projection()	= m_Projector.Get_Target();

	for(i=0; i<pGrids->Get_Count(); i++)
	{
		pPoints->Add_Field(pGrids->asGrid(i)->Get_Name(), pGrids->asGrid(i)->Get_Type());
	}

	for(y=0, Point.y=pGrid->Get_YMin(); y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++, Point.y+=pGrid->Get_Cellsize())
	{
		for(x=0, Point.x=pGrid->Get_XMin(); x<pGrid->Get_NX(); x++, Point.x+=pGrid->Get_Cellsize())
		{
			TSG_Point	Point_Transformed	= Point;

			if( m_Projector.Get_Projection(Point_Transformed) )
			{
				CSG_Shape	*pPoint	= pPoints->Add_Shape();

				pPoint->Add_Point(Point_Transformed);

				for(i=0; i<pGrids->Get_Count(); i++)
				{
					if( !pGrids->asGrid(i)->is_NoData(x, y) )
					{
						pPoint->Set_Value(i, pGrids->asGrid(i)->asDouble(x, y));
					}
					else
					{
						pPoint->Set_NoData(i);
					}
				}
			}
		}
	}

	return( true );
}
Beispiel #26
0
//---------------------------------------------------------
bool Trace_Polygon(CSG_Shape *pPolygon, CSG_Network &Network, int iEdge)
{
	bool		bAscending	= true;
	CSG_Shape	*pEdge		= Network.Get_Edges().Get_Shape(iEdge);

	if( pEdge->asInt(3) == SHAPE_TYPE_Polygon )
	{
		if( pEdge->asInt(4) )
		{
			return( false );
		}

		bAscending	= true;
	}
	else if( (pEdge->asInt(4) & 0x1) == 0 )
	{
		bAscending	= true;
	}
	else if( (pEdge->asInt(4) & 0x2) == 0 )
	{
		bAscending	= false;
	}
	else
	{
		return( false );
	}

	while( pEdge != NULL )
	{
		pEdge->Set_Value(4, pEdge->asInt(4) | (bAscending ? 0x1 : 0x2));

		for(int iPoint=0; iPoint<pEdge->Get_Point_Count(0); iPoint++)
		{
			pPolygon->Add_Point(pEdge->Get_Point(iPoint, 0, bAscending));
		}

		int	End_Node	= pEdge->asInt(bAscending ? 2 : 1);

		iEdge		= Network.Get_Node(End_Node).Get_Edge_Next(iEdge, false);
		pEdge		= Network.Get_Edges().Get_Shape(iEdge);

		if( pEdge )
		{
			bAscending	= pEdge->asInt(3) == SHAPE_TYPE_Polygon || End_Node == pEdge->asInt(1);

			if( (pEdge->asInt(4) & (bAscending ? 0x1 : 0x2)) )
			{
				pEdge	= NULL;
			}
		}
	}

	return( pPolygon->is_Valid() );
}
Beispiel #27
0
//---------------------------------------------------------
bool CPROJ4_Grid::Set_Shapes(CSG_Parameter_Grid_List *pSources, CSG_Shapes *pTarget)
{
	int			x, y, i;
	double		z;
	TSG_Point	Pt_Source, Pt_Target;
	CSG_Grid	*pSource;
	CSG_Shape	*pShape;

	if( pSources && pSources->Get_Count() > 0 && pTarget )
	{
		pSource	= pSources->asGrid(0);

		pTarget->Create(SHAPE_TYPE_Point, CSG_String::Format(SG_T("%s [%s]"), pSource->Get_Name(), Get_Proj_Name().c_str()));

		for(i=0; i<pSources->Get_Count(); i++)
		{
			pTarget->Add_Field(pSources->asGrid(i)->Get_Name(), pSources->asGrid(i)->Get_Type());
		}

		for(y=0, Pt_Source.y=pSource->Get_YMin(); y<pSource->Get_NY() && Set_Progress(y, pSource->Get_NY()); y++, Pt_Source.y+=pSource->Get_Cellsize())
		{
			for(x=0, Pt_Source.x=pSource->Get_XMin(); x<pSource->Get_NX(); x++, Pt_Source.x+=pSource->Get_Cellsize())
			{
				if( !pSource->is_NoData(x, y) )
				{
					Pt_Target	= Pt_Source;

					if( Get_Converted(Pt_Target) )
					{
						pShape	= pTarget->Add_Shape();
						pShape->Add_Point(Pt_Target);

						for(i=0; i<pSources->Get_Count(); i++)
						{
							if( pSources->asGrid(i)->Get_Value(Pt_Source, z, m_Interpolation) )
							{
								pShape->Set_Value(i, z);
							}
							else
							{
								pShape->Set_NoData(i);
							}
						}
					}
				}
			}
		}

		return( true );
	}

	return( false );
}
Beispiel #28
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 );
}
//---------------------------------------------------------
bool CCollect_Points::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
{
	if( Mode == MODULE_INTERACTIVE_LUP )
	{
		TSG_Point	ptTarget;

		if( m_Engine.Get_Converted(ptTarget = ptWorld) )
		{
			Get_Parameters("REFERENCE")->Get_Parameter("X")->Set_Value(ptTarget.x);
			Get_Parameters("REFERENCE")->Get_Parameter("Y")->Set_Value(ptTarget.y);
		}

		if( Dlg_Parameters("REFERENCE") )
		{
			int	Method	= Parameters("METHOD")->asInt();
			int	Order	= Parameters("ORDER" )->asInt();

			CSG_Shape	*pPoint	= m_pPoints->Add_Shape();

			pPoint->Add_Point(ptWorld);
			pPoint->Set_Value(0, ptWorld.Get_X());
			pPoint->Set_Value(1, ptWorld.Get_Y());
			pPoint->Set_Value(2, ptTarget.x = Get_Parameters("REFERENCE")->Get_Parameter("X")->asDouble());
			pPoint->Set_Value(3, ptTarget.y = Get_Parameters("REFERENCE")->Get_Parameter("Y")->asDouble());

			if( m_Engine.Add_Reference(ptWorld, ptTarget) && m_Engine.Evaluate(Method, Order) && m_pPoints->Get_Count() == m_Engine.Get_Reference_Count() )
			{
				for(int i=0; i<m_pPoints->Get_Count(); i++)
				{
					m_pPoints->Get_Shape(i)->Set_Value(4, m_Engine.Get_Reference_Residual(i));
				}
			}

			DataObject_Update(m_pPoints);
		}
	}

	return( true );
}
Beispiel #30
0
//---------------------------------------------------------
void CExercise_14::Vectorise(void)
{
	int			x, y, Segment_ID;
	double		Length;
	CSG_Shape	*pSegment;

	m_pShapes->Create(SHAPE_TYPE_Line, _TL("Channels"));

	m_pShapes->Add_Field("SEGMENT_ID"	, SG_DATATYPE_Int);
	m_pShapes->Add_Field("LENGTH"		, SG_DATATYPE_Double);

	//-----------------------------------------------------
	for(y=0, Segment_ID=0; y<Get_NY() && Set_Progress(y); y++)
	{
		for(x=0; x<Get_NX(); x++)
		{
			switch( m_pChnl->asInt(x, y) )
			{
			case SPRING: case MOUTH:
				pSegment	= m_pShapes->Add_Shape();

				Length		= Vectorise(x, y, pSegment);

				if( Length > 0.0 )
				{
					pSegment->Set_Value(0, ++Segment_ID);
					pSegment->Set_Value(1, Length);
				}
				else
				{
					m_pShapes->Del_Shape(pSegment);
				}

				break;
			}
		}
	}
}