Beispiel #1
0
        /// <summary>
        /// 栅格传输
        /// </summary>
        /// <param name="task"></param>
        public static void CopyRaster(string sourceFileName, string destFileName, RenameMode renameMode)
        {
            RasterReadHelper inputReadHelper            = new RasterReadHelper(sourceFileName);
            RasterReadHelper outputReadHelper           = new RasterReadHelper(destFileName);
            string           outputNameWithoutExtention = string.Empty;

            if (renameMode.Equals(RenameMode.Overwrite))
            {
                outputReadHelper.Delete(outputReadHelper.NameWithoutExtension + outputReadHelper.Extension);
                outputNameWithoutExtention = outputReadHelper.NameWithoutExtension;
            }
            else
            {
                outputNameWithoutExtention = outputReadHelper.AccumulativeName;
            }

            ESRI.ArcGIS.DataManagementTools.CopyRaster CpyRst = new ESRI.ArcGIS.DataManagementTools.CopyRaster(sourceFileName, outputReadHelper.Directory + "\\" + outputNameWithoutExtention);
            Geoprocessor gp = new Geoprocessor();

            gp.SetEnvironmentValue("Compression", inputReadHelper.RstDs.CompressionType);
            gp.OverwriteOutput = true;
            IGeoProcessorResult gpResult = gp.Execute(CpyRst, null) as IGeoProcessorResult;

            if (gpResult == null || gpResult.Status == esriJobStatus.esriJobFailed)
            {
                for (int i = 0; i < gpResult.MessageCount; i++)
                {
                    MessageBox.Show(gpResult.GetMessage(i));
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Raster导入GDB
 /// </summary>
 /// <param name="in_Raster">输入Raster</param>
 /// <param name="gdb_Path">库完整路径</param>
 /// <param name="rst_Name">库内文件名</param>
 /// <param name="result">运行结果</param>
 /// <returns></returns>
 public static bool ImportRasterToGDB(IRaster in_Raster, string gdb_Path, string rst_Name, out string result)
 {
     try
     {
         ESRI.ArcGIS.DataManagementTools.CopyRaster cr = new ESRI.ArcGIS.DataManagementTools.CopyRaster();
         cr.in_raster         = in_Raster;
         cr.out_rasterdataset = gdb_Path + "/" + GetNameGDB(gdb_Path, rst_Name);
         cr.background_value  = 0;
         Geoprocessor gp = new Geoprocessor();
         gp.OverwriteOutput = true;
         IGeoProcessorResult gpr = gp.Execute(cr, null) as IGeoProcessorResult;
         if (gpr != null && gpr.Status == esriJobStatus.esriJobSucceeded)
         {
             result = "Success";
             return(true);
         }
         else
         {
             result = "Failure";
             return(false);
         }
     }
     catch (Exception e)
     {
         result = e.Message;
         return(false);
     }
 }
Beispiel #3
0
        public static void ExportLayerToUploadableRaster(string outputFilePath, string name, ILayer source)
        {
            try
            {
                // cast the selected/requested layer into a raster layer
                ESRI.ArcGIS.Carto.IRasterLayer rasterLayer = (IRasterLayer)source;

                // create a new raster to raster converter utility
                ESRI.ArcGIS.DataManagementTools.CopyRaster raster2raster
                    = new ESRI.ArcGIS.DataManagementTools.CopyRaster();

                // set the input raster layer
                raster2raster.in_raster = rasterLayer;

                // set the output path and Shapefile name

                /* The name and location of the raster dataset to be created.
                 * .bil—Esri BIL
                 * .bip—Esri BIP
                 * .bmp—BMP
                 * .bsq—Esri BSQ
                 * .dat—ENVI DAT
                 * .gif—GIF
                 * .img—ERDAS IMAGINE
                 * .jpg—JPEG
                 * .jp2—JPEG 2000
                 * .png—PNG
                 * .tif—TIFF
                 * no extension for Esri Grid
                 */
                raster2raster.out_rasterdataset = outputFilePath + "\\" + name + ".tif";

                // create a new GeoProcessor
                Geoprocessor geoprocessor = new Geoprocessor();
                geoprocessor.TemporaryMapLayers = true;

                // execute the RasterToOtherFormat
                geoprocessor.Execute(raster2raster, null);
            }
            catch (Exception ex)
            {
                // an error occured
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message);
            }
        }
        public static void ExportLayerToUploadableRaster(string outputFilePath, string name, ILayer source)
        {
            try
            {
                // cast the selected/requested layer into a raster layer
                ESRI.ArcGIS.Carto.IRasterLayer rasterLayer = (IRasterLayer)source;
                
                // create a new raster to raster converter utility
                ESRI.ArcGIS.DataManagementTools.CopyRaster raster2raster
                    = new ESRI.ArcGIS.DataManagementTools.CopyRaster();

                // set the input raster layer
                raster2raster.in_raster = rasterLayer;

                // set the output path and Shapefile name
                /* The name and location of the raster dataset to be created.
                 * .bil—Esri BIL
                 * .bip—Esri BIP
                 * .bmp—BMP
                 * .bsq—Esri BSQ
                 * .dat—ENVI DAT
                 * .gif—GIF
                 * .img—ERDAS IMAGINE
                 * .jpg—JPEG
                 * .jp2—JPEG 2000
                 * .png—PNG
                 * .tif—TIFF
                 * no extension for Esri Grid
                 */
                raster2raster.out_rasterdataset = outputFilePath + "\\" + name + ".tif";

                // create a new GeoProcessor
                Geoprocessor geoprocessor = new Geoprocessor();
                geoprocessor.TemporaryMapLayers = true;

                // execute the RasterToOtherFormat
                geoprocessor.Execute(raster2raster, null);
            }
            catch (Exception ex)
            {
                // an error occured
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message);
            }
        }
Beispiel #5
0
        private void CopyRasterMethod()
        {
            try
            {
                double Size             = 0;
                string gdb_Path         = target.In_Directory;
                string feat_Name        = target.In_FileName;
                string outputFolderPath = target.Out_Directory;
                string outputName       = target.Out_FileName;

                ESRI.ArcGIS.DataManagementTools.CopyRaster cr = new ESRI.ArcGIS.DataManagementTools.CopyRaster();
                cr.in_raster = gdb_Path + "\\" + feat_Name;
                if (System.IO.Path.GetExtension(outputFolderPath).ToUpper().Equals(".GDB"))
                {
                    cr.out_rasterdataset = outputFolderPath + "\\" + GetNameGDB(outputFolderPath, outputName);
                }
                else
                {
                    cr.out_rasterdataset = outputFolderPath + "\\" + GetNameRaster(outputFolderPath, outputName);
                }

                IWorkspaceFactory2 in_wsf    = new FileGDBWorkspaceFactoryClass();
                IRasterWorkspace2  in_rstWs  = (IRasterWorkspace2)in_wsf.OpenFromFile(gdb_Path, 0);
                IRasterLayer       in_rstLyr = new RasterLayerClass();
                IRasterDataset     in_rstDs  = in_rstWs.OpenRasterDataset(feat_Name);
                in_rstLyr.CreateFromDataset(in_rstDs);

                IRasterProps in_rasterProps           = (IRasterProps)in_rstLyr.Raster;
                int          Height                   = in_rasterProps.Height;
                int          Width                    = in_rasterProps.Width;
                rstPixelType in_rstPT                 = in_rasterProps.PixelType;
                int          BandsCount               = in_rstLyr.BandCount;
                Dictionary <rstPixelType, int> DictPT = new Dictionary <rstPixelType, int>();
                DictPT.Clear();
                DictPT.Add(rstPixelType.PT_DOUBLE, 64);
                DictPT.Add(rstPixelType.PT_FLOAT, 32);
                DictPT.Add(rstPixelType.PT_LONG, 32);
                DictPT.Add(rstPixelType.PT_SHORT, 32);
                DictPT.Add(rstPixelType.PT_UCHAR, 8);
                DictPT.Add(rstPixelType.PT_ULONG, 32);
                DictPT.Add(rstPixelType.PT_USHORT, 32);
                DictPT.Add(rstPixelType.PT_CHAR, 8);

                int Depth = 32;
                DictPT.TryGetValue(in_rasterProps.PixelType, out Depth);

                Size        = 1.0 * Height * Width * BandsCount * Depth / 8.0 / 1024 / 1024;
                target.Size = Size;

                Geoprocessor gp = new Geoprocessor();
                gp.OverwriteOutput = true;
                IGeoProcessorResult gpr = gp.Execute(cr, null) as IGeoProcessorResult;

                if (gpr != null && gpr.Status == esriJobStatus.esriJobSucceeded)
                {
                    DateTime tm2 = DateTime.Now;
                    TimeSpan ts1 = new TimeSpan(startTime.Ticks);
                    TimeSpan ts2 = new TimeSpan(tm2.Ticks);
                    TimeSpan ts3 = ts2.Subtract(ts1);

                    string out1, out2;
                    GetConfig("Size", out out1);
                    GetConfig("Time", out out2);
                    double size = double.Parse(out1);
                    double time = double.Parse(out2);
                    SaveConfig("Size", (size + Size).ToString());
                    SaveConfig("Time", (time + ts3.TotalSeconds).ToString());
                    target.IsFinished = true;
                    target.IsBusy     = false;
                    OnFinished(new LayerOperaEventArgs(target));
                }
                else
                {
                }
            }
            catch (Exception e)
            {
            }
        }