Can you write in Python3 a function that will create an PNG image of a satellite map…
- User
Can you write in Python3 a function that will create an PNG image of a satellite map with markers for both departure and arrival of a flight for instance. This function take as parameter coordinates for both departure and arrival. And I would like also a curved line between the two markers to see an approximate route of the flight.
- Assistant
- User
I got the following error : "Traceback (most recent call last): File "/home/blue/Documents/Dev/CarbonPlane/map4.py", line 39, in create_flight_map(departure_coord=(-74.0059731, 40.7127753), # New York File "/home/blue/Documents/Dev/CarbonPlane/map4.py", line 17, in create_flight_map ax.stock_img() AttributeError: 'MollweideAxes' object has no attribute 'stock_img'"
- Assistant
- User
It work ! Is is possible now to have the map in Mercator Projection ? And change the coordonnate for New York to Londo : from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np
def create_flight_map(departure_coord, arrival_coord, image_path='flight_map.png'): # Create a map using the Mollweide projection m = Basemap(projection='moll', lon_0=0, resolution='c')
# Draw map details m.etopo(scale=0.5, alpha=0.5) # Define the departure and arrival points dep_lon, dep_lat = departure_coord arr_lon, arr_lat = arrival_coord # Draw the great circle route between departure and arrival points m.drawgreatcircle(dep_lon, dep_lat, arr_lon, arr_lat, linewidth=2, color='b') # Project the coordinates onto the map and place a marker x_dep, y_dep = m(dep_lon, dep_lat) x_arr, y_arr = m(arr_lon, arr_lat) m.scatter(x_dep, y_dep, s=100, c='red', marker='o', edgecolors='k', zorder=5) m.scatter(x_arr, y_arr, s=100, c='green', marker='o', edgecolors='k', zorder=5) # Save and show the image plt.savefig(image_path, format='png', bbox_inches='tight', dpi=300) plt.show()Test the function with departure and arrival coordinates.
create_flight_map(departure_coord=(-74.0059731, 40.7127753), # New York Coordinates arrival_coord=(151.2092955, -33.8688197)) # Sydney Coordinates
- Assistant
- User
Thank you, it work perfectly :)
- Assistant
You're welcome! I'm delighted to hear that it worked perfectly for you. If you have any more questions or need further assistance with your project, feel free to ask. Happy coding!
- User
Is it possible to have a plane figure above the curved line ? : "from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt
def create_flight_map(departure_coord, arrival_coord, image_path='flight_map.png'): # Determine the bounding box lats = [departure_coord[1], arrival_coord[1]] lons = [departure_coord[0], arrival_coord[0]] margin = 20 # margin in degrees llcrnrlat = min(lats) - margin urcrnrlat = max(lats) + margin llcrnrlon = min(lons) - margin urcrnrlon = max(lons) + margin
# Create a map using the Mercator projection m = Basemap(projection='merc', llcrnrlon=llcrnrlon, llcrnrlat=llcrnrlat, urcrnrlon=urcrnrlon, urcrnrlat=urcrnrlat, resolution='i') # Draw map details m.drawcoastlines(linewidth=0.2) #m.fillcontinents(color='lightgray',lake_color='aqua') #m.drawmapboundary(fill_color='aqua') m.drawcountries(linewidth=0.2) m.bluemarble() # Define the departure and arrival points dep_lon, dep_lat = departure_coord arr_lon, arr_lat = arrival_coord # Draw the great circle route between departure and arrival points m.drawgreatcircle(dep_lon, dep_lat, arr_lon, arr_lat, linewidth=2, color='w') # Project the coordinates onto the map and place a marker x_dep, y_dep = m(dep_lon, dep_lat) x_arr, y_arr = m(arr_lon, arr_lat) m.scatter(x_dep, y_dep, s=100, c='grey', marker='^', edgecolor='k', zorder=5) m.scatter(x_arr, y_arr, s=100, c='grey', marker='v', edgecolor='k', zorder=5) # Save and show the image plt.savefig(image_path, format='png', bbox_inches='tight', dpi=300) plt.show() - Assistant
- User
/home/blue/Documents/Dev/CarbonPlane/map4.py:52: UserWarning: Glyph 128745 (\N{SMALL AIRPLANE}) missing from current font. plt.savefig(image_path, format='png', bbox_inches='tight', dpi=300) /home/blue/Documents/Dev/CarbonPlane/map4.py:53: UserWarning: Glyph 128745 (\N{SMALL AIRPLANE}) missing from current font. plt.show() /usr/lib/python3/dist-packages/gi/overrides/Gio.py:42: UserWarning: Glyph 128745 (\N{SMALL AIRPLANE}) missing from current font. return Gio.Application.run(self, *args, **kwargs)
- Assistant
- User
Finalement j'aimerais juste avoir une fleche au mileu de la ligne courbée pour indiquer le sens du vol, merci : from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt
def midpoint(coords1, coords2): # Helper function to calculate the midpoint of two coordinates return ((coords1[0] + coords2[0]) / 2, (coords1[1] + coords2[1]) / 2)
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.