Running a client side Raster Clip on an ImageryLayer

2106
8
Jump to solution
06-30-2021 12:36 AM
IGCMCGIS
New Contributor III

We are trying to run a ClientSide clip on an image service layer using the JavaScript API. Ideally we would want it to work like the the create feature layer from shapefile sample (https://developers.arcgis.com/javascript/latest/sample-code/layers-featurelayer-shapefile/) where we would like to generate landcover charts using the clipped extent.

While it seems that creating a GP task is a good alternative, will this be possible over client side and if so could someone direct us to any samples.

Thanks for your help!

 

0 Kudos
1 Solution

Accepted Solutions
JohnGrayson
Esri Regular Contributor

It can depend on many, many things and there are probably several ways to do most steps depending on the application requirements.  Do you control the image service?  Do you control the polygon vector data?  Is it necessary for the application to allow for the polygon vector data to come from a shapefile?  What is the desired user experience? What is the desired output?  As you can see there are too many things involved to provide a simple answer.  Here's a quick example of one way in which you can use the Clip raster function, but how this raster function is applied in your use-case will depend on the image service you use and how it's configured.  I hope this helps.

https://codepen.io/john-grayson/pen/ExmXBLr 

https://developers.arcgis.com/documentation/common-data-types/raster-function-objects.htm

https://desktop.arcgis.com/en/arcmap/latest/manage-data/raster-and-images/clip-function.htm

 

View solution in original post

8 Replies
JohnGrayson
Esri Regular Contributor
0 Kudos
IGCMCGIS
New Contributor III

Thank you @JohnGrayson ,

Essentially we did refer to the sample and did work on it. What this sample does is bases the extraction on a buffer generated via the mouse event. We want this to work using the boundary of an uploaded polygon shapefile. 

We are loking to use the ouput feature collection defined by the following sample (https://developers.arcgis.com/javascript/latest/sample-code/layers-featurelayer-shapefile/) to query the attributes of the image service.

Please do let us know if it is possible as we have been trying to implement this for a while now.

We had outlined our problem within the following post: https://community.esri.com/t5/arcgis-api-for-javascript-questions/imagerylayer-client-side-chart-usi...

Thanks a ton!

0 Kudos
JohnGrayson
Esri Regular Contributor

In looking at your other question, an important concept to understand is that the buffer/circle constructed to filter the data is based on a pixel location and distances, but what you get back from converting the shapefile are vector based geometries.  The first step in combining these concepts is that you will need to re-write the calls to the ImageryLayer to include your vector based geometry filter (a geometry from one of the converted shapefile layers) before retrieving the pixels.  You can use the 'Clip' raster function to help with this task.  You could then create the chart from those returned pixels.  What you want to do will require a lot of changes to the code, but it should be possible.  This process will result in a different user experience from the sample as you will loose the interactive calculations, which will now only happen when the view extent changes.

IGCMCGIS
New Contributor III

Hello @JohnGrayson ,

Thank you somuch for your response. 

Is it advisable to use a GP service with teh Clip Raster function and consume that within the application or is there a way to have this entire process be executed over a client side and then maybe create the resulting charts.

We are new to the the JavaScript API and have been using samples to learn how to build applications. Is there any sample you could direct us to which uses a raster clip?

We really appreciate all the help you've provided us. 

Thanks again.

0 Kudos
JohnGrayson
Esri Regular Contributor

It can depend on many, many things and there are probably several ways to do most steps depending on the application requirements.  Do you control the image service?  Do you control the polygon vector data?  Is it necessary for the application to allow for the polygon vector data to come from a shapefile?  What is the desired user experience? What is the desired output?  As you can see there are too many things involved to provide a simple answer.  Here's a quick example of one way in which you can use the Clip raster function, but how this raster function is applied in your use-case will depend on the image service you use and how it's configured.  I hope this helps.

https://codepen.io/john-grayson/pen/ExmXBLr 

https://developers.arcgis.com/documentation/common-data-types/raster-function-objects.htm

https://desktop.arcgis.com/en/arcmap/latest/manage-data/raster-and-images/clip-function.htm

 

IGCMCGIS
New Contributor III

Thank you so much for a detailed response @JohnGrayson !

We are really glad you were able to send us an example of the clip raster function.

To answer your question and give this a bit more clarity, we would do have control of the image services but we would not have control over the polygon layer. The image services will be added to the map all formatted in the same manner as NLCDLandCover2001 ensuring the same raster attribute table is used.
It is neccessary that we would want the polygon layer to come from a shapefile only.
The desired used experience would be that they would upload a shapefile boundary of their choice and in turn this would generate multiple landcover charts for all the image services that have been added to the map ( Which is why we ensure that the image services would use the same formats). Something like this multiple charts image which uses the same sample for two different raster layersMultiple Charts imageMultiple Charts image

The charts would be the desired output. We do no need the clipped raster layers to be added to the map but if we have to its absolutly fine.

Please do let us knwo if you have any insight on this.

Thank you again for all your help.

 

0 Kudos
IGCMCGIS
New Contributor III

Hello @JohnGrayson ,

Was the above description helpful amd will it be possible to run this entire operation over client side.

Thanks again.

0 Kudos
JohnGrayson
Esri Regular Contributor

As mentioned previously there are more than one way to do this task depending on your needs.  If you have multiple layers but don't want to display them in the map and still create these types of charts, then using a client-side pixel filter is probably not the way to do this as your use-case and workflow are very, very different.  I would suggest you investigate the use of histograms as a possibility.  You can still pass in the 'clip' raster function as part of the renderingRule.  The counts you get back would represent the number of pixels in each class and you could build the charts based on those values.

0 Kudos