
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "io_examples/import_export/pc_from_xyz.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_import_export_pc_from_xyz.py>`
        to download the full example code.

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

.. _sphx_glr_io_examples_import_export_pc_from_xyz.py:


Creating a point cloud from arrays
==================================

This example demonstrates the creation of a point cloud through :func:`~geoutils.Raster.from_xyz`, :func:`~geoutils.Raster.from_array` or
:func:`~geoutils.Raster.from_tuples`.

.. GENERATED FROM PYTHON SOURCE LINES 8-12

.. code-block:: Python


    import numpy as np
    import pyproj








.. GENERATED FROM PYTHON SOURCE LINES 13-14

We create a data array as :class:`~numpy.ndarray`, and a coordinate reference system (CRS) as :class:`pyproj.CRS`.

.. GENERATED FROM PYTHON SOURCE LINES 14-26

.. code-block:: Python

    import geoutils as gu

    # A random N x 3 array
    rng = np.random.default_rng(42)
    arr = rng.normal(size=(5, 3))
    # A CRS, here geographic (latitude/longitude)
    crs = pyproj.CRS.from_epsg(4326)

    # Create a point cloud using three 1-d arrays
    pc = gu.PointCloud.from_xyz(x=arr[:, 0], y=arr[:, 1], z=arr[:, 2], crs=crs, data_column="z")
    pc






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <pre><span style="white-space: pre-wrap"><b><em>PointCloud</em></b>(
      <b>ds=</b>          z                  geometry
           0  0.750451  POINT (0.30472 -1.03998)
           1 -1.302180  POINT (0.94056 -1.95104)
           2 -0.016801  POINT (0.12784 -0.31624)
           3  0.777792   POINT (-0.85304 0.8794)
           4  0.467509   POINT (0.06603 1.12724)
      <b>crs=</b>EPSG:4326
      <b>bounds=</b>BoundingBox(left=np.float64(-0.85304392757358), bottom=np.float64(-1.9510351886538364), right=np.float64(0.9405647163912139), top=np.float64(1.1272412069680329)))</span></pre>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 27-28

We can print info on the point cloud.

.. GENERATED FROM PYTHON SOURCE LINES 28-30

.. code-block:: Python

    pc.info()





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

 .. code-block:: none

    Filename:           None 
    Coordinate system:  EPSG:4326
    Extent:             [-0.85304392757358, -1.9510351886538364, 0.9405647163912139, 1.1272412069680329] 
    Number of features: 5 
    Attributes:         ['z', 'geometry']




.. GENERATED FROM PYTHON SOURCE LINES 31-32

Note that we can also use the N x 3 array directly, or also an iterable of 3-tuples

.. GENERATED FROM PYTHON SOURCE LINES 32-34

.. code-block:: Python

    pc = gu.PointCloud.from_array(arr, crs=crs, data_column="z")








.. GENERATED FROM PYTHON SOURCE LINES 35-36

The different functionalities of GeoUtils will use :attr:`~geoutils.Raster.data` as default as the main data column, including plotting.

.. GENERATED FROM PYTHON SOURCE LINES 36-37

.. code-block:: Python

    pc.plot(cmap="copper")



.. image-sg:: /io_examples/import_export/images/sphx_glr_pc_from_xyz_001.png
   :alt: pc from xyz
   :srcset: /io_examples/import_export/images/sphx_glr_pc_from_xyz_001.png
   :class: sphx-glr-single-img






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

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


.. _sphx_glr_download_io_examples_import_export_pc_from_xyz.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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