Can the Viewshed Analysis Sample take height as a parameter?

295
6
Jump to solution
04-15-2021 01:23 PM
Neocyte
New Contributor II

The ArcGIS JavaScript API has a viewshed analysis sample that calculates a viewshed after clicking the scene view. The geoprocessor takes an Input_Observation_Point and a Viewshed_Distance, executes its task, and draws the viewshed:

 

var params = {
Input_Observation_Point: featureSet,
Viewshed_Distance: vsDistance
};
gp.execute(params).then(drawResultData);

 

Here is the geoprocessor: https://sampleserver6.arcgisonline.com/arcgis/rest/services/Elevation/ESRI_Elevation_World/GPServer/...

Does the Input_Observation_Point parameter have any variables for height? If so, how can I set it in the sample program?



Tags (3)
0 Kudos
1 Solution

Accepted Solutions
Tim_McGinnes
Occasional Contributor III

If you have a look at the REST page for the Viewshed task you will see that under Input_Observation_Point it will accept a field called OffsetA. In here you can specify an offset from elevation surface for the input point.

I have attached a screenshot showing how to modify the sample to use the offset. The viewshed goes much further to the north over that ridge when using an offset of 100.

View solution in original post

6 Replies
Tim_McGinnes
Occasional Contributor III

If you have a look at the REST page for the Viewshed task you will see that under Input_Observation_Point it will accept a field called OffsetA. In here you can specify an offset from elevation surface for the input point.

I have attached a screenshot showing how to modify the sample to use the offset. The viewshed goes much further to the north over that ridge when using an offset of 100.

View solution in original post

Neocyte
New Contributor II

Tim,

Thank you so much for that screenshot!

I was also wondering if it was somehow possible to incorporate azimuth into the viewshed application. That way, users could constrain the viewshed to a specific angle. Unfortunately, the REST page doesn't appear to have a variable for azimuth. Maybe there's a way to limit the graphics returned from drawResultData(result)?

Also, sometimes when you click to create a viewshed, an uncaught promise is thrown. You can replicate this by clicking anywhere on the north pole or by just randomly clicking. How can I fix this?

Neocyte_0-1618526836169.png

 

0 Kudos
Tim_McGinnes
Occasional Contributor III

Unfortunately the viewshed api is not sophisticated enough to do the azimuth stuff. You would probably have to do something client side with the results. Also see the Line of Sight widget for a different take on view analysis.

I was also getting those random uncaught promise errors. The north pole is understandable because the elevation layers don't cover that area - from the Viewshed page on ArcGIS Online:

By default, this tool currently works worldwide between 60 degrees north and 56 degrees south based on the 3 arc-second (approximately 90 meter) resolution SRTM dataset.

However I was also getting errors just clicking around and don't know why.

JohnGrayson
Esri Regular Contributor

Please note that the service referenced in the SDK sample is for demonstration purposes and not intended for production use-case.  Please see the Elevation Analysis services and specifically the Viewshed task. Here is a CodePen of the above sample modified to use the online Viewshed task.  Another option is to publish your own GP service against your own datasets that exposes all the necessary parameters for your task: Controlling the visibility analysis 

Neocyte
New Contributor II

John,

Thank you for pointing me in the direction of the Elevation Analysis services. I will be sure to use the Viewshed task instead of the sample.

But do you happen to know why an uncaught promise is sometimes thrown in the sample? Clicking the north pole is understandable, as Tim explained. But why is it being thrown when clicking on valid locations?

0 Kudos
JohnGrayson
Esri Regular Contributor

The error says you're trying to call the service with no observer locations passed in, so the first thing to check is to make sure there's at least  one valid observer location before making the call.  Hard to tell otherwise unless we have a reproducible use-case.  My guess is that the there's no logic in the code to pause the interaction while there's processing going on and maybe that could be an issue, but just a guess as I haven't run into the situation described.

0 Kudos