//--------------------------------------------------------- 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 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 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 CPoints_From_Table::On_Execute(void) { int iRecord, iXField, iYField; double dX, dY; CSG_Table *pTable; CSG_Table_Record *pRecord; CSG_Shapes *pShapes; CSG_Shape *pShape; pTable = Parameters("TABLE") ->asTable(); pShapes = Parameters("POINTS") ->asShapes(); iXField = Parameters("X") ->asInt(); iYField = Parameters("Y") ->asInt(); pShapes->Create(SHAPE_TYPE_Point, pTable->Get_Name(), pTable); if( pTable->Get_Field_Count() > 1 && pTable->Get_Record_Count() > 0 ) { for(iRecord=0; iRecord<pTable->Get_Record_Count() && Set_Progress(iRecord, pTable->Get_Record_Count()); iRecord++) { pRecord = pTable->Get_Record(iRecord); dX = pRecord->asDouble(iXField); dY = pRecord->asDouble(iYField); pShape = pShapes->Add_Shape(pRecord, SHAPE_COPY_ATTR); pShape->Add_Point(dX, dY); }//for return( true ); }//if return( false ); }//method
//--------------------------------------------------------- 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 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 ); }
//--------------------------------------------------------- void CGrid_Cross_Profiles::Make_Report(const SG_Char *FileName, CSG_Grid *pDEM, CSG_Shapes *pLines, CSG_Shapes *pProfiles, double Distance) { if( FileName ) { int iProfile, iPoint, nSamples, iBox; CSG_Rect r; CSG_Shape *pProfile, *pLine; CSG_Shapes Profile; CSG_Doc_PDF pdf; pdf.Open(PDF_PAGE_SIZE_A4, PDF_PAGE_ORIENTATION_PORTRAIT, _TL("Cross Profiles")); pdf.Layout_Add_Box(5, 5, 95, 20); pdf.Layout_Add_Box(5, 25, 95, 45); pdf.Layout_Add_Box(5, 50, 95, 70); pdf.Layout_Add_Box(5, 75, 95, 90); nSamples = pProfiles->Get_Field_Count() - OFFSET; Distance = Distance / (nSamples - 1); iBox = 0; for(iProfile=0; iProfile<pProfiles->Get_Count() && Set_Progress(iProfile, pProfiles->Get_Count()); iProfile++) { pProfile = pProfiles->Get_Shape(iProfile); Profile.Create(SHAPE_TYPE_Line); pLine = Profile.Add_Shape(); for(iPoint=0; iPoint<nSamples; iPoint++) { if( !pProfile->is_NoData(OFFSET + iPoint) ) { pLine->Add_Point( (iPoint - nSamples / 2) * Distance, pProfile->asDouble(OFFSET + iPoint) ); } } if( pLine->Get_Point_Count(0) > 1 ) { if( iBox >= NBOXES ) { pdf.Add_Page(); iBox = 0; } // pdf.Draw_Graticule (pdf.Layout_Get_Box(iBox), Profile.Get_Extent(), 20); // pdf.Draw_Shapes (pdf.Layout_Get_Box(iBox), &Profile); r = pLine->Get_Extent(); r.Inflate(10); pdf.Draw_Graticule (pdf.Layout_Get_Box(iBox), r, 15); pdf.Draw_Shape (pdf.Layout_Get_Box(iBox), pLine, PDF_STYLE_POLYGON_FILLSTROKE, SG_COLOR_GREEN, SG_COLOR_BLACK, 1, &r); iBox++; } } pdf.Save(Parameters("DOCUMENT")->asString()); } }
//--------------------------------------------------------- bool CCRS_Transform_Shapes::On_Execute_Transformation(void) { if( m_bList ) { CSG_Parameter_Shapes_List *pSources, *pTargets; pSources = Parameters("SOURCE")->asShapesList(); pTargets = Parameters("TARGET")->asShapesList(); pTargets->Del_Items(); for(int i=0; i<pSources->Get_Count() && Process_Get_Okay(false); i++) { CSG_Shapes *pSource = pSources->asShapes(i); CSG_Shapes *pTarget = SG_Create_Shapes(pSource); if( Transform(pSource, pTarget) ) { pTargets->Add_Item(pTarget); } else { delete(pTarget); } } return( pTargets->Get_Count() > 0 ); } else { CSG_Shapes *pSource = Parameters("SOURCE")->asShapes(); CSG_Shapes *pTarget = Parameters("TARGET")->asShapes(); if( pSource == pTarget ) { pTarget = SG_Create_Shapes(pSource); if( Transform(pSource, pTarget) ) { pSource->Assign(pTarget); return( true ); } else { delete(pTarget); return( false ); } } else { pTarget->Create(pSource->Get_Type(), pSource->Get_Name(), pSource, pSource->Get_Vertex_Type()); } return( Transform(pSource, pTarget) ); } }
//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- 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 CPolygon_Vertex_Check::On_Execute(void) { //----------------------------------------------------- CSG_Shapes *pPolygons = Parameters("POLYGONS")->asShapes(); if( Parameters("CHECKED")->asShapes() && Parameters("CHECKED")->asShapes() != pPolygons ) { CSG_Shapes *pCopy = Parameters("CHECKED")->asShapes(); pCopy->Create(*pPolygons); pCopy->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pPolygons->Get_Name(), _TL("checked"))); pPolygons = pCopy; } if( (m_pAdded = Parameters("ADDED")->asShapes()) != NULL ) { m_pAdded->Create(SHAPE_TYPE_Point, _TL("Added")); } double Epsilon = Parameters("EPSILON")->asDouble(); //----------------------------------------------------- for(int iPolygon=0; iPolygon<pPolygons->Get_Count()-1 && Set_Progress(iPolygon, pPolygons->Get_Count()-1); iPolygon++) { CSG_Shape_Polygon *pA = (CSG_Shape_Polygon *)pPolygons->Get_Shape(iPolygon); for(int jPolygon=iPolygon+1; jPolygon<pPolygons->Get_Count() && Process_Get_Okay(); jPolygon++) { CSG_Shape_Polygon *pB = (CSG_Shape_Polygon *)pPolygons->Get_Shape(jPolygon); for(int iPart=0; iPart<pA->Get_Part_Count() && Process_Get_Okay(); iPart++) { for(int jPart=0; jPart<pB->Get_Part_Count() && Process_Get_Okay(); jPart++) { if( pA->Get_Part(iPart)->Get_Extent().Intersects(pB->Get_Part(jPart)->Get_Extent()) ) { Check_Vertices(pA->Get_Part(iPart), pB->Get_Part(jPart), Epsilon); Check_Vertices(pB->Get_Part(jPart), pA->Get_Part(iPart), Epsilon); } } } } } //----------------------------------------------------- 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 ); }
//--------------------------------------------------------- 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 CPoints_From_MultiPoints::On_Execute(void) { //----------------------------------------------------- CSG_Shapes *pMultipoints = Parameters("MULTIPOINTS") ->asShapes(); CSG_Shapes *pPoints = Parameters("POINTS") ->asShapes(); pPoints->Create(SHAPE_TYPE_Point, pMultipoints->Get_Name(), pMultipoints, pMultipoints->Get_Vertex_Type()); //----------------------------------------------------- for(int iMultipoint=0; iMultipoint<pMultipoints->Get_Count() && Set_Progress(iMultipoint, pMultipoints->Get_Count()); iMultipoint++) { CSG_Shape *pMultipoint = pMultipoints->Get_Shape(iMultipoint); for(int iPart=0; iPart<pMultipoint->Get_Part_Count(); iPart++) { for(int iPoint=0; iPoint<pMultipoint->Get_Point_Count(iPart); iPoint++) { CSG_Shape *pPoint = pPoints->Add_Shape(pMultipoint, SHAPE_COPY_ATTR); pPoint->Add_Point(pMultipoint->Get_Point(iPoint, iPart)); if( pMultipoints->Get_Vertex_Type() != SG_VERTEX_TYPE_XY ) { pPoint->Set_Z(pMultipoint->Get_Z(iPoint, iPart), 0); if( pMultipoints->Get_Vertex_Type() == SG_VERTEX_TYPE_XYZM ) { pPoint->Set_M(pMultipoint->Get_M(iPoint, iPart), 0); } } } } } return( true ); }
//--------------------------------------------------------- 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 CTIN_From_Grid_Specific_Points::On_Execute(void) { bool bResult; int x, y, i; CSG_TIN *pTIN; CSG_Grid *pGrid, Grid; CSG_Parameter_Grid_List *pValues; CSG_Shape *pPoint; CSG_Shapes Points; //----------------------------------------------------- pGrid = Parameters("GRID")->asGrid(); Grid.Create(pGrid, SG_DATATYPE_Byte); //----------------------------------------------------- switch( Parameters("METHOD")->asInt() ) { default: bResult = false; break; case 0: bResult = Get_MarkHighestNB (&Grid, pGrid); break; case 1: bResult = Get_OppositeNB (&Grid, pGrid, Parameters("HIGH")->asInt()); break; case 2: bResult = Get_FlowDirection (&Grid, pGrid, (int)Parameters("FLOW")->asRange()->Get_LoVal(), (int)Parameters("FLOW")->asRange()->Get_HiVal() ); break; case 3: bResult = Get_FlowDirection2(&Grid, pGrid, (int)Parameters("FLOW")->asRange()->Get_HiVal() ); break; case 4: bResult = Get_Peucker (&Grid, pGrid, Parameters("PEUCKER")->asDouble()); break; } //----------------------------------------------------- if( bResult ) { pValues = Parameters("VALUES")->asGridList(); Points.Create(SHAPE_TYPE_Point); Points.Add_Field(_TL("VALUE"), SG_DATATYPE_Double); for(i=0; i<pValues->Get_Count(); i++) { Points.Add_Field(pValues->asGrid(i)->Get_Name(), SG_DATATYPE_Double); } for(y=0; y<Get_NY() && Set_Progress(y, Get_NY()); y++) { for(x=0; x<Get_NX(); x++) { if( Grid.asInt(x, y) != 0 ) { pPoint = Points.Add_Shape(); pPoint->Add_Point( Get_XMin() + Get_Cellsize() * x, Get_YMin() + Get_Cellsize() * y ); pPoint->Set_Value(0, pGrid->asDouble(x, y)); for(i=0; i<pValues->Get_Count(); i++) { pPoint->Set_Value(1 + i, pValues->asGrid(i)->asDouble(x, y)); } } } } //------------------------------------------------- if( Points.Get_Count() >= 3 ) { pTIN = Parameters("TIN")->asTIN(); pTIN->Create(&Points); pTIN->Set_Name(pGrid->Get_Name()); } } return( bResult ); }
//--------------------------------------------------------- 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 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 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 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 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 ); }
//--------------------------------------------------------- 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 CDirect_Georeferencing_WorldFile::On_Execute(void) { //----------------------------------------------------- int nx = Parameters("NX")->asInt(); int ny = Parameters("NY")->asInt(); if( !m_Georeferencer.Set_Transformation(Parameters, nx, ny) ) { return( false ); } //----------------------------------------------------- CSG_String File = Parameters("FILE")->asString(); if( File.is_Empty() ) { return( false ); } //----------------------------------------------------- CSG_File Stream; if( !Stream.Open(File, SG_FILE_W, false) ) { return( false ); } //----------------------------------------------------- CSG_Matrix R(m_Georeferencer.Get_Transformation()); R *= 0.001 * Parameters("Z")->asDouble() / Parameters("CFL")->asDouble() * Parameters("PXSIZE")->asDouble(); TSG_Point p = m_Georeferencer.Image_to_World(0, ny); Stream.Printf(SG_T("%.10f\n%.10f\n%.10f\n%.10f\n%.10f\n%.10f\n"), R[0][0], // A: pixel size in the x-direction in map units/pixel R[1][0], // D: rotation about y-axis -R[0][1], // B: rotation about x-axis -R[1][1], // E: pixel size in the y-direction in map units, almost always negative p.x, // X: top left pixel center p.y // Y: top left pixel center ); //----------------------------------------------------- CSG_Shapes *pExtents = Parameters("EXTENT")->asShapes(); if( pExtents ) { pExtents->Create(SHAPE_TYPE_Polygon, SG_File_Get_Name(File, false)); pExtents->Add_Field(_TL("NAME"), SG_DATATYPE_String); CSG_Shape *pExtent = pExtents->Add_Shape(); p = m_Georeferencer.Image_to_World( 0, 0); pExtent->Add_Point(p.x, p.y); p = m_Georeferencer.Image_to_World( 0, ny); pExtent->Add_Point(p.x, p.y); p = m_Georeferencer.Image_to_World(nx, ny); pExtent->Add_Point(p.x, p.y); p = m_Georeferencer.Image_to_World(nx, 0); pExtent->Add_Point(p.x, p.y); pExtent->Set_Value(0, SG_File_Get_Name(File, false)); } //----------------------------------------------------- return( true ); }