.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery_vignettes/plot_create_plots.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_vignettes_plot_create_plots.py: Download Data with StreamStats =============================================================== Learn how to use StreamStats python library to download watershed boundary data available in USGS StreamStats API. StreamStats provides information including HUC code, a GeoJSON representation of the polygon associated with the watershed, and basin characteristics. .. GENERATED FROM PYTHON SOURCE LINES 12-17 Import Packages ------------------------------------------------------- Download the necessary Python packages. The ``GeoPandas`` package is an open source project that assists in working with geospatial data in Python. Learn more about `GeoPandas `_. .. GENERATED FROM PYTHON SOURCE LINES 17-21 .. code-block:: default import streamstats import geopandas as gpd .. GENERATED FROM PYTHON SOURCE LINES 22-28 Identify watershed --------------------- To identify a HUC, use a latitude and longitude value to select a specific watershed. Assign cordinates to variables ``lat`` and ``lon``. Using StreamStat's data, assign location to a variable that will represent the delineated watershed using the USGS StreamStats API. .. GENERATED FROM PYTHON SOURCE LINES 28-32 .. code-block:: default lat, lon = 39.966256, -105.482227 ws = streamstats.Watershed(lat=lat, lon=lon) .. GENERATED FROM PYTHON SOURCE LINES 33-38 Find boundary properties of the watershed ------------------------------------------ ``ws.boundary`` is a stored variable in the watershed object and will return the full watershed GeoJSON as a dictionary. You can access the CRS through the GeoJSON object. .. GENERATED FROM PYTHON SOURCE LINES 38-42 .. code-block:: default ws.boundary ws.boundary['crs'] .. rst-class:: sphx-glr-script-out Out: .. code-block:: none {'type': 'ESPG', 'properties': {'code': 4326}} .. GENERATED FROM PYTHON SOURCE LINES 43-46 Create plot of the Watershed ----------------------------- Open the GeoJSON with GeoPandas and plot the data. .. GENERATED FROM PYTHON SOURCE LINES 46-52 .. code-block:: default ws.boundary poly = gpd.GeoDataFrame.from_features(ws.boundary["features"], crs="EPSG:4326") ax = poly.plot(figsize=(20, 10), edgecolor='k') ax.set_title("Single Watershed", fontsize=30, fontweight = 'bold') ax.set_axis_off() .. image:: /gallery_vignettes/images/sphx_glr_plot_create_plots_001.png :alt: Single Watershed :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 44.197 seconds) .. _sphx_glr_download_gallery_vignettes_plot_create_plots.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_create_plots.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_create_plots.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_