public static string LasClip(string classifyFilePath) { string shapefilePath = CParameterSetter.GetStringSettings(ESettings.shapeFilePath); string shapefileName = CUtils.GetFileName(shapefilePath); if (!File.Exists(shapefilePath)) { throw new Exception($"shapefile does not exist. {shapefilePath}"); } string clipFileName = $"{forestFileName}_clip[{shapefileName}]"; string clipFilePath = currentTmpFolder + clipFileName + LAZ; if (File.Exists(clipFilePath)) { return(clipFilePath); //already created } string clip = "lasclip -i " + classifyFilePath + " -poly " + shapefilePath + " -o " + clipFilePath; CCmdController.RunLasToolsCmd(clip, clipFilePath); return(clipFilePath); }
public static void Init() { string eq = CParameterSetter.GetStringSettings(ESettings.treeRadius); treeRadiusExpression = CreateExpression(eq); NeedsReinit = false; }
/// <summary> /// Returns path to folder containing tiles of given size. /// If doesnt exist => create it /// </summary> private static string GetTiledFilesFolder(string pSourceFileName, int pTileSize) { string forestFileName = CUtils.GetFileName(CParameterSetter.GetStringSettings(ESettings.forestFileName)); string path = currentTmpFolder + $"_tiles[{pTileSize}]_{pSourceFileName}\\"; Directory.CreateDirectory(path); return(path); }
private static void CheckTreeRadius() { string problem = CTreeRadiusCalculator.IsValidEquation(CParameterSetter.GetStringSettings(ESettings.treeRadius)); if (problem.Length > 0) { problems.Add($"tree radius equation problem: {problem}"); } }
private static void CheckAGB() { string problem = CBiomassController.IsValidEquation(CParameterSetter.GetStringSettings(ESettings.agb)); if (problem.Length > 0) { problems.Add($"DBH equation problem: {problem}"); } }
private static void ExportCsv(List <Tuple <string, object> > pParams, string pName, bool pExportGlobal = false) { string fileName = pName + ".csv"; string filePath = CProjectData.outputTileSubfolder + "/" + fileName; string[] pathSplit = CProjectData.outputTileSubfolder.Split('\\'); string folderName = pathSplit[pathSplit.Length - 2]; string line; using (var outStream = File.OpenWrite(filePath)) using (var writer = new StreamWriter(outStream)) { writer.WriteLine(GetHeaderString(pParams)); writer.Write(folderName); line = folderName; foreach (Tuple <string, object> param in pParams) { string val = "," + param.Item2; writer.Write(val); line += val; } } string mainSummaryFile = CParameterSetter.GetStringSettings(ESettings.analyticsFilePath); FileMode fileMode = FileMode.Append; if (!File.Exists(mainSummaryFile)) { CDebug.WriteLine("analytics file not defined"); if (!string.IsNullOrEmpty(mainSummaryFile)) { fileMode = FileMode.Create; CDebug.WriteLine(" - creating"); } else { return; } } //if Append => file exists //just check if already contains some text //we expect, that if it already has text, it also contains header bool hasHeader = fileMode == FileMode.Append && File.ReadAllLines(mainSummaryFile).Length != 0; using (FileStream fs = new FileStream(mainSummaryFile, fileMode, FileAccess.Write)) using (var writer = new StreamWriter(fs)) { if (!hasHeader) { writer.WriteLine(GetHeaderString(pParams)); } writer.WriteLine(line); } }
public static bool IsSequence() { string mainFile = CParameterSetter.GetStringSettings(ESettings.forestFileName); if (!File.Exists(mainFile)) { return(false); } return(Path.GetExtension(mainFile) == SEQ_EXTENSION); }
public static void Init() { saveFileName = CUtils.GetFileName( CParameterSetter.GetStringSettings(ESettings.forestFileFullName)); string outputFolderSettings = CParameterSetter.GetStringSettings(ESettings.outputFolderPath); //include the method alias into the main folder name EDetectionMethod method = CTreeManager.GetDetectMethod(); string suffix = CUtils.GetMethodSuffix(method); saveFileName += suffix; outputFolder = CObjExporter.CreateFolderIn(saveFileName, outputFolderSettings); Points = new CPointsHolder(); }
private static void CheckRange() { switch ((ESplitMode)CParameterSetter.GetIntSettings(ESettings.currentSplitMode)) { case ESplitMode.Manual: SSplitRange range = CParameterSetter.GetSplitRange(); if (!range.IsValid()) { problems.Add($"range {range} is not valid"); } break; case ESplitMode.Shapefile: string shapefilePath = CParameterSetter.GetStringSettings(ESettings.shapeFilePath); if (!File.Exists(shapefilePath)) { problems.Add($"shapefile not defined. {shapefilePath}"); } break; } }
/// <summary> /// True = everything ok /// </summary> public static bool CheckProblems() { Reset(); CheckPath("Forest", CParameterSetter.GetStringSettings(ESettings.forestFileFullName), true); //if(!CRxpParser.IsRxp) //{ // CheckPath("Reftree", CParameterSetter.GetStringSettings(ESettings.reftreeFolderPath), false); //} CheckPath("Output", CParameterSetter.GetStringSettings(ESettings.outputFolderPath), false); if (CParameterSetter.GetBoolSettings(ESettings.useCheckTreeFile)) { CheckPath("Checktree", CParameterSetter.GetStringSettings(ESettings.checkTreeFilePath), true); } CheckRange(); CheckExport(); if (CShpController.exportShape) { if (CParameterSetter.GetBoolSettings(ESettings.calculateDBH)) { CheckDBH(); } if (CParameterSetter.GetBoolSettings(ESettings.calculateAGB)) { CheckAGB(); } CheckTreeRadius(); } bool hasProblems = problems.Count > 0; if (hasProblems) { CDebug.WriteProblems(problems); problems.Clear(); } return(!hasProblems); }
internal static string ProcessForestFolder() { //string forestFolder = CParameterSetter.GetStringSettings(ESettings.forestFolderPath); DirectoryInfo forestFolder = new DirectoryInfo(CParameterSetter.GetStringSettings(ESettings.forestFolderPath)); if (!forestFolder.Exists) { CDebug.Error("forestFolderPath not set"); return(""); } string outputFilePath = forestFolder.FullName + $"\\{forestFolder.Name}_merged.laz"; //merge all LAS and LAX files in the folder into 1 file string merge = "lasmerge -i " + forestFolder.FullName + "\\*.las " + forestFolder.FullName + "\\*.laz " + " -o " + outputFilePath; CCmdController.RunLasToolsCmd(merge, outputFilePath); return(outputFilePath); }
private static List <string> GetTreeFileNames() { List <string> names = new List <string>(); string folderPath = CParameterSetter.GetStringSettings(ESettings.reftreeFolderPath); string[] subfolders = Directory.GetDirectories(folderPath); for (int i = 0; i < subfolders.Length; i++) { string subfolderPath = subfolders[i]; string[] pathSplit = subfolderPath.Split('\\'); string subfolderName = pathSplit[pathSplit.Length - 1]; //skip folder named "ignore" if (subfolderName.Contains("ignore")) { continue; } names.Add(subfolderName); } return(names); }
public static void Init() { configs = new List <SSequenceConfig>(); currentConfigIndex = 0; if (!IsSequence()) { return; } lastSequenceFile = CParameterSetter.GetStringSettings(ESettings.forestFileFullName); string[] lines = File.ReadAllLines(lastSequenceFile); for (int i = 0; i < lines.Length; i += oneSequenceLength) { string[] configLines = new string[oneSequenceLength]; configLines[0] = lines[i]; configLines[1] = lines[i + 1]; configLines[2] = lines[i + 2]; configLines[3] = lines[i + 3]; SSequenceConfig config = GetConfig(configLines); configs.Add(config); } }
public static EProcessResult Start() { CSequenceController.SetValues(); DateTime startTime = DateTime.Now; CProjectData.Init(); CTreeManager.Init(); CAnalytics.Init(); CDartTxt.Init(); CLasExporter.Init(); CBiomassController.Init( CParameterSetter.GetStringSettings(ESettings.dbh), CParameterSetter.GetStringSettings(ESettings.agb)); CTreeRadiusCalculator.Init(); CShpController.Init(); CReftreeManager.Init(); Thread.CurrentThread.CurrentCulture = new CultureInfo("en"); //GENERAL CProjectData.useMaterial = true; CObjExporter.simplePointsObj = false; CMaterialManager.Init(); string[] workerResult = new string[2]; workerResult[0] = "this string"; workerResult[1] = "some other string"; CProjectData.backgroundWorker.ReportProgress(10, workerResult); try { List <string> tiledFiles = CProgramLoader.GetTiledPreprocessedFilePaths(); tilesCount = tiledFiles.Count; int startTile = CParameterSetter.GetIntSettings(ESettings.startIndex); if (startTile < 0 || startTile >= tiledFiles.Count) { throw new Exception($"Parameter startTile = {startTile}, tiledFiles.Count = {tiledFiles.Count}"); } for (int i = startTile; i < tiledFiles.Count; i++) { string tiledFilePath = tiledFiles[i]; EProcessResult tileProcess = ProcessTile(tiledFilePath, i); if (CProjectData.backgroundWorker.CancellationPending) { break; } } } catch (Exception e) { CDebug.Error( $"{Environment.NewLine}exception: {e.Message} {Environment.NewLine}{Environment.NewLine}" + $"StackTrace: {e.StackTrace}{Environment.NewLine}"); OnException(); return(EProcessResult.Exception); } if (CProjectData.backgroundWorker.CancellationPending) { CDebug.Step(EProgramStep.Cancelled); return(EProcessResult.Cancelled); } CDebug.Step(EProgramStep.ExportMainFiles); //TODO: implement this in super class for all controllers //dont create the main file if not needed if (tilesCount > 1) { CDartTxt.ExportMain(); CLasExporter.ExportMain(); CShpController.ExportMain(); } CBitmapExporter.ExportMain(); CDebug.Step(EProgramStep.Done); if (CSequenceController.IsLastSequence()) { CSequenceController.OnLastSequenceEnd(); return(EProcessResult.Done); } CSequenceController.currentConfigIndex++; return(Start()); }
private static string GetRefTreeFolder(string pSubfolder) { return(CParameterSetter.GetStringSettings(ESettings.reftreeFolderPath) + "\\" + pSubfolder); }