//--------------------------------------------------------- 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::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 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 ); }
//--------------------------------------------------------- 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_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 ); }