//--------------------------------------------------------- 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 CErosion_LS_Fields::Set_Fields(void) { CSG_Shapes *pFields = Parameters("FIELDS")->asShapes(); //----------------------------------------------------- if( !pFields || pFields->Get_Count() <= 0 ) { m_Fields.Create(*Get_System(), SG_DATATYPE_Char); // m_Fields.Set_NoData_Value(1.0); // m_Fields.Assign(0.0); #pragma omp parallel for for(int y=0; y<Get_NY(); y++) { for(int x=0; x<Get_NX(); x++) { if( !m_pDEM->is_InGrid(x, y) ) { m_Fields.Set_NoData(x, y); } } } return( true ); } //----------------------------------------------------- Process_Set_Text(_TL("Initializing Fields")); m_nFields = pFields->Get_Count(); m_Fields.Create(*Get_System(), m_nFields < pow(2.0, 16.0) - 1.0 ? SG_DATATYPE_Word : SG_DATATYPE_DWord); m_Fields.Set_NoData_Value(m_nFields); m_Fields.Assign_NoData(); //----------------------------------------------------- for(int iField=0; iField<pFields->Get_Count() && Set_Progress(iField, pFields->Get_Count()); iField++) { CSG_Shape_Polygon *pField = (CSG_Shape_Polygon *)pFields->Get_Shape(iField); int xMin = Get_System()->Get_xWorld_to_Grid(pField->Get_Extent().Get_XMin()) - 1; if( xMin < 0 ) xMin = 0; int xMax = Get_System()->Get_xWorld_to_Grid(pField->Get_Extent().Get_XMax()) + 1; if( xMax >= Get_NX() ) xMax = Get_NX() - 1; int yMin = Get_System()->Get_yWorld_to_Grid(pField->Get_Extent().Get_YMin()) - 1; if( yMin < 0 ) yMin = 0; int yMax = Get_System()->Get_yWorld_to_Grid(pField->Get_Extent().Get_YMax()) + 1; if( yMax >= Get_NY() ) yMax = Get_NY() - 1; for(int y=yMin; y<=yMax; y++) { for(int x=xMin; x<=xMax; x++) { if( m_pDEM->is_InGrid(x, y) && pField->Contains(Get_System()->Get_Grid_to_World(x, y)) ) { m_Fields.Set_Value(x, y, iField); } } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CSG_Shapes::Assign(CSG_Data_Object *pObject) { int iShape; CSG_Shape *pShape; CSG_Shapes *pShapes; //----------------------------------------------------- if( pObject && pObject->is_Valid() && (pObject->Get_ObjectType() == DATAOBJECT_TYPE_Shapes || pObject->Get_ObjectType() == DATAOBJECT_TYPE_PointCloud) ) { pShapes = (CSG_Shapes *)pObject; Create(pShapes->Get_Type(), pShapes->Get_Name(), pShapes, pShapes->Get_Vertex_Type()); for(iShape=0; iShape<pShapes->Get_Count() && SG_UI_Process_Set_Progress(iShape, pShapes->Get_Count()); iShape++) { pShape = Add_Shape(); pShape->Assign(pShapes->Get_Shape(iShape)); } SG_UI_Process_Set_Ready(); Update(); Get_History() = pObject->Get_History(); return( true ); } return( false ); }
//--------------------------------------------------------- bool CPC_From_Shapes::On_Execute(void) { int zField, iField, nFields, *Fields; CSG_PointCloud *pPoints; CSG_Shapes *pShapes; pShapes = Parameters("SHAPES") ->asShapes(); pPoints = Parameters("POINTS") ->asPointCloud(); zField = Parameters("ZFIELD") ->asInt(); if( !pShapes->is_Valid() ) { return( false ); } //----------------------------------------------------- pPoints->Create(); pPoints->Set_Name(pShapes->Get_Name()); nFields = 0; Fields = new int[pShapes->Get_Field_Count()]; if( Parameters("OUTPUT")->asInt() == 1 ) { for(iField=0, nFields=0; iField<pShapes->Get_Field_Count(); iField++) { if( iField != zField && SG_Data_Type_Get_Size(pShapes->Get_Field_Type(iField)) > 0 ) { Fields[nFields++] = iField; pPoints->Add_Field(pShapes->Get_Field_Name(iField), pShapes->Get_Field_Type(iField)); } } } //----------------------------------------------------- for(int iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++) { CSG_Shape *pShape = pShapes->Get_Shape(iShape); for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++) { for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++) { TSG_Point p = pShape->Get_Point(iPoint, iPart); pPoints->Add_Point(p.x, p.y, zField < 0 ? pShape->Get_Z(iPoint, iPart) : pShape->asDouble(zField)); for(iField=0; iField<nFields; iField++) { pPoints->Set_Value(3 + iField, pShape->asDouble(Fields[iField])); } } } } //----------------------------------------------------- delete [] Fields; return( pPoints->Get_Count() > 0 ); }
//--------------------------------------------------------- bool CSurfer_BLN_Export::On_Execute(void) { //----------------------------------------------------- CSG_File Stream; if( !Stream.Open(Parameters("FILE")->asString(), SG_FILE_W) ) { return( false ); } CSG_Shapes *pShapes = Parameters("SHAPES")->asShapes(); if( !pShapes->is_Valid() || pShapes->Get_Count() <= 0 ) { return( false ); } //----------------------------------------------------- int iName = Parameters("BNAME" )->asBool() ? Parameters("NAME")->asInt() : -1; int iDesc = Parameters("BDESC" )->asBool() ? Parameters("DESC")->asInt() : -1; int iZVal = Parameters("BZVAL" )->asBool() ? Parameters("ZVAL")->asInt() : -1; int Flag = 1; //----------------------------------------------------- for(int iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++) { CSG_Shape *pShape = pShapes->Get_Shape(iShape); for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++) { Stream.Printf(SG_T("%d,%d"), pShape->Get_Point_Count(iPart), Flag); if( iName >= 0 ) { Stream.Printf(SG_T(",\"%s\""), pShape->asString(iName)); } if( iDesc >= 0 ) { Stream.Printf(SG_T(",\"%s\""), pShape->asString(iDesc)); } Stream.Printf(SG_T("\n")); for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++) { TSG_Point p = pShape->Get_Point(iPoint, iPart); if( iZVal >= 0 ) { Stream.Printf(SG_T("%f,%f,%f\n"), p.x, p.y, pShape->asDouble(iZVal)); } else { Stream.Printf(SG_T("%f,%f\n" ), p.x, p.y); } } } } //----------------------------------------------------- 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 CKernel_Density::On_Execute(void) { int Population; double Radius; CSG_Shapes *pPoints; //----------------------------------------------------- pPoints = Parameters("POINTS" )->asShapes(); Population = Parameters("POPULATION")->asInt(); Radius = Parameters("RADIUS" )->asDouble(); m_Kernel = Parameters("KERNEL" )->asInt(); if( Population < 0 || Population >= pPoints->Get_Field_Count() || pPoints->Get_Field_Type(Population) == SG_DATATYPE_String ) { Population = -1; } //----------------------------------------------------- if( (m_pGrid = m_Grid_Target.Get_Grid()) == NULL ) { return( false ); } m_pGrid->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pPoints->Get_Name(), _TL("Kernel Density"))); m_pGrid->Set_NoData_Value(0.0); m_pGrid->Assign(0.0); DataObject_Set_Colors(m_pGrid, 100, SG_COLORS_BLACK_WHITE, true); m_dRadius = Radius / m_pGrid->Get_Cellsize(); m_iRadius = 1 + (int)m_dRadius; //----------------------------------------------------- if( pPoints->Get_Selection_Count() > 0 ) { for(int iPoint=0; iPoint<pPoints->Get_Selection_Count() && Set_Progress(iPoint, pPoints->Get_Selection_Count()); iPoint++) { CSG_Shape *pPoint = pPoints->Get_Selection(iPoint); Set_Kernel(pPoint->Get_Point(0), Population < 0 ? 1.0 : pPoint->asDouble(Population)); } } else { for(int iPoint=0; iPoint<pPoints->Get_Count() && Set_Progress(iPoint, pPoints->Get_Count()); iPoint++) { CSG_Shape *pPoint = pPoints->Get_Shape(iPoint); Set_Kernel(pPoint->Get_Point(0), Population < 0 ? 1.0 : pPoint->asDouble(Population)); } } return( true ); }
//--------------------------------------------------------- bool CLine_Properties::On_Execute(void) { //------------------------------------------------- int bParts = Parameters("BPARTS") ->asBool() ? 0 : -1; int bPoints = Parameters("BPOINTS") ->asBool() ? 0 : -1; int bLength = Parameters("BLENGTH") ->asBool() ? 0 : -1; if( bParts && bPoints && bLength ) { Error_Set(_TL("no properties selected")); return( false ); } //------------------------------------------------- CSG_Shapes *pLines = Parameters("LINES")->asShapes(); if( !pLines->is_Valid() || pLines->Get_Count() <= 0 ) { Error_Set(_TL("invalid lines layer")); return( false ); } if( Parameters("OUTPUT")->asShapes() && Parameters("OUTPUT")->asShapes() != pLines ) { pLines = Parameters("OUTPUT")->asShapes(); pLines->Create(*Parameters("LINES")->asShapes()); } //------------------------------------------------- if( !bParts ) { bParts = pLines->Get_Field_Count(); pLines->Add_Field(SG_T("NPARTS") , SG_DATATYPE_Int ); } if( !bPoints ) { bPoints = pLines->Get_Field_Count(); pLines->Add_Field(SG_T("NPOINTS"), SG_DATATYPE_Int ); } if( !bLength ) { bLength = pLines->Get_Field_Count(); pLines->Add_Field(SG_T("LENGTH") , SG_DATATYPE_Double); } //------------------------------------------------- for(int i=0; i<pLines->Get_Count() && Set_Progress(i, pLines->Get_Count()); i++) { CSG_Shape *pLine = pLines->Get_Shape(i); if( bParts >= 0 ) pLine->Set_Value(bParts , pLine->Get_Part_Count()); if( bPoints >= 0 ) pLine->Set_Value(bPoints, pLine->Get_Point_Count()); if( bLength >= 0 ) pLine->Set_Value(bLength, ((CSG_Shape_Line *)pLine)->Get_Length()); } //------------------------------------------------- if( pLines == Parameters("LINES")->asShapes() ) { DataObject_Update(pLines); } return( true ); }
//--------------------------------------------------------- bool CGridding_Spline_Base::_Get_Points(CSG_Points_Z &Points, bool bInGridOnly) { Points.Clear(); if( m_bGridPoints ) { int x, y; TSG_Point p; CSG_Grid *pGrid = Parameters("GRIDPOINTS") ->asGrid(); for(y=0, p.y=pGrid->Get_YMin(); y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++, p.y+=pGrid->Get_Cellsize()) { for(x=0, p.x=pGrid->Get_XMin(); x<pGrid->Get_NX(); x++, p.x+=pGrid->Get_Cellsize()) { if( !pGrid->is_NoData(x, y) && (!bInGridOnly || m_pGrid->is_InGrid_byPos(p)) ) { Points.Add(p.x, p.y, pGrid->asDouble(x, y)); } } } } else { CSG_Shapes *pShapes = Parameters("SHAPES") ->asShapes(); int zField = Parameters("FIELD") ->asInt(); for(int iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++) { CSG_Shape *pShape = pShapes->Get_Shape(iShape); if( !pShape->is_NoData(zField) ) { double zValue = pShape->asDouble(zField); for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++) { for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++) { TSG_Point p = pShape->Get_Point(iPoint, iPart); if( !bInGridOnly || m_pGrid->is_InGrid_byPos(p) ) { Points.Add(p.x, p.y, zValue); } } } } } } return( Points.Get_Count() >= 3 ); }
//--------------------------------------------------------- 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 CGSPoints_Distances::On_Execute(void) { //----------------------------------------------------- CSG_Shapes *pPoints = Parameters("POINTS") ->asShapes(); CSG_Table *pTable = Parameters("TABLE") ->asTable(); //----------------------------------------------------- CSG_PRQuadTree QT(pPoints, 0); CSG_Simple_Statistics s; double x, y, z; for(int iPoint=0; iPoint<pPoints->Get_Count() && Set_Progress(iPoint, pPoints->Get_Count()); iPoint++) { TSG_Point p = pPoints->Get_Shape(iPoint)->Get_Point(0); if( QT.Select_Nearest_Points(p.x, p.y, 2) && QT.Get_Selected_Point(1, x, y, z) && (x != p.x || y != p.y) ) { s.Add_Value(SG_Get_Distance(x, y, p.x, p.y)); } } //----------------------------------------------------- if( s.Get_Count() > 0 ) { CSG_Table_Record *pRecord; pTable->Destroy(); pTable->Set_Name(CSG_String::Format(SG_T("%s [%s]"), _TL("Minimum Distance Analysis"), pPoints->Get_Name())); pTable->Add_Field(SG_T("NAME") , SG_DATATYPE_String); pTable->Add_Field(SG_T("VALUE") , SG_DATATYPE_Double); SET_VALUE(_TL("Mean Average") , s.Get_Mean()); SET_VALUE(_TL("Minimum") , s.Get_Minimum()); SET_VALUE(_TL("Maximum") , s.Get_Maximum()); SET_VALUE(_TL("Standard Deviation") , s.Get_StdDev()); SET_VALUE(_TL("Duplicates") , pPoints->Get_Count() - s.Get_Count()); DataObject_Update(pTable, SG_UI_DATAOBJECT_SHOW); return( true ); } Message_Dlg(_TL("not enough observations")); return( false ); }
//--------------------------------------------------------- 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 CCost_Accumulated::Get_Destinations(CPoints &Points) { Points.Clear(); m_pAccumulated->Set_NoData_Value(-1.0); m_pAccumulated->Assign(-1.0); m_pAllocation ->Set_NoData_Value(-1.0); m_pAllocation ->Assign( 0.0); if( Parameters("DEST_TYPE")->asInt() == 0 ) // Point { CSG_Shapes *pDestinations = Parameters("DEST_POINTS")->asShapes(); for(int i=0, x, y; i<pDestinations->Get_Count(); i++) { if( Get_System().Get_World_to_Grid(x, y, pDestinations->Get_Shape(i)->Get_Point(0)) && !m_pCost->is_NoData(x, y) ) { Points.Add(x, y); m_pAllocation->Set_Value(x, y, Points.Get_Count()); m_pAccumulated->Set_Value(x, y, 0.0); } } } else // Grid { CSG_Grid *pDestinations = Parameters("DEST_GRID")->asGrid(); for(int y=0; y<Get_NY(); y++) for(int x=0; x<Get_NX(); x++) { if( !pDestinations->is_NoData(x, y) && !m_pCost->is_NoData(x, y) ) { Points.Add(x, y); m_pAllocation->Set_Value(x, y, Points.Get_Count()); m_pAccumulated->Set_Value(x, y, 0.0); } } } return( Points.Get_Count() > 0 ); }
//--------------------------------------------------------- bool CSG_Network::Update(void) { int iEdge; //----------------------------------------------------- for(iEdge=m_Edges.Get_Count()-1; iEdge>=0; iEdge--) { CSG_Shape *pEdge = m_Edges.Get_Shape(iEdge); if( !(((CSG_Shape_Line *)pEdge)->Get_Length() > 0.0) ) { m_Edges.Del_Shape(iEdge); } } //----------------------------------------------------- for(int i=0; i<Get_Node_Count(); i++) { delete(&Get_Node(i)); } m_Nodes.Set_Array(0); //----------------------------------------------------- CSG_PRQuadTree Search(m_Edges.Get_Extent()); for(iEdge=0; iEdge<m_Edges.Get_Count(); iEdge++) { CSG_Shape *pEdge = m_Edges.Get_Shape(iEdge); pEdge->Set_Value(0, iEdge); pEdge->Set_Value(1, _Add_Node(Search, iEdge, pEdge->Get_Point(0), pEdge->Get_Point(1) )); pEdge->Set_Value(2, _Add_Node(Search, iEdge, pEdge->Get_Point(pEdge->Get_Point_Count(0) - 1), pEdge->Get_Point(pEdge->Get_Point_Count(0) - 2) )); } //----------------------------------------------------- return( true ); }
bool CCreateChartLayer::On_Execute(void){ CSG_Shapes *pInput; int i=0; int iType; int iSizeField; if (GetExtraParameters()){ iSizeField = Parameters("SIZE")->asInt(); m_fMaxSize = (float) Parameters("MAXSIZE")->asDouble(); m_fMinSize = (float) Parameters("MINSIZE")->asDouble(); if (m_fMinSize > m_fMaxSize){ m_fMinSize = m_fMaxSize; }//if iType = Parameters("TYPE")->asInt(); pInput = Parameters("INPUT")->asShapes(); m_fMaxValue = pInput->Get_Maximum(iSizeField); m_fMinValue = pInput->Get_Minimum(iSizeField); if (iType == TYPE_PIE){ m_pOutput = SG_Create_Shapes(SHAPE_TYPE_Polygon, _TL("Chart (sectors):")); }//if else{ m_pOutput = SG_Create_Shapes(SHAPE_TYPE_Polygon, _TL("Chart (bars):")); }//else m_pOutput->Add_Field(_TL("Field (ID)"), SG_DATATYPE_Int); m_pOutput->Add_Field(_TL("Field (Name)"), SG_DATATYPE_String); for (i = 0; i < pInput->Get_Count(); i++){ if (iType == TYPE_PIE){ // AddPieChart(pInput->Get_Shape(i),m_pOutput->Get_Type()); AddPieChart(pInput->Get_Shape(i),pInput->Get_Type()); }//if else{ // AddBarChart(pInput->Get_Shape(i),m_pOutput->Get_Type()); AddBarChart(pInput->Get_Shape(i),pInput->Get_Type()); }//else }//for DataObject_Add(m_pOutput, false); delete [] m_bIncludeParam; return true; }//if delete [] m_bIncludeParam; return false; }//method
//--------------------------------------------------------- bool CAddCoordinates::On_Execute(void) { CSG_Shapes *pShapes = Parameters("OUTPUT")->asShapes(); if( pShapes ) { pShapes->Assign(Parameters("INPUT")->asShapes()); } else { pShapes = Parameters("INPUT")->asShapes(); } //----------------------------------------------------- int xField = pShapes->Get_Field_Count(); pShapes->Add_Field("X", SG_DATATYPE_Double); int yField = pShapes->Get_Field_Count(); pShapes->Add_Field("Y", SG_DATATYPE_Double); int zField = 0, mField = 0; if( pShapes->Get_Vertex_Type() != SG_VERTEX_TYPE_XY ) { zField = pShapes->Get_Field_Count(); pShapes->Add_Field("Z", SG_DATATYPE_Double); if( pShapes->Get_Vertex_Type() == SG_VERTEX_TYPE_XYZM ) { mField = pShapes->Get_Field_Count(); pShapes->Add_Field("M", SG_DATATYPE_Double); } } //----------------------------------------------------- for(int i=0; i<pShapes->Get_Count(); i++) { CSG_Shape *pShape = pShapes->Get_Shape(i); pShape->Set_Value(xField, pShape->Get_Point(0).x); pShape->Set_Value(yField, pShape->Get_Point(0).y); if( pShapes->Get_Vertex_Type() != SG_VERTEX_TYPE_XY ) { pShape->Set_Value(zField, pShape->Get_Z(0)); if( pShapes->Get_Vertex_Type() == SG_VERTEX_TYPE_XYZM ) { pShape->Set_Value(mField, pShape->Get_M(0)); } } } DataObject_Update(pShapes); return( true ); }
//--------------------------------------------------------- bool CVIEW_ScatterPlot::_Initialize_Shapes(void) { CSG_Shapes *pPoints = m_Parameters("POINTS")->asShapes(); int Field = m_Parameters("FIELD" )->asInt(); TSG_Grid_Resampling Resampling; switch( m_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; } CHECK_DATA(m_pGrid); CHECK_DATA(pPoints); if( !m_pGrid || !pPoints || Field < 0 || Field >= pPoints->Get_Field_Count() ) { return( false ); } m_sTitle.Printf("%s: [%s/%s]", _TL("Scatterplot"), m_pGrid->Get_Name(), pPoints->Get_Name()); m_sX.Printf("%s", m_pGrid->Get_Name()); m_sY.Printf("%s", pPoints->Get_Field_Name(Field)); int maxSamples = m_Options("SAMPLES_MAX")->asInt(); double x, Step = maxSamples > 0 && pPoints->Get_Count() > maxSamples ? pPoints->Get_Count() / maxSamples : 1.0; for(double i=0; i<pPoints->Get_Count() && PROGRESSBAR_Set_Position(i, pPoints->Get_Count()); i+=Step) { CSG_Shape *pShape = pPoints->Get_Shape((int)i); if( !pShape->is_NoData(Field) && m_pGrid->Get_Value(pShape->Get_Point(0), x, Resampling) ) { m_Trend.Add_Data(x, pShape->asDouble(Field)); } } return( true ); }
//--------------------------------------------------------- bool CGPX_Import::On_Execute(void) { CSG_Shapes *pWay; CSG_MetaData GPX; //----------------------------------------------------- m_Name = Parameters("FILE") ->asString(); m_pShapes = Parameters("SHAPES") ->asShapesList(); m_bTime = Parameters("TIME") ->asBool(); //----------------------------------------------------- if( !GPX.Create(m_Name) || GPX.Get_Name().CmpNoCase(SG_T("gpx")) ) { return( false ); } //----------------------------------------------------- pWay = SG_Create_Shapes(SHAPE_TYPE_Point, m_Name); m_Name = SG_File_Get_Name(m_Name, false); m_pShapes->Del_Items(); //----------------------------------------------------- for(int i=0; i<GPX.Get_Children_Count(); i++) { CSG_MetaData *pChild = GPX.Get_Child(i); if( pChild->Get_Name().CmpNoCase(SG_T("wpt")) == 0 ) { Add_Point(pChild, pWay); } else if( pChild->Get_Name().CmpNoCase(SG_T("rte")) == 0 ) { Add_Route(pChild); } else if( pChild->Get_Name().CmpNoCase(SG_T("trk")) == 0 ) { Add_Track(pChild); } } //----------------------------------------------------- if( pWay->Get_Count() > 0 ) { m_pShapes->Add_Item(pWay); } else { delete(pWay); } return( m_pShapes->Get_Count() > 0 ); }
//--------------------------------------------------------- bool CGPX_Export::On_Execute(void) { int iEle, iName, iCmt, iDesc; CSG_String File; CSG_MetaData GPX; CSG_Shapes *pShapes; //----------------------------------------------------- File = Parameters("FILE") ->asString(); pShapes = Parameters("SHAPES") ->asShapes(); iEle = Parameters("ELE") ->asInt(); if( iEle >= pShapes->Get_Field_Count() ) iEle = -1; iName = Parameters("NAME") ->asInt(); if( iName >= pShapes->Get_Field_Count() ) iName = -1; iCmt = Parameters("CMT") ->asInt(); if( iCmt >= pShapes->Get_Field_Count() ) iCmt = -1; iDesc = Parameters("DESC") ->asInt(); if( iDesc >= pShapes->Get_Field_Count() ) iDesc = -1; //----------------------------------------------------- GPX.Set_Name(SG_T("gpx")); GPX.Add_Property(SG_T("version") , SG_T("1.0")); GPX.Add_Property(SG_T("creator") , SG_T("SAGA - System for Automated Geoscientific Analyses - http://www.saga-gis.org")); GPX.Add_Property(SG_T("xmlns:xsi") , SG_T("http://www.w3.org/2001/XMLSchema-instance")); GPX.Add_Property(SG_T("xmlns") , SG_T("http://www.topografix.com/GPX/1/0")); GPX.Add_Property(SG_T("xsi:schemaLocation") , SG_T("http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd")); for(int iShape=0; iShape<pShapes->Get_Count(); iShape++) { CSG_Shape *pShape = pShapes->Get_Shape(iShape); for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++) { for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++) { CSG_MetaData *pPoint = GPX.Add_Child(SG_T("wpt")); pPoint->Add_Property(SG_T("lon"), pShape->Get_Point(iPoint, iPart).x); pPoint->Add_Property(SG_T("lat"), pShape->Get_Point(iPoint, iPart).y); if( iEle > 0 ) pPoint->Add_Child(SG_T("ele" ), pShape->asString(iEle)); if( iName > 0 ) pPoint->Add_Child(SG_T("name"), pShape->asString(iName)); if( iCmt > 0 ) pPoint->Add_Child(SG_T("cmt" ), pShape->asString(iCmt)); if( iDesc > 0 ) pPoint->Add_Child(SG_T("desc"), pShape->asString(iDesc)); } } } //----------------------------------------------------- if( !GPX.Save(File) ) { return( false ); } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- void CGrid_3D_Image::_Set_Shapes(CSG_Shapes *pInput) { int iShape, iPart, iPoint; double x, y, z, dx, dy; T3DPoint p; TSG_Point Point; CSG_Shape *pShape; CSG_Shapes *pOutput; if( pInput && pInput->is_Valid() ) { Process_Set_Text("%s \"%s\"", _TL("Project"), pInput->Get_Name()); pOutput = SG_Create_Shapes(*pInput); dx = (double)Get_NX() / Get_System().Get_XRange(); dy = (double)Get_NY() / Get_System().Get_YRange(); for(iShape=0; iShape<pOutput->Get_Count() && Set_Progress(iShape, pOutput->Get_Count()); iShape++) { pShape = pOutput->Get_Shape(iShape); for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++) { for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++) { Point = pShape->Get_Point(iPoint, iPart); x = dx * (Point.x - Get_XMin()); y = dy * (Point.y - Get_YMin()); z = m_pDEM->is_InGrid((int)x, (int)y, true) ? m_pDEM->asDouble((int)x, (int)y) : 0.0; _Get_Position(x, y, z, p); pShape->Set_Point(p.x, p.y, iPoint, iPart); } } } DataObject_Add(pOutput); } }
//--------------------------------------------------------- bool CPolygon_Line_Intersection::On_Execute(void) { CSG_Shapes *pPolygons; //-------------------------------------------------------- pPolygons = Parameters("POLYGONS") ->asShapes(); m_pLines = Parameters("LINES") ->asShapes(); m_pIntersection = Parameters("INTERSECT") ->asShapes(); //-------------------------------------------------------- if( !m_pLines ->is_Valid() || m_pLines ->Get_Count() < 1 || !pPolygons->is_Valid() || pPolygons->Get_Count() < 1 || m_pLines->Get_Extent().Intersects(pPolygons->Get_Extent()) == INTERSECTION_None ) { Error_Set(_TL("no shapes for intersection found")); return( false ); } //-------------------------------------------------------- m_pIntersection->Create(SHAPE_TYPE_Polygon, CSG_String::Format(SG_T("%s [%s: %s]"), pPolygons->Get_Name(), _TL("Intersection"), m_pLines->Get_Name()), pPolygons ); //-------------------------------------------------------- for(int iPolygon=0; iPolygon<pPolygons->Get_Count() && Set_Progress(iPolygon, pPolygons->Get_Count()); iPolygon++) { if( !Get_Intersection((CSG_Shape_Polygon *)pPolygons->Get_Shape(iPolygon)) ) { m_pIntersection->Add_Shape(pPolygons->Get_Shape(iPolygon)); } } 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 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 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 CWASP_MAP_Export::On_Execute(void) { int zField; FILE *Stream; CSG_String fName; CSG_Shape *pLine; CSG_Shapes *pLines; //----------------------------------------------------- pLines = Parameters("SHAPES") ->asShapes(); zField = Parameters("ELEVATION") ->asInt(); fName = Parameters("FILE") ->asString(); //----------------------------------------------------- if( pLines && pLines->is_Valid() && (Stream = fopen(fName.b_str(), "w")) != NULL ) { // 1) Text string identifying the terrain map: + ... fprintf(Stream, "+ %s\n", pLines->Get_Name()); // 2) Fixed point #1 in user and metric [m] coordinates: // X1(user) Y1(user) X1(metric) Y1(metric) fprintf(Stream, "%f %f %f %f\n", 0.0, 0.0, 0.0, 0.0); // 3) Fixed point #2 in user and metric [m] coordinates: // X2(user) Y2(user) X2(metric) Y2(metric) fprintf(Stream, "%f %f %f %f\n", 1.0, 1.0, 1.0, 1.0); // 4) Scaling factor and offset for height scale (Z): // Zmetric = {scaling factor}(Zuser + {offset}) fprintf(Stream, "%f %f\n", 1.0, 0.0); for(int iLine=0; iLine<pLines->Get_Count() && Set_Progress(iLine, pLines->Get_Count()); iLine++) { pLine = pLines->Get_Shape(iLine); for(int iPart=0; iPart<pLine->Get_Part_Count(); iPart++) { if( pLine->Get_Point_Count(iPart) > 1 ) { // 5a) Height contour: elevation (Z) and number of points (n) in line: // Z n fprintf(Stream, "%f %d\n", pLine->asDouble(zField), pLine->Get_Point_Count(iPart)); // 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 // 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 // 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 iPoint=0; iPoint<pLine->Get_Point_Count(iPart); iPoint++) { TSG_Point p = pLine->Get_Point(iPoint, iPart); fprintf(Stream, "%f\t%f\n", p.x, p.y); } } } } fclose(Stream); return( true ); } return( false ); }
//--------------------------------------------------------- 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 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 CGSPoints_Semi_Variances::On_Execute(void) { int i, j, k, n, nDistances, nSkip, Attribute; double zi, zj, zMean, v, c, maxDistance, lagDistance; TSG_Point Pt_i, Pt_j; CSG_Vector Count, Variance, Covariance; CSG_Table_Record *pRecord; CSG_Table *pTable; CSG_Shape *pPoint; CSG_Shapes *pPoints; //----------------------------------------------------- pPoints = Parameters("POINTS") ->asShapes(); pTable = Parameters("RESULT") ->asTable(); Attribute = Parameters("FIELD") ->asInt(); nSkip = Parameters("NSKIP") ->asInt(); maxDistance = Parameters("DISTMAX") ->asDouble(); nDistances = Parameters("DISTCOUNT") ->asInt(); if( maxDistance <= 0.0 ) { maxDistance = SG_Get_Length(pPoints->Get_Extent().Get_XRange(), pPoints->Get_Extent().Get_YRange()); } lagDistance = maxDistance / nDistances; zMean = pPoints->Get_Mean(Attribute); Count .Create(nDistances); Variance .Create(nDistances); Covariance .Create(nDistances); //----------------------------------------------------- for(i=0, n=0; i<pPoints->Get_Count() && Set_Progress(n, SG_Get_Square(pPoints->Get_Count()/nSkip)/2); i+=nSkip) { pPoint = pPoints->Get_Shape(i); if( !pPoint->is_NoData(Attribute) ) { Pt_i = pPoint->Get_Point(0); zi = pPoint->asDouble(Attribute); for(j=i+nSkip; j<pPoints->Get_Count(); j+=nSkip, n++) { pPoint = pPoints->Get_Shape(j); if( !pPoint->is_NoData(Attribute) ) { Pt_j = pPoint->Get_Point(0); k = (int)(SG_Get_Distance(Pt_i, Pt_j) / lagDistance); if( k < nDistances ) { zj = pPoint->asDouble(Attribute); v = SG_Get_Square(zi - zj); c = (zi - zMean) * (zj - zMean); Count [k] ++; Variance [k] += v; Covariance[k] += c; } } } } } //----------------------------------------------------- pTable->Destroy(); pTable->Set_Name(CSG_String::Format(SG_T("%s [%s: %s]"), pPoints->Get_Name(), _TL("Variogram"), pPoints->Get_Field_Name(Attribute))); pTable->Add_Field(_TL("Class") , SG_DATATYPE_Int); // FIELD_CLASSNR pTable->Add_Field(_TL("Distance") , SG_DATATYPE_Double); // FIELD_DISTANCE pTable->Add_Field(_TL("Count") , SG_DATATYPE_Int); // FIELD_COUNT pTable->Add_Field(_TL("Variance") , SG_DATATYPE_Double); // FIELD_VARIANCE pTable->Add_Field(_TL("Cum.Var.") , SG_DATATYPE_Double); // FIELD_VARCUMUL pTable->Add_Field(_TL("Covariance") , SG_DATATYPE_Double); // FIELD_COVARIANCE pTable->Add_Field(_TL("Cum.Covar.") , SG_DATATYPE_Double); // FIELD_COVARCUMUL for(i=0, v=0.0, c=0.0, n=0; i<nDistances; i++) { if( Count[i] > 0 ) { n += (int)Count[i]; v += Variance [i]; c += Covariance[i]; pRecord = pTable->Add_Record(); pRecord->Set_Value(FIELD_CLASSNR , (i + 1)); pRecord->Set_Value(FIELD_DISTANCE , (i + 1) * lagDistance); pRecord->Set_Value(FIELD_COUNT , Count[i]); pRecord->Set_Value(FIELD_VARIANCE , 0.5 * Variance [i] / Count[i]); pRecord->Set_Value(FIELD_VARCUMUL , 0.5 * v / n); pRecord->Set_Value(FIELD_COVARIANCE , 1.0 * Covariance[i] / Count[i]); pRecord->Set_Value(FIELD_COVARCUMUL , 1.0 * c / n); } } 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 ); }