Best way to get min/max from Raster?

2976
5
10-05-2017 11:48 AM
DrewD
by
New Contributor III

From a BasicRasterLayer you can use the CIMRasterStretchColorizer.StretchStats to get the min/max values, but I want to get the min/max from a custom extent. Since a Raster lets me set a new extent, I've been trying to get some useful values out of it.

Any suggestions or recommendations?

0 Kudos
5 Replies
GKmieliauskas
Esri Regular Contributor

Hi Drew,

In ArcGIS Pro1.4 there was no way to get statistics about raster except using geoprocessing. This is a part of code I use in my application:

                    var parameters = Geoprocessing.MakeValueArray(raster, "MINIMUM");
                    var environments = Geoprocessing.MakeEnvironmentArray(workspace: sWorkspace);
                    return Geoprocessing.ExecuteToolAsync("GetRasterProperties_management", parameters,                                            environments, CancelableProgressor.None, GPExecuteToolFlags.AddToHistory);

The worst thing that you can get only one type of statistics at time. To get "MAX" you need to call geoprocessing another time with "MAX" parameter.

ArcGIS Pro 2.0 has raster object, but I have not checked if it has statisrtics like IRaster in ArcObjects.

0 Kudos
DrewD
by
New Contributor III

Thanks for the suggestion, unfortunately the tool becomes unresponsive after hitting 

Geoprocessing.MakeValueArray(raster, "MIN");

0 Kudos
GKmieliauskas
Esri Regular Contributor

I have wrote that is a part of code You need to organize all async/wait things and etc. "raster" parameter could be RasterLayer or raster path (string). I could. send you more code, but there are snippets on executing geoprocessing from ArcGIS Pro like this https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-Geoprocessing.

0 Kudos
DrewD
by
New Contributor III

I think it's because the raster is very large. I will test some things out though, thank you!

0 Kudos
GKmieliauskas
Esri Regular Contributor

Sorry, it must be "MINIMUM" value for parameter not "MIN". It was parameter name in the original code. After pasting code I have changed to "MIN".

0 Kudos