//--------------------------------------------------------- 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 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 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 ); }
//--------------------------------------------------------- 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 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 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 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 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 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 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 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 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 ); }
//--------------------------------------------------------- void CD8_Flow_Analysis::Get_Segment(int x, int y) { int i = m_pDir->asInt(x, y); if( i >= 0 ) { CSG_Shape *pSegment = m_pSegments->Add_Shape(); pSegment->Set_Value(0, m_pSegments->Get_Count()); // SEGMENT_ID pSegment->Set_Value(1, m_Nodes.asInt(x, y)); // NODE_A pSegment->Set_Value(3, m_pBasins->asInt(x, y)); // BASIN pSegment->Set_Value(4, m_pOrder->asInt(x, y) + 1 - m_Threshold); // ORDER pSegment->Set_Value(5, m_pOrder->asInt(x, y)); // ORDER_CELL pSegment->Add_Point(Get_System()->Get_Grid_to_World(x, y)); pSegment->Set_Z(m_pDEM->asDouble(x, y), pSegment->Get_Point_Count() - 1); do { x += Get_xTo(i); y += Get_yTo(i); pSegment->Add_Point(Get_System()->Get_Grid_to_World(x, y)); pSegment->Set_Z(m_pDEM->asDouble(x, y), pSegment->Get_Point_Count() - 1); if( m_Nodes.asInt(x, y) ) { pSegment->Set_Value(2, m_Nodes.asInt(x, y)); // NODE_B pSegment->Set_Value(6, ((CSG_Shape_Line *)pSegment)->Get_Length()); // LENGTH return; } } while( (i = m_pDir->asInt(x, y)) >= 0 ); } }
//--------------------------------------------------------- bool CSelection_Copy::On_Execute(void) { CSG_Shapes *pInput, *pOutput; pInput = Parameters("INPUT") ->asShapes(); pOutput = Parameters("OUTPUT")->asShapes(); if( pInput->Get_Selection_Count() <= 0 ) { Error_Set(_TL("no shapes in selection")); return( false ); } if( pOutput->Get_Type() != SHAPE_TYPE_Undefined && pOutput->Get_Type() != pInput->Get_Type() && pOutput->Get_Vertex_Type() != pInput->Get_Vertex_Type() ) { Parameters("OUTPUT")->Set_Value(pOutput = SG_Create_Shapes()); } pOutput->Create(pInput->Get_Type(), CSG_String::Format(SG_T("%s [%s]"), pInput->Get_Name(), _TL("Selection")), pInput, pInput->Get_Vertex_Type()); for(int i=0; i<pInput->Get_Selection_Count() && Set_Progress(i, pInput->Get_Selection_Count()); i++) { CSG_Shape *pShape = pInput->Get_Selection(i); pOutput->Add_Shape(pShape); if( pInput->Get_Vertex_Type() > SG_VERTEX_TYPE_XY ) { for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++) { for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++) { pOutput->Get_Shape(i)->Set_Z(pShape->Get_Z(iPoint, iPart), iPoint, iPart); if( pInput->Get_Vertex_Type() == SG_VERTEX_TYPE_XYZM ) { pOutput->Get_Shape(i)->Set_M(pShape->Get_M(iPoint, iPart), iPoint, iPart); } } } } } 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 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 CSG_Network::Add_Shape(CSG_Shape *pShape) { if( !pShape || !pShape->is_Valid() ) { return( false ); } //----------------------------------------------------- CSG_Shapes Part(SHAPE_TYPE_Line); CSG_Shape *pPart = Part.Add_Shape(); for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++) { if( pShape->Get_Point_Count(iPart) > 1 ) { bool bAscending = pShape->Get_Type() != SHAPE_TYPE_Polygon || ((CSG_Shape_Polygon *)pShape)->is_Lake(iPart) != ((CSG_Shape_Polygon *)pShape)->is_Clockwise(iPart); CSG_Point q, p = pShape->Get_Point(0, iPart, bAscending); pPart->Add_Point(p); for(int iPoint=1; iPoint<pShape->Get_Point_Count(iPart); iPoint++) { if( !p.is_Equal(q = pShape->Get_Point(iPoint, iPart, bAscending)) ) { p = q; pPart->Add_Point(p); } } if( pPart->Get_Point_Count(0) > 1 ) { _Add_Line(pPart, pShape->Get_Type()); } pPart->Del_Parts(); } } 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); } }
//--------------------------------------------------------- CSG_Shapes * CInterpolation::Get_Points(bool bOnlyNonPoints) { m_pShapes = Parameters("SHAPES") ->asShapes(); if( !bOnlyNonPoints || m_pShapes->Get_Type() != SHAPE_TYPE_Point ) { CSG_Shapes *pPoints = SG_Create_Shapes(SHAPE_TYPE_Point); pPoints->Set_NoData_Value_Range(m_pShapes->Get_NoData_Value(), m_pShapes->Get_NoData_hiValue()); pPoints->Add_Field(SG_T("Z"), SG_DATATYPE_Double); for(int iShape=0; iShape<m_pShapes->Get_Count() && Set_Progress(iShape, m_pShapes->Get_Count()); iShape++) { CSG_Shape *pShape = m_pShapes->Get_Shape(iShape); if( !pShape->is_NoData(m_zField) ) { for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++) { for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++) { CSG_Shape *pPoint = pPoints->Add_Shape(); pPoint->Add_Point(pShape->Get_Point(iPoint, iPart)); pPoint->Set_Value(0, pShape->asDouble(m_zField)); } } } } m_zField = 0; m_pShapes = pPoints; } return( m_pShapes ); }
//--------------------------------------------------------- bool CWKSP_Shapes::_Edit_Merge(void) { if( Get_Shapes()->Get_Selection_Count() < 2 || Get_Shapes()->Get_Type() == SHAPE_TYPE_Point ) { return( false ); } //----------------------------------------------------- CSG_Shape *pMerged = Get_Shapes()->Get_Selection(0); for(int i=1; i<Get_Shapes()->Get_Selection_Count(); i++) { CSG_Shape *pShape = Get_Shapes()->Get_Selection(i); for(int iPart=0, jPart=pMerged->Get_Part_Count(); iPart<pShape->Get_Part_Count(); iPart++, jPart++) { for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++) { pMerged->Add_Point(pShape->Get_Point(iPoint, iPart), jPart); } } } if( Get_Shapes()->Get_Type() == SHAPE_TYPE_Polygon ) { SG_Polygon_Dissolve(pMerged); } Get_Shapes()->Select(pMerged, true); Get_Shapes()->Del_Selection(); Get_Shapes()->Select(pMerged, false); Update_Views(true); 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 CWKSP_Shapes::_Edit_Split(void) { if( Get_Shapes()->Get_Type() == SHAPE_TYPE_Polygon || Get_Shapes()->Get_Type() == SHAPE_TYPE_Line ) { switch( m_Edit_Mode ) { default: break; //------------------------------------------------- case EDIT_SHAPE_MODE_Normal: m_Edit_Mode = EDIT_SHAPE_MODE_Split; if( m_Edit_Shapes.Get_Count() == 0 ) { m_Edit_Shapes.Add_Shape(Get_Shapes()->Get_Selection()); } if( m_Edit_Shapes.Get_Count() > 1 ) { m_Edit_Shapes.Get_Shape(1)->Del_Parts(); } else { m_Edit_Shapes.Add_Shape(); } return( true ); //------------------------------------------------- case EDIT_SHAPE_MODE_Split: m_Edit_Mode = EDIT_SHAPE_MODE_Normal; CSG_Module *pModule = Get_Shapes()->Get_Type() == SHAPE_TYPE_Polygon ? SG_Get_Module_Library_Manager().Get_Module(SG_T("shapes_polygons"), 8) // Polygon-Line Intersection : SG_Get_Module_Library_Manager().Get_Module(SG_T("shapes_lines" ), 6); // Split Lines with Lines if( pModule ) { CSG_Shapes Line(SHAPE_TYPE_Line), Split(Get_Shapes()->Get_Type()); Line.Add_Shape(); for(int i=0; i<m_Edit_Shapes.Get_Shape(1)->Get_Point_Count(); i++) { Line.Get_Shape(0)->Add_Point(m_Edit_Shapes.Get_Shape(1)->Get_Point(i)); } m_Edit_Shapes.Del_Shape(1); //----------------------------------------- bool bResult; CSG_Parameters P; P.Assign(pModule->Get_Parameters()); pModule->Set_Manager(NULL); if( Get_Shapes()->Get_Type() == SHAPE_TYPE_Polygon ) { bResult = pModule->Get_Parameters()->Set_Parameter("POLYGONS" , &m_Edit_Shapes) && pModule->Get_Parameters()->Set_Parameter("LINES" , &Line) && pModule->Get_Parameters()->Set_Parameter("INTERSECT", &Split) && pModule->Execute(); } else // if( Get_Shapes()->Get_Type() == SHAPE_TYPE_Line ) { bResult = pModule->Get_Parameters()->Set_Parameter("LINES" , &m_Edit_Shapes) && pModule->Get_Parameters()->Set_Parameter("SPLIT" , &Line) && pModule->Get_Parameters()->Set_Parameter("INTERSECT", &Split) && pModule->Execute(); } //----------------------------------------- if( bResult ) { if( m_Edit_pShape ) { m_Edit_pShape->Assign(Split.Get_Shape(0), false); for(int iSplit=1; iSplit<Split.Get_Count(); iSplit++) { CSG_Shape *pSplit = Split.Get_Shape(iSplit); for(int iPart=0; iPart<pSplit->Get_Part_Count(); iPart++) { for(int iPoint=0, jPart=m_Edit_pShape->Get_Part_Count(); iPoint<pSplit->Get_Point_Count(iPart); iPoint++) { m_Edit_pShape->Add_Point(pSplit->Get_Point(iPoint, iPart), jPart); } } } } else if( Get_Shapes()->Get_Selection_Count() == 1 ) // if( !m_Edit_pShape ) { CSG_Shape *pSelection = Get_Shapes()->Get_Selection(); pSelection->Assign(Split.Get_Shape(0), false); for(int iSplit=1; iSplit<Split.Get_Count(); iSplit++) { CSG_Shape *pSplit = Get_Shapes()->Add_Shape(Split.Get_Shape(iSplit)); ((CSG_Table_Record *)pSplit)->Assign(pSelection); Get_Shapes()->Select(pSplit, true); } m_Edit_Shapes.Del_Shapes(); } } pModule->Get_Parameters()->Assign_Values(&P); pModule->Set_Manager(P.Get_Manager()); } Update_Views(false); return( true ); } } return( false ); }
//--------------------------------------------------------- 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 Cut_Shapes(CSG_Shapes *pPolygons, int Method, CSG_Shapes *pShapes, CSG_Shapes *pCut) { if( pCut && pShapes && pShapes->is_Valid() && pPolygons && pPolygons->is_Valid() && pPolygons->Get_Extent().Intersects(pShapes->Get_Extent()) ) { pCut->Create( pShapes->Get_Type(), CSG_String::Format(SG_T("%s [%s]"), pShapes->Get_Name(), _TL("Cut")), pShapes ); for(int iShape=0; iShape<pShapes->Get_Count() && SG_UI_Process_Set_Progress(iShape, pShapes->Get_Count()); iShape++) { bool bAdd; CSG_Shape *pShape = pShapes->Get_Shape(iShape); if( Method == 2 ) // center { bAdd = false; TSG_Point Center; if( pShapes->Get_Type() == SHAPE_TYPE_Polygon ) Center = ((CSG_Shape_Polygon *)pShape)->Get_Centroid(); else Center = pShape->Get_Extent().Get_Center(); if( pPolygons->Select(Center) ) { bAdd = true; } } else if( Method == 1 ) // intersects { bAdd = false; for(int iPart=0; iPart<pShape->Get_Part_Count() && !bAdd; iPart++) { for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart) && !bAdd; iPoint++) { if( pPolygons->Select(pShape->Get_Point(iPoint, iPart)) ) { bAdd = true; } } } } else // completely contained { bAdd = true; for(int iPart=0; iPart<pShape->Get_Part_Count() && bAdd; iPart++) { for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart) && bAdd; iPoint++) { if( pPolygons->Select(pShape->Get_Point(iPoint, iPart)) == false ) { bAdd = false; } } } } if( bAdd ) { pCut->Add_Shape(pShape); } } return( pCut->Get_Count() > 0 ); } return( false ); }
//--------------------------------------------------------- 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 ); }