pythonimageopenstreetmapgeomesa

Get Open street map image of an area by longitude and latitude, with highlight on specific latitude and longitude


So I am trying to get open street map image by latitude and longitude with specific latitude and longitude highlighted on that image. Something like this enter image description here

The above image I got from using the mesa geo agent based model (Mesa geo github). I have been looking online to figure out how to do this and I found this Slippy Map Tile names but I am not getting the correct tiles when I try the method that they have suggested. Also I am unable to figure out how to add the highlighted points on the image.

I'll be very grateful if anyone can point me to resource that can help me out.


Solution

  • Plotly is my go to for any kind of figure. If you haven't installed it yet, go here.

    Assuming you already have a list of coordinates, colors assigned based on some category, and that you're interested in points in and around Columbus, OH.

    import pandas as pd
    import numpy as np
    import plotly.express as px
    import random
    
    #creating random data
    df = pd.DataFrame({'lat':[random.uniform(39.86, 40.08) for i in range(100)],
           'lon':[random.uniform(-83.1, -82.86) for i in range(100)],
           'category':[random.choice(['a', 'b', 'c', 'd']) for i in range(100)]})
    
    fig = px.scatter_mapbox(df, 
                            lat='lat',
                            lon='lon',
                            color='category',
                            center={'lat':39.983334,
                                    'lon':-82.983330},
                            zoom=10)
    
    fig.update_layout(mapbox_style='open-street-map')
    
    fig.show()
    

    Figure