.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_01_base_classes.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_01_base_classes.py: Berlin to Oslo to Paris ======================================== Introduction to GeoPoint and GeoVector3D. .. GENERATED FROM PYTHON SOURCE LINES 9-13 .. code-block:: Python import matplotlib matplotlib.rcParams['savefig.dpi'] = 300 import geonum .. GENERATED FROM PYTHON SOURCE LINES 14-22 Create some GeoPoints --------------------- GeoPoints represent locations on Earth specified via latitude, longtitude and altitude relative sea level. Here we create 2, points, one located in Paris, one in Oslo, and one in Berlin. The latitudes and longitudes for each city were looked up online, the altitudes can be retrieved automatically using the SRTM dataset, as shown below. .. GENERATED FROM PYTHON SOURCE LINES 23-30 .. code-block:: Python paris = geonum.GeoPoint(name='Paris', latitude=48.8566, longitude=2.3522, auto_topo_access=True ) .. rst-class:: sphx-glr-script-out .. code-block:: none Retrieving SRTM data (this might take a while) ... Creating /home/docs/.cache/srtm 4 2884802 .. GENERATED FROM PYTHON SOURCE LINES 31-33 .. code-block:: Python print(paris) .. rst-class:: sphx-glr-script-out .. code-block:: none GeoPoint Paris Lat: 48.8566, Lon: 2.3522000000000105, Alt: 46.0 m .. GENERATED FROM PYTHON SOURCE LINES 34-40 .. code-block:: Python oslo = geonum.GeoPoint(name='Oslo', latitude=59.9139, longitude=10.7522, auto_topo_access=True ) .. rst-class:: sphx-glr-script-out .. code-block:: none Retrieving SRTM data (this might take a while) ... 4 2884802 .. GENERATED FROM PYTHON SOURCE LINES 41-43 .. code-block:: Python print(oslo) .. rst-class:: sphx-glr-script-out .. code-block:: none GeoPoint Oslo Lat: 59.9139, Lon: 10.752199999999988, Alt: 26.0 m .. GENERATED FROM PYTHON SOURCE LINES 44-50 .. code-block:: Python berlin = geonum.GeoPoint(name='Berlin', latitude=52.5200, longitude=13.4050, auto_topo_access=True ) .. rst-class:: sphx-glr-script-out .. code-block:: none Retrieving SRTM data (this might take a while) ... 4 2884802 .. GENERATED FROM PYTHON SOURCE LINES 51-53 .. code-block:: Python print(berlin) .. rst-class:: sphx-glr-script-out .. code-block:: none GeoPoint Berlin Lat: 52.52, Lon: 13.405000000000001, Alt: 54.0 m .. GENERATED FROM PYTHON SOURCE LINES 54-59 Compute connection vectors between the 3 locations -------------------------------------------------- The connection vectors (dlat, dlon, dh) can be computed by subtracting 2 GeoPoint instances. .. GENERATED FROM PYTHON SOURCE LINES 60-75 .. code-block:: Python paris_to_berlin = berlin - paris print(paris_to_berlin) berlin_to_oslo = oslo - berlin print(berlin_to_oslo) oslo_to_paris = paris - oslo print(oslo_to_paris) # Assign the corresponding starting points for the vectors paris_to_berlin.set_anchor(paris) berlin_to_oslo.set_anchor(berlin) oslo_to_paris.set_anchor(oslo) .. rst-class:: sphx-glr-script-out .. code-block:: none GeoVector3D Paris->Berlin Azimuth: 58.24°, Elevation: 0.0005°, Magnitude: 879.70 km (hor: 879.70 km) GeoVector3D Berlin->Oslo Azimuth: -10.21°, Elevation: -0.0019°, Magnitude: 839.39 km (hor: 839.39 km) GeoVector3D Oslo->Paris Azimuth: -152.59°, Elevation: 0.0009°, Magnitude: 1343.87 km (hor: 1343.87 km) .. GENERATED FROM PYTHON SOURCE LINES 76-78 Draw map of western Europe and add points and vectors ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 79-171 .. code-block:: Python import cartopy.feature as cfeature from cartopy import crs import matplotlib.pyplot as plt # Init map with lat lon range ax = geonum.plot_helpers.init_figure_with_geoaxes(xlim=(0, 20), ylim=(45, 65)) # Add some features to make it look nicer ax.coastlines(alpha=0.3) ax.add_feature(cfeature.LAND, color='#fff9e6', alpha=0.4) ax.add_feature(cfeature.OCEAN, color='#e6f7ff', alpha=0.4) ax.add_feature(cfeature.BORDERS, color='#808080', ls='--', alpha=0.4) # Plot paris GeoPoint into map ax = geonum.plot_helpers.plot_geopoint_into_map( ax, paris, annotate=True, marker='o', facecolor='none', color='#5c5c3d', annot_kwargs=dict(xytext=(paris.longitude, paris.latitude-2), ha='center')) # Plot oslo GeoPoint into map ax = geonum.plot_helpers.plot_geopoint_into_map( ax, oslo, annotate=True, marker='o', facecolor='none', color='#5c5c3d', annot_kwargs=dict(xytext=(oslo.longitude, oslo.latitude+1.5), ha='center') ) # Plot berlin GeoPoint into map ax = geonum.plot_helpers.plot_geopoint_into_map( ax, berlin, annotate=True, marker='o', facecolor='none', color='#5c5c3d', annot_kwargs=dict(xytext=(berlin.longitude, berlin.latitude-1.5), ha='center') ) # Draw GeoVector3D Oslo->Paris into map ax = geonum.plot_helpers.plot_geovector3d_into_map(ax, oslo_to_paris, color='#5c5c3d', ls='--', lw=1) # annotate text specifying distance between points: half_way_vec = oslo_to_paris/2 half_way = oslo + half_way_vec # distance between Oslo and Paris distance = oslo_to_paris.dist_hor ax.annotate(text=f'Oslo/Paris:\n {distance:.0f} km', xy=(half_way.longitude, half_way.latitude), xytext=(half_way.longitude-1.5, half_way.latitude+1), color='#5c5c3d', fontweight='bold', ha='left', fontsize=6) # Draw GeoVector3D Paris->Berlin into map ax = geonum.plot_helpers.plot_geovector3d_into_map(ax, paris_to_berlin, color='#5c5c3d', ls='--', lw=1) half_way_vec = paris_to_berlin/2 half_way = paris + half_way_vec distance = paris_to_berlin.dist_hor ax.annotate(text=f'Paris/Berlin:\n {distance:.0f} km', xy=(half_way.longitude, half_way.latitude), xytext=(half_way.longitude+2, half_way.latitude-1), color='#5c5c3d', fontweight='bold', ha='center', fontsize=6) # Draw GeoVector3D Berlin->Oslo into map ax = geonum.plot_helpers.plot_geovector3d_into_map(ax, berlin_to_oslo, color='#5c5c3d', ls='--', lw=1) half_way_vec = berlin_to_oslo/2 half_way = berlin + half_way_vec distance = berlin_to_oslo.dist_hor ax.annotate(text=f'Berlin/Oslo:\n {distance:.0f} km', xy=(half_way.longitude, half_way.latitude), xytext=(half_way.longitude+1, half_way.latitude+1.8), color='#5c5c3d', fontweight='bold', ha='center', fontsize=6) # Add x and y ticks geonum.plot_helpers.set_map_ticks(ax) # Add title ax.set_title('Berlin to Oslo to Paris') plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_01_base_classes_001.png :alt: Berlin to Oslo to Paris :srcset: /auto_examples/images/sphx_glr_plot_01_base_classes_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/geonum/envs/latest/lib/python3.10/site-packages/cartopy/mpl/feature_artist.py:143: UserWarning: facecolor will have no effect as it has been defined as "never". warnings.warn('facecolor will have no effect as it has been ' .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.871 seconds) .. _sphx_glr_download_auto_examples_plot_01_base_classes.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_base_classes.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_base_classes.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_base_classes.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_