You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.4KB

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