//--------------------------------------------------------- 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 CTable_Create_Empty::On_Execute(void) { CSG_Table *pTable = SG_Create_Table(); pTable->Set_Name(Parameters("NAME")->asString()); //----------------------------------------------------- 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; } pTable->Add_Field(pAttributes->Get_Parameter(GET_NAME(i))->asString(), Type); } Parameters("TABLE")->Set_Value(pTable); return( true ); }
//--------------------------------------------------------- void CData_Source_PgSQL::Table_Info(const wxTreeItemId &Item) { CData_Source_PgSQL_Data *pData = Item.IsOk() ? (CData_Source_PgSQL_Data *)GetItemData(Item) : NULL; if( pData == NULL ) return; CSG_Table *pTable = SG_Create_Table(); RUN_MODULE(DB_PGSQL_Table_Info, true, // CTable_Info 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); } }
bool Cihacres_elev::On_Execute() { CSG_Parameters P; //std::ofstream f("_out_elev.txt"); // Assign Parameters from first Module Dialog //--------------------------------------------------------- int eb = Parameters("NELEVBANDS") ->asInt(); m_nElevBands = eb + 2; // because list starts with 2 ! m_Area_tot = Parameters("AREA_tot") ->asDouble(); m_IHAC_version = Parameters("IHACVERS") ->asInt(); m_StorConf = Parameters("STORAGE") ->asInt(); m_bSnowModule = Parameters("SNOW_MODULE") ->asBool(); //--------------------------------------------------------- //--------------------------------------------------------- // Assign number of storages m_nStorages = ihacres.Assign_nStorages(m_StorConf); //--------------------------------------------------------- //--------------------------------------------------------- // Initialize pointers _Init_ElevBands(m_nElevBands); m_p_linparms = new C_IHAC_LinearParms(m_nElevBands,m_nStorages); m_p_nonlinparms = new C_IHAC_NonLinearParms(m_nElevBands); //--------------------------------------------------------- //--------------------------------------------------------- // open second and third user dialog if ( _CreateDialog2() && _CreateDialog3()) { //--------------------------------------------------------- // searching the first and the last record of the time range ihacres.AssignFirstLastRec(*m_p_InputTable, m_first, m_last, m_date1, m_date2, m_dateField); m_nValues = m_last - m_first + 1; //--------------------------------------------------------- //--------------------------------------------------------- _Init_Pointers(m_nValues); //--------------------------------------------------------- //--------------------------------------------------------- // read input table _ReadInputFile(); //--------------------------------------------------------- //--------------------------------------------------------- // PERFORM STREAMFLOW SIMULATION // FOR EACH ELEVATION BAND //--------------------------------------------------------- // Convert Streamflow vector from m3/s*day-1 to mm/day m_p_Q_obs_mmday = model_tools::m3s_to_mmday(m_p_Q_obs_m3s, m_p_Q_obs_mmday, m_nValues, m_Area_tot); //--------------------------------------------------------- // SNOW MODULE //--------------------------------------------------------- for (int i = 0; i < m_nElevBands; i++) { if (m_bSnowModule) { _CalcSnowModule(i); } _Simulate_NonLinearModule(i); _Simulate_Streamflow(i); } //--------------------------------------------------------- m_pTable = SG_Create_Table(); _CreateTableSim(); // add tables to SAGA Workspace m_pTable->Set_Name(SG_T("IHACRES_ElevBands_output")); Parameters("TABLEout")->Set_Value(m_pTable); delete[] m_p_elevbands; // sämtliche Unter-Pointer noch löschen delete[] m_p_pcpField; delete[] m_p_tmpField; delete m_p_linparms; delete m_p_nonlinparms; if (m_bSnowModule) delete[] m_pSnowparms; return(true); } // end if ( _CreateDialog2() ) // delete[] m_p_elevbands; // delete[] m_p_pcpFields; // delete[] m_p_tmpFields; // delete m_p_linparms; // delete m_p_nonlinparms; return(false); }
//--------------------------------------------------------- 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 CTable_Rotate::On_Execute(void) { bool bCopy; int x, y; TSG_Data_Type FieldType; CSG_Table *pInput, *pOutput; CSG_Table_Record *pRec_In, *pRec_Out; //----------------------------------------------------- pInput = Parameters("INPUT") ->asTable(); pOutput = Parameters("OUTPUT") ->asTable(); //----------------------------------------------------- if( pInput->Get_Field_Count() > 0 && pInput->Get_Record_Count() > 0 ) { if( pInput != pOutput ) { bCopy = true; } else { bCopy = false; pOutput = SG_Create_Table(); } pOutput->Destroy(); pOutput->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pInput->Get_Name(), _TL("rotated"))); FieldType = SG_DATATYPE_String; //------------------------------------------------- pOutput->Add_Field(pInput->Get_Field_Name(0), SG_DATATYPE_String); for(y=0; y<pInput->Get_Record_Count(); y++) { pOutput->Add_Field(pInput->Get_Record(y)->asString(0), FieldType); } for(y=1; y<pInput->Get_Field_Count(); y++) { pRec_Out = pOutput->Add_Record(); pRec_Out->Set_Value(0, pInput->Get_Field_Name(y)); for(x=0; x<pInput->Get_Record_Count(); x++) { pRec_In = pInput->Get_Record(x); if( FieldType == SG_DATATYPE_String ) { pRec_Out->Set_Value(x + 1, pRec_In->asString(y)); } else { pRec_Out->Set_Value(x + 1, pRec_In->asDouble(y)); } } } //------------------------------------------------- if( !bCopy ) { pInput->Assign(pOutput); delete(pOutput); } return( true ); } return( false ); }
//--------------------------------------------------------- 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 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 ); }