Query a raster for pixel value from ImageServer/AGOL

581
8
04-28-2021 03:46 AM
Vidar
by
Occasional Contributor

Hi

 

I have a raster published in AGOL and it’s URL is like this https://tiledimageservices1.arcgis.com/IB7Kf2F8K18M2LKr/arcgis/rest/services/fooRaster/ImageServer

 

I want to access the raster via the Pro SDK but NOT add it to the map, and the only example code I can find is below:

 

string dataSoureUrl = @”https://tiledimageservices1.arcgis.com/IB7Kf2F8K18M2LKr/arcgis/rest/services/fooRaster/ImageServer”;

 

ImageServiceLayer rasterLayer = null;

 

await QueuedTask.Run(() =>

{

       // Create a layer based on the url. In this case the layer we are creating is an image service layer.

       rasterLayer = (ImageServiceLayer)LayerFactory.Instance.CreateLayer(new Uri(dataSoureUrl), myMap);

});

 

 

The reason I don’t want to add it to the map – is because I am doing a “drill down” on about 10 rasters based on an x,y coordinate the user has selected on the map (with some background mapping of the world) – and extract the pixel value at that coordinate. It’s too much unnecessary overhead to load the rasters into Pro and do the analysis after the event.

 

Is there a way to query a pixel value in memory based on the an x,y location??

 

Tags (1)
0 Kudos
8 Replies
GintautasKmieliauskas
Regular Contributor

Hi,

For creating layer in memory look here:

https://community.esri.com/t5/arcgis-pro-sdk-questions/making-a-group-layer-or-layer-in-memory/m-p/7... 

To get pixel value from layer:

var raster = imageServiceLayer.GetRaster();

object pixelValue = raster.GetPixelValue(0, 150000, 150000);

 

0 Kudos
Vidar
by
Occasional Contributor

Hi,

Thanks for your reply - I think the LayerParams only works with feature data, not rasters.  But the second part of your reply looks good.

0 Kudos
GintautasKmieliauskas
Regular Contributor

Hi,

What about this workaround?

Create FeatureLayer and set to not display in Map.

//The catalog path of the feature layer to add to the map
var featureClassUriVisibility = new Uri(@"C:\Data\Admin\AdminData.gdb\USA\cities");
//Define the Feature Layer's parameters.
var layerParamsVisibility = new FeatureLayerCreationParams(featureClassUriVisibility)
{
  //Set visibility
  IsVisible = false,
};
//Create the layer with the feature layer parameters and add it to the active map
var createdFC = LayerFactory.Instance.CreateLayer<FeatureLayer>(layerParamsVisibility, MapView.Active.Map);

 

0 Kudos
Vidar
by
Occasional Contributor

I think thats the same sort of solution in the link provided before - again, its dealing with FeatureLayers - but here we are dealing with rasters, specifically ImageServer. Also the example adds it to the map which I don't really want to do.

0 Kudos
GintautasKmieliauskas
Regular Contributor

HI,

I have checked right now. It works. Code below:

var imageServiceUriVisibility = new Uri(path);

var layerParamsVisibility = new LayerCreationParams(imageServiceUriVisibility)
{
//Set visibility
IsVisible = false,
};

// Creates a layer based on the url. In this case the layer we are creating is an image service layer.
imageServiceLayer = LayerFactory.Instance.CreateLayer<ImageServiceLayer>(layerParamsVisibility, MapView.Active.Map);
if (imageServiceLayer == null)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Failed to create layer for url:" + path);
return null;
}

GintautasKmieliauskas
Regular Contributor

Hi,

It looks  like Pro only adds layer with unchecked visibility checkbox, I understand  that it does not show in TOC.

Sorry. 🙂

Vidar
by
Occasional Contributor

It does work, I've tried it too - unfortunately it adds it to the map. Maybe I'll have to work with this until there is a better solution from ESRI.

Thanks for your help on this though.

0 Kudos
Vidar
by
Occasional Contributor

Is there anyone from ESRI who can give an official line on this - at the moment my add-in behaviour is horrible and clunky - I am having to add 10 rasters to my map before I can do my queries which is taking an inordinate amount of time and it looks clunky to the user. Plus I have to clean up and remove the layers after I have queried my rasters. It's just not an acceptable user experience.