Skip to content

Commit

Permalink
Merge pull request #73 from windnage/master
Browse files Browse the repository at this point in the history
Updated spatial-raster.rst and spatial-vector.rst with new documenatation
  • Loading branch information
Leah Wasser committed Oct 30, 2018
2 parents c325d4a + fce6d4c commit 2843887
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
28 changes: 28 additions & 0 deletions docs/spatial-raster.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,33 @@ Example:
arr, arr_meta = es.stack_raster_tifs(all__paths, destfile)
Calculate Normalized Difference
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The ``normalized_diff`` function takes two numpy arrays of the same shape and
calculates the normalized difference from them.

``normalized_diff`` takes two input parameters:

``b1``, ``b2``: arrays with the same shape
Math will be calculated (b2-b1) / (b2+b1)

The ``normalized_diff`` function returns a masked array of the normalized difference with the same shape as the input arrays.

Example:

.. code-block:: python
import numpy as np
import earthpy.spatial as es
red_band = np.array([[1, 2, 3, 4, 5],[11,12,13,14,15]])
nir_band = np.array([[6, 7, 8, 9, 10],[16,17,18,19,20]])
# Calculate normalized difference
ndiff = es.normalized_diff(b2=nir_band, b1=red_band)
Plot Raster File Bands
~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -177,3 +204,4 @@ Example:
# Create hillshade numpy array
hillshade = es.hillshade(arr, 315, 45)
34 changes: 33 additions & 1 deletion docs/spatial-vector.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
Earthpy Spatial Vector Data
===========================

Edits go here.
The ``earthpy`` spatial module provides functions that wrap around the ``rasterio``
and ``geopandas`` to work with raster and vector data in Python.

Clip Vector Data
~~~~~~~~~~~~~~~~

The ``clip_shp`` function takes two geopandas GeoDataframe objects. The first
object is a point or line polygon GeoDataframe that needs to be spatially clipped.
The second object will be used as the spatial extent to clip the first object.

All inputs must be in the same Coordinate Refenence System (CRS).

``clip_shp`` takes 2 input parameters:

``shp``: geopandas GeoDataframe you wish to clip

``clip_obj``: geopandas GeoDataframe with the point or bounds you wish to clip to

The output of ``clip_shp`` is a geopandas GeoDataframe clipped to the clip object.

Example:

.. code-block:: python
import geopandas as gpd
import earthpy.clip as cl
# Open shapefiles as geopandas GeoDataframe
shp_2_clip = gpd.read_file(shapefile.shp)
clip_obj = gpd.read_file(clip.shp)
# Clip data
clipped_gdf = cl.clip_shp(shp=shp_2_clip, clip_obj=clip_obj)

0 comments on commit 2843887

Please sign in to comment.