//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- 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 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 ); }
//--------------------------------------------------------- void CSG_Network::_On_Construction(void) { m_Nodes.Create(sizeof(CSG_Network_Node **), 0, SG_ARRAY_GROWTH_1); m_Edges.Create(SHAPE_TYPE_Line , SG_T("EDGES")); m_Edges.Add_Field(SG_T("ID") , SG_DATATYPE_Int); m_Edges.Add_Field(SG_T("NODE_A") , SG_DATATYPE_Int); m_Edges.Add_Field(SG_T("NODE_B") , SG_DATATYPE_Int); m_Edges.Add_Field(SG_T("SHAPE_TYPE"), SG_DATATYPE_Int); m_Edges.Add_Field(SG_T("PROCESSED") , SG_DATATYPE_Int); }
//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- 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 ); }
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
//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- bool CShapes_Create_Empty::On_Execute(void) { TSG_Vertex_Type Vertex; switch( Parameters("VERTEX")->asInt() ) { default: case 0: Vertex = SG_VERTEX_TYPE_XY; break; case 1: Vertex = SG_VERTEX_TYPE_XYZ; break; case 2: Vertex = SG_VERTEX_TYPE_XYZM; break; } //----------------------------------------------------- CSG_Shapes *pShapes; switch( Parameters("TYPE")->asInt() ) { default: return( false ); case 0: pShapes = SG_Create_Shapes(SHAPE_TYPE_Point , Parameters("NAME")->asString(), NULL, Vertex); break; case 1: pShapes = SG_Create_Shapes(SHAPE_TYPE_Points , Parameters("NAME")->asString(), NULL, Vertex); break; case 2: pShapes = SG_Create_Shapes(SHAPE_TYPE_Line , Parameters("NAME")->asString(), NULL, Vertex); break; case 3: pShapes = SG_Create_Shapes(SHAPE_TYPE_Polygon, Parameters("NAME")->asString(), NULL, Vertex); break; } //----------------------------------------------------- int i, n; TSG_Data_Type Type; CSG_Parameters *pAttributes; pAttributes = Parameters("FIELDS")->asParameters(); n = pAttributes->Get_Count() / 3; for(i=0; i<n; i++) { switch( pAttributes->Get_Parameter(GET_TYPE(i))->asInt() ) { default: case 0: Type = SG_DATATYPE_String; break; case 1: Type = SG_DATATYPE_Date; break; case 2: Type = SG_DATATYPE_Color; break; case 3: Type = SG_DATATYPE_Byte; break; case 4: Type = SG_DATATYPE_Char; break; case 5: Type = SG_DATATYPE_Word; break; case 6: Type = SG_DATATYPE_Short; break; case 7: Type = SG_DATATYPE_DWord; break; case 8: Type = SG_DATATYPE_Int; break; case 9: Type = SG_DATATYPE_ULong; break; case 10: Type = SG_DATATYPE_Long; break; case 11: Type = SG_DATATYPE_Float; break; case 12: Type = SG_DATATYPE_Double; break; case 13: Type = SG_DATATYPE_Binary; break; } pShapes->Add_Field(pAttributes->Get_Parameter(GET_NAME(i))->asString(), Type); } Parameters("SHAPES")->Set_Value(pShapes); return( true ); }
//--------------------------------------------------------- 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 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 ); }
//--------------------------------------------------------- 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 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 ); }
//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- bool CAdd_Polygon_Attributes::On_Execute(void) { //----------------------------------------------------- CSG_Shapes *pInput = Parameters("INPUT")->asShapes(); if( !pInput->is_Valid() ) { Error_Set(_TL("Invalid points layer.")); return( false ); } //----------------------------------------------------- CSG_Shapes *pPolygons = Parameters("POLYGONS")->asShapes(); if( !pPolygons->is_Valid() ) { Error_Set(_TL("Invalid polygon layer.")); return( false ); } //----------------------------------------------------- CSG_Parameter_Table_Fields *pFields = Parameters("FIELDS")->asTableFields(); if( pFields->Get_Count() == 0 ) { CSG_String sFields; for(int iField=0; iField<pPolygons->Get_Field_Count(); iField++) { sFields += CSG_String::Format(SG_T("%d,"), iField); } pFields->Set_Value(sFields); } //----------------------------------------------------- CSG_Shapes *pOutput = Parameters("OUTPUT")->asShapes(); if( pOutput && pOutput != pInput ) { pOutput->Create(*pInput); } else { Parameters("OUTPUT")->Set_Value(pOutput = pInput); } pOutput->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pInput->Get_Name(), pPolygons->Get_Name())); //----------------------------------------------------- int outField = pOutput->Get_Field_Count(); { for(int iField=0; iField<pFields->Get_Count(); iField++) { int jField = pFields->Get_Index(iField); pOutput->Add_Field(pPolygons->Get_Field_Name(jField), pPolygons->Get_Field_Type(jField)); } } //----------------------------------------------------- for(int iPoint=0; iPoint<pOutput->Get_Count() && Set_Progress(iPoint, pOutput->Get_Count()); iPoint++) { CSG_Shape *pPoint = pOutput ->Get_Shape(iPoint); CSG_Shape *pPolygon = pPolygons ->Get_Shape(pPoint->Get_Point(0)); if( pPolygon ) { for(int iField=0; iField<pFields->Get_Count(); iField++) { int jField = pFields->Get_Index(iField); switch( pPolygons->Get_Field_Type(jField) ) { case SG_DATATYPE_String: case SG_DATATYPE_Date: pPoint->Set_Value(outField + iField, pPolygon->asString(jField)); break; default: pPoint->Set_Value(outField + iField, pPolygon->asDouble(jField)); break; } } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CGrid_Values_AddTo_Points::On_Execute(void) { int iShape, iGrid, iField, Offset, Interpolation; double Value; CSG_Shapes *pShapes; CSG_Parameter_Grid_List *pGrids; //----------------------------------------------------- pShapes = Parameters("RESULT") ->asShapes(); pGrids = Parameters("GRIDS" ) ->asGridList(); Interpolation = Parameters("INTERPOL") ->asInt(); //----------------------------------------------------- if( pGrids->Get_Count() <= 0 ) { return( false ); } //----------------------------------------------------- if( pShapes == NULL ) { pShapes = Parameters("SHAPES")->asShapes(); } else if( pShapes != Parameters("SHAPES")->asShapes() ) { pShapes->Create(*Parameters("SHAPES")->asShapes()); } Offset = pShapes->Get_Field_Count(); //----------------------------------------------------- for(iGrid=0; iGrid<pGrids->Get_Count(); iGrid++) { pShapes->Add_Field(pGrids->asGrid(iGrid)->Get_Name(), SG_DATATYPE_Double); } //----------------------------------------------------- for(iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++) { CSG_Shape *pShape = pShapes->Get_Shape(iShape); for(iGrid=0, iField=Offset; iGrid<pGrids->Get_Count(); iGrid++, iField++) { CSG_Grid *pGrid = pGrids->asGrid(iGrid); if( pGrid->Get_Value(pShape->Get_Point(0), Value, Interpolation) ) { pShape->Set_Value(iField, Value); } else { pShape->Set_NoData(iField); } } } //----------------------------------------------------- if( pShapes == Parameters("SHAPES")->asShapes() ) { DataObject_Update(pShapes); } return( true ); }
//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- 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() ); }
//--------------------------------------------------------- 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 ); }
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
//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- 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() ); }
//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- bool CPolygonStatisticsFromPoints::On_Execute(void) { //----------------------------------------------------- bool bSum = Parameters("SUM")->asBool(); bool bAvg = Parameters("AVG")->asBool(); bool bVar = Parameters("VAR")->asBool(); bool bDev = Parameters("DEV")->asBool(); bool bMin = Parameters("MIN")->asBool(); bool bMax = Parameters("MAX")->asBool(); bool bNum = Parameters("NUM")->asBool(); if( !bSum && !bAvg && !bVar && !bDev && !bMin && !bMax && !bNum ) { Error_Set(_TL("no target variable in selection")); return( false ); } //----------------------------------------------------- CSG_Parameter_Table_Fields *pFields = Parameters("FIELDS")->asTableFields(); if( pFields->Get_Count() <= 0 ) { Error_Set(_TL("no attributes in selection")); return( false ); } //----------------------------------------------------- CSG_Shapes *pPoints = Parameters("POINTS" )->asShapes(); CSG_Shapes *pPolygons = Parameters("POLYGONS")->asShapes(); if( pPolygons->Get_Count() <= 0 || pPoints->Get_Count() <= 0 ) { Error_Set(_TL("no records in input data")); return( false ); } //----------------------------------------------------- if( Parameters("STATISTICS")->asShapes() == NULL ) { Parameters("STATISTICS")->Set_Value(pPolygons); } else if( pPolygons != Parameters("STATISTICS")->asShapes() ) { Parameters("STATISTICS")->asShapes()->Assign(pPolygons); pPolygons = Parameters("STATISTICS")->asShapes(); } //----------------------------------------------------- int i, n, Offset = pPolygons->Get_Field_Count(); for(i=0; i<pFields->Get_Count(); i++) { CSG_String sName = pPoints->Get_Field_Name(pFields->Get_Index(i)); if( bSum ) { pPolygons->Add_Field(Get_Field_Name("SUM", sName), SG_DATATYPE_Double); } if( bAvg ) { pPolygons->Add_Field(Get_Field_Name("AVG", sName), SG_DATATYPE_Double); } if( bVar ) { pPolygons->Add_Field(Get_Field_Name("VAR", sName), SG_DATATYPE_Double); } if( bDev ) { pPolygons->Add_Field(Get_Field_Name("DEV", sName), SG_DATATYPE_Double); } if( bMin ) { pPolygons->Add_Field(Get_Field_Name("MIN", sName), SG_DATATYPE_Double); } if( bMax ) { pPolygons->Add_Field(Get_Field_Name("MAX", sName), SG_DATATYPE_Double); } if( bNum ) { pPolygons->Add_Field(Get_Field_Name("NUM", sName), SG_DATATYPE_Long ); } } //----------------------------------------------------- CSG_Simple_Statistics *Statistics = new CSG_Simple_Statistics[pFields->Get_Count()]; 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); //------------------------------------------------- for(i=0; i<pFields->Get_Count(); i++) { Statistics[i].Invalidate(); } //------------------------------------------------- for(int iPoint=0; iPoint<pPoints->Get_Count() && Process_Get_Okay(); iPoint++) { CSG_Shape *pPoint = pPoints->Get_Shape(iPoint); if( pPolygon->Contains(pPoint->Get_Point(0)) ) { for(i=0; i<pFields->Get_Count(); i++) { if( !pPoint->is_NoData(pFields->Get_Index(i))) { Statistics[i].Add_Value(pPoint->asDouble(pFields->Get_Index(i))); } } } } //------------------------------------------------- for(i=0, n=Offset; i<pFields->Get_Count(); i++) { if( Statistics[i].Get_Count() > 0 ) { if( bSum ) { pPolygon->Set_Value (n++, Statistics[i].Get_Sum()); } if( bAvg ) { pPolygon->Set_Value (n++, Statistics[i].Get_Mean()); } if( bVar ) { pPolygon->Set_Value (n++, Statistics[i].Get_Variance()); } if( bDev ) { pPolygon->Set_Value (n++, Statistics[i].Get_StdDev()); } if( bMin ) { pPolygon->Set_Value (n++, Statistics[i].Get_Minimum()); } if( bMax ) { pPolygon->Set_Value (n++, Statistics[i].Get_Maximum()); } if( bNum ) { pPolygon->Set_Value (n++, (double)Statistics[i].Get_Count()); } } else { if( bSum ) { pPolygon->Set_NoData(n++); } if( bAvg ) { pPolygon->Set_NoData(n++); } if( bVar ) { pPolygon->Set_NoData(n++); } if( bDev ) { pPolygon->Set_NoData(n++); } if( bMin ) { pPolygon->Set_NoData(n++); } if( bMax ) { pPolygon->Set_NoData(n++); } if( bNum ) { pPolygon->Set_Value (n++, 0.0); } } } } //----------------------------------------------------- delete[](Statistics); DataObject_Update(pPolygons); return( true ); }
//--------------------------------------------------------- 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() ); }
//--------------------------------------------------------- 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 ); }