
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "handling_examples/georeferencing/reproj_vector.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_handling_examples_georeferencing_reproj_vector.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_handling_examples_georeferencing_reproj_vector.py:


Reproject a vector
==================

This example demonstrates the reprojection of a vector using :func:`geoutils.Vector.reproject`.

.. GENERATED FROM PYTHON SOURCE LINES 9-10

We open a raster and vector.

.. GENERATED FROM PYTHON SOURCE LINES 10-18

.. code-block:: Python


    import geoutils as gu

    filename_rast = gu.examples.get_path("everest_landsat_b4_cropped")
    filename_vect = gu.examples.get_path("everest_rgi_outlines")
    rast = gu.Raster(filename_rast)
    vect = gu.Vector(filename_vect)








.. GENERATED FROM PYTHON SOURCE LINES 20-21

The two objects are in different projections.

.. GENERATED FROM PYTHON SOURCE LINES 21-24

.. code-block:: Python

    rast.info()
    vect.info()





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Driver:               GTiff 
    Opened from file:     /home/docs/checkouts/readthedocs.org/user_builds/adebardo-geoutils/checkouts/latest/geoutils/example_data/Everest_Landsat/LE71400412000304SGS00_B4_cropped.tif 
    Filename:             /home/docs/checkouts/readthedocs.org/user_builds/adebardo-geoutils/checkouts/latest/geoutils/example_data/Everest_Landsat/LE71400412000304SGS00_B4_cropped.tif 
    Loaded?               False 
    Modified since load?  False 
    Grid size:            492, 315
    Number of bands:      1
    Data types:           uint8
    Coordinate system:    ['EPSG:32645']
    Nodata value:         None
    Pixel interpretation: Area
    Pixel size:           30.0, 30.0
    Upper left corner:    483430.0, 3102710.0
    Lower right corner:   498190.0, 3093260.0

    Filename:           /home/docs/checkouts/readthedocs.org/user_builds/adebardo-geoutils/checkouts/latest/geoutils/example_data/Everest_Landsat/15_rgi60_glacier_outlines.gpkg 
    Coordinate system:  EPSG:4326
    Extent:             [86.70393205700003, 27.847778695000045, 87.11409458600008, 28.14549759700003] 
    Number of features: 86 
    Attributes:         ['RGIId', 'GLIMSId', 'BgnDate', 'EndDate', 'CenLon', 'CenLat', 'O1Region', 'O2Region', 'Area', 'Zmin', 'Zmax', 'Zmed', 'Slope', 'Aspect', 'Lmax', 'Status', 'Connect', 'Form', 'TermType', 'Surging', 'Linkages', 'Name', 'geometry']




.. GENERATED FROM PYTHON SOURCE LINES 25-26

Let's plot the two in their original projection.

.. GENERATED FROM PYTHON SOURCE LINES 26-29

.. code-block:: Python

    rast.plot(cmap="Greys_r")
    vect.plot(ax="new", fc="none", ec="tab:purple", lw=3)




.. rst-class:: sphx-glr-horizontal


    *

      .. image-sg:: /handling_examples/georeferencing/images/sphx_glr_reproj_vector_001.png
         :alt: reproj vector
         :srcset: /handling_examples/georeferencing/images/sphx_glr_reproj_vector_001.png
         :class: sphx-glr-multi-img

    *

      .. image-sg:: /handling_examples/georeferencing/images/sphx_glr_reproj_vector_002.png
         :alt: reproj vector
         :srcset: /handling_examples/georeferencing/images/sphx_glr_reproj_vector_002.png
         :class: sphx-glr-multi-img





.. GENERATED FROM PYTHON SOURCE LINES 30-32

**First option:** using the raster as a reference to match, we reproject the vector. We simply have to pass the :class:`~geoutils.Raster` as an argument
to :func:`~geoutils.Vector.reproject`. See :ref:`core-match-ref` for more details.

.. GENERATED FROM PYTHON SOURCE LINES 32-35

.. code-block:: Python


    vect_reproj = vect.reproject(rast)








.. GENERATED FROM PYTHON SOURCE LINES 36-37

We can plot the vector in its new projection.

.. GENERATED FROM PYTHON SOURCE LINES 37-40

.. code-block:: Python


    vect_reproj.plot(ax="new", fc="none", ec="tab:purple", lw=3)




.. image-sg:: /handling_examples/georeferencing/images/sphx_glr_reproj_vector_003.png
   :alt: reproj vector
   :srcset: /handling_examples/georeferencing/images/sphx_glr_reproj_vector_003.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 41-43

**Second option:** we can pass the georeferencing argument ``dst_crs`` to :func:`~geoutils.Vector.reproject` (an EPSG code can be passed directly as
:class:`int`).

.. GENERATED FROM PYTHON SOURCE LINES 43-47

.. code-block:: Python


    # Reproject in UTM zone 45N.
    vect_reproj = vect.reproject(crs=32645)
    vect_reproj





.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <pre><span style="white-space: pre-wrap"><b><em>Vector</em></b>(
      <b>ds=</b>             RGIId  ...                                           geometry
           0   RGI60-15.03410  ...  POLYGON ((492957.601 3089314.26, 492981.141 30...
           1   RGI60-15.03411  ...  POLYGON ((494171.838 3088756.723, 494154.107 3...
           2   RGI60-15.03412  ...  POLYGON ((485583.154 3091398.082, 485579.012 3...
           3   RGI60-15.03413  ...  POLYGON ((485023.954 3091501.638, 485023.954 3...
           4   RGI60-15.03414  ...  POLYGON ((484821.599 3093784.463, 484821.599 3...
           ..             ...  ...                                                ...
           81  RGI60-15.10070  ...  POLYGON ((494217.057 3109893.624, 494233.434 3...
           82  RGI60-15.10075  ...  POLYGON ((495932.461 3102375.067, 495918.707 3...
           83  RGI60-15.10077  ...  POLYGON ((496516.356 3105890.705, 496506.863 3...
           84  RGI60-15.10078  ...  POLYGON ((496366.016 3102647.385, 496368.08 31...
           85  RGI60-15.10079  ...  POLYGON ((497125.488 3107721.651, 497091.543 3...
       
           [86 rows x 23 columns]
      <b>crs=</b>PROJCS["WGS 84 / UTM zone 45N",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",87],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","32645"]]
      <b>bounds=</b>BoundingBox(left=np.float64(470889.8334359533), bottom=np.float64(3080342.6652930346), right=np.float64(511219.57766997576), top=np.float64(3113331.061389028)))</span></pre>
    </div>
    <br />
    <br />


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 0.976 seconds)


.. _sphx_glr_download_handling_examples_georeferencing_reproj_vector.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: reproj_vector.ipynb <reproj_vector.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: reproj_vector.py <reproj_vector.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: reproj_vector.zip <reproj_vector.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
