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.

72 satır
2.3KB

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