Thursday, October 8, 2015

Clip a raster from feature shape file using C# and ArcObject's geoprocessor

Code snippet in clipping a raster from feature shape file using C# and ArcObject's geoprocessor -

 public static void ClipRaster(string inRaster, string inClipFeature, string outTempRaster)  
     {  
       Clip clipTool = new Clip();  
   
       //set clip parameters  
       clipTool.in_raster = inRaster;  
       clipTool.out_raster = outTempRaster;  
   
       //clip extent  
       clipTool.in_template_dataset = inClipFeature;  
   
       Geoprocessor gp = new Geoprocessor();  
       gp.OverwriteOutput = true;  
       gp.AddOutputsToMap = false;  
         
       try  
       {  
         IGeoProcessorResult result = (IGeoProcessorResult)gp.ExecuteAsync(clipTool);  
         while(result.Status != esriJobStatus.esriJobSucceeded)  
         {  
           //Console.WriteLine(result.Status.ToString());  
           System.Threading.Thread.Sleep(100);  
         }  
       }  
       catch (Exception ex)  
       {  
         object level = 0;  
         Console.WriteLine(gp.GetMessages(ref level));  
         Console.WriteLine(" Failed to clip raster using ESRI clip tool " + ex.Message);  
       }  
   
     }  

If you execute gp.Execute(...), which will execute the clip in synchronous mode, which only writes the data in memory (good for smaller raster data set) but doesn't write/store the data on the disk.

arcobject , C#

0 comments :

Post a Comment

 

© 2011 GIS and Remote Sensing Tools, Tips and more .. ToS | Privacy Policy | Sitemap

About Me