//--------------------------------------------------------- int CSG_ODBC_Connection::Get_Tables(CSG_Strings &Tables) const { Tables.Clear(); if( is_Connected() ) { try { otl_stream Stream(m_Size_Buffer, "$SQLTables", m_Connection); // get a list of all tables in the current database. while( !Stream.eof() ) { std_string Catalog, Schema, Table, Type, Remarks; Stream >> Catalog >> Schema >> Table >> Type >> Remarks; Tables += Table.c_str(); } } catch( otl_exception &e ) { _Error_Message(e); } } return( Tables.Get_Count() ); }
//--------------------------------------------------------- bool CTable_List::On_Execute(void) { CSG_Table *pTables = Parameters("TABLES")->asTable(); pTables->Destroy(); pTables->Set_Name(_TL("Tables")); pTables->Add_Field(_TL("Table"), SG_DATATYPE_String); if( Get_Connection() ) { CSG_Strings Tables; Get_Connection()->Get_Tables(Tables); for(int i=0; i<Tables.Get_Count(); i++) { CSG_Table_Record *pTable = pTables->Add_Record(); pTable->Set_Value(0, Tables[i]); } pTables->Set_Name(Get_Connection()->Get_Server() + " [" + _TL("Tables") + "]"); return( true ); } return( false ); }
//--------------------------------------------------------- bool CImport_Clip_Resample::On_Execute(void) { //----------------------------------------------------- CSG_Strings Files; if( !Parameters("FILES")->asFilePath()->Get_FilePaths(Files) || Files.Get_Count() == 0 ) { return( false ); } //----------------------------------------------------- m_pGrids = Parameters("GRIDS")->asGridList(); m_pGrids->Del_Items(); //----------------------------------------------------- for(int i=0; i<Files.Get_Count() && Process_Get_Okay(); i++) { Load_File(Files[i]); } //----------------------------------------------------- if( m_pGrids->Get_Count() == 0 ) { Error_Set(_TL("no grids have been imported")); } return( true ); }
//--------------------------------------------------------- int CSG_ODBC_Connections::Get_Servers(CSG_String &Servers) { CSG_Strings s = Get_Servers(); for(int i=0; i<s.Get_Count(); i++) { Servers += s[i] + SG_T("|"); } return( s.Get_Count() ); }
//--------------------------------------------------------- CSG_Strings CSG_ODBC_Connections::Get_Connections(void) { CSG_Strings Connections; for(int i=0; i<m_nConnections; i++) { Connections.Add(m_pConnections[i]->Get_Server()); } return( Connections ); }
bool Cdodproperror::LoadTIFFsAsGrids(CSG_Strings tiffpaths, CSG_Grid** grids, CSG_Strings names) { bool success = false; for (int i = 0; i < tiffpaths.Get_Count(); i++) { success = LoadTIFFAsGrid(tiffpaths.Get_String(i), grids[i], names[i]); if (!success) { return false; } } return success; }
bool Cdodproperror::DeleteFiles(CSG_Strings paths) { bool success = false; for (int i = 0; i < paths.Get_Count(); i++) { success = DeleteFile(paths.Get_String(i)); if (!success) { return false; } } return success; }
//--------------------------------------------------------- int CSG_ODBC_Connections::Get_Connections(CSG_String &Connections) { CSG_Strings s = Get_Connections(); Connections.Clear(); for(int i=0; i<s.Get_Count(); i++) { Connections += CSG_String::Format(SG_T("%s|"), s[i].c_str()); } return( s.Get_Count() ); }
//--------------------------------------------------------- bool CLandsat_Import::On_Execute(void) { CSG_Strings Files; if( !Parameters("FILES")->asFilePath()->Get_FilePaths(Files) || Files.Get_Count() <= 0 ) { return( false ); } //----------------------------------------------------- CSG_Parameter_Grid_List *pBands = Parameters("BANDS")->asGridList(); pBands->Del_Items(); for(int i=0; i<Files.Get_Count(); i++) { Message_Add(CSG_String::Format(SG_T("%s: %s"), _TL("loading"), SG_File_Get_Name(Files[i], false).c_str())); CSG_Grid *pBand = Get_Band(Files[i]); if( pBand ) { pBands->Add_Item(pBand); DataObject_Add(pBand); DataObject_Set_Colors(pBand, 11, SG_COLORS_BLACK_WHITE); } } //----------------------------------------------------- if( Parameters("SHOW_RGB")->is_Enabled() && Parameters("SHOW_RGB")->asBool() ) { CSG_Grid *pR = pBands->asGrid(Parameters("SHOW_R")->asInt()); CSG_Grid *pG = pBands->asGrid(Parameters("SHOW_G")->asInt()); CSG_Grid *pB = pBands->asGrid(Parameters("SHOW_B")->asInt()); if( pR && pG && pB ) { DataObject_Set_Parameter(pR, "COLORS_TYPE" , 5); // _TL("RGB Overlay") // CLASSIFY_OVERLAY DataObject_Set_Parameter(pR, "OVERLAY_MODE", 0); // _TL("red=this, green=1, blue=2") DataObject_Set_Parameter(pR, "OVERLAY_G" , pG); DataObject_Set_Parameter(pR, "OVERLAY_B" , pB); DataObject_Update(pR, true); } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CWKSP_Project::_Load_DBConnections(CSG_MetaData &Data) { int i; CSG_Strings Connections; for(i=0; i<Data.Get_Children_Count(); i++) { CSG_String Connection(Data[i].Get_Child("FILE") ? Data[i].Get_Child("FILE")->Get_Content() : ""); if( !Connection.BeforeFirst(':').CmpNoCase("PGSQL") ) { Connection = Connection.AfterFirst(':'); CSG_String Host (Connection.BeforeFirst(':')); Connection = Connection.AfterFirst(':'); CSG_String Port (Connection.BeforeFirst(':')); Connection = Connection.AfterFirst(':'); CSG_String DBName(Connection.BeforeFirst(':')); Connection = Host + ":" + Port + ":" + DBName; bool bAdd = true; for(int j=0; j<Connections.Get_Count() && bAdd; j++) { if( !Connection.Cmp(Connections[j]) ) { bAdd = false; } } if( bAdd ) { Connections += Connection; } } } for(i=0; i<Connections.Get_Count(); i++) { CSG_String Host (Connections[i].BeforeFirst(':')); CSG_String Port (Connections[i].AfterFirst (':').BeforeLast(':')); CSG_String DBName(Connections[i].AfterLast (':')); if( !PGSQL_Connect(Host, Port, DBName) ) { return( false ); } } return( true ); }
bool Cdodproperror::SaveGridsAsTIFF(CSG_Grid** grids, CSG_Strings paths) { TSG_Data_Type Type; CSG_String FilePath; CSG_Grid* Grid; // SAVE TIFFS for (int i = 0; i < paths.Get_Count(); i++) { FilePath = paths[i]; Grid = grids[i]; Type = Grid->Get_Type(); if( !GDALDataSet.Open_Write(FilePath, GDALDriver, GDALOptions, Type, 1, *Get_System(), Projection) ) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to open file for writing: "), FilePath.c_str())); return( false ); } GDALDataSet.Write(0, Grid); if( !GDALDataSet.Close() ) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to close file after writing: "), FilePath.c_str())); return( false ); } } return true; }
//--------------------------------------------------------- int CLandsat_Import::On_Parameters_Enable(CSG_Parameters *pParameters, CSG_Parameter *pParameter) { if( !SG_STR_CMP(pParameter->Get_Identifier(), "FILES") ) { CSG_Strings Files; pParameter->asFilePath()->Get_FilePaths(Files); if( Files.Get_Count() < 3 ) { pParameters->Set_Enabled("SHOW_RGB", false); } else { pParameters->Set_Enabled("SHOW_RGB", true); CSG_String Choices; for(int i=0; i<Files.Get_Count(); i++) { Choices += SG_File_Get_Name(Files[i], false) + "|"; } int iR = pParameters->Get_Parameter("SHOW_R")->asChoice()->Get_Count() > 1 ? pParameters->Get_Parameter("SHOW_R")->asInt() : 2; int iG = pParameters->Get_Parameter("SHOW_G")->asChoice()->Get_Count() > 1 ? pParameters->Get_Parameter("SHOW_G")->asInt() : 1; int iB = pParameters->Get_Parameter("SHOW_B")->asChoice()->Get_Count() > 1 ? pParameters->Get_Parameter("SHOW_B")->asInt() : 0; pParameters->Get_Parameter("SHOW_R")->asChoice()->Set_Items(Choices); pParameters->Get_Parameter("SHOW_R")->Set_Value(iR); pParameters->Get_Parameter("SHOW_G")->asChoice()->Set_Items(Choices); pParameters->Get_Parameter("SHOW_G")->Set_Value(iG); pParameters->Get_Parameter("SHOW_B")->asChoice()->Set_Items(Choices); pParameters->Get_Parameter("SHOW_B")->Set_Value(iB); } } if( !SG_STR_CMP(pParameter->Get_Identifier(), "PROJECTION") ) { pParameters->Set_Enabled("INTERPOLATION", pParameter->asInt() == 2); } if( !SG_STR_CMP(pParameter->Get_Identifier(), "SHOW_RGB") ) { pParameters->Set_Enabled("SHOW_R", pParameter->asBool()); pParameters->Set_Enabled("SHOW_G", pParameter->asBool()); pParameters->Set_Enabled("SHOW_B", pParameter->asBool()); } return( 1 ); }
//--------------------------------------------------------- bool PGSQL_Get_Connections (CSG_Strings &Servers, double vPostGIS) { Servers.Clear(); CSG_Table Connections; RUN_MODULE(DB_PGSQL_Get_Connections, false, SET_PARAMETER("CONNECTIONS", &Connections)); // CGet_Connections for(int i=0; bResult && i<Connections.Get_Count(); i++) { if( vPostGIS <= 0.0 || vPostGIS <= Connections[i].asDouble("PostGIS") ) { Servers += Connections[i].asString(0); } } return( Servers.Get_Count() > 0 ); }
//--------------------------------------------------------- bool COGR_Import::On_Execute(void) { CSG_Strings Files; COGR_DataSource ds; //----------------------------------------------------- if( !Parameters("FILES")->asFilePath()->Get_FilePaths(Files) ) { return( false ); } //----------------------------------------------------- Parameters("SHAPES")->asShapesList()->Del_Items(); for(int i=0; i<Files.Get_Count(); i++) { Message_Add(CSG_String::Format(SG_T("%s: %s"), _TL("loading"), Files[i].c_str())); if( !ds.Create(Files[i]) ) { Message_Add(_TL("could not open data source")); } else if( ds.Get_Count() <= 0 ) { Message_Add(_TL("no layers in data source")); } else { for(int iLayer=0; iLayer<ds.Get_Count(); iLayer++) { CSG_Shapes *pShapes = ds.Read_Shapes(iLayer); if( pShapes ) { Parameters("SHAPES")->asShapesList()->Add_Item(pShapes); } } } } return( Parameters("SHAPES")->asShapesList()->Get_Count() > 0 ); }
//--------------------------------------------------------- void CTable_Query_GUI::On_Connection_Changed(CSG_Parameters *pParameters) { CSG_Parameters *pTables = pParameters->Get_Parameter("TABLES")->asParameters(); pTables->Del_Parameters(); CSG_Strings Tables; if( Get_Connection()->Get_Tables(Tables) > 0 ) { for(int i=0; i<Tables.Get_Count(); i++) { pTables->Add_Bool("", Tables[i], Tables[i], ""); } } pParameters->Get_Parameter("FIELDS")->asParameters()->Del_Parameters(); pParameters->Get_Parameter("GROUP" )->asParameters()->Del_Parameters(); On_Parameter_Changed(pParameters, pParameters->Get_Parameter("TABLES")); }
//--------------------------------------------------------- bool CTable_List::On_Execute(void) { CSG_Table *pTables = Parameters("TABLES")->asTable(); pTables->Destroy(); pTables->Set_Name(Get_Connection()->Get_Connection() + " [" + _TL("Tables") + "]"); pTables->Add_Field(_TL("Table"), SG_DATATYPE_String); pTables->Add_Field(_TL("Type" ), SG_DATATYPE_String); CSG_Strings Tables; if( Get_Connection()->Get_Tables(Tables) ) { CSG_Table t; for(int i=0; i<Tables.Get_Count(); i++) { CSG_Table_Record *pTable = pTables->Add_Record(); pTable->Set_Value(0, Tables[i]); if( Get_Connection()->Table_Load(t, "geometry_columns", "type", CSG_String::Format("f_table_name='%s'", Tables[i].c_str())) && t.Get_Count() == 1 ) { pTable->Set_Value(1, t[0][0].asString()); } else if( Get_Connection()->Table_Load(t, "raster_columns", "*", CSG_String::Format("r_table_name='%s'", Tables[i].c_str())) && t.Get_Count() == 1 ) { pTable->Set_Value(1, "RASTER"); } else { pTable->Set_Value(1, "TABLE"); } } } return( pTables->Get_Count() > 0 ); }
//--------------------------------------------------------- bool CPointCloud_Create_SPCVF::On_Execute(void) { CSG_Strings sFiles; CSG_String sFileInputList, sFileName; int iMethodPaths; CSG_MetaData SPCVF; CSG_Projection projSPCVF; double dNoData; std::vector<TSG_Data_Type> vFieldTypes; std::vector<CSG_String> vFieldNames; double dBBoxXMin = std::numeric_limits<int>::max(); double dBBoxYMin = std::numeric_limits<int>::max(); double dBBoxXMax = std::numeric_limits<int>::min(); double dBBoxYMax = std::numeric_limits<int>::min(); int iSkipped = 0, iEmpty = 0; int iDatasetCount = 0; double dPointCount = 0.0; double dZMin = std::numeric_limits<double>::max(); double dZMax = -std::numeric_limits<double>::max(); //----------------------------------------------------- sFileName = Parameters("FILENAME")->asString(); iMethodPaths = Parameters("METHOD_PATHS")->asInt(); sFileInputList = Parameters("INPUT_FILE_LIST")->asString(); //----------------------------------------------------- if( !Parameters("FILES")->asFilePath()->Get_FilePaths(sFiles) && sFileInputList.Length() <= 0 ) { SG_UI_Msg_Add_Error(_TL("Please provide some input files!")); return( false ); } //----------------------------------------------------- if( sFiles.Get_Count() <= 0 ) { CSG_Table *pTable = new CSG_Table(); if( !pTable->Create(sFileInputList, TABLE_FILETYPE_Text_NoHeadLine) ) { SG_UI_Msg_Add_Error(_TL("Input file list could not be opened!")); delete( pTable ); return( false ); } sFiles.Clear(); for (int i=0; i<pTable->Get_Record_Count(); i++) { sFiles.Add(pTable->Get_Record(i)->asString(0)); } delete( pTable ); } //----------------------------------------------------- SPCVF.Set_Name(SG_T("SPCVFDataset")); SPCVF.Add_Property(SG_T("Version"), SG_T("1.1")); switch( iMethodPaths ) { default: case 0: SPCVF.Add_Property(SG_T("Paths"), SG_T("absolute")); break; case 1: SPCVF.Add_Property(SG_T("Paths"), SG_T("relative")); break; } //----------------------------------------------------- CSG_MetaData *pSPCVFHeader = SPCVF.Add_Child( SG_T("Header")); CSG_MetaData *pSPCVFFiles = pSPCVFHeader->Add_Child( SG_T("Datasets")); CSG_MetaData *pSPCVFPoints = pSPCVFHeader->Add_Child( SG_T("Points")); CSG_MetaData *pSRS = pSPCVFHeader->Add_Child( SG_T("SRS")); CSG_MetaData *pSPCVFBBox = pSPCVFHeader->Add_Child( SG_T("BBox")); CSG_MetaData *pSPCVFZStats = pSPCVFHeader->Add_Child( SG_T("ZStats")); CSG_MetaData *pSPCVFNoData = pSPCVFHeader->Add_Child( SG_T("NoData")); CSG_MetaData *pSPCVFAttr = pSPCVFHeader->Add_Child( SG_T("Attributes")); CSG_MetaData *pSPCVFDatasets = NULL; //----------------------------------------------------- for(int i=0; i<sFiles.Get_Count() && Set_Progress(i, sFiles.Get_Count()); i++) { CSG_PointCloud *pPC = SG_Create_PointCloud(sFiles[i]); //----------------------------------------------------- if( i==0 ) // first dataset determines projection, NoData value and table structure { projSPCVF = pPC->Get_Projection(); dNoData = pPC->Get_NoData_Value(); pSPCVFNoData->Add_Property(SG_T("Value"), dNoData); pSPCVFAttr->Add_Property(SG_T("Count"), pPC->Get_Field_Count()); for(int iField=0; iField<pPC->Get_Field_Count(); iField++) { vFieldTypes.push_back(pPC->Get_Field_Type(iField)); vFieldNames.push_back(pPC->Get_Field_Name(iField)); CSG_MetaData *pSPCVFField = pSPCVFAttr->Add_Child(CSG_String::Format(SG_T("Field_%d"), iField + 1)); pSPCVFField->Add_Property(SG_T("Name"), pPC->Get_Field_Name(iField)); pSPCVFField->Add_Property(SG_T("Type"), gSG_Data_Type_Identifier[pPC->Get_Field_Type(iField)]); } if( projSPCVF.is_Okay() ) { pSRS->Add_Property(SG_T("Projection"), projSPCVF.Get_Name()); pSRS->Add_Property(SG_T("WKT"), projSPCVF.Get_WKT()); } else { pSRS->Add_Property(SG_T("Projection"), SG_T("Undefined Coordinate System")); } pSPCVFDatasets = SPCVF.Add_Child(SG_T("Datasets")); } else // validate projection, NoData value and table structure { bool bSkip = false; if( pPC->Get_Field_Count() != (int)vFieldTypes.size() ) { bSkip = true; } if( !bSkip && projSPCVF.is_Okay() ) { if ( !pPC->Get_Projection().is_Okay() || SG_STR_CMP(pPC->Get_Projection().Get_WKT(), projSPCVF.Get_WKT()) ) { bSkip = true; } } if( !bSkip ) { for(int iField=0; iField<pPC->Get_Field_Count(); iField++) { if( pPC->Get_Field_Type(iField) != vFieldTypes.at(iField) ) { bSkip = true; break; } if( SG_STR_CMP(pPC->Get_Field_Name(iField), vFieldNames.at(iField)) ) { bSkip = true; break; } } } if( bSkip ) { SG_UI_Msg_Add(CSG_String::Format(_TL("Skipping dataset %s because of incompatibility with the first input dataset!"), sFiles[i].c_str()), true); delete( pPC ); iSkipped++; continue; } } //----------------------------------------------------- if( pPC->Get_Point_Count() <= 0 ) { delete( pPC ); iEmpty++; continue; } //----------------------------------------------------- CSG_MetaData *pDataset = pSPCVFDatasets->Add_Child(SG_T("PointCloud")); CSG_String sFilePath; switch( iMethodPaths ) { default: case 0: sFilePath = SG_File_Get_Path_Absolute(sFiles.Get_String(i)); break; case 1: sFilePath = SG_File_Get_Path_Relative(SG_File_Get_Path(sFileName), sFiles.Get_String(i)); break; } sFilePath.Replace(SG_T("\\"), SG_T("/")); pDataset->Add_Property(SG_T("File"), sFilePath); pDataset->Add_Property(SG_T("Points"), pPC->Get_Point_Count()); pDataset->Add_Property(SG_T("ZMin"), pPC->Get_ZMin()); pDataset->Add_Property(SG_T("ZMax"), pPC->Get_ZMax()); //----------------------------------------------------- CSG_MetaData *pBBox = pDataset->Add_Child(SG_T("BBox")); pBBox->Add_Property(SG_T("XMin"), pPC->Get_Extent().Get_XMin()); pBBox->Add_Property(SG_T("YMin"), pPC->Get_Extent().Get_YMin()); pBBox->Add_Property(SG_T("XMax"), pPC->Get_Extent().Get_XMax()); pBBox->Add_Property(SG_T("YMax"), pPC->Get_Extent().Get_YMax()); if( dBBoxXMin > pPC->Get_Extent().Get_XMin() ) dBBoxXMin = pPC->Get_Extent().Get_XMin(); if( dBBoxYMin > pPC->Get_Extent().Get_YMin() ) dBBoxYMin = pPC->Get_Extent().Get_YMin(); if( dBBoxXMax < pPC->Get_Extent().Get_XMax() ) dBBoxXMax = pPC->Get_Extent().Get_XMax(); if( dBBoxYMax < pPC->Get_Extent().Get_YMax() ) dBBoxYMax = pPC->Get_Extent().Get_YMax(); iDatasetCount += 1; dPointCount += pPC->Get_Point_Count(); if( dZMin > pPC->Get_ZMin() ) dZMin = pPC->Get_ZMin(); if( dZMax < pPC->Get_ZMax() ) dZMax = pPC->Get_ZMax(); delete( pPC ); } //----------------------------------------------------- pSPCVFBBox->Add_Property(SG_T("XMin"), dBBoxXMin); pSPCVFBBox->Add_Property(SG_T("YMin"), dBBoxYMin); pSPCVFBBox->Add_Property(SG_T("XMax"), dBBoxXMax); pSPCVFBBox->Add_Property(SG_T("YMax"), dBBoxYMax); pSPCVFFiles->Add_Property(SG_T("Count"), iDatasetCount); pSPCVFPoints->Add_Property(SG_T("Count"), CSG_String::Format(SG_T("%.0f"), dPointCount)); pSPCVFZStats->Add_Property(SG_T("ZMin"), dZMin); pSPCVFZStats->Add_Property(SG_T("ZMax"), dZMax); //----------------------------------------------------- if( !SPCVF.Save(sFileName) ) { SG_UI_Msg_Add_Error(CSG_String::Format(_TL("Unable to save %s file!"), sFileName.c_str())); return( false ); } //----------------------------------------------------- if( iSkipped > 0 ) { SG_UI_Msg_Add(CSG_String::Format(_TL("WARNING: %d dataset(s) skipped because of incompatibilities!"), iSkipped), true); } if( iEmpty > 0 ) { SG_UI_Msg_Add(CSG_String::Format(_TL("WARNING: %d dataset(s) skipped because they are empty!"), iEmpty), true); } SG_UI_Msg_Add(CSG_String::Format(_TL("SPCVF successfully created from %d dataset(s)."), iDatasetCount), true); //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CPresence_Prediction::On_Execute(void) { //----------------------------------------------------- EventSet DL_Events ; m_DL_Events = &DL_Events ; GISTrainer DL_Trainer; m_DL_Trainer = &DL_Trainer; MaxEntModel DL_Model ; m_DL_Model = &DL_Model ; m_YT_Model.clear(); //----------------------------------------------------- CSG_Grid *pPrediction = Parameters("PREDICTION" )->asGrid(); CSG_Grid *pProbability = Parameters("PROBABILITY")->asGrid(); if( !pPrediction ->Get_Range() ) DataObject_Set_Colors(pPrediction , 11, SG_COLORS_YELLOW_GREEN); if( !pProbability->Get_Range() ) DataObject_Set_Colors(pProbability, 11, SG_COLORS_YELLOW_GREEN); m_Method = Parameters("METHOD" )->asInt (); m_nNumClasses = Parameters("NUM_CLASSES" )->asInt (); m_bYT_Weights = Parameters("YT_NUMASREAL")->asBool(); //----------------------------------------------------- CSG_Array Features; if( !Get_Features(Features) ) { Error_Set(_TL("invalid features")); return( false ); } //----------------------------------------------------- if( m_Method == 0 && SG_File_Exists(Parameters("YT_FILE_LOAD")->asString()) ) { if( !Get_File(Parameters("YT_FILE_LOAD")->asString()) ) { return( false ); } } else if( !Get_Training() ) { return( false ); } //----------------------------------------------------- Process_Set_Text(_TL("prediction")); for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { int i; CSG_Strings Values; for(i=0; i<m_nFeatures; i++) { if( !m_Features[i].pGrid->is_NoData(x, y) ) { Values.Add(Get_Feature(x, y, i)); } else { break; } } if( Values.Get_Count() != m_nFeatures ) { pPrediction ->Set_NoData(x, y); pProbability->Set_NoData(x, y); } else switch( m_Method ) { //--------------------------------------------- default: // Kyoshida { ME_Sample Sample; for(i=0; i<m_nFeatures; i++) { if( m_bYT_Weights && m_Features[i].bNumeric ) { Sample.add_feature(m_Features[i].Name, m_Features[i].pGrid->asDouble(x, y)); } else { Sample.add_feature(Values[i].b_str()); } } vector<double> Probs = m_YT_Model.classify(Sample); pPrediction ->Set_Value(x, y, m_YT_Model.get_class_id(Sample.label) == 0 ? 1 : 0); pProbability->Set_Value(x, y, Probs[0]); } break; //--------------------------------------------- case 1: // Dekang Lin { MaxEntEvent Event; Event.count(1); for(i=0; i<m_nFeatures; i++) { Event.push_back(m_DL_Trainer->getId(Values[i].b_str())); } vector<double> Probs; pPrediction ->Set_Value(x, y, m_DL_Model->getProbs(Event, Probs) == 0 ? 1 : 0); pProbability->Set_Value(x, y, Probs[0]); } break; } } } return( true ); }
//--------------------------------------------------------- int CSG_ODBC_Connections::Get_Servers(CSG_Strings &Servers) { Servers = Get_Servers(); return( Servers.Get_Count() ); }
//--------------------------------------------------------- bool CPresence_Prediction::Get_Training(int x, int y, const char *ID) { int i; //----------------------------------------------------- CSG_Strings Values; for(i=0; i<m_nFeatures; i++) { if( !m_Features[i].pGrid->is_InGrid(x, y) ) { return( false ); } Values.Add(Get_Feature(x, y, i)); } //----------------------------------------------------- switch( m_Method ) { //----------------------------------------------------- default: // Kyoshida { ME_Sample Sample(ID); for(i=0; i<m_nFeatures; i++) { if( m_bYT_Weights && m_Features[i].bNumeric ) { Sample.add_feature(m_Features[i].Name, m_Features[i].pGrid->asDouble(x, y)); } else { Sample.add_feature(Values[i].b_str()); } } m_YT_Model.add_training_sample(Sample); } break; //----------------------------------------------------- case 1: // Dekang Lin { MaxEntEvent *pEvent = new MaxEntEvent; pEvent->count(1); pEvent->classId(m_DL_Trainer->getClassId(ID)); for(i=0; i<m_nFeatures; i++) { pEvent->push_back(m_DL_Trainer->getId(Values[i].b_str())); } m_DL_Events->push_back(pEvent); } break; } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CPointCloud_From_Text_File::On_Execute(void) { //----------------------------------------------------- CSG_File Stream; if( !Stream.Open(Parameters("FILE")->asString(), SG_FILE_R, false) ) { Error_Set(_TL("Unable to open input file!")); return( false ); } //----------------------------------------------------- int xField = Parameters("XFIELD")->asInt() - 1; int yField = Parameters("YFIELD")->asInt() - 1; int zField = Parameters("ZFIELD")->asInt() - 1; char Separator; switch( Parameters("SEPARATOR")->asInt() ) { default: Separator = '\t'; break; case 1: Separator = ' '; break; case 2: Separator = ','; break; } //----------------------------------------------------- CSG_String sLine; CSG_Strings Values; if( !Stream.Read_Line(sLine) ) { Error_Set(_TL("Empty file!")); return( false ); } if( Parameters("SKIP_HEADER")->asBool() ) // header contains field names { CSG_String_Tokenizer tokValues(sLine, Separator); // read each field name for later use while( tokValues.Has_More_Tokens() ) { Values += tokValues.Get_Next_Token(); } } else { Stream.Seek_Start(); } //----------------------------------------------------- CSG_PointCloud *pPoints = SG_Create_PointCloud(); pPoints->Set_Name(SG_File_Get_Name(Parameters("FILE")->asString(), false)); Parameters("POINTS")->Set_Value(pPoints); CSG_Array_Int Fields; //----------------------------------------------------- if( SG_UI_Get_Window_Main() ) { CSG_Parameters &Fields = *Parameters("FIELDSPECS")->asParameters(); int nFields = Fields.Get_Count() / 2; CSG_String Names, Types; for(int iField=0; iField<nFields; iField++) { Names += CSG_String::Format("%s;", Fields(CSG_String::Format("NAME%03d", iField))->asString()); Types += CSG_String::Format("%d;", Fields(CSG_String::Format("TYPE%03d", iField))->asInt ()); } Parameters("FIELDNAMES")->Set_Value(Names); Parameters("FIELDTYPES")->Set_Value(Types); } { TSG_Data_Type Type = SG_DATATYPE_Float; // default CSG_String_Tokenizer tokFields(Parameters("FIELDS" )->asString(), ";"); CSG_String_Tokenizer tokTypes (Parameters("FIELDTYPES")->asString(), ";"); CSG_String_Tokenizer tokNames (Parameters("FIELDNAMES")->asString(), ";"); while( tokFields.Has_More_Tokens() ) { int iField; if( !tokFields.Get_Next_Token().asInt(iField) || iField < 1 ) { Error_Set(_TL("Error parsing attribute field index")); return( false ); } Fields += iField - 1; CSG_String Name; if( tokNames.Has_More_Tokens() ) { Name = tokNames.Get_Next_Token(); Name.Trim(true); Name.Trim(false); } if( Name.is_Empty() ) { if( iField - 1 < Values.Get_Count() ) { Name = Values[iField - 1]; } else { Name.Printf("FIELD%02d", iField); } } if( tokTypes.Has_More_Tokens() ) { Get_Data_Type(Type, tokTypes.Get_Next_Token()); } pPoints->Add_Field(Name, Type); } } //----------------------------------------------------- Process_Set_Text(_TL("Importing data ...")); int nLines = 0; sLong Length = Stream.Length(); while( Stream.Read_Line(sLine) ) { nLines++; if( pPoints->Get_Count() % 10000 == 0 && !Set_Progress((double)Stream.Tell(), (double)Length) ) { return( true ); // user break } //------------------------------------------------- CSG_String_Tokenizer tokValues(sLine, Separator); Values.Clear(); while( tokValues.Has_More_Tokens() ) // read every column in this line and fill vector { Values += tokValues.Get_Next_Token(); } //------------------------------------------------- double x, y, z; if( xField >= Values.Get_Count() || !Values[xField].asDouble(x) || yField >= Values.Get_Count() || !Values[yField].asDouble(y) || zField >= Values.Get_Count() || !Values[zField].asDouble(z) ) { Message_Fmt("\n%s: %s [%d]", _TL("Warning"), _TL("Skipping misformatted line"), nLines); continue; } pPoints->Add_Point(x, y, z); //------------------------------------------------- for(int iAttribute=0; iAttribute<pPoints->Get_Attribute_Count(); iAttribute++) { if( Fields[iAttribute] >= Values.Get_Count() ) { pPoints->Set_NoData(3 + iAttribute); } else switch( pPoints->Get_Attribute_Type(iAttribute) ) { case SG_DATATYPE_String: pPoints->Set_Attribute(iAttribute, Values[Fields[iAttribute]]); break; default: { double Value; if( Values[Fields[iAttribute]].asDouble(Value) ) { pPoints->Set_Attribute(iAttribute, Value); } else { pPoints->Set_NoData(3 + iAttribute); } } break; } } } //----------------------------------------------------- DataObject_Set_Parameter(pPoints, "DISPLAY_VALUE_AGGREGATE", 3); // highest z DataObject_Set_Parameter(pPoints, "COLORS_TYPE" , 3); // graduated colors DataObject_Set_Parameter(pPoints, "METRIC_ATTRIB" , 2); // z attrib DataObject_Set_Parameter(pPoints, "METRIC_ZRANGE", pPoints->Get_Minimum(2), pPoints->Get_Maximum(2)); DataObject_Update(pPoints); //----------------------------------------------------- if( nLines > pPoints->Get_Count() ) { Message_Add(" ", true); Message_Fmt("%s: %d %s", _TL("Warning"), nLines - pPoints->Get_Count(), _TL("invalid points have been skipped")); } Message_Add(" ", true); Message_Fmt("%d %s", pPoints->Get_Count(), _TL("points have been imported with success")); return( true ); }
//--------------------------------------------------------- bool CTL_Merge::On_Execute(void) { CSG_String Target = Parameters("TARGET")->asString(); CSG_Strings Files; if( !Parameters("FILES")->asFilePath()->Get_FilePaths(Files) || Files.Get_Count() <= 1 ) { Error_Set(SG_T("no files to merge")); return( false ); } //----------------------------------------------------- int i, j; CSG_Table Merge; if( !Merge.Create(Files[0], TABLE_FILETYPE_Text) ) { Merge.Destroy(); Merge.Add_Field(SG_T("ORIGINAL") , SG_DATATYPE_String); Merge.Add_Field(SG_T("TRANSLATION") , SG_DATATYPE_String); } Merge.Save(Target, TABLE_FILETYPE_Text); //----------------------------------------------------- for(i=1; i<Files.Get_Count() && Process_Get_Okay(); i++) { CSG_Translator Translator(Target, false); CSG_Table Add(Target, TABLE_FILETYPE_Text); if( Merge.Create(Files[i], TABLE_FILETYPE_Text) ) { for(j=0; j<Merge.Get_Count() && Set_Progress(j, Merge.Get_Count()); j++) { if( !Translator.Get_Translation(Merge[j].asString(0), true) ) { Add.Add_Record(Merge.Get_Record(j)); } } if( Add.Get_Count() > Translator.Get_Count() ) { Add.Save(Target, TABLE_FILETYPE_Text); } } } //----------------------------------------------------- for(i=Merge.Get_Count()-1; i>0 && Process_Get_Okay(); i--) { if( !SG_STR_CMP(Merge[i].asString(0), Merge[i - 1].asString(0)) ) { Merge.Del_Record(i); } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool Cdodproperror::On_Execute(void) { if (!GetParameterValues()) { return false; } CSG_String TempDirPath = Parameters("TEMP_DIR")->asFilePath()->asString(); LogOutput = SG_File_Make_Path(TempDirPath, CSG_String("out"), CSG_String("txt")); LogError = SG_File_Make_Path(TempDirPath, CSG_String("error"), CSG_String("txt"));; NewDEM_InputPath = SG_File_Make_Path(TempDirPath, CSG_String("newdem"), CSG_String("tif")); OldDEM_InputPath = SG_File_Make_Path(TempDirPath, CSG_String("olddem"), CSG_String("tif")); PropError_InputPath = SG_File_Make_Path(TempDirPath, CSG_String("properror"), CSG_String("tif")); RawDoD_OutputPath = SG_File_Make_Path(TempDirPath, CSG_String("rawdodoutput"), CSG_String("tif")); ThresholdedDoD_OutputPath = SG_File_Make_Path(TempDirPath, CSG_String("threshdodoutput"), CSG_String("tif")); // convert grids to tiffs for command input CSG_Grid* InputGrids [3] = {NewDEM, OldDEM, PropError}; CSG_Strings InputGridPaths = CSG_Strings(); InputGridPaths.Add(NewDEM_InputPath); InputGridPaths.Add(OldDEM_InputPath); InputGridPaths.Add(PropError_InputPath); if (!SaveGridsAsTIFF(InputGrids, InputGridPaths)) { return false; } CSG_Strings OutputGridPaths = CSG_Strings(); OutputGridPaths.Add(RawDoD_OutputPath); OutputGridPaths.Add(ThresholdedDoD_OutputPath); CSG_Strings OutputGridNames = CSG_Strings(); OutputGridNames.Add("Raw DoD"); OutputGridNames.Add("Thresholded DoD"); // delete old output files (GCD throws an error if a file already exists) if (!DeleteFiles(OutputGridPaths)) { return false; } CSG_String CMD = CSG_String::Format(SG_T("\"\"%s\" %s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" >\"%s\" 2>\"%s\"\""), GCD.c_str(), GCD_CMD.c_str(), NewDEM_InputPath.c_str(), OldDEM_InputPath.c_str(), PropError_InputPath.c_str(), RawDoD_OutputPath.c_str(), ThresholdedDoD_OutputPath.c_str(), LogOutput.c_str(), LogError.c_str()); Message_Add(CSG_String("Executing: ") + CMD); if (system(CMD.b_str()) != 0) { Message_Dlg(CSG_String::Format(SG_T("Error while executing %s, see Execution Log for details"), GCD_CMD.c_str())); DisplayLogs(); return false; } CSG_Grid* OutputGrids [3] = {RawDoD, ThresholdedDoD}; if (!LoadTIFFsAsGrids(OutputGridPaths, OutputGrids, OutputGridNames)) { return false; } Parameters("RAW_DOD")->Set_Value(RawDoD); Parameters("THRESHOLDED_DOD")->Set_Value(ThresholdedDoD); ApplyColors(NewDEM, RawDoD); ApplyColors(NewDEM, ThresholdedDoD); DisplayFile(LogOutput); return true; }
//--------------------------------------------------------- bool CCMD_Module::_Save_Output(CSG_Parameters *pParameters) { for(int j=0; j<pParameters->Get_Count(); j++) { wxString FileName; CSG_Parameter *pParameter = pParameters->Get_Parameter(j); //------------------------------------------------- if( pParameter->is_Input() ) { if( pParameter->is_DataObject() ) { CSG_Data_Object *pObject = pParameter->asDataObject(); if( pObject && pObject->is_Modified() && SG_File_Exists(pObject->Get_File_Name()) ) { pObject->Save(pObject->Get_File_Name()); } } else if( pParameter->is_DataObject_List() ) { for(int i=0; i<pParameter->asList()->Get_Count(); i++) { CSG_Data_Object *pObject = pParameter->asList()->asDataObject(i); if( pObject->is_Modified() && SG_File_Exists(pObject->Get_File_Name()) ) { pObject->Save(pObject->Get_File_Name()); } } } } //------------------------------------------------- else if( pParameter->is_Output() && m_CMD.Found(_Get_ID(pParameter), &FileName) && FileName.Length() > 0 ) { if( pParameter->is_DataObject() ) { if( pParameter->asDataObject() ) { pParameter->asDataObject()->Save(&FileName); } } else if( pParameter->is_DataObject_List() ) { CSG_Strings FileNames; while( FileName.Length() > 0 ) { CSG_String s(&FileName); s = s.BeforeFirst(';'); if( s.Length() > 0 ) { FileNames += s; FileName = FileName.AfterFirst(';'); } else { FileNames += &FileName; FileName .Clear(); } } int nFileNames = pParameter->asList()->Get_Count() <= FileNames.Get_Count() ? FileNames.Get_Count() : FileNames.Get_Count() - 1; for(int i=0; i<pParameter->asList()->Get_Count(); i++) { if( i < nFileNames ) { pParameter->asList()->asDataObject(i)->Save(FileNames[i]); } else { pParameter->asList()->asDataObject(i)->Save(CSG_String::Format(SG_T("%s_%0*d"), FileNames[FileNames.Get_Count() - 1].c_str(), SG_Get_Digit_Count(pParameter->asList()->Get_Count()), 1 + i - nFileNames )); } } } } } return( true ); }
//--------------------------------------------------------- bool CLAS_Import::On_Execute(void) { CSG_Parameter_PointCloud_List *pPointsList; bool bValidity; CSG_Strings Files; int RGBrange; int cntInvalid = 0; bValidity = Parameters("VALID")->asBool(); RGBrange = Parameters("RGB_RANGE")->asInt(); //----------------------------------------------------- if( !Parameters("FILES")->asFilePath()->Get_FilePaths(Files) ) { return( false ); } //----------------------------------------------------- pPointsList = Parameters("POINTS")->asPointCloudList(); pPointsList ->Del_Items(); for(int i=0; i<Files.Get_Count(); i++) { SG_UI_Msg_Add(CSG_String::Format(_TL("Parsing %s ... "), SG_File_Get_Name(Files[i], true).c_str()), true); std::ifstream ifs; ifs.open(Files[i].b_str(), std::ios::in | std::ios::binary); if( !ifs ) { SG_UI_Msg_Add_Error(CSG_String::Format(_TL("Unable to open LAS file!"))); continue; } //----------------------------------------------------- // Check if LAS version is supported liblas::LASReader *pReader; try { pReader = new liblas::LASReader(ifs); } catch(std::exception &e) { SG_UI_Msg_Add_Error(CSG_String::Format(_TL("LAS header exception: %s"), e.what())); ifs.close(); return( false ); } catch(...) { SG_UI_Msg_Add_Error(CSG_String::Format(_TL("Unknown LAS header exception!"))); ifs.close(); return( false ); } delete (pReader); ifs.clear(); //----------------------------------------------------- liblas::LASReader reader(ifs); liblas::LASHeader const& header = reader.GetHeader(); //----------------------------------------------------- int nFields, iField[VAR_Count]; CSG_PointCloud *pPoints = SG_Create_PointCloud(); pPoints->Set_Name(SG_File_Get_Name(Files[i], false)); nFields = 3; ADD_FIELD("T", VAR_T, _TL("gps-time") , SG_DATATYPE_Double); // SG_DATATYPE_Long ADD_FIELD("i", VAR_i, _TL("intensity") , SG_DATATYPE_Float); // SG_DATATYPE_Word ADD_FIELD("a", VAR_a, _TL("scan angle") , SG_DATATYPE_Float); // SG_DATATYPE_Byte ADD_FIELD("r", VAR_r, _TL("number of the return") , SG_DATATYPE_Int); ADD_FIELD("c", VAR_c, _TL("classification") , SG_DATATYPE_Int); // SG_DATATYPE_Byte ADD_FIELD("u", VAR_u, _TL("user data") , SG_DATATYPE_Double); // SG_DATATYPE_Byte ADD_FIELD("n", VAR_n, _TL("number of returns of given pulse") , SG_DATATYPE_Int); ADD_FIELD("R", VAR_R, _TL("red channel color") , SG_DATATYPE_Int); // SG_DATATYPE_Word ADD_FIELD("G", VAR_G, _TL("green channel color") , SG_DATATYPE_Int); ADD_FIELD("B", VAR_B, _TL("blue channel color") , SG_DATATYPE_Int); ADD_FIELD("e", VAR_e, _TL("edge of flight line flag") , SG_DATATYPE_Char); ADD_FIELD("d", VAR_d, _TL("direction of scan flag") , SG_DATATYPE_Char); ADD_FIELD("p", VAR_p, _TL("point source ID") , SG_DATATYPE_Int); // SG_DATATYPE_Word ADD_FIELD("C", VAR_C, _TL("rgb color") , SG_DATATYPE_Int); //----------------------------------------------------- int iPoint = 0; try { while( reader.ReadNextPoint() ) { if (iPoint % 100000) SG_UI_Process_Set_Progress(iPoint, header.GetPointRecordsCount()); liblas::LASPoint const& point = reader.GetPoint(); if( bValidity ) { if( !point.IsValid() ) { cntInvalid++; continue; } } pPoints->Add_Point(point.GetX(), point.GetY(), point.GetZ()); if( iField[VAR_T] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_T], point.GetTime()); if( iField[VAR_i] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_i], point.GetIntensity()); if( iField[VAR_a] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_a], point.GetScanAngleRank()); if( iField[VAR_r] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_r], point.GetReturnNumber()); if( iField[VAR_c] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_c], point.GetClassification()); if( iField[VAR_u] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_u], point.GetUserData()); if( iField[VAR_n] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_n], point.GetNumberOfReturns()); if( iField[VAR_R] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_R], point.GetColor().GetRed()); if( iField[VAR_G] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_G], point.GetColor().GetGreen()); if( iField[VAR_B] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_B], point.GetColor().GetBlue()); if( iField[VAR_e] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_e], point.GetFlightLineEdge()); if( iField[VAR_d] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_d], point.GetScanDirection()); if( iField[VAR_p] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_p], point.GetPointSourceID()); if( iField[VAR_C] > 0 ) { double r, g, b; r = point.GetColor().GetRed(); g = point.GetColor().GetGreen(); b = point.GetColor().GetBlue(); if (RGBrange == 0) // 16 bit { r = r / 65535 * 255; g = g / 65535 * 255; b = b / 65535 * 255; } pPoints->Set_Value(iPoint, iField[VAR_C], SG_GET_RGB(r, g, b)); } iPoint++; } } catch(std::exception &e) { SG_UI_Msg_Add_Error(CSG_String::Format(_TL("LAS reader exception: %s"), e.what())); ifs.close(); return( false ); } catch(...) { SG_UI_Msg_Add_Error(CSG_String::Format(_TL("Unknown LAS reader exception!"))); ifs.close(); return( false ); } ifs.close(); pPointsList->Add_Item(pPoints); DataObject_Add(pPoints); //----------------------------------------------------- CSG_Parameters sParms; DataObject_Get_Parameters(pPoints, sParms); if (sParms("METRIC_ATTRIB") && sParms("COLORS_TYPE") && sParms("METRIC_COLORS") && sParms("METRIC_ZRANGE") && sParms("DISPLAY_VALUE_AGGREGATE")) { sParms("DISPLAY_VALUE_AGGREGATE")->Set_Value(3); // highest z sParms("COLORS_TYPE")->Set_Value(2); // graduated color sParms("METRIC_COLORS")->asColors()->Set_Count(255); // number of colors sParms("METRIC_ATTRIB")->Set_Value(2); // z attrib sParms("METRIC_ZRANGE")->asRange()->Set_Range(pPoints->Get_Minimum(2),pPoints->Get_Maximum(2)); } DataObject_Set_Parameters(pPoints, sParms); SG_UI_Msg_Add(_TL("okay"), false); } //----------------------------------------------------- if( bValidity && cntInvalid > 0 ) SG_UI_Msg_Add(CSG_String::Format(_TL("WARNING: %d invalid points skipped!"), cntInvalid), true); return( true ); }