0

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:

  1. 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)
FlyingTeller
  • 17,638
  • 3
  • 38
  • 53
  • Have you searched for it? What did you get? – NoDataDumpNoContribution Jun 20 '23 at 20:07
  • Welcome to [so]. This is not a code-writing or tutoring service. It is not possible to provide a specific answer without you providing sufficient information to understand your problem. Please see: [Why is Can someone help me? not an actual question?](https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question) for more details. – itprorh66 Jun 20 '23 at 23:50
  • @NoDataDumpNoContribution I've been searching, but can't seem to be phrasing my search with the correct syntax to find a mechanism. The closest I can find are [1] (https://stackoverflow.com/questions/73788533/how-to-draw-overlapping-2d-circles-and-adjust-shapes-based-on-collision?rq=3) and [2] (https://stackoverflow.com/questions/14607317/in-python-how-can-i-identify-clusters-of-overlapping-circles?rq=3). The 1st would work if I can remove the line in the middle of the circles where they collide. The 2nd identifies overlapping circles which helps but doesn't show a mechanism for removing lines – user22049219 Jun 21 '23 at 11:57
  • Thanks for the welcome, @itprorh66. Do you have any specific questions that might help with supplying the information that you think would be sufficient to answer my question? In life I've found that someone saying "This isn't sufficient." without additional context as to why it isn't sufficient or how it can be improved just causes an inefficient back and forth that amounts to guess and check. – user22049219 Jun 21 '23 at 12:25
  • (Continued, @itprorh66) took a look at the link that you provided and it seems like the 4th answer encapsulates where you and I are at. It is the one that says: "To this end, I also propose we favour actually explaining what's wrong with the question as a whole as opposed to fixating on "Can you help me"." And "Simply linking here DOES NOT HELP - at best it gives some vague guidelines for what a good question should look like (which can be found in the help center as well), where concrete guidance specific to their situation would be much more beneficial to them (in my opinion)." – user22049219 Jun 21 '23 at 12:25
  • Please edit the search results from your comment into the question. – NoDataDumpNoContribution Jun 21 '23 at 12:27
  • In general what you are describing is boolean geometry, for example you may want to compute the *union*, *intersection*, or *difference* between your polygons. Check out the [shapely](https://shapely.readthedocs.io/en/stable/) library for an example of how to do this. – Cory Kramer Jun 21 '23 at 12:53

0 Answers0