//--------------------------------------------------------- bool COGR_Export_KML::On_Execute(void) { CSG_String File_Name, Driver_Name = "KML"; CSG_Shapes *pShapes, Shapes; pShapes = Parameters("SHAPES")->asShapes(); File_Name = Parameters("FILE" )->asString(); //----------------------------------------------------- if( pShapes->Get_Projection().Get_Type() == SG_PROJ_TYPE_CS_Undefined ) { Message_Add(_TL("layer uses undefined coordinate system, assuming geographic coordinates")); } else if( pShapes->Get_Projection().Get_Type() != SG_PROJ_TYPE_CS_Geographic ) { Message_Add(CSG_String::Format(SG_T("\n%s (%s: %s)\n"), _TL("re-projection to geographic coordinates"), _TL("original"), pShapes->Get_Projection().Get_Name().c_str()), false); bool bResult; SG_RUN_MODULE(bResult, "pj_proj4", 2, pModule->Get_Parameters()->Set_Parameter(SG_T("SOURCE"), pShapes) && pModule->Get_Parameters()->Set_Parameter(SG_T("TARGET"), &Shapes) && pModule->Get_Parameters()->Set_Parameter(SG_T("CRS_PROJ4"), SG_T("+proj=longlat +ellps=WGS84 +datum=WGS84")) ); if( bResult ) { pShapes = &Shapes; Message_Add(CSG_String::Format(SG_T("\n%s: %s\n"), _TL("re-projection"), _TL("success")), false); } else { Message_Add(CSG_String::Format(SG_T("\n%s: %s\n"), _TL("re-projection"), _TL("failed")), false); } } //----------------------------------------------------- CSG_OGR_DataSource DataSource; if( DataSource.Create(File_Name, Driver_Name) == false ) { Message_Add(_TL("could not create KML file")); } else if( DataSource.Write(pShapes, Driver_Name) ) { return( true ); } return( false ); }
bool CGridNet::On_Execute(void) { TSG_Data_Type Type; CSG_String InputBasename = CSG_String("input"); CSG_String OutputBasename = CSG_String("output"); CSG_String FLOWD8_INPUT_FileName, FLOWD8_INPUT_FilePath; CSG_String LONGEST_OUTPUT_FileName, LONGEST_OUTPUT_FilePath; CSG_String TOTAL_LENGTH_OUTPUT_FileName, TOTAL_LENGTH_OUTPUT_FilePath; CSG_String ORDER_OUTPUT_FileName, ORDER_OUTPUT_FilePath; CSG_String OUTLET_INPUT_FileName, OUTLET_INPUT_FilePath, MASK_INPUT_FileName, MASK_INPUT_FilePath; CSG_String GDALDriver, sCmd, TempDirPath, TauDEMBinDir, BinaryName, BinaryPath, LogFile; CSG_String LONGESTName, LENGTHName, ORDERName; CSG_Projection Projection; CSG_GDAL_DataSet DataSet; CSG_Grid *FLOWD8_INPUT_Grid, *LONGEST_OUTPUT_Grid, *TOTAL_LENGTH_OUTPUT_Grid, *ORDER_OUTPUT_Grid, *MASK_INPUT_Grid; CSG_Shapes *OUTLET_INPUT_Grid; int Threshold, nproc; FLOWD8_INPUT_Grid = Parameters("FLOWD8_INPUT")->asGrid(); LONGEST_OUTPUT_Grid = Parameters("LONGEST_OUTPUT")->asGrid(); TOTAL_LENGTH_OUTPUT_Grid = Parameters("TOTAL_LENGTH_OUTPUT")->asGrid(); ORDER_OUTPUT_Grid = Parameters("ORDER_OUTPUT")->asGrid(); MASK_INPUT_Grid = Parameters("MASK_INPUT")->asGrid(); OUTLET_INPUT_Grid = Parameters("OUTLET_INPUT")->asShapes(); Threshold = Parameters("THRESHOLD")->asInt(); nproc = Parameters("NPROC")->asInt(); GDALDriver = CSG_String("GTiff"); Get_Projection(Projection); Type = FLOWD8_INPUT_Grid->Get_Type(); //TempDirPath = SG_File_Get_Path_Absolute(CSG_String("taudem_tmp")); TempDirPath = Parameters("TEMP_DIR")->asFilePath()->asString(); FLOWD8_INPUT_FileName = InputBasename + CSG_String("p"); FLOWD8_INPUT_FilePath = SG_File_Make_Path(TempDirPath, FLOWD8_INPUT_FileName, CSG_String("tif")); LONGEST_OUTPUT_FileName = OutputBasename + CSG_String("plen"); LONGEST_OUTPUT_FilePath = SG_File_Make_Path(TempDirPath, LONGEST_OUTPUT_FileName, CSG_String("tif")); TOTAL_LENGTH_OUTPUT_FileName = OutputBasename + CSG_String("tlen"); TOTAL_LENGTH_OUTPUT_FilePath = SG_File_Make_Path(TempDirPath, TOTAL_LENGTH_OUTPUT_FileName, CSG_String("tif")); ORDER_OUTPUT_FileName = OutputBasename + CSG_String("gord"); ORDER_OUTPUT_FilePath = SG_File_Make_Path(TempDirPath, ORDER_OUTPUT_FileName, CSG_String("tif")); OUTLET_INPUT_FileName = InputBasename + CSG_String("o"); OUTLET_INPUT_FilePath = SG_File_Make_Path(TempDirPath, OUTLET_INPUT_FileName, CSG_String("shp")); MASK_INPUT_FileName = InputBasename + CSG_String("wg"); MASK_INPUT_FilePath = SG_File_Make_Path(TempDirPath, MASK_INPUT_FileName, CSG_String("tif")); LogFile = SG_File_Make_Path(TempDirPath, CSG_String("taudem_log.txt")); LogFile = SG_File_Get_Path_Absolute(LogFile); TauDEMBinDir = SG_File_Make_Path(CSG_String("bin"), CSG_String("TauDEM")); TauDEMBinDir = SG_File_Get_Path_Absolute(TauDEMBinDir); // optional flags CSG_String OptionalFlags = CSG_String(""); if (OUTLET_INPUT_Grid != NULL) { OptionalFlags = CSG_String::Format(SG_T(" -o \"%s\""), OUTLET_INPUT_FilePath.c_str()); } if (MASK_INPUT_Grid != NULL) { OptionalFlags = OptionalFlags + CSG_String::Format(SG_T(" -mask \"%s\" -thresh %d"), MASK_INPUT_FilePath.c_str(), Threshold); } BinaryName = CSG_String("GridNet"); BinaryPath = SG_File_Make_Path(TauDEMBinDir, BinaryName); sCmd = CSG_String::Format(SG_T("\"mpiexec -n %d \"%s\" -p \"%s\" -plen \"%s\" -tlen \"%s\" -gord \"%s\" %s > \"%s\" 2>&1\""), nproc, BinaryPath.c_str(), FLOWD8_INPUT_FilePath.c_str(), LONGEST_OUTPUT_FilePath.c_str(), TOTAL_LENGTH_OUTPUT_FilePath.c_str(), ORDER_OUTPUT_FilePath.c_str(), OptionalFlags.c_str(), LogFile.c_str()); LONGESTName = CSG_String("D8 LongestPath"); LENGTHName = CSG_String("D8 TotalLength"); ORDERName = CSG_String("D8 GridOrder"); // make sure temp dir exists if (!SG_Dir_Exists(TempDirPath)) { if (!SG_Dir_Create(TempDirPath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to create temp directory"), TempDirPath.c_str())); } } // Delete old input file if exists if (SG_File_Exists(FLOWD8_INPUT_FilePath)) { if (!SG_File_Delete(FLOWD8_INPUT_FilePath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to delete previous input file: "), FLOWD8_INPUT_FilePath.c_str())); return( false ); } } if (OUTLET_INPUT_Grid != NULL) { // Delete old input file if exists if (SG_File_Exists(OUTLET_INPUT_FilePath)) { if (!SG_File_Delete(OUTLET_INPUT_FilePath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to delete previous input file: "), OUTLET_INPUT_FilePath.c_str())); return( false ); } } } if (MASK_INPUT_Grid != NULL) { // Delete old input file if exists if (SG_File_Exists(MASK_INPUT_FilePath)) { if (!SG_File_Delete(MASK_INPUT_FilePath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to delete previous input file: "), MASK_INPUT_FilePath.c_str())); return( false ); } } } // Delete old output files if (SG_File_Exists(LONGEST_OUTPUT_FilePath)) { if (!SG_File_Delete(LONGEST_OUTPUT_FilePath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to delete previous output file: "), LONGEST_OUTPUT_FilePath.c_str())); return( false ); } } // Delete old output files if (SG_File_Exists(TOTAL_LENGTH_OUTPUT_FilePath)) { if (!SG_File_Delete(TOTAL_LENGTH_OUTPUT_FilePath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to delete previous output file: "), TOTAL_LENGTH_OUTPUT_FilePath.c_str())); return( false ); } } // Delete old output files if (SG_File_Exists(ORDER_OUTPUT_FilePath)) { if (!SG_File_Delete(ORDER_OUTPUT_FilePath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to delete previous output file: "), ORDER_OUTPUT_FilePath.c_str())); return( false ); } } // save input file if( !DataSet.Open_Write(FLOWD8_INPUT_FilePath, GDALDriver, CSG_String(""), Type, 1, *Get_System(), Projection) ) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to open file for writing: "), FLOWD8_INPUT_FilePath.c_str())); return( false ); } DataSet.Write(0, FLOWD8_INPUT_Grid); if( !DataSet.Close() ) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to close file after writing: "), FLOWD8_INPUT_FilePath.c_str())); return( false ); } // save mask grid if (MASK_INPUT_Grid != NULL) { if( !DataSet.Open_Write(MASK_INPUT_FilePath, GDALDriver, CSG_String(""), Type, 1, *Get_System(), Projection) ) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to open file for writing: "), MASK_INPUT_FilePath.c_str())); return( false ); } DataSet.Write(0, MASK_INPUT_Grid); if( !DataSet.Close() ) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to close file after writing: "), MASK_INPUT_FilePath.c_str())); return( false ); } } // save outlet shapefile if (OUTLET_INPUT_Grid != NULL) { CSG_OGR_DataSource DataSource; CSG_String OGRDriver = CSG_String("ESRI Shapefile"); if( !DataSource.Create(OUTLET_INPUT_FilePath, OGRDriver) ) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to open file for writing: "), OUTLET_INPUT_FilePath.c_str())); return( false ); } DataSource.Write(OUTLET_INPUT_Grid, OGRDriver); } // Run TauDEM GridNet Message_Add(CSG_String("Executing ") + sCmd); // run process if (system(sCmd.b_str()) != 0) { Error_Set(CSG_String::Format(SG_T("Error executing '%s' see Execution log for details"), BinaryName.c_str())); // read log output CSG_File File; if (File.Open(LogFile, SG_FILE_R, false)) { CSG_String Line; while (! File.is_EOF() && File.Read_Line(Line)) { Message_Add(Line); } File.Close(); } else { Message_Add(CSG_String("Unable to open " + LogFile + CSG_String(" for reading"))); } return( false ); } // Open new output tif file if( !DataSet.Open_Read(LONGEST_OUTPUT_FilePath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to open generated file: "), LONGEST_OUTPUT_FilePath.c_str())); return( false ); } else { LONGEST_OUTPUT_Grid->Assign(DataSet.Read(0)); LONGEST_OUTPUT_Grid->Set_Name(LONGESTName); Parameters("LONGEST_OUTPUT")->Set_Value(LONGEST_OUTPUT_Grid); CSG_Colors colors; DataObject_Get_Colors(FLOWD8_INPUT_Grid, colors); DataObject_Set_Colors(LONGEST_OUTPUT_Grid, colors); DataObject_Update(LONGEST_OUTPUT_Grid, false); } // Open new output tif file if( !DataSet.Open_Read(TOTAL_LENGTH_OUTPUT_FilePath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to open generated file: "), TOTAL_LENGTH_OUTPUT_FilePath.c_str())); return( false ); } else { TOTAL_LENGTH_OUTPUT_Grid->Assign(DataSet.Read(0)); TOTAL_LENGTH_OUTPUT_Grid->Set_Name(LENGTHName); Parameters("TOTAL_LENGTH_OUTPUT")->Set_Value(TOTAL_LENGTH_OUTPUT_Grid); CSG_Colors colors; DataObject_Get_Colors(FLOWD8_INPUT_Grid, colors); DataObject_Set_Colors(TOTAL_LENGTH_OUTPUT_Grid, colors); DataObject_Update(TOTAL_LENGTH_OUTPUT_Grid, false); } // Open new output tif if( !DataSet.Open_Read(ORDER_OUTPUT_FilePath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to open generated file: "), ORDER_OUTPUT_FilePath.c_str())); return( false ); } else { ORDER_OUTPUT_Grid->Assign(DataSet.Read(0)); ORDER_OUTPUT_Grid->Set_Name(ORDERName); Parameters("ORDER_OUTPUT")->Set_Value(ORDER_OUTPUT_Grid); CSG_Colors colors; DataObject_Get_Colors(FLOWD8_INPUT_Grid, colors); DataObject_Set_Colors(ORDER_OUTPUT_Grid, colors); DataObject_Update(ORDER_OUTPUT_Grid, false); } return( true ); }
bool CStreamNet::On_Execute(void) { // Inputs and Output Strings CSG_String InputBasename = CSG_String("input"); CSG_String OutputBasename = CSG_String("output"); CSG_String FEL_INPUT_FileName, FEL_INPUT_FilePath; CSG_String FLOWD8_INPUT_FileName, FLOWD8_INPUT_FilePath; CSG_String AREAD8_INPUT_FileName, AREAD8_INPUT_FilePath; CSG_String SRC_INPUT_FileName, SRC_INPUT_FilePath; CSG_String ORD_OUTPUT_FileName, ORD_OUTPUT_FilePath, ORD_OUTPUT_Name; CSG_String W_OUTPUT_FileName, W_OUTPUT_FilePath, W_OUTPUT_Name; CSG_String NET_OUTPUT_FileName, NET_OUTPUT_FilePath, NET_OUTPUT_Name; CSG_String TREE_OUTPUT_FileName, TREE_OUTPUT_FilePath, TREE_OUTPUT_Name; CSG_String COORD_OUTPUT_FileName, COORD_OUTPUT_FilePath, COORD_OUTPUT_Name; CSG_String OUTLET_INPUT_FileName, OUTLET_INPUT_FilePath; // Data Objects CSG_Grid *FEL_INPUT_Grid, *FLOWD8_INPUT_Grid, *SRC_INPUT_Grid, *AREAD8_INPUT_Grid, *ORD_OUTPUT_Grid, *W_OUTPUT_Grid; CSG_Shapes *OUTLET_INPUT_Shapes, *NET_OUTPUT_Shapes; CSG_Table *TREE_OUTPUT_Table, *COORD_OUTPUT_Table; // Misc TSG_Data_Type Type; CSG_String GDALDriver, sCmd, TempDirPath, TauDEMBinDir, BinaryName, BinaryPath, LogFile; CSG_Projection Projection; CSG_GDAL_DataSet DataSet; CSG_OGR_DataSource OGRDataSource; CSG_String OGRDriver = CSG_String("ESRI Shapefile"); bool sw; int nproc; // Grab inputs FEL_INPUT_Grid = Parameters("FEL_INPUT")->asGrid(); FLOWD8_INPUT_Grid = Parameters("FLOWD8_INPUT")->asGrid(); SRC_INPUT_Grid = Parameters("SRC_INPUT")->asGrid(); AREAD8_INPUT_Grid = Parameters("AREAD8_INPUT")->asGrid(); ORD_OUTPUT_Grid = Parameters("ORD_OUTPUT")->asGrid(); W_OUTPUT_Grid = Parameters("W_OUTPUT")->asGrid(); nproc = Parameters("NPROC")->asInt(); OUTLET_INPUT_Shapes = Parameters("OUTLET_INPUT")->asShapes(); NET_OUTPUT_Shapes = Parameters("NET_OUTPUT")->asShapes(); TREE_OUTPUT_Table = Parameters("TREE_OUTPUT")->asTable(); COORD_OUTPUT_Table = Parameters("COORD_OUTPUT")->asTable(); sw = Parameters("SW")->asBool(); GDALDriver = CSG_String("GTiff"); Get_Projection(Projection); Type = FEL_INPUT_Grid->Get_Type(); //TempDirPath = SG_File_Get_Path_Absolute(CSG_String("taudem_tmp")); TempDirPath = Parameters("TEMP_DIR")->asFilePath()->asString(); FEL_INPUT_FileName = InputBasename + CSG_String("fel"); FEL_INPUT_FilePath = SG_File_Make_Path(TempDirPath, FEL_INPUT_FileName, CSG_String("tif")); FLOWD8_INPUT_FileName = InputBasename + CSG_String("p"); FLOWD8_INPUT_FilePath = SG_File_Make_Path(TempDirPath, FLOWD8_INPUT_FileName, CSG_String("tif")); SRC_INPUT_FileName = InputBasename + CSG_String("src"); SRC_INPUT_FilePath = SG_File_Make_Path(TempDirPath, SRC_INPUT_FileName, CSG_String("tif")); AREAD8_INPUT_FileName = InputBasename + CSG_String("ad8"); AREAD8_INPUT_FilePath = SG_File_Make_Path(TempDirPath, AREAD8_INPUT_FileName, CSG_String("tif")); ORD_OUTPUT_FileName = OutputBasename + CSG_String("ord"); ORD_OUTPUT_FilePath = SG_File_Make_Path(TempDirPath, ORD_OUTPUT_FileName, CSG_String("tif")); ORD_OUTPUT_Name = CSG_String("NetworkOrder"); W_OUTPUT_FileName = OutputBasename + CSG_String("w"); W_OUTPUT_FilePath = SG_File_Make_Path(TempDirPath, W_OUTPUT_FileName, CSG_String("tif")); W_OUTPUT_Name = CSG_String("WatershedIDs"); OUTLET_INPUT_FileName = InputBasename + CSG_String("o"); OUTLET_INPUT_FilePath = SG_File_Make_Path(TempDirPath, OUTLET_INPUT_FileName, CSG_String("shp")); NET_OUTPUT_FileName = OutputBasename + CSG_String("net"); NET_OUTPUT_FilePath = SG_File_Make_Path(TempDirPath, NET_OUTPUT_FileName, CSG_String("shp")); NET_OUTPUT_Name = CSG_String("Channel Network"); TREE_OUTPUT_FileName = OutputBasename + CSG_String("tree"); TREE_OUTPUT_FilePath = SG_File_Make_Path(TempDirPath, TREE_OUTPUT_FileName, CSG_String("dat")); TREE_OUTPUT_Name = CSG_String("Channel Network Tree"); COORD_OUTPUT_FileName = OutputBasename + CSG_String("coord"); COORD_OUTPUT_FilePath = SG_File_Make_Path(TempDirPath, COORD_OUTPUT_FileName, CSG_String("dat")); COORD_OUTPUT_Name = CSG_String("Channel Network Coords"); LogFile = SG_File_Make_Path(TempDirPath, CSG_String("taudem_log.txt")); LogFile = SG_File_Get_Path_Absolute(LogFile); TauDEMBinDir = SG_File_Make_Path(CSG_String("bin"), CSG_String("TauDEM")); TauDEMBinDir = SG_File_Get_Path_Absolute(TauDEMBinDir); // options CSG_String OptionalFlags = CSG_String(""); if (OUTLET_INPUT_Shapes != NULL) { OptionalFlags = CSG_String::Format(SG_T("-o \"%s\" "), OUTLET_INPUT_FilePath.c_str()); } if (sw) { OptionalFlags = OptionalFlags + CSG_String::Format(SG_T("-sw")); } // exec commnad BinaryName = CSG_String("StreamNet"); // D8 BinaryPath = SG_File_Make_Path(TauDEMBinDir, BinaryName); sCmd = CSG_String::Format(SG_T("\"mpiexec -n %d \"%s\" -fel \"%s\" -p \"%s\" -ad8 \"%s\" -src \"%s\" -ord \"%s\" -tree \"%s\" -coord \"%s\" -net \"%s\" -w \"%s\" %s >\"%s\" 2>&1\""), nproc, BinaryPath.c_str(), FEL_INPUT_FilePath.c_str(), FLOWD8_INPUT_FilePath.c_str(), AREAD8_INPUT_FilePath.c_str(), SRC_INPUT_FilePath.c_str(), ORD_OUTPUT_FilePath.c_str(), TREE_OUTPUT_FilePath.c_str(), COORD_OUTPUT_FilePath.c_str(), NET_OUTPUT_FilePath.c_str(), W_OUTPUT_FilePath.c_str(), OptionalFlags.c_str(), LogFile.c_str()); // make sure temp dir exists if (!SG_Dir_Exists(TempDirPath)) { if (!SG_Dir_Create(TempDirPath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to create temp directory"), TempDirPath.c_str())); } } CSG_String FilePaths [10] = {FEL_INPUT_FilePath, FLOWD8_INPUT_FilePath, SRC_INPUT_FilePath, AREAD8_INPUT_FilePath, ORD_OUTPUT_FilePath, W_OUTPUT_FilePath, OUTLET_INPUT_FilePath, NET_OUTPUT_FilePath, TREE_OUTPUT_FilePath, COORD_OUTPUT_FilePath}; for (int i = 0; i < 10; i++) { CSG_String FilePath = FilePaths[i]; // Delete old file if exists if (SG_File_Exists(FilePath)) { if (!SG_File_Delete(FilePath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to delete existing file: "), FilePath.c_str())); return( false ); } } } // SAVE TIFFS CSG_String TIFF_INPUT_FilePaths [4] = {FEL_INPUT_FilePath, FLOWD8_INPUT_FilePath, SRC_INPUT_FilePath, AREAD8_INPUT_FilePath}; CSG_Grid* TIFF_INPUT_Grids [4] = {FEL_INPUT_Grid, FLOWD8_INPUT_Grid, SRC_INPUT_Grid, AREAD8_INPUT_Grid}; for (int i = 0; i < 4; i++) { CSG_String FilePath = TIFF_INPUT_FilePaths[i]; CSG_Grid* Grid = TIFF_INPUT_Grids[i]; if( !DataSet.Open_Write(FilePath, GDALDriver, CSG_String(""), 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 ); } DataSet.Write(0, Grid); if( !DataSet.Close() ) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to close file after writing: "), FilePath.c_str())); return( false ); } } if (OUTLET_INPUT_Shapes != NULL) { // save outlet shapefile CSG_String OGRDriver = CSG_String("ESRI Shapefile"); if( !OGRDataSource.Create(OUTLET_INPUT_FilePath, OGRDriver) ) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to open file for writing: "), OUTLET_INPUT_FilePath.c_str())); return( false ); } OGRDataSource.Write(OUTLET_INPUT_Shapes, OGRDriver); OGRDataSource.Destroy(); } // Run TauDEM StreamNet Message_Add(CSG_String("Executing ") + sCmd); if (system(sCmd.b_str()) != 0) { Error_Set(CSG_String::Format(SG_T("Error executing '%s' see Execution log for details"), BinaryName.c_str())); // read log output CSG_File File; if (File.Open(LogFile, SG_FILE_R, false)) { CSG_String Line; while (! File.is_EOF() && File.Read_Line(Line)) { Message_Add(Line); } File.Close(); } else { Message_Add(CSG_String("Unable to open " + LogFile + CSG_String(" for reading"))); } return( false ); } // Load output tiffs if( !DataSet.Open_Read(ORD_OUTPUT_FilePath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to open output file: "), ORD_OUTPUT_FilePath.c_str())); return( false ); } else { ORD_OUTPUT_Grid->Assign(DataSet.Read(0)); ORD_OUTPUT_Grid->Set_Name(ORD_OUTPUT_Name); Parameters("ORD_OUTPUT")->Set_Value(ORD_OUTPUT_Grid); } if( !DataSet.Open_Read(W_OUTPUT_FilePath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to open output file: "), W_OUTPUT_FilePath.c_str())); return( false ); } else { W_OUTPUT_Grid->Assign(DataSet.Read(0)); W_OUTPUT_Grid->Set_Name(W_OUTPUT_Name); Parameters("W_OUTPUT")->Set_Value(W_OUTPUT_Grid); CSG_Colors colors; DataObject_Get_Colors(SRC_INPUT_Grid, colors); DataObject_Set_Colors(ORD_OUTPUT_Grid, colors); DataObject_Update(ORD_OUTPUT_Grid, false); } // load output shapefile if( !OGRDataSource.Create(NET_OUTPUT_FilePath) ) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to open file for reading: "), NET_OUTPUT_FilePath.c_str())); return( false ); } NET_OUTPUT_Shapes->Assign(OGRDataSource.Read(0, 0)); NET_OUTPUT_Shapes->Set_Name(NET_OUTPUT_Name); OGRDataSource.Destroy(); // load table data if (!SG_File_Exists(COORD_OUTPUT_FilePath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Output file does not exist: "), COORD_OUTPUT_FilePath.c_str())); return false; } else { COORD_OUTPUT_Table->Destroy(); COORD_OUTPUT_Table->Set_Name(COORD_OUTPUT_Name); // create table fields COORD_OUTPUT_Table->Add_Field(SG_T("X"), SG_DATATYPE_Double); COORD_OUTPUT_Table->Add_Field(SG_T("Y"), SG_DATATYPE_Double); COORD_OUTPUT_Table->Add_Field(SG_T("Terminal Distance"), SG_DATATYPE_Double); COORD_OUTPUT_Table->Add_Field(SG_T("Elevation"), SG_DATATYPE_Double); COORD_OUTPUT_Table->Add_Field(SG_T("Contributing Area"), SG_DATATYPE_Double); // read table data CSG_File File; if (File.Open(COORD_OUTPUT_FilePath, SG_FILE_R, false)) { CSG_String Line; // determine number of lines while (! File.is_EOF() && File.Read_Line(Line)) { Line.Trim(); if (Line.Length() == 0) { break; } else { CSG_Table_Record *Record = COORD_OUTPUT_Table->Add_Record(); for (int i = 0; i < COORD_OUTPUT_Table->Get_Field_Count(); i++) { Record->Set_Value(i, Line.asDouble()); Line = Line.AfterFirst('\t'); Line.Trim(); } } } File.Close(); } else { Message_Add(CSG_String("Unable to open " + COORD_OUTPUT_FilePath + CSG_String(" for reading"))); } } if (!SG_File_Exists(TREE_OUTPUT_FilePath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Output file does not exist: "), TREE_OUTPUT_FilePath.c_str())); return false; } else { TREE_OUTPUT_Table->Destroy(); TREE_OUTPUT_Table->Set_Name(TREE_OUTPUT_Name); // create table fields TREE_OUTPUT_Table->Add_Field(SG_T("Link"), SG_DATATYPE_Int); TREE_OUTPUT_Table->Add_Field(SG_T("Start Point"), SG_DATATYPE_Int); TREE_OUTPUT_Table->Add_Field(SG_T("End Point"), SG_DATATYPE_Int); TREE_OUTPUT_Table->Add_Field(SG_T("Next (Downstream) Link"), SG_DATATYPE_Int); TREE_OUTPUT_Table->Add_Field(SG_T("First Previous (Upstream) Link"), SG_DATATYPE_Int); TREE_OUTPUT_Table->Add_Field(SG_T("Second Previous (Upstream) Link"), SG_DATATYPE_Int); TREE_OUTPUT_Table->Add_Field(SG_T("Strahler Order"), SG_DATATYPE_Int); TREE_OUTPUT_Table->Add_Field(SG_T("Monitoring Point ID"), SG_DATATYPE_Int); TREE_OUTPUT_Table->Add_Field(SG_T("Link Network Magnitude"), SG_DATATYPE_Int); // read table data CSG_File File; if (File.Open(TREE_OUTPUT_FilePath, SG_FILE_R, false)) { CSG_String Line; // determine number of lines while (! File.is_EOF() && File.Read_Line(Line)) { Line.Trim(); if (Line.Length() == 0) { break; } else { CSG_Table_Record *Record = TREE_OUTPUT_Table->Add_Record(); for (int i = 0; i < TREE_OUTPUT_Table->Get_Field_Count(); i++) { Record->Set_Value(i, Line.asDouble()); Line = Line.AfterFirst('\t'); Line.Trim(); } } } File.Close(); } else { Message_Add(CSG_String("Unable to open " + TREE_OUTPUT_FilePath + CSG_String(" for reading"))); } } return( true ); }