Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map Tile Baselayer in Plot #687

Closed
frapit opened this issue Jul 18, 2024 · 8 comments
Closed

Map Tile Baselayer in Plot #687

frapit opened this issue Jul 18, 2024 · 8 comments

Comments

@frapit
Copy link

frapit commented Jul 18, 2024

Thanks a lot for this great tool!

Is your feature request related to a problem? Please describe.
It would be nice if we could interface a small map tile library such as contextily to display a map background. I often want to plot a trajectory from a rosbag, for instance using /tf:utm.base_link.

Describe the solution you'd like
It would be nice if I could easily add a map baselayer for the UTM (or whatever) extent if the coordinates are geo-referenced anyway.

Describe alternatives you've considered
This can be achieved through --ros_map_yaml with a rgb image which could for instance be generated with a snippet as:

import contextily as cx
import matplotlib.pyplot as plt

west, south, east, north = (8.0, 49.0, 8.1, 49.1)
img, ext = cx.bounds2img(west, south, east, north, ll=True, source=cx.providers.CartoDB.PositronNoLabels)

plt.imshow(img, extent=ext)
plt.axis('off')
plt.savefig('tile.png', bbox_inches='tight', pad_inches=0)

This at least requires the extent of the plot generated by evo_plot. It would be a help if this could be written to the stat file or somewhere else.

@frapit
Copy link
Author

frapit commented Jul 23, 2024

I quickly added it to the code as it is just a oneliner for my purpose. If someone needs to do the same thing, just add the import import contextily as cx and then call

cx.add_basemap(ax_traj, crs="epsg:32632", source=cx.providers.CartoDB.PositronNoLabels, zoom=20)

with the respective projection (UTM in this case) and zoom level as crs string. I did the call where the ros_map is applied as well.

If you are willing to add this feature, one would need to have additional configuration options: base_map_crs, base_map_source and base_map_zoom. But it also needs a bunch of libraries so I also understand if you don't want too many external dependencies. Just wanted to leave it here as reference.

@MichaelGrupp
Copy link
Owner

Sounds like a neat add-on, the question would be for me how you would envision to use this in the command line interface.

If you are willing to add this feature, one would need to have additional configuration options: base_map_crs, base_map_source and base_map_zoom.

I would say that it's probably easier to have a single flag, named for example --geo_tile and then take the three arguments from it? Maybe also having a default (configurable) map provider, so you can also just pass the crs and the zoom?

So either...

  1. --geo_tile epsg:32632 20 (+ geo_tile_provider in global settings)
  2. --geo_tile epsg:32632 20 CartoDB.PositronNoLabels

I guess first one is more user friendly, as you probably don't want to specify/change the provider all the time.

But it also needs a bunch of libraries so I also understand if you don't want too many external dependencies.

We can have optional dependencies, so this is not a blocker.

@frapit
Copy link
Author

frapit commented Jul 31, 2024

I would say that it's probably easier to have a single flag, named for example --geo_tile and then take the three arguments from it? Maybe also having a default (configurable) map provider, so you can also just pass the crs and the zoom?

Sounds good! contextily figures out a good zoom level according to the requested size if none is given, so this could be optional as well.

I guess first one is more user friendly, as you probably don't want to specify/change the provider all the time.

Agreed!

We can have optional dependencies, so this is not a blocker.

Great!

@MichaelGrupp
Copy link
Owner

Since I don't have georeferenced data: do you have maybe a minimal example that you could share for testing? One random file with corresponding EPSG should be enough.

The feature seems rather easy to add, but would be good to check if everything works as expected 😉

@frapit
Copy link
Author

frapit commented Aug 5, 2024

Sure, the file example_traj_tf_utm_baselink.txt produces the following output:

plot_trajectories

when calling evo_traj tum example_traj_tf_utm_baselink.txt --plot_mode xy -p

with epsg:32632 as crs. (By simply adding the code line above)

I have other examples if required.

MichaelGrupp added a commit that referenced this issue Sep 1, 2024
Allows to add a map tile to the plot if the trajectory coordinates are
geo-referenced.

See feature request #687
@MichaelGrupp
Copy link
Owner

Thanks for the data! I added the feature now: 29c20d0 (Release v1.30.0)
Tested with OpenStreetMap, CartoDB, HEREv3 (requires token).

Basic usage to get your example would be:

evo_config set map_tile_provider CartoDB.PositronNoLabels

(for providers with API token also set map_tile_api_token)

evo_traj tum example_traj_tf_utm_baselink.txt --plot --map_tile epsg:32632

I would like to use your data as example data / plot for the documentation, would that be fine?

@frapit
Copy link
Author

frapit commented Sep 6, 2024

Looks good, thanks a lot!

I would like to use your data as example data / plot for the documentation, would that be fine?

Sure, feel free to use the data and close the issue.

MichaelGrupp added a commit that referenced this issue Sep 9, 2024
@MichaelGrupp
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants