static void Main(string[] args)
        {
            if(args.Length < 6)
            {
                Log.WriteLine("Input parameter is invalid. Please use \"strabo.core.exe double west_x, double north_y, string intermediate_folder, string output_folder, string layer, int thread_number\"");
                return;
            }
            try
            {
                BoundingBox bbx = new BoundingBox();
                bbx.BBW = args[0];
                bbx.BBN = args[1];
                InputArgs inputArgs = new InputArgs();
                inputArgs.outputFileName = "geojson";
                inputArgs.bbx = bbx;
                inputArgs.intermediatePath = args[2];
                inputArgs.outputPath = args[3];
                inputArgs.mapLayerName = args[4];
                inputArgs.threadNumber = Int32.Parse(args[5]);

                CommandLineWorker cmdWorker = new CommandLineWorker();
                cmdWorker.Apply(inputArgs, false,0,0,0,0);
                Log.WriteLine("Strabo process finised.");
            }
            catch(Exception e)
            {
                Log.WriteLine(e.Message);
                Log.WriteLine(e.Source);
                Log.WriteLine(e.StackTrace);
            }
        }
        //do not change this function, write your own test function instead
        public void Test(string layer)
        {
            BoundingBox bbx = new BoundingBox();
            InputArgs inputArgs = new InputArgs();
            inputArgs.outputFileName = "layer";

            if (layer == "nls-sixinch")
            {
                inputArgs.mapLayerName = layer;
                bbx.BBW = "597528";
                bbx.BBN = "210822";
                //417600 274400
                //482400 262400
                //412000 202400
                //488000 221600

                //417600 275200
                //482400 263200
                //412000 203200
                //488000 222400
            }
            if (layer == "nls-cs-1920")
            {
                inputArgs.mapLayerName = layer;
                bbx.BBW = "2977681";
                bbx.BBN = "5248978";
            }
            if (layer == "Tianditu_cva")
            {
                inputArgs.mapLayerName = layer;
                bbx.BBW = "13006520";
                bbx.BBN = "4853838";
            }
            if (layer == "Tianditu_eva")
            {
                inputArgs.mapLayerName = layer;
                bbx.BBW = "12957312";
                bbx.BBN = "4852401";
            }
            string appPath = AppDomain.CurrentDomain.BaseDirectory;
            string dataPath = Directory.GetParent(appPath).Parent.Parent.FullName + "\\data\\";
            inputArgs.bbx = bbx;

            inputArgs.intermediatePath = dataPath + "intermediate\\";
            inputArgs.outputPath = dataPath + "output\\";

            inputArgs.threadNumber = 8;

            CommandLineWorker cmdWorker = new CommandLineWorker();
            //cmdWorker.Apply(inputArgs, false);
            //cmdWorker.Apply(inputArgs, true);
            File.Copy(inputArgs.outputPath + "SourceMapImage.png", dataPath + layer + ".png", true);
            File.Copy(inputArgs.outputPath + layer + "ByPixels.txt", dataPath + layer + "geojsonByPixels.txt", true);
            Log.WriteLine("Process finished");
        }
        //do not change this function, write your own test function instead
        public void TestLocalFiles()
        {
            BoundingBox bbx = new BoundingBox();
            bbx.BBW = "2977681";
            bbx.BBN = "5248978";

            InputArgs inputArgs = new InputArgs();
            inputArgs.outputFileName = "Geojson";

            inputArgs.bbx = bbx;
            inputArgs.mapLayerName = "nls-cs-1920";
            inputArgs.threadNumber = 8;

            string appPath = AppDomain.CurrentDomain.BaseDirectory;
            string dataPath = Directory.GetParent(appPath).Parent.Parent.FullName + "\\data\\";

            inputArgs.bbx = bbx;

            inputArgs.intermediatePath = dataPath + "intermediate\\";
            inputArgs.outputPath = dataPath + "output\\";
            try
            {
                double[,] coordinates = new double[,] {{ 51.612961808346, 0.7341333483182767, 51.62160570111173, 0.7491015465216221 },
                { 51.6269443576099, 0.8062426299015226, 51.63557875288053, 0.8212288917069887 },
                { 51.65805109006676, 0.8217285148953754, 51.666683266211315, 0.8367281449327424 },
                { 51.675516021954614, 0.7646911667890038, 51.68415554029906, 0.779686123859217 },
                { 51.725724823274724, 0.6620249144045003, 51.73437743111727, 0.6770177479248397 },
                { 51.740352303690166, 0.7500629858262108, 51.74899333124705, 0.7650771692544902 },
                { 51.754711721550926, 0.8237386829167501, 51.7633430256784, 0.8387714425072738 },
                { 51.755968540487856, 0.8432213588349019, 51.76459728647148, 0.858258165853294 },
                { 51.76956959182837, 0.9015968337365646, 51.778190603233256, 0.9166491091661833 },
                { 51.84555647676825, 1.2579248616697, 51.85413007413581, 1.2730691065924755 }};
                CommandLineWorker cmdWorker = new CommandLineWorker();
                for (int i = 1; i <=10; i++)
                {
                    //if (i <5) continue;
                    File.Copy(dataPath + "1920-" + i + ".png", inputArgs.outputPath + "SourceMapImage.png", true);
                    inputArgs.outputFileName = "1920-" + i + ".png";
                    cmdWorker.Apply(inputArgs, true, coordinates[i-1, 0], coordinates[i-1, 1], coordinates[i-1, 2], coordinates[i-1, 3]);
                    File.Copy(inputArgs.outputPath + "1920-" + i + ".pngByPixels.txt", dataPath + "1920-" + i + ".pngByPixels.txt", true);
                }
            }
            catch (Exception e) { Log.WriteLine(e.Message); Log.WriteLine(e.StackTrace); };
            Log.WriteLine("Process finished");
        }
        //do not change this function, write your own test function instead
        public void TestLocalTianditu_evaFiles()
        {
            BoundingBox bbx = new BoundingBox();
            bbx.BBW = "2977681";
            bbx.BBN = "5248978";

            InputArgs inputArgs = new InputArgs();
            inputArgs.outputFileName = "Geojson";

            inputArgs.bbx = bbx;
            inputArgs.mapLayerName = "Tianditu_eva";
            inputArgs.threadNumber = 8;

            string appPath = AppDomain.CurrentDomain.BaseDirectory;
            string dataPath = Directory.GetParent(appPath).Parent.Parent.FullName + "\\data\\";

            inputArgs.bbx = bbx;

            inputArgs.intermediatePath = dataPath + "intermediate\\";
            inputArgs.outputPath = dataPath + "output\\";
            try
            {
                CommandLineWorker cmdWorker = new CommandLineWorker();
                //for (int i = 1; i < 11; i++)
                {
                    //if (i != 10) continue;
                    File.Copy(dataPath + "Tianditu_eva.png", inputArgs.outputPath + "SourceMapImage.png", true);
                    inputArgs.outputFileName = "Tianditu_eva.png";
                    cmdWorker.Apply(inputArgs, true,0,0,0,0);
                    File.Copy(inputArgs.outputPath + "Tianditu_eva.pngByPixels.txt", dataPath + "Tianditu_eva.pngByPixels.txt", true);
                }
            }
            catch (Exception e) { Log.WriteLine(e.Message); Log.WriteLine(e.StackTrace); };
            Log.WriteLine("Process finished");
        }
        public void Apply(InputArgs inputArgs, bool processLocalFiles, double top, double left, double bottom, double right)
        {
            ExtractTextLayerFromMapWorker _textLayerExtractionWorker = new ExtractTextLayerFromMapWorker();
            TextDetectionWorker           _textDetectionWorker       = new TextDetectionWorker();
            TextRecognitionWorker         _textRecognitionWorker     = new TextRecognitionWorker();
            ColorSegmentationWorker       _colorSegmentationWorker   = new ColorSegmentationWorker();

            //set log folders
            Log.SetLogDir(inputArgs.intermediatePath);
            Log.SetOutputDir(inputArgs.intermediatePath);
            Log.WriteLine("************Strabo Starts************");
            Log.WriteLine("CommandLineWorker in progress...");


            Log.SetStartTime();
            //read settings
            try
            {
                StraboParameters.readConfigFile(inputArgs.mapLayerName);
            }
            catch (Exception e)
            {
                Log.WriteLine("Error reading app.config: " + e.Message);
                throw;
            }

            Log.WriteLine("Strabo release version:" + StraboParameters.straboReleaseVersion);
            Log.WriteLine("Process map: " + inputArgs.mapLayerName);
            //set and clear folders
            SetFolder(inputArgs.intermediatePath);
            SetFolder(inputArgs.outputPath);

            if (!inputArgs.intermediatePath.EndsWith("\\"))
            {
                inputArgs.intermediatePath = inputArgs.intermediatePath + "\\";
            }
            if (!inputArgs.outputPath.EndsWith("\\"))
            {
                inputArgs.outputPath = inputArgs.outputPath + "\\";
            }
            Log.WriteLine("Initialization finished. Folders checked and cleaned.");

            try
            {
                MapServerParameters.BBOXW = inputArgs.bbx.BBW;
                MapServerParameters.BBOXN = inputArgs.bbx.BBN;
                MapServerParameters.layer = inputArgs.mapLayerName;
                MapServerParameters.URLBuilder();

                if (!processLocalFiles)
                {
                    GetMapFromServiceWorker gmfsWoker = new GetMapFromServiceWorker();
                    gmfsWoker.Apply(inputArgs);
                }
                else
                {
                    File.Copy(inputArgs.outputPath + StraboParameters.sourceMapFileName, inputArgs.intermediatePath + StraboParameters.sourceMapFileName, true);
                }
                File.Copy(inputArgs.intermediatePath + StraboParameters.sourceMapFileName, inputArgs.outputPath + StraboParameters.sourceMapFileName, true);
            }
            catch (Exception e)
            {
                Log.WriteLine("ApplyWMSWorker/ApplyWMTSWorker: " + e.Message);
                throw;
            }

            string color_segmentation_result_fn;

            if (StraboParameters.numberOfSegmentationColor > 0)
            {
                try
                {
                    Log.WriteLine("ColorSegmentationWorker in progress...");
                    color_segmentation_result_fn = _colorSegmentationWorker.Apply(inputArgs.intermediatePath, inputArgs.threadNumber);
                    Log.WriteLine("ColorSegmentationWorker finished");
                }
                catch (Exception e)
                {
                    Log.WriteLine("ColorSegmentationWorker: " + e.Message);
                    throw;
                }
            }
            else
            {
                color_segmentation_result_fn = inputArgs.intermediatePath + StraboParameters.sourceMapFileName;
            }

            try
            {
                Log.WriteLine("TextExtractionWorker in progress...");
                _textLayerExtractionWorker.Apply(color_segmentation_result_fn, inputArgs.intermediatePath, inputArgs.threadNumber);
                Log.WriteLine("ApplyTextExtarionWorker finished");
            }
            catch (Exception e)
            {
                Log.WriteLine("ApplyTextExtractionWorker: " + e.Message);
                throw;
            }
            try
            {
                Log.WriteLine("TextDetectionWorker in progress...");
                _textDetectionWorker.Apply(inputArgs.intermediatePath, 2.5, false, inputArgs.threadNumber);
                Log.WriteLine("ApllyTextDetection finished");
            }
            catch (Exception e)
            {
                Log.WriteLine("ApplyTextDetectionWorker: " + e.Message);
                throw;
            }
            try
            {
                Log.WriteLine("TextRecognition in progress...");
                _textRecognitionWorker.Apply(inputArgs.intermediatePath, inputArgs.outputPath, inputArgs.outputFileName, top, left, bottom, right);
                Log.WriteLine("TextRecognitionWorker finished");
            }
            catch (Exception e)
            {
                Log.WriteLine("ApplyTextRecognition: " + e.Message);
                throw;
            }

            Log.WriteLine("Execution time: " + Log.GetDurationInSeconds().ToString());
        }
        public void Apply(InputArgs inputArgs, bool processLocalFiles, double top, double left, double bottom, double right)
        {
            ExtractTextLayerFromMapWorker _textLayerExtractionWorker = new ExtractTextLayerFromMapWorker();
            TextDetectionWorker _textDetectionWorker = new TextDetectionWorker();
            TextRecognitionWorker _textRecognitionWorker = new TextRecognitionWorker();
            ColorSegmentationWorker _colorSegmentationWorker = new ColorSegmentationWorker();

            //set log folders
            Log.SetLogDir(inputArgs.intermediatePath);
            Log.SetOutputDir(inputArgs.intermediatePath);
            Log.WriteLine("************Strabo Starts************");
            Log.WriteLine("CommandLineWorker in progress...");

            Log.SetStartTime();
            //read settings
            try
            {
                StraboParameters.readConfigFile(inputArgs.mapLayerName);
            }
            catch (Exception e)
            {
                Log.WriteLine("Error reading app.config: " + e.Message);
                throw;
            }

            Log.WriteLine("Strabo release version:" + StraboParameters.straboReleaseVersion);
            Log.WriteLine("Process map: " + inputArgs.mapLayerName);
            //set and clear folders
            SetFolder(inputArgs.intermediatePath);
            SetFolder(inputArgs.outputPath);

            if (!inputArgs.intermediatePath.EndsWith("\\"))
                inputArgs.intermediatePath = inputArgs.intermediatePath + "\\";
            if (!inputArgs.outputPath.EndsWith("\\"))
                inputArgs.outputPath = inputArgs.outputPath + "\\";
            Log.WriteLine("Initialization finished. Folders checked and cleaned.");

            try
            {
                MapServerParameters.BBOXW = inputArgs.bbx.BBW;
                MapServerParameters.BBOXN = inputArgs.bbx.BBN;
                MapServerParameters.layer = inputArgs.mapLayerName;
                MapServerParameters.URLBuilder();

                if (!processLocalFiles)
                {
                    GetMapFromServiceWorker gmfsWoker = new GetMapFromServiceWorker();
                    gmfsWoker.Apply(inputArgs);
                }
                else
                    File.Copy(inputArgs.outputPath + StraboParameters.sourceMapFileName, inputArgs.intermediatePath + StraboParameters.sourceMapFileName, true);
                File.Copy(inputArgs.intermediatePath+StraboParameters.sourceMapFileName, inputArgs.outputPath+StraboParameters.sourceMapFileName,true);
            }
            catch (Exception e)
            {
                Log.WriteLine("ApplyWMSWorker/ApplyWMTSWorker: " + e.Message);
                throw;
            }

            string color_segmentation_result_fn;

            if (StraboParameters.numberOfSegmentationColor > 0)
            {
                try
                {
                    Log.WriteLine("ColorSegmentationWorker in progress...");
                    color_segmentation_result_fn = _colorSegmentationWorker.Apply(inputArgs.intermediatePath, inputArgs.threadNumber);
                    Log.WriteLine("ColorSegmentationWorker finished");
                }
                catch (Exception e)
                {
                    Log.WriteLine("ColorSegmentationWorker: " + e.Message);
                    throw;
                }
            }
            else
                color_segmentation_result_fn = inputArgs.intermediatePath + StraboParameters.sourceMapFileName;

            try
            {
                Log.WriteLine("TextExtractionWorker in progress...");
                _textLayerExtractionWorker.Apply(color_segmentation_result_fn, inputArgs.intermediatePath, inputArgs.threadNumber);
                Log.WriteLine("ApplyTextExtarionWorker finished");
            }
            catch (Exception e)
            {
                Log.WriteLine("ApplyTextExtractionWorker: " + e.Message);
                throw;
            }
            try
            {
                Log.WriteLine("TextDetectionWorker in progress...");
                _textDetectionWorker.Apply(inputArgs.intermediatePath, 2.5, false, inputArgs.threadNumber);
                Log.WriteLine("ApllyTextDetection finished");
            }
            catch (Exception e)
            {
                Log.WriteLine("ApplyTextDetectionWorker: " + e.Message);
                throw;
            }
            try
            {
                Log.WriteLine("TextRecognition in progress...");
                _textRecognitionWorker.Apply(inputArgs.intermediatePath, inputArgs.outputPath, inputArgs.outputFileName, top, left, bottom, right);
                Log.WriteLine("TextRecognitionWorker finished");
            }
            catch (Exception e)
            {
                Log.WriteLine("ApplyTextRecognition: " + e.Message);
                throw;
            }

            Log.WriteLine("Execution time: " + Log.GetDurationInSeconds().ToString());
        }
 public void Apply(InputArgs inputArgs)
 {
     Apply(inputArgs.bbx.BBW, inputArgs.bbx.BBN, inputArgs.mapLayerName, inputArgs.intermediatePath, StraboParameters.sourceMapFileName);
 }