//--------------------------------------------------------- void CPolygon_Clip::Clip_Points(CSG_Shapes *pClips, CSG_Shapes *pInputs, CSG_Shapes *pOutputs) { for(int iClip=0; iClip<pClips->Get_Count() && Set_Progress(iClip, pClips->Get_Count()); iClip++) { CSG_Shape_Polygon *pClip = (CSG_Shape_Polygon *)pClips->Get_Shape(iClip); for(int iInput=0; iInput<pInputs->Get_Count(); iInput++) { CSG_Shape *pInput = pInputs->Get_Shape(iInput); CSG_Shape *pOutput = NULL; for(int iPoint=0; iPoint<pInput->Get_Point_Count(0); iPoint++) { if( pClip->Contains(pInput->Get_Point(iPoint, 0)) ) { if( pOutput == NULL ) { pOutput = pOutputs->Add_Shape(pInput, SHAPE_COPY_ATTR); } pOutput->Add_Point(pInput->Get_Point(iPoint, 0)); } } } } }
//--------------------------------------------------------- bool CLines_From_Polygons::On_Execute(void) { CSG_Shapes *pLines, *pPolygons; pPolygons = Parameters("POLYGONS") ->asShapes(); pLines = Parameters("LINES") ->asShapes(); //----------------------------------------------------- if( pPolygons->Get_Count() <= 0 ) { Error_Set(_TL("no polygons in input")); return( false ); } //----------------------------------------------------- pLines->Create(SHAPE_TYPE_Line, pPolygons->Get_Name(), pPolygons, pPolygons->Get_Vertex_Type()); for(int iPolygon=0; iPolygon<pPolygons->Get_Count(); iPolygon++) { CSG_Shape *pPolygon = pPolygons ->Get_Shape(iPolygon); CSG_Shape *pLine = pLines ->Add_Shape(pPolygon, SHAPE_COPY_ATTR); for(int iPart=0; iPart<pPolygon->Get_Part_Count(); iPart++) { for(int iPoint=0; iPoint<pPolygon->Get_Point_Count(iPart); iPoint++) { pLine->Add_Point(pPolygon->Get_Point(iPoint, iPart), iPart); if( pPolygons->Get_Vertex_Type() != SG_VERTEX_TYPE_XY ) { pLine->Set_Z(pPolygon->Get_Z(iPoint, iPart), iPoint, iPart); if( pPolygons->Get_Vertex_Type() == SG_VERTEX_TYPE_XYZM ) { pLine->Set_M(pPolygon->Get_M(iPoint, iPart), iPoint, iPart); } } } if( !CSG_Point(pPolygon->Get_Point(0, iPart)).is_Equal(pPolygon->Get_Point(pPolygon->Get_Point_Count(iPart) - 1, iPart)) ) { pLine->Add_Point(pPolygon->Get_Point(0, iPart), iPart); if( pPolygons->Get_Vertex_Type() != SG_VERTEX_TYPE_XY ) { pLine->Set_Z(pPolygon->Get_Z(0, iPart), pLine->Get_Point_Count(iPart) - 1, iPart); if( pPolygons->Get_Vertex_Type() == SG_VERTEX_TYPE_XYZM ) { pLine->Set_M(pPolygon->Get_M(0, iPart), pLine->Get_Point_Count(iPart) - 1, iPart); } } } } } return( true ); }
//--------------------------------------------------------- bool CKriging_Universal::On_Initialize(void) { m_pGrids = Parameters("GRIDS" )->asGridList(); m_Interpolation = Parameters("INTERPOL" )->asInt(); m_nPoints_Min = Parameters("SEARCH_POINTS_MIN")->asInt (); m_nPoints_Max = Parameters("SEARCH_POINTS_ALL")->asInt () == 0 ? Parameters("SEARCH_POINTS_MAX")->asInt () : 0; m_Radius = Parameters("SEARCH_RANGE" )->asInt () == 0 ? Parameters("SEARCH_RADIUS" )->asDouble() : 0.0; m_Direction = Parameters("SEARCH_DIRECTION" )->asInt () == 0 ? -1 : 4; //----------------------------------------------------- if( m_nPoints_Max <= 0 && m_Radius <= 0 ) // global { return( CKriging_Universal_Global::On_Initialize() ); } //----------------------------------------------------- m_Search.Create(m_pPoints->Get_Extent()); for(int iPoint=0; iPoint<m_pPoints->Get_Count() && Set_Progress(iPoint, m_pPoints->Get_Count()); iPoint++) { CSG_Shape *pPoint = m_pPoints->Get_Shape(iPoint); if( !pPoint->is_NoData(m_zField) ) { bool bAdd = true; for(int iGrid=0; iGrid<m_pGrids->Get_Count(); iGrid++) { if( !m_pGrids->asGrid(iGrid)->is_InGrid_byPos(pPoint->Get_Point(0)) ) { bAdd = false; } } if( bAdd ) { m_Search.Add_Point(pPoint->Get_Point(0).x, pPoint->Get_Point(0).y, m_bLog ? log(pPoint->asDouble(m_zField)) : pPoint->asDouble(m_zField)); } } } if( !m_Search.is_Okay() ) { SG_UI_Msg_Add(_TL("could not initialize point search engine"), true); return( false ); } //----------------------------------------------------- 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 ); }
//--------------------------------------------------------- int CGW_Multi_Regression_Grid::Get_Variables(int x, int y, CSG_Vector &z, CSG_Vector &w, CSG_Matrix &Y) { TSG_Point Point = m_dimModel.Get_Grid_to_World(x, y); int nPoints = m_Search.is_Okay() ? (int)m_Search.Select_Nearest_Points(Point.x, Point.y, m_nPoints_Max, m_Radius, m_Direction) : m_Points.Get_Count(); z.Create(nPoints); w.Create(nPoints); Y.Create(1 + m_nPredictors, nPoints); for(int iPoint=0; iPoint<nPoints; iPoint++) { double ix, iy, iz; CSG_Shape *pPoint = m_Search.is_Okay() && m_Search.Get_Selected_Point(iPoint, ix, iy, iz) ? m_Points.Get_Shape((int)iz) : m_Points.Get_Shape(iPoint); z[iPoint] = pPoint->asDouble(0); w[iPoint] = m_Weighting.Get_Weight(SG_Get_Distance(Point, pPoint->Get_Point(0))); Y[iPoint][0] = 1.0; for(int iPredictor=1; iPredictor<=m_nPredictors; iPredictor++) { Y[iPoint][iPredictor] = pPoint->asDouble(iPredictor); } } return( nPoints ); }
//--------------------------------------------------------- bool CGW_Regression::Get_Model(int x, int y, CSG_Regression_Weighted &Model) { //----------------------------------------------------- TSG_Point Point = m_pIntercept->Get_System().Get_Grid_to_World(x, y); int nPoints = m_Search.Set_Location(Point); Model.Destroy(); for(int iPoint=0; iPoint<nPoints; iPoint++) { double ix, iy, iz; CSG_Shape *pPoint = m_Search.Do_Use_All() && m_Search.Get_Point(iPoint, ix, iy, iz) ? m_pPoints->Get_Shape((int)iz) : m_pPoints->Get_Shape(iPoint); if( !pPoint->is_NoData(m_iDependent) && !pPoint->is_NoData(m_iPredictor) ) { Model.Add_Sample( m_Weighting.Get_Weight(SG_Get_Distance(Point, pPoint->Get_Point(0))), pPoint->asDouble(m_iDependent), CSG_Vector(1, &(iz = pPoint->asDouble(m_iPredictor))) ); } } //----------------------------------------------------- return( Model.Calculate() ); }
//--------------------------------------------------------- bool C_Kriging_Base::_Get_Points(void) { int iShape, iPart, iPoint; CSG_Shape *pShape , *pPoint; CSG_Shapes *pPoints; m_pShapes = Parameters("SHAPES") ->asShapes(); m_zField = Parameters("FIELD") ->asInt(); if( m_pShapes->Get_Type() != SHAPE_TYPE_Point ) { pPoints = SG_Create_Shapes(SHAPE_TYPE_Point, SG_T(""), m_pShapes); for(iShape=0; iShape<m_pShapes->Get_Count() && Set_Progress(iShape, m_pShapes->Get_Count()); iShape++) { pShape = m_pShapes->Get_Shape(iShape); if( !pShape->is_NoData(m_zField) ) { for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++) { for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++) { pPoint = pPoints->Add_Shape(pShape, SHAPE_COPY_ATTR); pPoint->Add_Point(pShape->Get_Point(iPoint, iPart)); } } } } m_pShapes = pPoints; } return( m_pShapes->Get_Count() > 1 ); }
//--------------------------------------------------------- bool CSG_Parameters_Search_Points::Get_Point(int Index, double &x, double &y, double &z) { if( m_pPoints ) // without search engine { CSG_Shape *pPoint = m_pPoints->Get_Shape(Index); if( !pPoint || pPoint->is_NoData(m_zField) ) { return( false ); } x = pPoint->Get_Point(0).x; y = pPoint->Get_Point(0).y; z = m_zField < 0 ? Index : pPoint->asDouble(m_zField); } else // using search engine { if( !m_Search.Get_Selected_Point(Index, x, y, z) ) { return( false ); } } return( true ); }
//--------------------------------------------------------- bool CSG_PRQuadTree::Create(CSG_Shapes *pShapes, int Attribute, bool bStatistics) { Destroy(); if( pShapes && pShapes->is_Valid() && Create(pShapes->Get_Extent(), bStatistics) ) { for(int iShape=0; iShape<pShapes->Get_Count() && SG_UI_Process_Set_Progress(iShape, pShapes->Get_Count()); iShape++) { CSG_Shape *pShape = pShapes->Get_Shape(iShape); if( Attribute < 0 || !pShape->is_NoData(Attribute) ) { double z = Attribute < 0 ? iShape : pShape->asDouble(Attribute); for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++) { for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++) { Add_Point(pShape->Get_Point(iPoint, iPart), z); } } } } return( Get_Point_Count() > 0 ); } 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 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 CPolygon_Split_Parts::On_Execute(void) { bool bIgnoreLakes; CSG_Shapes *pPolygons, *pParts; pPolygons = Parameters("POLYGONS") ->asShapes(); pParts = Parameters("PARTS") ->asShapes(); bIgnoreLakes = Parameters("LAKES") ->asBool(); pParts->Create(SHAPE_TYPE_Polygon, CSG_String::Format(SG_T("%s [%s]"), pPolygons->Get_Name(), _TL("Parts")), pPolygons); //----------------------------------------------------- for(int iShape=0; iShape<pPolygons->Get_Count() && Set_Progress(iShape, pPolygons->Get_Count()); iShape++) { CSG_Shape *pPolygon = pPolygons->Get_Shape(iShape); for(int iPart=0; iPart<pPolygon->Get_Part_Count() && Process_Get_Okay(); iPart++) { if( bIgnoreLakes || !((CSG_Shape_Polygon *)pPolygon)->is_Lake(iPart) ) { CSG_Shape *pPart = pParts->Add_Shape(pPolygon, SHAPE_COPY_ATTR); for(int iPoint=0; iPoint<pPolygon->Get_Point_Count(iPart); iPoint++) { pPart->Add_Point(pPolygon->Get_Point(iPoint, iPart)); } if( !bIgnoreLakes ) { for(int jPart=0; jPart<pPolygon->Get_Part_Count(); jPart++) { if( ((CSG_Shape_Polygon *)pPolygon)->is_Lake(jPart) && ((CSG_Shape_Polygon *)pPart)->Contains(pPolygon->Get_Point(0, jPart)) ) { for(int jPoint=0, nPart=pPart->Get_Part_Count(); jPoint<pPolygon->Get_Point_Count(jPart); jPoint++) { pPart->Add_Point(pPolygon->Get_Point(jPoint, jPart), nPart); } } } } } } } return( true ); }
//--------------------------------------------------------- bool CPoint_Zonal_Multi_Grid_Regression::Set_Residuals(CSG_Shapes *pPoints, CSG_Grid *pRegression) { CSG_Shapes *pResiduals = Parameters("RESIDUALS")->asShapes(); int iAttribute = Parameters("ATTRIBUTE")->asInt (); if( !pRegression || !pResiduals ) { return( false ); } //----------------------------------------------------- pResiduals->Create(SHAPE_TYPE_Point, CSG_String::Format(SG_T("%s [%s]"), Parameters("ATTRIBUTE")->asString(), _TL("Residuals"))); pResiduals->Add_Field(pPoints->Get_Field_Name(iAttribute), SG_DATATYPE_Double); pResiduals->Add_Field("TREND" , SG_DATATYPE_Double); pResiduals->Add_Field("RESIDUAL", SG_DATATYPE_Double); TSG_Grid_Resampling Resampling; switch( Parameters("RESAMPLING")->asInt() ) { default: Resampling = GRID_RESAMPLING_NearestNeighbour; break; case 1: Resampling = GRID_RESAMPLING_Bilinear; break; case 2: Resampling = GRID_RESAMPLING_BicubicSpline; break; case 3: Resampling = GRID_RESAMPLING_BSpline; break; } //----------------------------------------------------- for(int iShape=0; iShape<pPoints->Get_Count() && Set_Progress(iShape, pPoints->Get_Count()); iShape++) { CSG_Shape *pShape = pPoints->Get_Shape(iShape); if( !pShape->is_NoData(iAttribute) ) { double zShape = pShape->asDouble(iAttribute); for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++) { for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++) { double zGrid; TSG_Point Point = pShape->Get_Point(iPoint, iPart); if( pRegression->Get_Value(Point, zGrid, Resampling) ) { CSG_Shape *pResidual = pResiduals->Add_Shape(); pResidual->Add_Point(Point); pResidual->Set_Value(0, zShape); pResidual->Set_Value(1, zGrid); pResidual->Set_Value(2, zShape - zGrid); } } } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool 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 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 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 CWKSP_Shapes::Edit_On_Mouse_Move(wxWindow *pMap, CSG_Rect rWorld, wxPoint pt, wxPoint ptLast, int Key) { switch( m_Edit_Mode ) { case EDIT_SHAPE_MODE_Split: case EDIT_SHAPE_MODE_Move: { CSG_Shape *pShape = m_Edit_Shapes.Get_Shape(1); if( pShape && pShape->Get_Point_Count() > 0 && (pt.x != ptLast.x || pt.y != ptLast.y) ) { wxClientDC dc(pMap); dc.SetLogicalFunction(wxINVERT); Edit_Shape_Draw_Move(dc, rWorld, ptLast, pShape->Get_Point(0, 0, false)); Edit_Shape_Draw_Move(dc, rWorld, pt , pShape->Get_Point(0, 0, false)); } return( true ); } //----------------------------------------------------- case EDIT_SHAPE_MODE_Normal: default: if( m_Edit_pShape ) { //--------------------------------------------- if( m_Edit_iPart >= 0 && (m_Edit_iPoint < 0 || Key & MODULE_INTERACTIVE_KEY_LEFT) && (pt.x != ptLast.x || pt.y != ptLast.y) ) { wxClientDC dc(pMap); dc.SetLogicalFunction(wxINVERT); Edit_Shape_Draw_Move(dc, rWorld, ptLast); Edit_Shape_Draw_Move(dc, rWorld, pt); return( true ); } //--------------------------------------------- else { int iPart, iPoint; double ClientToWorld = rWorld.Get_XRange() / (double)pMap->GetClientSize().x; CSG_Point Point(rWorld.Get_XMin() + pt.x * ClientToWorld, rWorld.Get_YMax() - pt.y * ClientToWorld); switch( Edit_Shape_HitTest(Point, EDIT_TICKMARK_SIZE * ClientToWorld, iPart, iPoint) ) { default: pMap->SetCursor(IMG_Get_Cursor(ID_IMG_CRS_SELECT )); break; case 1: pMap->SetCursor(IMG_Get_Cursor(ID_IMG_CRS_EDIT_POINT_MOVE)); break; case 2: pMap->SetCursor(IMG_Get_Cursor(ID_IMG_CRS_EDIT_POINT_ADD )); break; } return( true ); } } } return( false ); }
//--------------------------------------------------------- bool Trace_Polygon(CSG_Shape *pPolygon, CSG_Network &Network, int iEdge) { bool bAscending = true; CSG_Shape *pEdge = Network.Get_Edges().Get_Shape(iEdge); if( pEdge->asInt(3) == SHAPE_TYPE_Polygon ) { if( pEdge->asInt(4) ) { return( false ); } bAscending = true; } else if( (pEdge->asInt(4) & 0x1) == 0 ) { bAscending = true; } else if( (pEdge->asInt(4) & 0x2) == 0 ) { bAscending = false; } else { return( false ); } while( pEdge != NULL ) { pEdge->Set_Value(4, pEdge->asInt(4) | (bAscending ? 0x1 : 0x2)); for(int iPoint=0; iPoint<pEdge->Get_Point_Count(0); iPoint++) { pPolygon->Add_Point(pEdge->Get_Point(iPoint, 0, bAscending)); } int End_Node = pEdge->asInt(bAscending ? 2 : 1); iEdge = Network.Get_Node(End_Node).Get_Edge_Next(iEdge, false); pEdge = Network.Get_Edges().Get_Shape(iEdge); if( pEdge ) { bAscending = pEdge->asInt(3) == SHAPE_TYPE_Polygon || End_Node == pEdge->asInt(1); if( (pEdge->asInt(4) & (bAscending ? 0x1 : 0x2)) ) { pEdge = NULL; } } } return( pPolygon->is_Valid() ); }
//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- bool CGrid_Profile::Set_Profile(void) { int i; TSG_Point A, B; CSG_Shape *pLine; //----------------------------------------------------- m_pPoints->Create(SHAPE_TYPE_Point, CSG_String::Format(_TL("Profile [%s]"), m_pDEM->Get_Name())); m_pPoints->Add_Field("ID" , SG_DATATYPE_Int); m_pPoints->Add_Field(_TL("Distance") , SG_DATATYPE_Double); m_pPoints->Add_Field(_TL("Distance Overland") , SG_DATATYPE_Double); m_pPoints->Add_Field("X" , SG_DATATYPE_Double); m_pPoints->Add_Field("Y" , SG_DATATYPE_Double); m_pPoints->Add_Field("Z" , SG_DATATYPE_Double); for(i=0; i<m_pValues->Get_Count(); i++) { m_pPoints->Add_Field(m_pValues->asGrid(i)->Get_Name(), SG_DATATYPE_Double); } //----------------------------------------------------- if( (pLine = m_pLine->Get_Shape(0)) != NULL && pLine->Get_Point_Count(0) > 1 ) { B = pLine->Get_Point(0); for(i=1; i<pLine->Get_Point_Count(0); i++) { A = B; B = pLine->Get_Point(i); Set_Profile(A, B); } } //----------------------------------------------------- DataObject_Update(m_pLine); DataObject_Update(m_pPoints); return( m_pPoints->Get_Count() > 0 ); }
//--------------------------------------------------------- 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 C_Kriging_Ordinary_Global::Get_Weights(void) { int i, j, n; //----------------------------------------------------- for(int iShape=0; iShape<m_pShapes->Get_Count(); iShape++) { CSG_Shape *pShape = m_pShapes->Get_Shape(iShape); if( !pShape->is_NoData(m_zField) ) { for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++) { for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++) { m_Points.Add( pShape->Get_Point(iPoint, iPart).x, pShape->Get_Point(iPoint, iPart).y, pShape->asDouble(m_zField) ); } } } } //----------------------------------------------------- if( (n = m_Points.Get_Count()) > 4 ) { m_G .Create(n + 1); m_W .Create(n + 1, n + 1); for(i=0; i<n; i++) { m_W[i][i] = 0.0; // diagonal... m_W[i][n] = m_W[n][i] = 1.0; // edge... for(j=i+1; j<n; j++) { m_W[i][j] = m_W[j][i] = Get_Weight( m_Points[i].x - m_Points[j].x, m_Points[i].y - m_Points[j].y ); } } m_W[n][n] = 0.0; return( m_W.Set_Inverse(false) ); } return( false ); }
//--------------------------------------------------------- int CGW_Regression_Grid::Set_Variables(int x, int y) { int iPoint, jPoint, nPoints; double z; TSG_Point Point; CSG_Shape *pPoint; Point = Get_System()->Get_Grid_to_World(x, y); nPoints = m_Search.is_Okay() ? (int)m_Search.Select_Nearest_Points(Point.x, Point.y, m_nPoints_Max, m_Radius, m_Direction) : m_pPoints->Get_Count(); for(iPoint=0, jPoint=0; iPoint<nPoints; iPoint++) { if( m_Search.is_Okay() ) { double ix, iy, iz; m_Search.Get_Selected_Point(iPoint, ix, iy, iz); pPoint = m_pPoints->Get_Shape((int)iz); } else { pPoint = m_pPoints->Get_Shape(iPoint); } if( !pPoint->is_NoData(m_iDependent) && m_pPredictor->Get_Value(pPoint->Get_Point(0), z) ) { m_w[jPoint] = m_Weighting.Get_Weight(SG_Get_Distance(Point, pPoint->Get_Point(0))); m_z[jPoint] = pPoint->asDouble(m_iDependent); m_y[jPoint] = z; jPoint++; } } return( jPoint ); }
//--------------------------------------------------------- bool CGrid_Flow_Profile::Add_Point(int x, int y) { if( !m_pDEM->is_InGrid(x, y) ) { return( false ); } TSG_Point Point = Get_System()->Get_Grid_to_World(x, y); double d, dSurface; if( m_pPoints->Get_Count() == 0 ) { d = dSurface = 0.0; } else { CSG_Shape *pLast = m_pPoints->Get_Shape(m_pPoints->Get_Count() - 1); d = SG_Get_Distance(Point, pLast->Get_Point(0)); dSurface = pLast->asDouble(5) - m_pDEM->asDouble(x, y); dSurface = sqrt(d*d + dSurface*dSurface); d += pLast->asDouble(1); dSurface += pLast->asDouble(2); } CSG_Shape *pPoint = m_pPoints->Add_Shape(); pPoint->Add_Point(Point); pPoint->Set_Value(0, m_pPoints->Get_Count()); pPoint->Set_Value(1, d); pPoint->Set_Value(2, dSurface); pPoint->Set_Value(3, Point.x); pPoint->Set_Value(4, Point.y); pPoint->Set_Value(5, m_pDEM->asDouble(x, y)); for(int i=0; i<m_pValues->Get_Count(); i++) { pPoint->Set_Value(VALUE_OFFSET + i, m_pValues->asGrid(i)->asDouble(x, y)); } m_pLine->Add_Point(Point); return( true ); }
//--------------------------------------------------------- int CGW_Multi_Regression::Set_Variables(int x, int y) { int iPoint, jPoint, nPoints, iPredictor; TSG_Point Point; CSG_Shape *pPoint; Point = m_pIntercept->Get_System().Get_Grid_to_World(x, y); nPoints = m_Search.is_Okay() ? m_Search.Select_Nearest_Points(Point.x, Point.y, m_nPoints_Max, m_Radius, m_Mode == 0 ? -1 : 4) : m_pPoints->Get_Count(); for(iPoint=0, jPoint=0; iPoint<nPoints; iPoint++) { if( m_Search.is_Okay() ) { double ix, iy, iz; m_Search.Get_Selected_Point(iPoint, ix, iy, iz); pPoint = m_pPoints->Get_Shape((int)iz); } else { pPoint = m_pPoints->Get_Shape(iPoint); } m_z[iPoint] = pPoint->asDouble(m_iDependent); m_w[iPoint] = m_Weighting.Get_Weight(SG_Get_Distance(Point, pPoint->Get_Point(0))); for(iPredictor=0; iPredictor<m_nPredictors; iPredictor++) { if( !pPoint->is_NoData(m_iPredictor[iPredictor]) ) { m_y[jPoint][iPredictor] = pPoint->asDouble(m_iPredictor[iPredictor]); } else { iPredictor = m_nPredictors + 1; } } if( iPredictor == m_nPredictors ) { jPoint++; } } return( jPoint ); }
//--------------------------------------------------------- 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 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 ); }
//--------------------------------------------------------- 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 CCollect_Points::On_Execute(void) { m_Engine.Destroy(); m_pPoints = Parameters("REF_SOURCE")->asShapes(); Get_Parameters("REFERENCE")->Restore_Defaults(); if( !is_Compatible(m_pPoints) || Parameters("REFRESH")->asBool() ) { m_pPoints->Create(SHAPE_TYPE_Point, _TL("Reference Points (Origin)")); m_pPoints->Add_Field("X_SRC", SG_DATATYPE_Double); m_pPoints->Add_Field("Y_SRC", SG_DATATYPE_Double); m_pPoints->Add_Field("X_MAP", SG_DATATYPE_Double); m_pPoints->Add_Field("Y_MAP", SG_DATATYPE_Double); m_pPoints->Add_Field("RESID", SG_DATATYPE_Double); } else { for(int i=0; i<m_pPoints->Get_Count(); i++) { CSG_Shape *pPoint = m_pPoints->Get_Shape(i); m_Engine.Add_Reference(pPoint->Get_Point(0), CSG_Point( pPoint->asDouble(2), pPoint->asDouble(3) )); } int Method = Parameters("METHOD")->asInt(); int Order = Parameters("ORDER" )->asInt(); m_Engine.Evaluate(Method, Order); } return( true ); }
//--------------------------------------------------------- CSG_Shapes * CInterpolation::Get_Points(bool bOnlyNonPoints) { m_pShapes = Parameters("SHAPES") ->asShapes(); if( !bOnlyNonPoints || m_pShapes->Get_Type() != SHAPE_TYPE_Point ) { CSG_Shapes *pPoints = SG_Create_Shapes(SHAPE_TYPE_Point); pPoints->Set_NoData_Value_Range(m_pShapes->Get_NoData_Value(), m_pShapes->Get_NoData_hiValue()); pPoints->Add_Field(SG_T("Z"), SG_DATATYPE_Double); for(int iShape=0; iShape<m_pShapes->Get_Count() && Set_Progress(iShape, m_pShapes->Get_Count()); iShape++) { CSG_Shape *pShape = m_pShapes->Get_Shape(iShape); if( !pShape->is_NoData(m_zField) ) { for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++) { for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++) { CSG_Shape *pPoint = pPoints->Add_Shape(); pPoint->Add_Point(pShape->Get_Point(iPoint, iPart)); pPoint->Set_Value(0, pShape->asDouble(m_zField)); } } } } m_zField = 0; m_pShapes = pPoints; } return( m_pShapes ); }