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

.. only:: html

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

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

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

.. _sphx_glr_io_examples_open_save_read_vector.py:


Open/save a vector
==================

This example demonstrates the instantiation of a vector through :class:`geoutils.Vector` and saving with :func:`~geoutils.Vector.save`.

.. GENERATED FROM PYTHON SOURCE LINES 7-10

.. code-block:: Python


    import geoutils as gu








.. GENERATED FROM PYTHON SOURCE LINES 11-12

We open an example vector.

.. GENERATED FROM PYTHON SOURCE LINES 12-16

.. code-block:: Python

    filename_vect = gu.examples.get_path("everest_rgi_outlines")
    vect = gu.Vector(filename_vect)
    vect






.. 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 ((86.92842 27.92877, 86.92866 27.9293,...
           1   RGI60-15.03411  ...  POLYGON ((86.94077 27.92375, 86.94059 27.92295...
           2   RGI60-15.03412  ...  POLYGON ((86.85344 27.94752, 86.8534 27.94752,...
           3   RGI60-15.03413  ...  POLYGON ((86.84776 27.94845, 86.84776 27.94849...
           4   RGI60-15.03414  ...  POLYGON ((86.84567 27.96906, 86.84567 27.9691,...
           ..             ...  ...                                                ...
           81  RGI60-15.10070  ...  POLYGON ((86.94112 28.11455, 86.94129 28.11452...
           82  RGI60-15.10075  ...  POLYGON ((86.95861 28.04669, 86.95847 28.04701...
           83  RGI60-15.10077  ...  POLYGON ((86.96454 28.07843, 86.96445 28.07814...
           84  RGI60-15.10078  ...  POLYGON ((86.96302 28.04915, 86.96304 28.0492,...
           85  RGI60-15.10079  ...  POLYGON ((86.97074 28.09496, 86.97039 28.09488...
       
           [86 rows x 23 columns]
      <b>crs=</b>EPSG:4326
      <b>bounds=</b>BoundingBox(left=np.float64(86.70393205700003), bottom=np.float64(27.847778695000045), right=np.float64(87.11409458600008), top=np.float64(28.14549759700003)))</span></pre>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 17-19

A vector is composed of a single main attribute: a :class:`~geoutils.Vector.ds` geodataframe.
All other attributes are :ref:`inherited from Shapely and GeoPandas<vector-from-geopandas>`. See also :ref:`vector-class`.

.. GENERATED FROM PYTHON SOURCE LINES 21-25

.. note::
       A vector can also be instantiated with a :class:`geopandas.GeoDataFrame`, see :ref:`sphx_glr_io_examples_import_export_import_vector.py`.

We can print more info on the vector.

.. GENERATED FROM PYTHON SOURCE LINES 26-28

.. code-block:: Python

    vect.info()





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

 .. code-block:: none

    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 29-30

Let's plot by vector area

.. GENERATED FROM PYTHON SOURCE LINES 30-32

.. code-block:: Python

    vect.plot(column="Area", cbar_title="Area (km²)")




.. image-sg:: /io_examples/open_save/images/sphx_glr_read_vector_001.png
   :alt: read vector
   :srcset: /io_examples/open_save/images/sphx_glr_read_vector_001.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 33-34

Finally, a vector is saved using :func:`~geoutils.Vector.save`.

.. GENERATED FROM PYTHON SOURCE LINES 34-36

.. code-block:: Python


    vect.to_file("myvector.gpkg")








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

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


.. _sphx_glr_download_io_examples_open_save_read_vector.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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