HOW TO

Calculate shadow lengths using Arcade in the ArcGIS Enterprise portal and ArcGIS Online

Last Published: February 13, 2025

Summary

Shadow analysis such as calculating shadow lengths plays a crucial role for urban planning and environmental studies. For instance, in urban planning, calculating shadow lengths can help determine the optimal placement of new buildings to prevent casting long shadows over public parks, ensuring they receive adequate sunlight for recreational use.

This article provides the workflow to calculate shadow lengths using Arcade in the ArcGIS Enterprise portal and ArcGIS Online.

Procedure

  1. Log in to the ArcGIS Enterprise portal or ArcGIS Online and click Content > My Content.
  2. Click the hosted feature layer to open the item page.
  3. Add a new string field. Refer to Portal for ArcGIS: Add a field or ArcGIS Online: Add a field for instructions. In this example, a new field, 'ShadowGeometry', is added to the attribute table with three existing fields named 'Building_Height', 'SunAltitude', and 'SunAzimuth' respectively.
  4. Open the Arcade window. Refer to Portal for ArcGIS: Calculate values for a field from the item page or ArcGIS Online: Calculate values for a field from the item page for instructions.
  5. In the Expression box, specify the following Arcade expression:
    1. Input the necessary fields and variables.
var buildingHeight = $feature.Building_Height;
var sunAltitude = $feature.SunAltitude;
var sunAzimuth = $feature.SunAzimuth;
    1. Check for valid values.
if (IsEmpty(buildingHeight) || IsEmpty(sunAltitude) || IsEmpty(sunAzimuth) || sunAltitude <= 0) {
  return null;
}
    1. Convert degrees to radians.
var toRadians = PI / 180;
var sunAltitudeRadians = sunAltitude * toRadians;
    1. Calculate the shadow length using the tangent function.
var shadowLength = buildingHeight / Tan(sunAltitudeRadians);
    1. Return the shadow length and direction as a string.
return "Length: " + Round(shadowLength, 2) + " meters, Azimuth: " + Round(sunAzimuth, 2) + " degrees";

The code block below shows the example of the full working script:

var buildingHeight = $feature.Building_Height;
var sunAltitude = $feature.SunAltitude;
var sunAzimuth = $feature.SunAzimuth;

if (IsEmpty(buildingHeight) || IsEmpty(sunAltitude) || IsEmpty(sunAzimuth) || sunAltitude <= 0) {
    return null;
}

var toRadians = PI / 180;
var sunAltitudeRadians = sunAltitude * toRadians;

var shadowLength = buildingHeight / Tan(sunAltitudeRadians);

return "Length: " + Round(shadowLength, 2) + " meters, Azimuth: " + Round(sunAzimuth, 2) + " degrees";
  1. Click OK.

The attribute table below shows the calculated shadow lengths in the 'ShadowGeometry' field.

The calculated shadow lengths in the attribute table

Article ID: 000034650

Software:
  • ArcGIS Online
  • Portal for ArcGIS
  • ArcGIS Enterprise 11 3
  • ArcGIS Enterprise 11 2
  • ArcGIS Enterprise 11 4

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options