//--------------------------------------------------------- bool CShapes_Create_Empty::On_Execute(void) { TSG_Vertex_Type Vertex; switch( Parameters("VERTEX")->asInt() ) { default: case 0: Vertex = SG_VERTEX_TYPE_XY; break; case 1: Vertex = SG_VERTEX_TYPE_XYZ; break; case 2: Vertex = SG_VERTEX_TYPE_XYZM; break; } //----------------------------------------------------- CSG_Shapes *pShapes; switch( Parameters("TYPE")->asInt() ) { default: return( false ); case 0: pShapes = SG_Create_Shapes(SHAPE_TYPE_Point , Parameters("NAME")->asString(), NULL, Vertex); break; case 1: pShapes = SG_Create_Shapes(SHAPE_TYPE_Points , Parameters("NAME")->asString(), NULL, Vertex); break; case 2: pShapes = SG_Create_Shapes(SHAPE_TYPE_Line , Parameters("NAME")->asString(), NULL, Vertex); break; case 3: pShapes = SG_Create_Shapes(SHAPE_TYPE_Polygon, Parameters("NAME")->asString(), NULL, Vertex); break; } //----------------------------------------------------- int i, n; TSG_Data_Type Type; CSG_Parameters *pAttributes; pAttributes = Parameters("FIELDS")->asParameters(); n = pAttributes->Get_Count() / 3; for(i=0; i<n; i++) { switch( pAttributes->Get_Parameter(GET_TYPE(i))->asInt() ) { default: case 0: Type = SG_DATATYPE_String; break; case 1: Type = SG_DATATYPE_Date; break; case 2: Type = SG_DATATYPE_Color; break; case 3: Type = SG_DATATYPE_Byte; break; case 4: Type = SG_DATATYPE_Char; break; case 5: Type = SG_DATATYPE_Word; break; case 6: Type = SG_DATATYPE_Short; break; case 7: Type = SG_DATATYPE_DWord; break; case 8: Type = SG_DATATYPE_Int; break; case 9: Type = SG_DATATYPE_ULong; break; case 10: Type = SG_DATATYPE_Long; break; case 11: Type = SG_DATATYPE_Float; break; case 12: Type = SG_DATATYPE_Double; break; case 13: Type = SG_DATATYPE_Binary; break; } pShapes->Add_Field(pAttributes->Get_Parameter(GET_NAME(i))->asString(), Type); } Parameters("SHAPES")->Set_Value(pShapes); return( true ); }
//--------------------------------------------------------- bool CCRS_Transform_Shapes::On_Execute_Transformation(void) { if( m_bList ) { CSG_Parameter_Shapes_List *pSources, *pTargets; pSources = Parameters("SOURCE")->asShapesList(); pTargets = Parameters("TARGET")->asShapesList(); pTargets->Del_Items(); for(int i=0; i<pSources->Get_Count() && Process_Get_Okay(false); i++) { CSG_Shapes *pSource = pSources->asShapes(i); CSG_Shapes *pTarget = SG_Create_Shapes(pSource); if( Transform(pSource, pTarget) ) { pTargets->Add_Item(pTarget); } else { delete(pTarget); } } return( pTargets->Get_Count() > 0 ); } else { CSG_Shapes *pSource = Parameters("SOURCE")->asShapes(); CSG_Shapes *pTarget = Parameters("TARGET")->asShapes(); if( pSource == pTarget ) { pTarget = SG_Create_Shapes(pSource); if( Transform(pSource, pTarget) ) { pSource->Assign(pTarget); return( true ); } else { delete(pTarget); return( false ); } } else { pTarget->Create(pSource->Get_Type(), pSource->Get_Name(), pSource, pSource->Get_Vertex_Type()); } return( Transform(pSource, pTarget) ); } }
bool 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 CPROJ4_Shapes::On_Execute_Conversion(void) { bool bResult = false; CSG_Shapes *pSource, *pTarget; //----------------------------------------------------- if( m_bInputList ) { CSG_Parameter_Shapes_List *pSources, *pTargets; pSources = Parameters("SOURCE")->asShapesList(); pTargets = Parameters("TARGET")->asShapesList(); pTargets->Del_Items(); for(int i=0; i<pSources->Get_Count() && Process_Get_Okay(false); i++) { pSource = pSources->asShapes(i); pTarget = SG_Create_Shapes(); if( _Get_Conversion(pSource, pTarget) ) { bResult = true; pTargets->Add_Item(pTarget); } else { delete( pTarget ); } } } else { bool bCopy; pSource = Parameters("SOURCE")->asShapes(); pTarget = Parameters("TARGET")->asShapes(); if( (bCopy = pSource == pTarget) == true ) { pTarget = SG_Create_Shapes(); } //------------------------------------------------- bResult = _Get_Conversion(pSource, pTarget); //------------------------------------------------- if( bCopy ) { pSource->Assign(pTarget); delete( pTarget ); } } return( bResult ); }
//--------------------------------------------------------- bool CShapes_Cut::On_Execute(void) { int Method; CSG_Shapes *pExtent, *pCut; CSG_Parameter_Shapes_List *pShapes, *pCuts; //----------------------------------------------------- pShapes = Parameters("SHAPES") ->asShapesList(); pCuts = Parameters("CUT") ->asShapesList(); pExtent = Parameters("EXTENT") ->asShapes(); Method = Parameters("METHOD") ->asInt(); //----------------------------------------------------- if( pShapes->Get_Count() > 0 ) { int iLayer; CSG_Rect r(pShapes->asShapes(0)->Get_Extent()); for(iLayer=1; iLayer<pShapes->Get_Count(); iLayer++) { r.Union(pShapes->asShapes(iLayer)->Get_Extent()); } if( Get_Extent(r) ) { pCuts->Del_Items(); Cut_Set_Extent(r, pExtent, true); for(iLayer=0; iLayer<pShapes->Get_Count(); iLayer++) { if( m_pPolygons ) { if( Cut_Shapes(m_pPolygons, Method, pShapes->asShapes(iLayer), pCut = SG_Create_Shapes()) ) pCuts->Add_Item(pCut); else delete(pCut); } else { if( Cut_Shapes(r, Method, pShapes->asShapes(iLayer), pCut = SG_Create_Shapes()) ) pCuts->Add_Item(pCut); else delete(pCut); } } return( pCuts->Get_Count() > 0 ); } } return( false ); }
//--------------------------------------------------------- bool CGPX_Import::Add_Track(CSG_MetaData *pTrack) { // <name> xsd:string // <cmt> xsd:string // <desc> xsd:string // <src> xsd:string // <link> linkType // <number> xsd:nonNegativeInteger // <type> xsd:string CSG_MetaData *pSegment = pTrack->Get_Child(SG_T("trkseg")); if( pSegment ) { CSG_String Name(GET_CONTENT(pTrack, "name", "Track Segment")); CSG_Shapes *pPoints = SG_Create_Shapes(SHAPE_TYPE_Point, CSG_String::Format(SG_T("%s [%s]"), m_Name.c_str(), Name.c_str())); m_pShapes->Add_Item(pPoints); for(int i=0; i<pSegment->Get_Children_Count(); i++) { CSG_MetaData *pChild = pSegment->Get_Child(i); if( pChild->Get_Name().CmpNoCase(SG_T("trkpt")) == 0 ) { Add_Point(pChild, pPoints); } } return( true ); } return( false ); }
//--------------------------------------------------------- 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 CKinWav_D8::Gauges_Initialise(void) { if( m_pGauges_Flow != NULL ) { if( m_pGauges == NULL ) { DataObject_Add(m_pGauges = SG_Create_Shapes(SHAPE_TYPE_Point, _TL("Gauges"))); Parameters("GAUGES")->Set_Value(m_pGauges); m_pGauges->Add_Field(_TL("ID"), SG_DATATYPE_Int); for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { bool bBorder = false; bool bLowest = true; for(int i=0; i<8; i++) { int ix = Get_xTo(i, x); int iy = Get_yTo(i, y); if( !m_pDEM->is_InGrid(ix, iy) ) { bBorder = true; } else if( m_pDEM->asDouble(ix, iy) < m_pDEM->asDouble(x, y) ) { bLowest = false; } } if( bLowest && bBorder ) { CSG_Shape *pGauge = m_pGauges->Add_Shape(); pGauge->Add_Point(Get_System()->Get_Grid_to_World(x, y)); pGauge->Set_Value(0, m_pGauges->Get_Count() + 1); } } } } m_pGauges_Flow->Destroy(); m_pGauges_Flow->Set_Name(_TL("Outlet Hydrographs")); m_pGauges_Flow->Add_Field("TIME", SG_DATATYPE_Double); for(int i=0; i<m_pGauges->Get_Count(); i++) { m_pGauges_Flow->Add_Field(CSG_String::Format(SG_T("GAUGE_%02d"), i + 1), SG_DATATYPE_Double); } return( true ); } return( false ); }
//--------------------------------------------------------- CSG_Shapes * COGR_DataSource::Read_Shapes(int iLayer) { OGRLayer *pLayer = Get_Layer(iLayer); //----------------------------------------------------- if( pLayer && Get_Type(iLayer) != SHAPE_TYPE_Undefined ) { int iField; OGRFeature *pFeature; OGRFeatureDefn *pDef = pLayer->GetLayerDefn(); CSG_Shapes *pShapes = SG_Create_Shapes(Get_Type(iLayer), CSG_String(pDef->GetName())); for(iField=0; iField<pDef->GetFieldCount(); iField++) { OGRFieldDefn *pDefField = pDef->GetFieldDefn(iField); pShapes->Add_Field(pDefField->GetNameRef(), COGR_Driver::Get_Type(pDefField->GetType())); } pLayer->ResetReading(); //------------------------------------------------- while( (pFeature = pLayer->GetNextFeature()) != NULL && SG_UI_Process_Get_Okay(false) ) { OGRGeometry *pGeometry = pFeature->GetGeometryRef(); if( pGeometry != NULL ) { CSG_Shape *pShape = pShapes->Add_Shape(); for(iField=0; iField<pDef->GetFieldCount(); iField++) { OGRFieldDefn *pDefField = pDef->GetFieldDefn(iField); switch( pDefField->GetType() ) { default: pShape->Set_Value(iField, SG_STR_MBTOSG(pFeature->GetFieldAsString (iField))); break; case OFTString: pShape->Set_Value(iField, SG_STR_MBTOSG(pFeature->GetFieldAsString (iField))); break; case OFTInteger: pShape->Set_Value(iField, pFeature->GetFieldAsInteger(iField)); break; case OFTReal: pShape->Set_Value(iField, pFeature->GetFieldAsDouble (iField)); break; } } //----------------------------------------- if( _Read_Geometry(pShape, pGeometry) == false ) { pShapes->Del_Shape(pShape); } } OGRFeature::DestroyFeature(pFeature); } return( pShapes ); } //----------------------------------------------------- return( NULL ); }
//--------------------------------------------------------- bool 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 ); }
CSG_Shapes * Cut_Shapes(CSG_Rect Extent, int Method, CSG_Shapes *pShapes) { CSG_Shapes *pCut = SG_Create_Shapes(); if( Cut_Shapes(Extent, Method, pShapes, pCut) ) { return( pCut ); } delete(pCut); return( NULL ); }
//--------------------------------------------------------- CSG_Shapes * Cut_Shapes(CSG_Shapes *pPolygons, int Method, CSG_Shapes *pShapes) { CSG_Shapes *pCut = SG_Create_Shapes(); if( Cut_Shapes(pPolygons, Method, pShapes, pCut) ) { return( pCut ); } delete(pCut); return( NULL ); }
//--------------------------------------------------------- bool CShapes_Split_by_Attribute::On_Execute(void) { int iField; CSG_Table *pTable; //----------------------------------------------------- pTable = Parameters("TABLE") ->asTable(); iField = Parameters("FIELD") ->asInt(); Parameters("CUTS")->asTableList()->Del_Items(); //----------------------------------------------------- if( pTable->is_Valid() && pTable->Set_Index(iField, TABLE_INDEX_Ascending) ) { CSG_String sValue; CSG_Table *pCut = NULL; for(int iRecord=0; iRecord<pTable->Get_Count() && Set_Progress(iRecord, pTable->Get_Count()); iRecord++) { CSG_Table_Record *pRecord = pTable->Get_Record_byIndex(iRecord); if( !pCut || sValue.Cmp(pRecord->asString(iField)) ) { pCut = pTable->Get_ObjectType() == DATAOBJECT_TYPE_Shapes ? SG_Create_Shapes(((CSG_Shapes *)pTable)->Get_Type(), SG_T(""), pTable) : SG_Create_Table(pTable); pCut->Set_Name(CSG_String::Format(SG_T("%s [%s = %s]"), pTable->Get_Name(), pTable->Get_Field_Name(iField), pRecord->asString(iField) )); Parameters("CUTS")->asTableList()->Add_Item(pCut); sValue = pRecord->asString(iField); } pCut->Add_Record(pRecord); } return( pCut != NULL ); } return( false ); }
//--------------------------------------------------------- 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 CPolygon_Clip::On_Execute(void) { CSG_Shapes Clip, *pClip = Parameters("CLIP")->asShapes(); if( Parameters("DISSOLVE")->asBool() && Dissolve(pClip, &Clip) ) { pClip = &Clip; } //----------------------------------------------------- if( !Parameters("MULTIPLE")->asBool() ) // single input mode { return( Clip_Shapes(pClip, Parameters("S_INPUT" )->asShapes(), Parameters("S_OUTPUT")->asShapes() )); } //----------------------------------------------------- else // multiple input mode { CSG_Parameter_Shapes_List *pInput = Parameters("M_INPUT" )->asShapesList(); CSG_Parameter_Shapes_List *pOutput = Parameters("M_OUTPUT")->asShapesList(); pOutput->Del_Items(); for(int i=0; i<pInput->Get_Count() && Process_Get_Okay(); i++) { CSG_Shapes *pShapes = SG_Create_Shapes(); if( Clip_Shapes(pClip, pInput->asShapes(i), pShapes) ) { pOutput->Add_Item(pShapes); } else { delete(pShapes); } } return( pOutput->Get_Count() > 0 ); } }
//--------------------------------------------------------- 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 CCRS_Transform_Grid::Transform(CSG_Parameter_Grid_List *pGrids) { if( pGrids->Get_Count() > 0 && m_Projector.Set_Source(pGrids->asGrid(0)->Get_Projection()) ) { CSG_Grid_System System; switch( Parameters("TARGET_TYPE")->asInt() ) { case 0: // create user defined grid system... if( Get_Target_System(pGrids->asGrid(0)->Get_System(), true) && m_Grid_Target.Get_System_User(System) ) { return( Transform(pGrids, Parameters("TARGET")->asGridList(), System) ); } break; case 1: // select existing grid system... if( Dlg_Parameters("GET_SYSTEM") && m_Grid_Target.Get_System(System) ) { return( Transform(pGrids, Parameters("TARGET")->asGridList(), System) ); } break; case 2: // points as target... if( Dlg_Parameters("POINTS") ) { CSG_Shapes *pPoints = Get_Parameters("POINTS")->Get_Parameter("POINTS")->asShapes(); if( pPoints == DATAOBJECT_NOTSET || pPoints == DATAOBJECT_CREATE ) { Get_Parameters("POINTS")->Get_Parameter("POINTS")->Set_Value(pPoints = SG_Create_Shapes()); } return( Transform(pGrids, pPoints) ); } break; } } return( false ); }
//--------------------------------------------------------- bool CCRS_Transform_Grid::Transform(CSG_Grid *pGrid) { if( pGrid->Get_Projection().is_Okay() && m_Projector.Set_Source(pGrid->Get_Projection()) ) { TSG_Data_Type Type = m_Interpolation == 0 ? pGrid->Get_Type() : SG_DATATYPE_Float; switch( Parameters("TARGET_TYPE")->asInt() ) { case 0: // create user defined grid... if( Get_Target_System(pGrid->Get_System(), true) ) { return( Transform(pGrid, m_Grid_Target.Get_User(Type)) ); } break; case 1: // select existing grid system... if( Dlg_Parameters("GET_GRID") ) { return( Transform(pGrid, m_Grid_Target.Get_Grid(Type)) ); } break; case 2: // points as target... if( Dlg_Parameters("POINTS") ) { CSG_Shapes *pPoints = Get_Parameters("POINTS")->Get_Parameter("POINTS")->asShapes(); if( pPoints == DATAOBJECT_NOTSET || pPoints == DATAOBJECT_CREATE ) { Get_Parameters("POINTS")->Get_Parameter("POINTS")->Set_Value(pPoints = SG_Create_Shapes(SHAPE_TYPE_Point)); } return( Transform(pGrid, pPoints) ); } break; } } return( false ); }
//--------------------------------------------------------- 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 CSeparate_by_Direction::On_Execute(void) { int iSector, dir_Field; CSG_Shapes *pPoints; CSG_Parameter_Shapes_List *pOutput; //----------------------------------------------------- pOutput = Parameters("OUTPUT") ->asShapesList(); pPoints = Parameters("POINTS") ->asShapes(); m_Tolerance = Parameters("TOLERANCE") ->asDouble() * M_DEG_TO_RAD; m_nSectors = Parameters("DIRECTIONS") ->asInt(); m_dSector = M_PI_360 / m_nSectors; if( !pPoints || !pPoints->is_Valid() || pPoints->Get_Count() < 3 ) { return( false ); } //----------------------------------------------------- pOutput->Del_Items(); dir_Field = pPoints->Get_Field_Count(); for(iSector=0; iSector<m_nSectors; iSector++) { pOutput->Add_Item(SG_Create_Shapes(SHAPE_TYPE_Point, CSG_String::Format(SG_T("Direction %.2f"), iSector * m_dSector * M_RAD_TO_DEG), pPoints)); pOutput->asShapes(iSector)->Add_Field(_TL("Direction"), SG_DATATYPE_Double); } //----------------------------------------------------- int iPoint; double dir_A, dir_B, dir, dif; CSG_Shape *pt_A, *pt_B; pt_B = pPoints->Get_Shape(pPoints->Get_Count() - 2); pt_A = pPoints->Get_Shape(pPoints->Get_Count() - 1); dir_A = SG_Get_Angle_Of_Direction(pt_B->Get_Point(0), pt_A->Get_Point(0)); for(iPoint=0; iPoint<pPoints->Get_Count() && Set_Progress(iPoint, pPoints->Get_Count()); iPoint++) { pt_B = pt_A; pt_A = pPoints->Get_Shape(iPoint); dir_B = dir_A; dir_A = SG_Get_Angle_Of_Direction(pt_B->Get_Point(0), pt_A->Get_Point(0)); dif = fmod(dir_A - dir_B, M_PI_360); if( dif > M_PI_180 ) { dif -= M_PI_360; } else if( dif < -M_PI_180 ) { dif += M_PI_360; } if( fabs(dif) <= m_Tolerance ) { dir = dir_B + 0.5 * dif; iSector = (int)(fmod(M_PI_360 + 0.5 * m_dSector + dir, M_PI_360) / m_dSector); if( iSector >= 0 && iSector < m_nSectors ) { pOutput->asShapes(iSector)->Add_Shape(pt_B)->Set_Value(dir_Field, dir * M_RAD_TO_DEG); } } } //----------------------------------------------------- for(iSector=pOutput->Get_Count()-1; iSector>=0; iSector--) { if( pOutput->asShapes(iSector)->Get_Count() == 0 ) { delete(pOutput->asShapes(iSector)); pOutput->Del_Item(iSector); } } //----------------------------------------------------- return( pOutput->Get_Count() > 0 ); }
//--------------------------------------------------------- bool CDXF_Import::On_Execute(void) { CSG_String fName = Parameters("FILE")->asString(); Parameters("TABLES")->asTableList() ->Del_Items(); Parameters("SHAPES")->asShapesList()->Del_Items(); m_Filter = Parameters("FILTER") ->asInt(); m_dArc = Parameters("DCIRCLE") ->asDouble() * M_DEG_TO_RAD; //----------------------------------------------------- if( SG_File_Exists(fName) ) { m_pLayers = SG_Create_Table(); m_pLayers ->Set_Name(CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Layers"))); m_pLayers ->Add_Field("LAYER" , SG_DATATYPE_String); m_pLayers ->Add_Field("FLAGS" , SG_DATATYPE_Int); m_pBlocks = SG_Create_Table(); m_pBlocks ->Set_Name(CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Blocks"))); m_pBlocks ->Add_Field("BLOCK" , SG_DATATYPE_String); m_pBlocks ->Add_Field("FLAGS" , SG_DATATYPE_Int); m_pBlocks ->Add_Field("X" , SG_DATATYPE_Double); m_pBlocks ->Add_Field("Y" , SG_DATATYPE_Double); m_pBlocks ->Add_Field("Z" , SG_DATATYPE_Double); m_pPoints = SG_Create_Shapes(SHAPE_TYPE_Point , CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Points"))); m_pPoints ->Add_Field("LAYER" , SG_DATATYPE_String); m_pPoints ->Add_Field("Z" , SG_DATATYPE_Double); m_pLines = SG_Create_Shapes(SHAPE_TYPE_Line , CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Lines"))); m_pLines ->Add_Field("LAYER" , SG_DATATYPE_String); m_pLines ->Add_Field("Z1" , SG_DATATYPE_Double); m_pLines ->Add_Field("Z2" , SG_DATATYPE_Double); m_pPolyLines = SG_Create_Shapes(SHAPE_TYPE_Line , CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Polylines"))); m_pPolyLines ->Add_Field("LAYER" , SG_DATATYPE_String); m_pPolyLines ->Add_Field("FLAGS" , SG_DATATYPE_Int); m_pPolygons = SG_Create_Shapes(SHAPE_TYPE_Polygon , CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Polygons"))); m_pPolygons ->Add_Field("LAYER" , SG_DATATYPE_String); m_pPolygons ->Add_Field("FLAGS" , SG_DATATYPE_Int); m_pCircles = SG_Create_Shapes(SHAPE_TYPE_Line , CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Circles"))); m_pCircles ->Add_Field("LAYER" , SG_DATATYPE_String); m_pCircles ->Add_Field("FLAGS" , SG_DATATYPE_Int); m_pTriangles = SG_Create_Shapes(SHAPE_TYPE_Polygon , CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Triangles"))); m_pTriangles ->Add_Field("LAYER" , SG_DATATYPE_String); m_pTriangles ->Add_Field("THICK" , SG_DATATYPE_Int); m_pTriangles ->Add_Field("Z1" , SG_DATATYPE_Double); m_pTriangles ->Add_Field("Z2" , SG_DATATYPE_Double); m_pTriangles ->Add_Field("Z3" , SG_DATATYPE_Double); m_pText = SG_Create_Shapes(SHAPE_TYPE_Point , CSG_String::Format(SG_T("%s [%s]"), SG_File_Get_Name(fName, false).c_str(), _TL("Text"))); m_pText ->Add_Field("LAYER" , SG_DATATYPE_String); m_pText ->Add_Field("Z" , SG_DATATYPE_Double); m_pText ->Add_Field("TEXT" , SG_DATATYPE_String); m_pText ->Add_Field("HEIGHT", SG_DATATYPE_Int); m_pText ->Add_Field("ANGLE" , SG_DATATYPE_Double); m_pText ->Add_Field("APX" , SG_DATATYPE_Double); m_pText ->Add_Field("APY" , SG_DATATYPE_Double); m_pText ->Add_Field("APZ" , SG_DATATYPE_Double); m_pText ->Add_Field("SCALE" , SG_DATATYPE_Double); m_pText ->Add_Field("HJUST" , SG_DATATYPE_Int); m_pText ->Add_Field("VJUST" , SG_DATATYPE_Int); m_pText ->Add_Field("STYLE" , SG_DATATYPE_String); m_pText ->Add_Field("FLAGS" , SG_DATATYPE_Int); //------------------------------------------------- m_Offset.x = 0.0; m_Offset.y = 0.0; m_Offset.z = 0.0; m_pPolyLine = NULL; DL_Dxf *pDXF = new DL_Dxf(); pDXF->in(fName.b_str(), this); delete(pDXF); //------------------------------------------------- ADD_RESULT("TABLES", m_pLayers); ADD_RESULT("TABLES", m_pBlocks); ADD_RESULT("SHAPES", m_pPoints); ADD_RESULT("SHAPES", m_pLines); ADD_RESULT("SHAPES", m_pPolyLines); ADD_RESULT("SHAPES", m_pPolygons); ADD_RESULT("SHAPES", m_pCircles); ADD_RESULT("SHAPES", m_pTriangles); ADD_RESULT("SHAPES", m_pText); } //----------------------------------------------------- return( Parameters("SHAPES")->asShapesList()->Get_Count() > 0 ); }
//--------------------------------------------------------- bool CAtlas_BNA_Import::On_Execute(void) { bool bOk; int iPoint, nPoints; double x, y; FILE *Stream; CSG_String FileName, sLine, sName1, sName2; CSG_Shape *pShape; CSG_Shapes *pPoints, *pLines, *pPolygons; //----------------------------------------------------- FileName = Parameters("FILE") ->asString(); //----------------------------------------------------- if( (Stream = fopen(FileName.b_str(), "r")) != NULL ) { pPoints = SG_Create_Shapes(SHAPE_TYPE_Point , SG_File_Get_Name(FileName, false)); pPoints ->Add_Field("NAME1" , SG_DATATYPE_String); pPoints ->Add_Field("NAME2" , SG_DATATYPE_String); pLines = SG_Create_Shapes(SHAPE_TYPE_Line , SG_File_Get_Name(FileName, false)); pLines ->Add_Field("NAME1" , SG_DATATYPE_String); pLines ->Add_Field("NAME2" , SG_DATATYPE_String); pPolygons = SG_Create_Shapes(SHAPE_TYPE_Polygon, SG_File_Get_Name(FileName, false)); pPolygons ->Add_Field("NAME1" , SG_DATATYPE_String); pPolygons ->Add_Field("NAME2" , SG_DATATYPE_String); //------------------------------------------------- bOk = true; while( bOk && SG_Read_Line(Stream, sLine) && Process_Get_Okay(true) ) { sName1 = sLine.AfterFirst('\"').BeforeFirst('\"'); sName2 = sLine.BeforeLast('\"').AfterLast('\"'); sLine = sLine.AfterLast('\"'); if( sLine.Find(',', true) >= 0 ) sLine = sLine.AfterLast(','); nPoints = sLine.asInt(); if( nPoints == 1 ) { pShape = pPoints ->Add_Shape(); } else if( nPoints < 0 ) { pShape = pLines ->Add_Shape(); nPoints = -nPoints; } else if( nPoints > 2 ) { pShape = pPolygons ->Add_Shape(); } else { bOk = false; } if( bOk ) { pShape->Set_Value(0, sName1); pShape->Set_Value(1, sName2); for(iPoint=0; iPoint<nPoints && bOk; iPoint++) { if( (bOk = SG_Read_Line(Stream, sLine)) == true ) { SG_SSCANF(sLine, SG_T("%lf %lf"), &x, &y); pShape->Add_Point(x, y); } } } } fclose(Stream); //------------------------------------------------- bOk = false; if( pPoints->is_Valid() && pPoints->Get_Count() > 0 ) { bOk = true; DataObject_Add(pPoints); } else { delete(pPoints); } if( pLines->is_Valid() && pLines->Get_Count() > 0 ) { bOk = true; DataObject_Add(pLines); } else { delete(pLines); } if( pPolygons->is_Valid() && pPolygons->Get_Count() > 0 ) { bOk = true; DataObject_Add(pPolygons); } else { delete(pPolygons); } return( bOk ); } //----------------------------------------------------- return( false ); }
//--------------------------------------------------------- bool CLeastCostPathProfile_Points::On_Execute(void) { int x, y; CSG_Shape *pShape; CSG_Shapes *pSources; CSG_Shapes *pPoints, *pLine; CSG_Parameter_Shapes_List *pShapesPoints, *pShapesLine; pSources = Parameters("SOURCE") ->asShapes(); m_pDEM = Parameters("DEM") ->asGrid(); m_pValues = Parameters("VALUES") ->asGridList(); pShapesPoints = Parameters("POINTS") ->asShapesList(); pShapesLine = Parameters("LINE") ->asShapesList(); //----------------------------------------------------- pShapesPoints ->Del_Items(); pShapesLine ->Del_Items(); //----------------------------------------------------- for( int i=0; i<pSources->Get_Count(); i++ ) { pShape = pSources->Get_Shape(i); if( Get_System()->Get_World_to_Grid(x, y, pShape->Get_Point(0)) && m_pDEM->is_InGrid(x, y) ) { //----------------------------------------------------- pPoints = SG_Create_Shapes(SHAPE_TYPE_Point, CSG_String::Format(_TL("Profile_Points_[%s]_%d"), m_pDEM->Get_Name(), i+1)); pPoints ->Add_Field("ID" , SG_DATATYPE_Int); pPoints ->Add_Field("D" , SG_DATATYPE_Double); pPoints ->Add_Field("X" , SG_DATATYPE_Double); pPoints ->Add_Field("Y" , SG_DATATYPE_Double); pPoints ->Add_Field("Z" , SG_DATATYPE_Double); for( int j=0; j<m_pValues->Get_Count(); j++) { pPoints->Add_Field(m_pValues->asGrid(j)->Get_Name(), SG_DATATYPE_Double); } //----------------------------------------------------- pLine = SG_Create_Shapes(SHAPE_TYPE_Line, CSG_String::Format(_TL("Profile_Line_[%s]_%d"), m_pDEM->Get_Name(), i+1)); pLine ->Add_Field("ID", SG_DATATYPE_Int); pLine ->Add_Shape()->Set_Value(0, 1); Set_Profile(x, y, pPoints, pLine); //----------------------------------------------------- if( pPoints->Get_Count() > 0 ) { pShapesPoints->Add_Item(pPoints); pShapesLine->Add_Item(pLine); } else { delete(pPoints); delete(pLine); } } } return( pShapesPoints->Get_Count() > 0 ); }
//--------------------------------------------------------- void CData_Source_PgSQL::Table_Open(const wxTreeItemId &Item) { CData_Source_PgSQL_Data *pData = Item.IsOk() ? (CData_Source_PgSQL_Data *)GetItemData(Item) : NULL; if( pData == NULL ) return; //----------------------------------------------------- if( pData->Get_Type() == TYPE_TABLE ) { CSG_Table *pTable = SG_Create_Table(); RUN_MODULE(DB_PGSQL_Table_Load, true, // CTable_Load SET_PARAMETER("CONNECTION", pData->Get_Server()) && SET_PARAMETER("TABLES" , pData->Get_Value ()) && SET_PARAMETER("TABLE" , pTable) ); if( bResult ) { g_pData->Show(pTable, 0); } else { delete(pTable); } } //----------------------------------------------------- if( pData->Get_Type() == TYPE_SHAPES ) { CSG_Shapes *pShapes = SG_Create_Shapes(); RUN_MODULE(DB_PGSQL_Shapes_Load, true, // CPGIS_Shapes_Load SET_PARAMETER("CONNECTION", pData->Get_Server()) && SET_PARAMETER("TABLES" , pData->Get_Value ()) && SET_PARAMETER("SHAPES" , pShapes) ); if( bResult ) { // g_pData->Show(pShapes, SG_UI_DATAOBJECT_SHOW_NEW_MAP); } else { delete(pShapes); } } //----------------------------------------------------- if( pData->Get_Type() == TYPE_GRIDS ) { RUN_MODULE(DB_PGSQL_Raster_Load, true, SET_PARAMETER("CONNECTION", pData->Get_Server()) && SET_PARAMETER("TABLES" , pData->Get_Value ()) ); } //----------------------------------------------------- if( pData->Get_Type() == TYPE_GRID ) { RUN_MODULE(DB_PGSQL_Raster_Load, true, SET_PARAMETER("CONNECTION", pData->Get_Server()) && SET_PARAMETER("TABLES" , pData->Get_Value ().BeforeFirst(':')) && SET_PARAMETER("WHERE" , pData->Get_Value ().AfterFirst (':')) ); } }
bool CGPX2SHP::On_Execute(void) { CSG_String sCmd; CSG_String sFile = Parameters("FILE")->asString(); CSG_String sBasePath = Parameters("BASEPATH")->asString(); CSG_String sShapefile; bool bWaypoints = Parameters("WAYPOINTS")->asBool(); bool bTrackpoints = Parameters("TRACKPOINTS")->asBool(); bool bRoutes = Parameters("ROUTES")->asBool(); bool bAdd = Parameters("ADD")->asBool(); CSG_Shapes *pShapes; sCmd = sBasePath + SG_T("\\gpx2shp "); if (bWaypoints) { sCmd += SG_T("-w "); }//if if (bTrackpoints) { sCmd += SG_T("-t "); }//if if (bRoutes) { sCmd += SG_T("-r "); }//if sCmd += sFile; system(sCmd.b_str()); if( bAdd ) { CSG_String sDir(SG_File_Get_Path(sFile)), sName(SG_File_Get_Name(sFile, false)); //------------------------------------------------- sFile = SG_File_Make_Path(sDir, sName + SG_T("_wpt"), SG_T("shp")); pShapes = SG_Create_Shapes(sFile); if( pShapes->is_Valid() ) DataObject_Add(pShapes, false); else delete(pShapes); //------------------------------------------------- sFile = SG_File_Make_Path(sDir, sName + SG_T("_trk"), SG_T("shp")); pShapes = SG_Create_Shapes(sFile); if( pShapes->is_Valid() ) DataObject_Add(pShapes, false); else delete(pShapes); //------------------------------------------------- sFile = SG_File_Make_Path(sDir, sName + SG_T("_rte"), SG_T("shp")); pShapes = SG_Create_Shapes(sFile); if( pShapes->is_Valid() ) DataObject_Add(pShapes, false); else delete(pShapes); }//if return true; }//method
//--------------------------------------------------------- bool CPROJ4_Grid::On_Execute_Conversion(void) { TSG_Data_Type Type; TSG_Rect Extent; CSG_Grid *pSource, *pGrid; CSG_Shapes *pShapes; m_Interpolation = Parameters("INTERPOLATION")->asInt(); //----------------------------------------------------- if( m_bInputList ) { CSG_Parameter_Grid_List *pSources = Parameters("SOURCE")->asGridList(); CSG_Parameter_Grid_List *pTargets = Parameters("TARGET")->asGridList(); if( pSources->Get_Count() < 1 ) { return( false ); } pSource = pSources->asGrid(0); pGrid = NULL; pShapes = NULL; Type = m_Interpolation == 0 ? pSource->Get_Type() : SG_DATATYPE_Float; switch( Parameters("TARGET_TYPE")->asInt() ) { case 0: // create new user defined grid... if( Get_Target_Extent(pSource, Extent) && m_Grid_Target.Init_User(Extent, pSource->Get_NY()) && Dlg_Parameters("GET_USER") ) { pGrid = m_Grid_Target.Get_User(Type); } break; case 1: // select grid system... if( Dlg_Parameters("<") && Get_Parameters("GET_SYSTEM")->Get_Parameter("SYSTEM")->asGrid_System()->is_Valid() ) { pGrid = SG_Create_Grid(*Get_Parameters("GET_SYSTEM")->Get_Parameter("SYSTEM")->asGrid_System(), Type); } break; case 2: // shapes... if( Dlg_Parameters("GET_SHAPES") ) { pShapes = Get_Parameters("GET_SHAPES")->Get_Parameter("SHAPES")->asShapes(); if( pShapes == DATAOBJECT_NOTSET || pShapes == DATAOBJECT_CREATE ) { Get_Parameters("GET_SHAPES")->Get_Parameter("SHAPES")->Set_Value(pShapes = SG_Create_Shapes()); } } break; } //------------------------------------------------- if( pShapes ) { Parameters("SHAPES")->Set_Value(pShapes); return( Set_Shapes(pSources, pShapes) ); } if( pGrid ) { pTargets->Del_Items(); pTargets->Add_Item(pGrid); Init_Target(pSource, pGrid); for(int i=1; i<pSources->Get_Count(); i++) { pTargets->Add_Item(SG_Create_Grid(pGrid->Get_System(), m_Interpolation == 0 ? pSources->asGrid(i)->Get_Type() : SG_DATATYPE_Float)); Init_Target(pSources->asGrid(i), pTargets->asGrid(i)); } return( Set_Grids(pSources, pTargets) ); } } //----------------------------------------------------- else { pSource = Parameters("SOURCE")->asGrid(); pGrid = NULL; pShapes = NULL; Type = m_Interpolation == 0 ? pSource->Get_Type() : SG_DATATYPE_Float; switch( Parameters("TARGET_TYPE")->asInt() ) { case 0: // create new user defined grid... if( Get_Target_Extent(pSource, Extent) && m_Grid_Target.Init_User(Extent, pSource->Get_NY()) && Dlg_Parameters("GET_USER") ) { pGrid = m_Grid_Target.Get_User(Type); } break; case 1: // select grid... if( Dlg_Parameters("GET_GRID") ) { pGrid = m_Grid_Target.Get_Grid(Type); } break; case 2: // shapes... if( Dlg_Parameters("GET_SHAPES") ) { pShapes = Get_Parameters("GET_SHAPES")->Get_Parameter("SHAPES")->asShapes(); if( pShapes == DATAOBJECT_NOTSET || pShapes == DATAOBJECT_CREATE ) { Get_Parameters("GET_SHAPES")->Get_Parameter("SHAPES")->Set_Value(pShapes = SG_Create_Shapes()); } } break; } //------------------------------------------------- if( pShapes ) { Parameters("SHAPES")->Set_Value(pShapes); return( Set_Shapes(pSource, pShapes) ); } if( pGrid ) { return( Set_Grid(pSource, pGrid) ); } } //----------------------------------------------------- return( false ); }
//--------------------------------------------------------- bool CPGIS_Shapes_Load::On_Execute(void) { TSG_Vertex_Type tVertex; TSG_Shape_Type tShape; CSG_String Select, Geo_Table, Geo_Type, Geo_Field; CSG_Table Geo_Tables; CSG_Shapes *pShapes; pShapes = Parameters("SHAPES") ->asShapes(); Geo_Table = Parameters("TABLES") ->asString(); Select.Printf(SG_T("SELECT * FROM geometry_columns WHERE f_table_name = '%s'"), Geo_Table.c_str()); if( !Get_Connection()->Table_Load(Geo_Tables, SG_T("geometry_columns"), SG_T("*"), CSG_String::Format(SG_T("f_table_name = '%s'"), Geo_Table.c_str()), SG_T("")) ) { return( false ); } if( Geo_Tables.Get_Count() != 1 ) { return( false ); } Geo_Type = Geo_Tables[0].asString(SG_T("type")); Geo_Field = Geo_Tables[0].asString(SG_T("f_geometry_column")); //----------------------------------------------------- if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_Point ) ) { tShape = SHAPE_TYPE_Point; tVertex = SG_VERTEX_TYPE_XY; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_MultiPoint ) ) { tShape = SHAPE_TYPE_Points; tVertex = SG_VERTEX_TYPE_XY; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_Line ) ) { tShape = SHAPE_TYPE_Line; tVertex = SG_VERTEX_TYPE_XY; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_MultiLine ) ) { tShape = SHAPE_TYPE_Line; tVertex = SG_VERTEX_TYPE_XY; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_Polygon ) ) { tShape = SHAPE_TYPE_Polygon; tVertex = SG_VERTEX_TYPE_XY; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_MultiPolygon ) ) { tShape = SHAPE_TYPE_Polygon; tVertex = SG_VERTEX_TYPE_XY; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_Point_Z ) ) { tShape = SHAPE_TYPE_Point; tVertex = SG_VERTEX_TYPE_XYZ; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_MultiPoint_Z ) ) { tShape = SHAPE_TYPE_Points; tVertex = SG_VERTEX_TYPE_XYZ; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_Line_Z ) ) { tShape = SHAPE_TYPE_Line; tVertex = SG_VERTEX_TYPE_XYZ; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_MultiLine_Z ) ) { tShape = SHAPE_TYPE_Line; tVertex = SG_VERTEX_TYPE_XYZ; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_Polygon_Z ) ) { tShape = SHAPE_TYPE_Polygon; tVertex = SG_VERTEX_TYPE_XYZ; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_MultiPolygon_Z ) ) { tShape = SHAPE_TYPE_Polygon; tVertex = SG_VERTEX_TYPE_XYZ; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_Point_M ) ) { tShape = SHAPE_TYPE_Point; tVertex = SG_VERTEX_TYPE_XYZ; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_MultiPoint_M ) ) { tShape = SHAPE_TYPE_Points; tVertex = SG_VERTEX_TYPE_XYZ; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_Line_M ) ) { tShape = SHAPE_TYPE_Line; tVertex = SG_VERTEX_TYPE_XYZ; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_MultiLine_M ) ) { tShape = SHAPE_TYPE_Line; tVertex = SG_VERTEX_TYPE_XYZ; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_Polygon_M ) ) { tShape = SHAPE_TYPE_Polygon; tVertex = SG_VERTEX_TYPE_XYZ; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_MultiPolygon_M ) ) { tShape = SHAPE_TYPE_Polygon; tVertex = SG_VERTEX_TYPE_XYZ; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_Point_ZM ) ) { tShape = SHAPE_TYPE_Point; tVertex = SG_VERTEX_TYPE_XYZM; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_MultiPoint_ZM ) ) { tShape = SHAPE_TYPE_Points; tVertex = SG_VERTEX_TYPE_XYZM; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_Line_ZM ) ) { tShape = SHAPE_TYPE_Line; tVertex = SG_VERTEX_TYPE_XYZM; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_MultiLine_ZM ) ) { tShape = SHAPE_TYPE_Line; tVertex = SG_VERTEX_TYPE_XYZM; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_Polygon_ZM ) ) { tShape = SHAPE_TYPE_Polygon; tVertex = SG_VERTEX_TYPE_XYZM; } else if( !Geo_Type.CmpNoCase(SG_OGIS_TYPE_STR_MultiPolygon_ZM ) ) { tShape = SHAPE_TYPE_Polygon; tVertex = SG_VERTEX_TYPE_XYZM; } else { return( false ); } if( pShapes->Get_Type() != SHAPE_TYPE_Undefined && pShapes->Get_Type() != tShape ) { pShapes = SG_Create_Shapes(tShape, Geo_Table, NULL, tVertex); Parameters("SHAPES")->Set_Value(pShapes); } else { pShapes->Create(tShape, Geo_Table, NULL, tVertex); } //----------------------------------------------------- if( !Get_Connection()->Table_Load(*pShapes, Geo_Table) ) { return( false ); } //----------------------------------------------------- if( 1 ) // WKBinary { CSG_Bytes_Array BLOBs; Select.Printf(SG_T("AsBinary(%s) AS geom"), Geo_Field.c_str()); if( !Get_Connection()->Table_Load_BLOBs(BLOBs, Geo_Table, Select, SG_T(""), SG_T("")) ) { return( false ); } if( BLOBs.Get_Count() != pShapes->Get_Count() ) { return( false ); } for(int iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++) { CSG_Shapes_OGIS_Converter::from_WKBinary(BLOBs[iShape], pShapes->Get_Shape(iShape)); } } //----------------------------------------------------- else // WKText { CSG_Table Shapes; Select.Printf(SG_T("AsText(%s) AS geom"), Geo_Field.c_str()); if( !Get_Connection()->Table_Load(Shapes, Geo_Table, Select, SG_T(""), SG_T("")) ) { return( false ); } if( Shapes.Get_Count() != pShapes->Get_Count() ) { return( false ); } for(int iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++) { CSG_Shapes_OGIS_Converter::from_WKText(Shapes[iShape].asString(0), pShapes->Get_Shape(iShape)); } } return( true ); }
//--------------------------------------------------------- bool CSurfer_BLN_Import::On_Execute(void) { bool bOk; int ID, Flag, iPoint, nPoints; double x, y; FILE *Stream; TSG_Shape_Type Type; CSG_String FileName, sLine, sName, sDesc, sTemp; CSG_Table_Record *pRecord; CSG_Table *pTable; CSG_Shape *pShape; CSG_Shapes *pShapes; //----------------------------------------------------- pShapes = Parameters("SHAPES") ->asShapes(); pTable = Parameters("TABLE") ->asTable(); FileName = Parameters("FILE") ->asString(); switch( Parameters("TYPE")->asInt() ) { case 0: Type = SHAPE_TYPE_Point; break; case 1: default: Type = SHAPE_TYPE_Line; break; case 2: Type = SHAPE_TYPE_Polygon; break; } //----------------------------------------------------- if( (Stream = fopen(FileName.b_str(), "r")) != NULL ) { bOk = true; ID = 0; if( pShapes->Get_Type() != SHAPE_TYPE_Undefined && pShapes->Get_Type() != Type ) { pShapes = SG_Create_Shapes(Type, SG_File_Get_Name(FileName, false)); Parameters("SHAPES")->Set_Value(pShapes); DataObject_Add(pShapes); } else { pShapes->Create(Type, SG_File_Get_Name(FileName, false)); } if( Type == SHAPE_TYPE_Point ) { if( pTable == NULL ) { pTable = SG_Create_Table(); Parameters("TABLE")->Set_Value(pTable); } else { pTable->Destroy(); } pTable ->Add_Field("ID" , SG_DATATYPE_Int); pTable ->Add_Field("FLAG" , SG_DATATYPE_Int); pTable ->Add_Field("NAME" , SG_DATATYPE_String); pTable ->Add_Field("DESC" , SG_DATATYPE_String); pShapes->Add_Field("ID" , SG_DATATYPE_Int); pShapes->Add_Field("ID_LUT" , SG_DATATYPE_Int); pShapes->Add_Field("Z" , SG_DATATYPE_Double); } else { pShapes->Add_Field("ID" , SG_DATATYPE_Int); pShapes->Add_Field("FLAG" , SG_DATATYPE_Int); pShapes->Add_Field("NAME" , SG_DATATYPE_String); pShapes->Add_Field("DESC" , SG_DATATYPE_String); } //------------------------------------------------- while( bOk && SG_Read_Line(Stream, sLine) && sLine.BeforeFirst(',').asInt(nPoints) && nPoints > 0 && Process_Get_Okay(true) ) { Process_Set_Text(CSG_String::Format(SG_T("%d. %s"), ++ID, _TL("shape in process"))); sTemp = sLine.AfterFirst (','); sLine = sTemp; Flag = sLine.BeforeFirst(',').asInt(); sTemp = sLine.AfterFirst (','); sLine = sTemp; sTemp = sLine.BeforeFirst(','); sName = sTemp.AfterFirst('\"').BeforeLast('\"'); sTemp = sLine.AfterFirst (','); sLine = sTemp; sTemp = sLine.BeforeFirst(','); sDesc = sTemp.AfterFirst('\"').BeforeLast('\"'); if( Type == SHAPE_TYPE_Point ) { pRecord = pTable->Add_Record(); pRecord->Set_Value(0, ID); pRecord->Set_Value(1, Flag); pRecord->Set_Value(2, sName); pRecord->Set_Value(3, sDesc); for(iPoint=0; iPoint<nPoints && bOk; iPoint++) { if( (bOk = SG_Read_Line(Stream, sLine)) == true ) { pShape = pShapes->Add_Shape(); pShape->Set_Value(0, iPoint + 1); pShape->Set_Value(1, ID); pShape->Set_Value(2, sLine.AfterLast (',').asDouble()); x = sLine.BeforeFirst(',').asDouble(); y = sLine.AfterFirst (',').asDouble(); pShape->Add_Point(x, y); } } } else { pShape = pShapes->Add_Shape(); pShape->Set_Value(0, ID); pShape->Set_Value(1, Flag); pShape->Set_Value(2, sName); pShape->Set_Value(3, sDesc); for(iPoint=0; iPoint<nPoints && bOk; iPoint++) { if( (bOk = SG_Read_Line(Stream, sLine)) == true ) { x = sLine.BeforeFirst(',').asDouble(); y = sLine.AfterFirst (',').asDouble(); pShape->Add_Point(x, y); } } } } fclose(Stream); } //----------------------------------------------------- if( pShapes->is_Valid() && pShapes->Get_Count() > 0 ) { return( true ); } return( false ); }
//--------------------------------------------------------- bool CSTL_Import::On_Execute(void) { int Method; DWORD iFacette, nFacettes; TSTL_Point p[3]; CSG_String sFile, sHeader; CSG_File Stream; //----------------------------------------------------- sFile = Parameters("FILE") ->asString(); Method = Parameters("METHOD") ->asInt(); r_sin_x = sin(Parameters("ROT_X")->asDouble() * M_DEG_TO_RAD); r_sin_y = sin(Parameters("ROT_Y")->asDouble() * M_DEG_TO_RAD); r_sin_z = sin(Parameters("ROT_Z")->asDouble() * M_DEG_TO_RAD); r_cos_x = cos(Parameters("ROT_X")->asDouble() * M_DEG_TO_RAD); r_cos_y = cos(Parameters("ROT_Y")->asDouble() * M_DEG_TO_RAD); r_cos_z = cos(Parameters("ROT_Z")->asDouble() * M_DEG_TO_RAD); //----------------------------------------------------- if( !Stream.Open(sFile) ) { return( false ); } if( !Stream.Read(sHeader, 80) ) { return( false ); } Message_Add(sHeader); if( !Stream.Read(&nFacettes, sizeof(nFacettes)) ) { return( false ); } Message_Add(CSG_String::Format(SG_T("%s: %d"), _TL("Number of Facettes"), nFacettes)); //----------------------------------------------------- switch( Method ) { //----------------------------------------------------- case 0: { // Point Cloud CSG_Rect Extent; if( Get_Extent(Stream, Extent, nFacettes) ) { CSG_PRQuadTree Points(Extent); CSG_PointCloud *pPoints = SG_Create_PointCloud(); Parameters("POINTS")->Set_Value(pPoints); pPoints->Set_Name(SG_File_Get_Name(sFile, false)); pPoints->Add_Field((const char *)NULL, SG_DATATYPE_Undefined); for(iFacette=0; iFacette<nFacettes && !Stream.is_EOF() && Set_Progress(iFacette, nFacettes); iFacette++) { if( Read_Facette(Stream, p) ) { for(int i=0; i<3; i++) { if( Points.Add_Point(p[i].x, p[i].y, p[i].z) ) { pPoints->Add_Point(p[i].x, p[i].y, p[i].z); } } } } } break; } //----------------------------------------------------- case 1: { // Point Cloud (centered) CSG_PointCloud *pPoints = SG_Create_PointCloud(); Parameters("POINTS")->Set_Value(pPoints); pPoints->Set_Name(SG_File_Get_Name(sFile, false)); pPoints->Add_Field((const char *)NULL, SG_DATATYPE_Undefined); for(iFacette=0; iFacette<nFacettes && !Stream.is_EOF() && Set_Progress(iFacette, nFacettes); iFacette++) { if( Read_Facette(Stream, p) ) { pPoints->Add_Point( (p[0].x + p[1].x + p[2].x) / 3.0, (p[0].y + p[1].y + p[2].y) / 3.0, (p[0].z + p[1].z + p[2].z) / 3.0 ); } } break; } //----------------------------------------------------- case 2: { // Points CSG_Shapes *pPoints = SG_Create_Shapes(SHAPE_TYPE_Point, SG_File_Get_Name(sFile, false)); pPoints->Add_Field(SG_T("Z"), SG_DATATYPE_Float); Parameters("SHAPES")->Set_Value(pPoints); for(iFacette=0; iFacette<nFacettes && !Stream.is_EOF() && Set_Progress(iFacette, nFacettes); iFacette++) { if( Read_Facette(Stream, p) ) { CSG_Shape *pPoint = pPoints->Add_Shape(); pPoint->Add_Point( (p[0].x + p[1].x + p[2].x) / 3.0, (p[0].y + p[1].y + p[2].y) / 3.0 ); pPoint->Set_Value(0, (p[0].z + p[1].z + p[2].z) / 3.0 ); } } break; } //----------------------------------------------------- case 3: { // Raster CSG_Rect Extent; if( Get_Extent(Stream, Extent, nFacettes) ) { int nx, ny; double d; nx = Parameters("GRID_RES")->asInt(); d = Extent.Get_XRange() / nx; ny = 1 + (int)(Extent.Get_YRange() / d); m_pGrid = SG_Create_Grid(SG_DATATYPE_Float, nx, ny, d, Extent.Get_XMin(), Extent.Get_YMin()); m_pGrid->Set_Name(SG_File_Get_Name(sFile, false)); m_pGrid->Set_NoData_Value(-99999); m_pGrid->Assign_NoData(); Parameters("GRID")->Set_Value(m_pGrid); //--------------------------------------------- for(iFacette=0; iFacette<nFacettes && !Stream.is_EOF() && Set_Progress(iFacette, nFacettes); iFacette++) { if( Read_Facette(Stream, p) ) { TSG_Point_Z Point[3]; for(int i=0; i<3; i++) { Point[i].x = (p[i].x - m_pGrid->Get_XMin()) / m_pGrid->Get_Cellsize(); Point[i].y = (p[i].y - m_pGrid->Get_YMin()) / m_pGrid->Get_Cellsize(); Point[i].z = p[i].z; } Set_Triangle(Point); } } } break; } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CClip_Points::On_Execute(void) { int Method, iField; CSG_Shapes *pPoints, *pPolygons, *pClip; CSG_Parameter_Shapes_List *pClips; //----------------------------------------------------- pPoints = Parameters("POINTS") ->asShapes(); pPolygons = Parameters("POLYGONS") ->asShapes(); pClips = Parameters("CLIPS") ->asShapesList(); Method = Parameters("METHOD") ->asInt(); iField = Parameters("FIELD") ->asInt(); //----------------------------------------------------- if( !pPoints->is_Valid() ) { Message_Add(_TL("Invalid points layer.")); return( false ); } else if( !pPolygons->is_Valid() ) { Message_Add(_TL("Invalid polygon layer.")); return( false ); } //----------------------------------------------------- if( iField >= pPolygons->Get_Field_Count() ) { iField = -1; } pClips->Del_Items(); if( Method == 0 ) { pClip = SG_Create_Shapes(SHAPE_TYPE_Point, CSG_String::Format(SG_T("%s [%s]"), pPoints->Get_Name(), pPolygons->Get_Name()), pPoints); if( iField >= 0 ) { pClip->Add_Field(pPolygons->Get_Field_Name(iField), pPolygons->Get_Field_Type(iField)); } } //----------------------------------------------------- for(int iPolygon=0; iPolygon<pPolygons->Get_Count() && Set_Progress(iPolygon, pPolygons->Get_Count()); iPolygon++) { CSG_Shape_Polygon *pPolygon = (CSG_Shape_Polygon *)pPolygons->Get_Shape(iPolygon); if( Method == 1 ) { CSG_String Name(pPoints->Get_Name()); Name += iField >= 0 ? CSG_String::Format(SG_T(" [%s]"), pPolygon->asString(iField)) : CSG_String::Format(SG_T(" [%00d]"), 1 + pClips->Get_Count()); pClip = SG_Create_Shapes(SHAPE_TYPE_Point, Name, pPoints); if( iField >= 0 ) { pClip->Add_Field(pPolygons->Get_Field_Name(iField), pPolygons->Get_Field_Type(iField)); } } for(int iPoint=0; iPoint<pPoints->Get_Count() && Process_Get_Okay(false); iPoint++) { CSG_Shape *pPoint = pPoints->Get_Shape(iPoint); if( pPolygon->Contains(pPoint->Get_Point(0)) ) { pPoint = pClip->Add_Shape(pPoint, SHAPE_COPY); if( iField >= 0 ) { pPoint->Set_Value(pPoints->Get_Field_Count(), pPolygon->asString(iField)); } } } if( Method == 1 ) { if( pClip->Get_Count() > 0 ) { pClips->Add_Item(pClip); } else { delete(pClip); } } } //----------------------------------------------------- if( Method == 0 ) { if( pClip->Get_Count() > 0 ) { pClips->Add_Item(pClip); } else { delete(pClip); } } return( pClips->Get_Count() > 0 ); }