How to plot a radius in Quicksight
Sometimes analyses require extending the analytical focus from one point on the geospatial mapping (be that an exact location or a city) to a larger circled area around that one point. Calculating precise distances between two points on Earth that take altitude and the exact special curvature of the Earth into consideration (note that Earth is not a perfect sphere) requires special formulas which are not currently available in Quicksight. However, for small distances (1-30 or so miles) we can approximate the radius using the Euclidean distance between two points defined in latitude and longitude. See endnotes for more details.
This article shows how a user can select a point of interest as well as a dynamic radius to focus the analysis on the selected area. The proposed solution uses two maps: one that displays all the available data points on one map, and another one that only displays/filters for a radius (with a size controlled by a dynamic parameter) for any selected point on the first map.
In my dataset, I have the following fields: latitude, longitude, city and zip code
Steps:
- Create a map and plot all data points.
a. Add a visual and select Map (Points on Map).
b. Add Latitude and Longitude to the field well Geospatial, and zip code to both, the Size and Color field wells. For the purposes of this demo, only zip codes in continental US were selected.
- Create a parameter, name it ‘LatitudeParam’, as a Number Data Type, and enter a default value. I picked 41.34544 for Atlanta as the default latitude value
- Create another parameter, call it ‘LongituteParam‘, as a Number Data Type, and enter a default value. I picked 76.56764 for Atlanta as the default longitude value
- Create another parameter, name it ‘Radius’, as an Integer Data Type, and enter a small number between 1 and 10 as the static default value. This will be the default value of the Radius. I picked 5
- Create a calculated field, ‘Distance’, and enter the following formula
The distance is in miles. For km remove 0.621371 from the calculation.
- Duplicate the map visual and arrange the two visuals side by side
- On the second map, add the newly created calculated field, Distance, as a Filter and select ‘Less than or equal to’ as Filter Condition. Click ‘Use Parameters’ and select the Radius parameter we created in step 5
- Go to the first visual, the map on the left, click on it and then go to Actions on the menu to the left.
- Configure new action:
a. Navigation action
b. The target sheet should be the same sheet
c. Click on the + sign next to Parameters and add the three parameters we created: LatitudeParam, LongitudeParam and Radius.
d. For LatitudeParam the Parameter value should be the field ‘latitude’
e. For LongitudeParam the Parameter value should be field ‘longitude’
f. For the default value of the Radius parameter I entered 5 (miles) - Save
- Go to the Radius Parameter and add a control for it
- Now, when you click on any represented point on the source map to the left, the target map to the right will automatically zoom in on the selected point and show only the same points within a default radius of approximately 5 miles. The radius can be modified via the control added in step 12
- Optional: to display the city name in the title of the second map, create another string Parameter, name it ‘City’, and then edit the Navigation Action created in step 10. Add the new parameter to the list of parameters and make sure you set the parameter value to be the field in your dataset that references cities
- (Optional) You can add another table that can be controlled by a similar navigation action so that selecting a zip code on the first map will automatically scale the table to show only the locations within X number of miles within the Radius.
Notes:
- For more accurate results, coordinates in latitude and longitude should be converted into Cartesian coordinates on the flat-like Earth, but for the sake of simplicity we will use latitude and longitude as they as more commonly found in datasets.
- Using longitude and latitude, however, comes with limitations since longitudes converge at the North and South Poles. This means that this method only produces approximately good results for very short distances, along the lines of longitude, and along the Equator. For other short distances, the errors could be as large as 30%. For all other distances expect errors in proportion to the differences in latitude and longitude. For a detailed, simple yet non-academic explanation see here
- If your dataset does not have latitude and longitude coordinates, you can augment your data by finding and adding them if your data has geographical locations such as street addresses, zip codes or city names.