Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

76 lines
2.5KB

  1. #!/usr/bin/env python3
  2. import multiprocessing
  3. import os
  4. from argparse import ArgumentParser
  5. from math import ceil
  6. from time import sleep
  7. import pandas as pd
  8. import geopandas as gpd
  9. import contextily as cx
  10. import matplotlib.pyplot as plt
  11. if __name__ == "__main__":
  12. parser = ArgumentParser()
  13. parser.add_argument("-f", "--file", required=True, help="Messfahrt csv")
  14. parser.add_argument("-a", "--column", required=True, help="Column to plot")
  15. parser.add_argument("-l", "--label", help="Label above the plot.")
  16. parser.add_argument("--no_legend", action="store_false", default=True, help="Do not show legend.")
  17. parser.add_argument("--save", default=None, help="Location to save pdf file.")
  18. parser.add_argument("--time_offset", default=None, type=int, help="Minutes added to GPS datetime.")
  19. parser.add_argument(
  20. "--show_providerinfo",
  21. default=False,
  22. help="Show providerinfo for map tiles an zoom levels.",
  23. )
  24. args = parser.parse_args()
  25. df = pd.read_csv(args.file)
  26. gdf = gpd.GeoDataFrame(
  27. df,
  28. geometry=gpd.points_from_xy(df["longitude"], df["latitude"]),
  29. crs="EPSG:4326",
  30. )
  31. gdf["srtt"] = gdf["srtt"].apply(lambda x: x / 10 ** 6)
  32. print("Start plotting...")
  33. df_wm = gdf.to_crs(epsg=3857)
  34. ax2 = df_wm.plot()
  35. ax2 = df_wm.plot(args.column, cmap="hot", legend=args.no_legend, ax=ax2)
  36. # ax2 = df_wm.plot.scatter(x="longitude", y="latitude", c="kmh", cmap="hot")
  37. # zoom 17 is pretty
  38. cx.add_basemap(ax2, source=cx.providers.OpenStreetMap.Mapnik, zoom=17)
  39. # gdf.plot()
  40. ax2.set_axis_off()
  41. ax2.set_title(args.label if args.label else args.column)
  42. if args.show_providerinfo:
  43. #####################################
  44. # Identifying how many tiles
  45. latlon_outline = gdf.to_crs("epsg:4326").total_bounds
  46. def_zoom = cx.tile._calculate_zoom(*latlon_outline)
  47. print(f"Default Zoom level {def_zoom}")
  48. cx.howmany(*latlon_outline, def_zoom, ll=True)
  49. cx.howmany(*latlon_outline, def_zoom + 1, ll=True)
  50. cx.howmany(*latlon_outline, def_zoom + 2, ll=True)
  51. # Checking out some of the other providers and tiles
  52. print(cx.providers.CartoDB.Voyager)
  53. print(cx.providers.Stamen.TonerLite)
  54. print(cx.providers.Stamen.keys())
  55. #####################################
  56. # df.plot(x="longitude", y="latitude", kind="scatter", colormap="YlOrRd")
  57. if args.save:
  58. plt.savefig("{}gps_plot.pdf".format(args.save))
  59. else:
  60. plt.show()