Does ArcGIS pro sdk support raster clip with polygon function

786
3
Jump to solution
08-23-2019 03:56 PM
SamRideout1
New Contributor III

I am trying to write a C# program that loops raster processes.  Is there any way to access the raster  functionality without using the geoprocessing toolbox?  I have thousands of iterations.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
SamRideout1
New Contributor III

For anyone trying to clip a raster with a polygon feature layer, the following code works for me.  strFeature1 is the name of the water body feature layer and strDEM1 is the name of the elevation raster.  Both are stored in the default project geodatabase.  Water_Temp1 is the output raster clipped to the water body.

//Clip the elevation layer with water body
string out_workspace = Project.Current.DefaultGeodatabasePath;
string input_feature = Path.Combine(out_workspace, strFeature1);

string input_data = Path.Combine(out_workspace, strDEM1);
string out_data = Path.Combine(out_workspace, "Water_Temp1");

// make a value array of strings to be passed to ExecuteToolAsync
var parameters = Geoprocessing.MakeValueArray(input_data, "", out_data, input_feature, "", "ClippingGeometry", "MAINTAIN_EXTENT");

// execute the tool
Geoprocessing.ExecuteToolAsync("management.Clip", parameters, null, null, null, GPExecuteToolFlags.None);

View solution in original post

0 Kudos
3 Replies
SamRideout1
New Contributor III

For anyone trying to clip a raster with a polygon feature layer, the following code works for me.  strFeature1 is the name of the water body feature layer and strDEM1 is the name of the elevation raster.  Both are stored in the default project geodatabase.  Water_Temp1 is the output raster clipped to the water body.

//Clip the elevation layer with water body
string out_workspace = Project.Current.DefaultGeodatabasePath;
string input_feature = Path.Combine(out_workspace, strFeature1);

string input_data = Path.Combine(out_workspace, strDEM1);
string out_data = Path.Combine(out_workspace, "Water_Temp1");

// make a value array of strings to be passed to ExecuteToolAsync
var parameters = Geoprocessing.MakeValueArray(input_data, "", out_data, input_feature, "", "ClippingGeometry", "MAINTAIN_EXTENT");

// execute the tool
Geoprocessing.ExecuteToolAsync("management.Clip", parameters, null, null, null, GPExecuteToolFlags.None);

0 Kudos
Prashant_MukeshMangtani
Esri Contributor

Sam,

Can you expand on what raster process you are trying to loop? If you are doing clipping, the geoprocessing call is the probably the easiest way but you can do other raster based processes by using the core raster API to open a raster, access pixels and do something with them. Some code snippets can be found here

Hope that helps.

-Prashant

0 Kudos
SamRideout1
New Contributor III

Thanks Prashant...  I have seen those code snippets.  What I am trying to do is develop an application that repeatedly uses raster processes for analysis.  I have verified that my logic works by manually running the data using the tools in the toolboxes on the raster and feature layers.  Among others, I need to programatically (Visual Studio C#) run ClipRaster, Reclassify, Con, Raster to polygon and others.  There is not much documentation that I can find to get help.  Do you know of any resources that could support such programming?  Any help would be very welcome.  I figured out the clip raster yesterday and the reclassify today but in both cases, it took me all day to get there.  In either case, thank you for your assistance!

0 Kudos