1

I am plotting the route taken by a car on a graph, using matplotlib. I have the cordinates of the car over time and I have extracted them in UTM cordinates (tile 31U). Below are the arrays.

x = [673368.93057369 673368.93057369 673368.93071654 673368.93071654
 673368.93085732 673368.93085732 673368.93116152 673368.93116152
 673368.93116152 673368.93147221 673368.93147221 673368.93147221
 673368.93147221 673368.93199162 673368.93199162 673368.93223246
 673368.93223246 673368.93251396 673368.93251396 673368.93279624
 673368.93279624 673368.93307647 673368.93307647 673368.93301788
 673368.93301788 673368.9329213  673368.9329213  673368.93285223
 673368.93285223 673368.93282329 673368.93282329 673368.93282329
 673368.93282329 673368.93276313 673368.93276313 673368.93276313
 673368.93276313 673368.93276313 673368.93270986 673368.93270986
 673368.93270606 673368.93270606 673368.93253683 673368.93253683
 673368.93235368 673368.93235368 673368.93221551 673368.93221551
 673368.93202368 673368.93202368 673368.93182569 673368.93182569
 673368.93159753 673368.93159753 673368.93155848 673368.93155848
 673368.93155848 673368.93155848 673368.93246212 673368.93246212
 673368.93238838 673368.9]

y = [5702457.79814334 5702457.79814334 5702457.79890588 5702457.79890588
 5702457.79966019 5702457.79966019 5702457.80009669 5702457.80009669
 5702457.80009669 5702457.80049127 5702457.80049127 5702457.80049127
 5702457.80049127 5702457.80148707 5702457.80148707 5702457.80175725
 5702457.80175725 5702457.80194104 5702457.80194104 5702457.80214219
 5702457.80214219 5702457.80239853 5702457.80239853 5702457.80258191
 5702457.80258191 5702457.80276184 5702457.80276184 5702457.80296306
 5702457.80296306 5702457.80315357 5702457.80315357 5702457.80315357
 5702457.80315357 5702457.80328469 5702457.80328469 5702457.80328469
 5702457.80328469 5702457.80328469 5702457.80326844 5702457.80326844
 5702457.80325138 5702457.80325138 5702457.80342764 5702457.80342764
 5702457.80355677 5702457.80355677 5702457.80367075 5702457.80367075
 5702457.80388897 5702457.80388897 5702457.80397587 5702457.80397587
 5702457.80398278 5702457.80398278 5702457.80399363 5702457.80399363
 5702457.80399363 5702457.80399363]

I use Python and matplotlib to scatter plot them and visualise the route taken.

import matplotlib.pyplot as plt
plt.scatter(x, y, color='green')

Is there a simple way to have a map/satellite image on the background of the image? I'm open to other tools and libraries to perform this simply.

1
  • You can't drape objects in one coordinate reference system onto an image in a different coordinate system. One of them needs to be reprojected (and this is much easier for vector data). Your UTM coords are specified to Angstrom resolution; since you're not mapping covalent bonds, you can lop off 5-7 of the decimal places.
    – Vince
    Commented Aug 1, 2019 at 19:29

1 Answer 1

1

Updating my question as I found a solution for my use-case.

I used folium for plotting. I also had the lat-long cords of the same UTM cords and used them. Matplotlib was not used.

import folium
from pandas import read_csv
df = read_csv('my/location/data')
lat = df['latitude'].values
lon = df['longitude'].values
center_lat = np.mean(lat)
center_lon = np.mean(lon)
token="pk....."  # Your token here if using Mapbox or other API
tileurl = 'https://api.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}@2x.png?access_token=' + str(token)
my_map4 = folium.Map(location=[center_lat, center_lon], tiles=tileurl, attr='Mapbox', max_zoom=30, zoom_start=18) #, zoom_control=True)
locations = []
for i in range(len(lat)):
    location = (lat[i], lon[i])
    locations.append(location)
    folium.PolyLine(locations=locations, line_opacity=0.5).add_to(my_map4)
# Add other custom plotting elements if any like markers
my_map4.save("..path/to/save/the/results/map_with_trace.html")

The above code can be improved in terms of optimisation, but for me execution speed was not a concern as long as I got the plots running. If anyone has better solutions, suggestions are welcome. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.