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

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

.. _sphx_glr_handling_examples_raster_point_gridding.py:


Gridding points to raster
=========================

This example demonstrates the gridding of a point cloud into a raster using :func:`~geoutils.PointCloud.gridding`.

.. GENERATED FROM PYTHON SOURCE LINES 9-10

We open an example point cloud, an elevation dataset in New Zealand.

.. GENERATED FROM PYTHON SOURCE LINES 10-19

.. code-block:: Python


    import geoutils as gu

    filename_pc = gu.examples.get_path("coromandel_lidar")
    pc = gu.PointCloud(filename_pc, data_column="Z")

    # Plot the point cloud
    pc.plot(cmap="terrain", cbar_title="Elevation (m)")




.. image-sg:: /handling_examples/raster_point/images/sphx_glr_gridding_001.png
   :alt: gridding
   :srcset: /handling_examples/raster_point/images/sphx_glr_gridding_001.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 21-22

We generate grid coordinates to interpolate to, alternatively we could pass a raster to use as reference.

.. GENERATED FROM PYTHON SOURCE LINES 22-27

.. code-block:: Python


    import numpy as np

    grid_coords = (np.linspace(pc.bounds.left, pc.bounds.right, 100), np.linspace(pc.bounds.bottom, pc.bounds.top, 100))








.. GENERATED FROM PYTHON SOURCE LINES 28-29

We then perform the interpolation

.. GENERATED FROM PYTHON SOURCE LINES 29-31

.. code-block:: Python

    rast = pc.grid(grid_coords=grid_coords)








.. GENERATED FROM PYTHON SOURCE LINES 32-33

Finally, we plot the resulting raster

.. GENERATED FROM PYTHON SOURCE LINES 33-35

.. code-block:: Python


    rast.plot(ax="new", cmap="terrain", cbar_title="Elevation (m)")



.. image-sg:: /handling_examples/raster_point/images/sphx_glr_gridding_002.png
   :alt: gridding
   :srcset: /handling_examples/raster_point/images/sphx_glr_gridding_002.png
   :class: sphx-glr-single-img






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

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


.. _sphx_glr_download_handling_examples_raster_point_gridding.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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