Package: walkmapper2
walkmapperThis is a fork of theoriginal walkmapper packagefromsam-olson.AboutA Python package for plotting and animating your walk/run/bike ride routes.Install walkmapper using the command line:pipinstallwalkmapperYou can then run the example script:pythonexample.pyThe package works by analyzing .gpx files, a common file format used by GPS devices. TheAsics Runkeeperapp was used in the development of this package, as it allows you to record GPS locations on your smart phone and export them from your account in the browser.Open Street Mapis a great resource for grabbing maps to use as backgrounds. Just select "Share" on the map sidebar, size your image with "Set custom dimensions", and download. Rename the photo using the methods described below, allowing the package to properly parse the latitudes and longitudes.You can get the latitudes and longitudes of the image you have downloaded using "Share" in OpenStreetMap, by following these steps, as long as youhave notcheckedSet custom dimensions, and youhave notpanned or zoomed tha map after downloading the image:Paste this into your shell (including the single quote at the end), but do not press enter yet:python3 -c "import sys;print([round(float(s), 4) for s in sys.argv[1].split('?bbox=')[1].split('&amp')[0].split('%2C')])" 'SelectHTMLunder theLink or HTMLsection of the Share panel.Copy the HTML, it should start with<iframe, and it should be all in one line, with no line breaks.Then paste the copied HTML into your shell after the single quote, add a single quote at the end, and press Enter.The output will be in the format[LowerLeftLon, LowerLeftLat, UpperRightLon, UpperRightLat]. For example, processing the HTML for a map centered on Portland, OR would output[-122.7077, 45.4761, -122.5831, 45.5372].The classSingleRoutecontains methods for analyzing and plotting a single route. It is also possible to obfuscate your address with a privacy bubble if you plan on sharing on the internet:fromwalkmapper.routesimportSingleRouteroute=SingleRoute("path/to/your/file.gpx",home_lat=45.0000,home_lon=-122.0000,privacy_bubble_rad=150)From here you can plot the .gpx file over a map image using theSingleRoute.plotmethod. The map image should have the following format:Description_UpperRightLat_UpperRightLon_LowerLeftLat_LowerLeftLon.png. If a latitude or longitude is negative, its value should be preceded by anm. For example, a map centered on Portland, OR would have the file name:Portland_45.5372_m122.5831_45.4761_m122.7077.png. Providing the coordinates of the upper right and lower left corners of the map image in the title allows the plotting functions to parse these values and put appropriate boundaries on the matplotlib images.The functionmap_file_nameinwalkmapper.utilsmakes formatting an image title far easier:fromwalkmapper.utilsimportmap_file_name# this function automatically renames the imagemap_file_name("images/portland.png",45.5372,-122.5831,45.4761,-122.7077,"Portland")# saves over images/portland.png with images/Portland_45.5372_m122.5831_45.4761_m122.7077.pngYou can also create a snake animation, where the route is drawn out from start to finish, by using theSingleRoute.snake_animationmethod.The classMultipleRoutescontains methods for analyzing, plotting, and animating multiple routes:fromwalkmapper.routesimportMultipleRoutes# compile all .gpx files in a folder into a listfiles=[f"folder/{i}"foriinos.listdir("folder")ifi.endswith(".gpx")]# create instance of MultipleRoutesroutes=MultipleRoutes(files,home_lat=45.0000,home_lon=-122.0000,privacy_bubble_rad=150)Once aMultipleRoutesinstance is created, you can display the data several ways:map_file="Portland_45.5372_m122.5831_45.4761_m122.7077.png"# plot all routes with map backgroundroutes.basic_plot(map_file)# plot heat maproutes.heat_map(map_file,n_bins=100,alpha=0.5)# create .mp4 animation displaying one route after anotherroutes.basic_route_animation(map_file_path,fps=2,dpi=300)# create an .mp4 animation that draws out each route sequentiallyroutes.snake_animation(frame_distance=50,map_file_path=map_file,fps=60,dpi=300)Seeexample.pyfor an example script, and the directoryexamplefor example data, maps, and animations.