示例#1
0
        public void GdalWarp()
        {
            // gdalwarp -dstnodata 0 -multi -overwrite -crop_to_cutline -cutline border.shp "bc1b395d-5011-4b25-947c-b06db932493b_index_ci_red-uptake.Amersfoort - RD New.tif" clipped.tif
            const string inputFilename  = @"D:\dev\MapWindow\MapWinGIS\git\unittests\MapWinGISTests\Testdata\GeoTiff\Chlorofyl.tif";
            const string borderFilename = @"D:\dev\MapWindow\MapWinGIS\git\unittests\MapWinGISTests\Testdata\sf\ClipForChlorofyl.shp";
            const string outputFilename = inputFilename + "-clipped.vrt";

            if (File.Exists(outputFilename))
            {
                File.Delete(outputFilename);
            }

            var options = new[]
            {
                "-of", "vrt",
                "-overwrite",
                "-crop_to_cutline",
                "-cutline", borderFilename,
                "-dstnodata", "0"
            };
            var retVal = _gdalUtils.GdalRasterWarp(inputFilename, outputFilename, options);

            WriteLine("options.Length: " + options.Length);
            WriteLine("retVal: " + retVal);
            Assert.IsTrue(retVal, "gdalUtils.GDALWarp() returned false: " + _gdalUtils.ErrorMsg[_gdalUtils.LastErrorCode] + " Detailed error: " + _gdalUtils.DetailedErrorMsg);
            Assert.IsTrue(File.Exists(outputFilename), "Can't find the output file");
            WriteLine(outputFilename + " is created");
        }
        public void Run(string filename, string fileLocation, RasterLayer r)
        {
            string localData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            var    output    = localData + "\\ResTBDesktop\\temp\\" + filename;
            var    options   = new[]
            {
                "-t_srs", "EPSG:3857",
                "-overwrite"
            };



            var gdalUtils = new GdalUtils();

            RasterReprojectCallback callback = new RasterReprojectCallback(r, MapControlTools);

            gdalUtils.GlobalCallback = callback;

            if (!gdalUtils.GdalRasterWarp(fileLocation, output, options))
            {
                Events.MapControl_Error imghandle_error = new Events.MapControl_Error()
                {
                    ErrorCode = Events.ErrorCodes.GdalWarpError, InMethod = "AddRasterLayer", AxMapError = "GdalWarp failed: " + gdalUtils.ErrorMsg[gdalUtils.LastErrorCode] + " Detailed error: " + gdalUtils.DetailedErrorMsg
                };
                MapControlTools.On_Error(imghandle_error);
            }

            if (MapControl_RasterReprojected != null)
            {
                Events.MapControl_RasterReprojected eventArgs = new Events.MapControl_RasterReprojected();
                eventArgs.rasterLayer = r;
                MapControl_RasterReprojected(this, eventArgs);
            }

            Events.MapControl_BusyStateChange bc = new Events.MapControl_BusyStateChange();
            bc.BusyState   = Events.BusyState.Idle;
            bc.KeyOfSender = "Rasterreprojected";
            bc.Percent     = 100;
            bc.Message     = "";

            MapControlTools.On_BusyStateChange(bc);
        }