I have this code that creates a circle on a map (for each given location) that is X number of miles away from that given location. These circles overlap, and I want to remove the parts on the inside of the overlap. Essentially, I want to:
- Remove the inside lines so that there is just an outer "shape".
2. Get the area of that shape (in sq mi).
To illustrate this issue, I basically want to take the circles and create a shape like this Mickey Mouse silhouette but with more circles and then get the area of it (in sq mi).
What I am looking for: I don't necessarily need the code to accomplish this (though that would be appreciated). I am more looking for the mechanism to accomplish this as a starting off point so that I can figure it out.
If it matters, I am using Google Colab. I'm also open to suggestions on the code if you see inefficiencies.
This is my current code. I figure someone will ask, so I used the range(0, 450, 10) because I could get the circles to finish at 360.
import folium
from geopy import distance
from geopy.geocoders import Nominatim
from IPython.display import display
geolocator = Nominatim(user_agent="circle_map")
def draw_circle(latitude, longitude, radius, address, folium_map):
# Calculate the coordinates for the circle perimeter
perimeter_points = []
for bearing in range(0, 450, 10):
point = distance.distance(miles=radius).destination((latitude, longitude), bearing)
perimeter_points.append([point.latitude, point.longitude])
# Add the circle perimeter to the map as a polyline
folium.PolyLine(locations=perimeter_points, color='red').add_to(folium_map)
# Add address as a popup on the map
folium.Marker(location=[latitude, longitude], popup=address).add_to(folium_map)
# Define the addresses
addresses = [
(""),
(""),
(""),
(""),
(""),
(""),
(""),
(""),
(""),
(""),
(""),
(""),
(""),
("")
]
# Radius of the circle in miles
circle_radius = 50
# Create a folium map centered at X,X
map_center = [,]
folium_map = folium.Map(location=map_center, zoom_start=10)
# Generate circles for each address
for address in addresses:
location = geolocator.geocode(address[0] + " " + address[1])
if location is not None:
draw_circle(location.latitude, location.longitude, circle_radius, address[0] + ", " + address[1], folium_map)
# Display the map within the notebook
display(folium_map)