# How to plot a radius in Quicksight

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:

1. 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. 1. 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
2. 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
3. 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
4. Create a calculated field, ‘Distance’, and enter the following formula ``````The distance is in miles. For km remove 0.621371 from the calculation.
``````
1. Duplicate the map visual and arrange the two visuals side by side 1. 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 1. Go to the first visual, the map on the left, click on it and then go to Actions on the menu to the left.
2. Configure new 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)
3. Save
4. Go to the Radius Parameter and add a control for it 1. 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
2. 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 1. (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:

1. 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.
2. 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
3. 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.

Hi Gilbert, this is really useful.
What’s the rationale for the 108 in the distance calculation?

apologies in advance if I cover a few things you may already know:

Latitude and longitude coordinates measure the distance from the Equator, north/south and the Prime Meridian east/west respectively. As you know, the distance is measured in Degrees of a circle (not in miles or km).

Without converting these degrees into some sort of distance in a planar coordinate system, using them in Euclidean distance calculations would not make any sense.

108 was used as a scaling factor that converts the difference in degrees to a unit of distance.

One degree of longitude is approx. 69 miles at the equator. It decreases to 0 as you move closer to the poles.
One degree of latitude is always 69 miles.

I used 67 miles (which is 108km) for both as a scalar approximation since the distance in degrees of longitude can decrease.
67 miles = 108 km * 0.621371

Hope it helps,
GL

67 miles = 108 * 0.621371

I hope it helps,
GL

1 Like