Пример #1
0
        public static string[] GetHeaderLines(string pSourceFilePath, string pOutputFilePath)
        {
            if (!File.Exists(pSourceFilePath))
            {
                CDebug.Error($"file: {pSourceFilePath} not found");
                return(null);
            }

            //string infoFileName = Path.GetFileNameWithoutExtension(pSourceFilePath) + "_i.txt";
            //string infoFilePath = currentTmpFolder + infoFileName;

            string info =
                "lasinfo " +
                pSourceFilePath +
                " -o " +
                pOutputFilePath;

            try
            {
                CCmdController.RunLasToolsCmd(info, pOutputFilePath);
            }
            catch (Exception e)
            {
                CDebug.Error($"Exception {e}");
            }

            return(CProgramLoader.GetFileLines(pOutputFilePath, HEADER_FILE_LINES));
        }
Пример #2
0
        public static void ExportMain()
        {
            if (!export)
            {
                return;
            }

            if (exportedTiles.Count == 0)
            {
                CDebug.Warning($"CLasExporter: no mainoutput created");
                return;
            }
            string mainTxtFilePath = mainFilePath + ".txt";

            foreach (string filePath in exportedTiles)
            {
                //copy content of all exported tile files to one
                StringBuilder fileContent = new StringBuilder(File.ReadAllText(filePath));
                WriteToFile(fileContent, mainTxtFilePath);
            }

            //convert to las
            string cmd = $"{txt2lasCmd} {mainTxtFilePath}";

            CCmdController.RunLasToolsCmd(cmd, mainFilePath + ".las");

            //delete all txt files
            File.Delete(mainTxtFilePath);
            foreach (string filePath in exportedTiles)
            {
                File.Delete(filePath);
            }
        }
Пример #3
0
        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);
        }
Пример #4
0
        public static string LasSplit(string classifyFilePath)
        {
            SSplitRange range = CParameterSetter.GetSplitRange();

            if (!range.IsValid())
            {
                throw new Exception($"range {range} is not valid");
            }

            string splitFileName = $"{forestFileName}_s[{range.MinX},{range.MinY}]-[{range.MaxX},{range.MaxY}]";

            string keepXY        = $" -keep_xy {range.MinX} {range.MinY} {range.MaxX} {range.MaxY}";
            string splitFilePath = currentTmpFolder + splitFileName + LAZ;

            if (File.Exists(splitFilePath))
            {
                return(splitFilePath);                //already created
            }
            string split =
                "lassplit -i " +
                classifyFilePath +
                keepXY +
                " -o " +
                splitFilePath;

            //todo: when split file not created there is no error...(ie when invalid range is given)
            try
            {
                //todo: split fails on jen2_merged_preprocessed.laz
                CCmdController.RunLasToolsCmd(split, splitFilePath);
            }
            catch (Exception e)
            {
                //split command creates file with other name...
                CDebug.WriteLine($"exception {e}");
            }

            //for some reason output split file gets appendix: "_0000000" => rename it
            #region rename
            //rename split file

            //todo: move to Utils
            string   sourceFile = splitFileName + "_0000000" + LAZ;
            FileInfo fi         = new FileInfo(currentTmpFolder + sourceFile);
            if (fi.Exists)
            {
                fi.MoveTo(currentTmpFolder + splitFileName + LAZ);
                Console.WriteLine("Split file Renamed.");
            }
            else
            {
                //todo: implement my own exception
                throw new Exception($"Split file not created. Perhaps there are no points at range {range}?");
            }
            #endregion

            return(splitFilePath);
        }
Пример #5
0
        public static void ExportTile()
        {
            if (!export)
            {
                return;
            }
            DateTime exportStart = DateTime.Now;

            StringBuilder output = new StringBuilder();
            string        res;

            DateTime start     = DateTime.Now;
            DateTime lastDebug = DateTime.Now;

            AddPointsTo(ref output, EClass.Unassigned, ref start);
            AddPointsTo(ref output, EClass.Ground, ref start);
            AddPointsTo(ref output, EClass.Building, ref start);

            if (CTreeManager.GetDetectMethod() == EDetectionMethod.Balls)
            {
                AddPointsTo(ref output, EClass.BallsSurface, ref start);
                AddPointsTo(ref output, EClass.Balls, ref start);
                AddPointsTo(ref output, EClass.BallsMainPoints, ref start);
                AddPointsTo(ref output, EClass.BallsCenters, ref start);
            }

            //tree points
            AddTreePointsTo(ref output, true, ref start);
            //invalid tree points
            AddTreePointsTo(ref output, false, ref start);

            if (output.Length == 0)
            {
                CDebug.Warning($"CLasExporter: no output created on tile {CProgramStarter.currentTileIndex}");
                return;
            }

            //1. Create the text file
            string txtOutputPath = tileFilePath + ".txt";

            WriteToFile(output, txtOutputPath);
            //2. save output path for the main file export
            exportedTiles.Add(txtOutputPath);

            //3. Convert the txt to las using LasTools
            //format: x, y, z, class, user comment (id), R, G, B
            string cmd = $"{txt2lasCmd} {txtOutputPath}";

            CCmdController.RunLasToolsCmd(cmd, tileFilePath + ".las");

            CAnalytics.lasExportDuration = CAnalytics.GetDuration(exportStart);
        }
Пример #6
0
        private static void LasReverseTiles(List <string> pClassifyFilePaths)
        {
            //string pathsString = "";
            //foreach(string path in pClassifyFilePaths)
            //{
            //	pathsString += path + " ";
            //}

            string reverseTiles =
                "lastile -i " +
                currentTmpFolder + "*_c" + LAZ +
                " -reverse_tiling -o " + preprocessedFilePath;

            CCmdController.RunLasToolsCmd(reverseTiles, preprocessedFilePath);
        }
Пример #7
0
        private static string LasHeight(string pGroundFilePath)
        {
            string heightFileName = CUtils.GetFileName(pGroundFilePath) + "_h" + LAZ;
            string heightFilePath = currentTmpFolder + heightFileName;

            string height =
                "lasheight -i " +
                pGroundFilePath +
                " -o " +
                heightFilePath;

            CCmdController.RunLasToolsCmd(height, heightFilePath);

            return(heightFilePath);
        }
Пример #8
0
        private static string LasGround(string pNoiseFilePath)
        {
            string groundFileName = CUtils.GetFileName(pNoiseFilePath) + "_g" + LAZ;
            string groundFilePath = currentTmpFolder + groundFileName;

            string ground =
                "lasground_new -i " +
                pNoiseFilePath +
                " -o " +
                groundFilePath;

            CCmdController.RunLasToolsCmd(ground, groundFilePath);

            return(groundFilePath);
        }
Пример #9
0
        private static string LasNoise(string pForestFilePath)
        {
            string noiseFileName = CUtils.GetFileName(pForestFilePath) + "_n" + LAZ;
            string noiseFilePath = currentTmpFolder + noiseFileName;

            string ground =
                "lasnoise -i " +
                pForestFilePath +
                " -o " +
                noiseFilePath;

            CCmdController.RunLasToolsCmd(ground, noiseFilePath);

            return(noiseFilePath);
        }
Пример #10
0
        /*private static void LasMerge(List<string> pClassifyFilePaths)
         * {
         *      //string pathsString = "";
         *      //foreach(string path in pClassifyFilePaths)
         *      //{
         *      //	pathsString += path + " ";
         *      //}
         *
         *      string merge =
         *                      "lasmerge -i " +
         *                      currentTmpFolder + "*_c" + LAZ +
         *                      " -o " + preprocessedFilePath;
         *      CCmdController.RunLasToolsCmd(merge, preprocessedFilePath);
         * }*/

        private static string LasClassify(string pHeightFilePath)
        {
            //string classifyFileName = forestFileName + "_c" + LAZ;
            //string classifyFilePath = tmpFolder + classifyFileName;
            string classifyFileName = CUtils.GetFileName(pHeightFilePath) + "_c" + LAZ;
            string classifyFilePath = currentTmpFolder + classifyFileName;

            string classify =
                "lasclassify -i " +
                pHeightFilePath +
                " -o " +
                classifyFilePath;

            CCmdController.RunLasToolsCmd(classify, classifyFilePath);

            return(classifyFilePath);
        }
Пример #11
0
        internal static string Las2Txt(string splitFilePath, string pOutputFolder)
        {
            string splitFileName = CUtils.GetFileName(splitFilePath);

            //use split file name to get unique file name
            string txtFileName = splitFileName + ".txt";
            string txtFilePath = pOutputFolder + txtFileName;

            string toTxt =
                "las2txt -i " +
                splitFilePath +
                " -o " +
                txtFilePath +
                " -parse xyzc -sep tab -header percent";

            CCmdController.RunLasToolsCmd(toTxt, txtFilePath);

            return(txtFilePath);
        }
Пример #12
0
        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);
        }
Пример #13
0
        private static FileInfo[] GetTiledFiles(string pSourceFilePath, string pOutputFolderPath, int pTileSize, int pBufferSize)
        {
            DirectoryInfo tiledFilesFolderInfo = new DirectoryInfo(pOutputFolderPath);

            //we expect that only laz files in folder should be the expected output
            //if they are already there, skip the process
            FileInfo[] lazFilesInFolder = tiledFilesFolderInfo.GetFiles("*" + LAZ);
            if (lazFilesInFolder.Length > 0)
            {
                return(lazFilesInFolder);
            }

            string tile =
                "lastile -i " +
                pSourceFilePath +
                $" -tile_size {pTileSize} -buffer {pBufferSize}" +
                " -reversible -odir " +
                pOutputFolderPath +
                " -olaz";

            try
            {
                //dont know name of the ouput file name -> choose any and catch exception
                CCmdController.RunLasToolsCmd(tile, tmpTiledFilesFolder + "X");
            }
            catch (Exception e)
            {
                if (tiledFilesFolderInfo.GetFiles("*" + LAZ).Length == 0)
                {
                    throw e;
                }
            }

            lazFilesInFolder = tiledFilesFolderInfo.GetFiles("*" + LAZ);
            return(lazFilesInFolder);
        }