awips2/python/map-resources-and-topography/index.html
2017-09-27 11:24:37 -07:00

1511 lines
No EOL
40 KiB
HTML

<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="description" content="Documentation for all things AWIPS.">
<link rel="canonical" href="http://unidata.github.io/awips2/python/map-resources-and-topography/">
<meta name="author" content="mjames@ucar.edu">
<link rel="shortcut icon" href="../../images/favicon.ico">
<meta name="generator" content="mkdocs-0.16.3, mkdocs-unidata-1.5.4">
<title>Map Resources and Topography - Unidata AWIPS User Manual</title>
<script src="../../assets/javascripts/modernizr-56ade86843.js"></script>
<link rel="stylesheet" href="../../assets/stylesheets/application-b1a1975878.css">
<link rel="stylesheet" href="../../assets/stylesheets/application-f78e5cb881.palette.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700|Roboto+Mono">
<style>body,input{font-family:"Roboto","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono","Courier New",Courier,monospace}</style>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="../../css/extra.css">
</head>
<body data-md-color-primary="blue-grey" data-md-color-accent="light-blue">
<svg class="md-svg">
<defs>
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448" viewBox="0 0 416 448" id="github"><path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19T128 352t-18.125-8.5-10.75-19T96 304t3.125-20.5 10.75-19T128 256t18.125 8.5 10.75 19T160 304zm160 0q0 10-3.125 20.5t-10.75 19T288 352t-18.125-8.5-10.75-19T256 304t3.125-20.5 10.75-19T288 256t18.125 8.5 10.75 19T320 304zm40 0q0-30-17.25-51T296 232q-10.25 0-48.75 5.25Q229.5 240 208 240t-39.25-2.75Q130.75 232 120 232q-29.5 0-46.75 21T56 304q0 22 8 38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0 37.25-1.75t35-7.375 30.5-15 20.25-25.75T360 304zm56-44q0 51.75-15.25 82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5T212 416q-19.5 0-35.5-.75t-36.875-3.125-38.125-7.5-34.25-12.875T37 371.5t-21.5-28.75Q0 312 0 260q0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25 30.875Q171.5 96 212 96q37 0 70 8 26.25-20.5 46.75-30.25T376 64q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34 99.5z"/></svg>
</defs>
</svg>
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="drawer">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="search">
<label class="md-overlay" data-md-component="overlay" for="drawer"></label>
<header class="md-header" data-md-component="header">
<nav class="md-header-nav md-grid">
<a href="../.."><div class="background-logo" style="background-image: url(../../images/cave.png);"></div>
<div class="md-flex">
<div class="md-flex__cell md-flex__cell--shrink">
<a href="../.." title="Unidata AWIPS User Manual" class="md-icon md-icon--home md-header-nav__button">
</a>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--menu md-header-nav__button" for="drawer"></label>
</div>
<div class="md-flex__cell md-flex__cell--stretch">
<span class="md-flex__ellipsis md-header-nav__title">
<span class="md-header-nav__parent">
Python API
</span>
Map Resources and Topography
</span>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--search md-header-nav__button" for="search"></label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="search"></label>
<div class="md-search__inner">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" required placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query">
<label class="md-icon md-search__icon" for="search"></label>
<button type="reset" class="md-icon md-search__icon" data-md-component="reset">&#xE5CD;</button>
</form>
<div class="md-search__output">
<div class="md-search__scrollwrap" data-md-scrollfix>
<div class="md-search-result" data-md-component="result" data-md-lang-search="" data-md-lang-tokenizer="[\s\-]+">
<div class="md-search-result__meta" data-md-lang-result-none="No matching documents" data-md-lang-result-one="1 matching document" data-md-lang-result-other="# matching documents">
Type to start searching
</div>
<ol class="md-search-result__list"></ol>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<div class="md-header-nav__source">
<a href="https://github.com/Unidata/awips2" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
GitHub
</div>
</a>
</div>
</div>
</div>
</nav>
</header>
<div class="md-container">
<main class="md-main">
<div class="md-main__inner md-grid" data-md-component="container">
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary" data-md-level="0">
<label class="md-nav__title md-nav__title--site" for="drawer">
<div class="md-nav__button md-logo">
<i class="md-icon md-icon--home"></i>
</div>
Unidata AWIPS User Manual
</label>
<div class="md-nav__source">
<a href="https://github.com/Unidata/awips2" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
GitHub
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../.." title="Home" class="md-nav__link">
Home
</a>
</li>
<li class="md-nav__item">
<a href="../../install/install-cave/" title="Install CAVE" class="md-nav__link">
Install CAVE
</a>
</li>
<li class="md-nav__item">
<a href="../../install/install-edex/" title="Install EDEX" class="md-nav__link">
Install EDEX
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-toggle md-nav__toggle" data-md-toggle="nav-4" type="checkbox" id="nav-4">
<label class="md-nav__link" for="nav-4">
CAVE User Manual
</label>
<nav class="md-nav" data-md-component="collapsible" data-md-level="1">
<label class="md-nav__title" for="nav-4">
CAVE User Manual
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../cave/d2d-perspective/" title="D2D Perspective" class="md-nav__link">
D2D Perspective
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/maps-views-projections/" title="Maps, Views, Projections" class="md-nav__link">
Maps, Views, Projections
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/bundles-and-procedures/" title="Bundles and Procedures" class="md-nav__link">
Bundles and Procedures
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/import-export/" title="Import/Export" class="md-nav__link">
Import/Export
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/localization-perspective/" title="Localization Perspective" class="md-nav__link">
Localization Perspective
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/ncp-perspective/" title="NCP Perspective" class="md-nav__link">
NCP Perspective
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/nsharp/" title="NSHARP" class="md-nav__link">
NSHARP
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/warngen/" title="WarnGen Walkthrough" class="md-nav__link">
WarnGen Walkthrough
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/goes-16-satellite/" title="GOES-16 (GOES-R)" class="md-nav__link">
GOES-16 (GOES-R)
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/d2d-gis-shapefiles/" title="GIS and Shapefiles" class="md-nav__link">
GIS and Shapefiles
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/d2d-gridded-models/" title="Volume Browser" class="md-nav__link">
Volume Browser
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/d2d-tools/" title="Display Tools" class="md-nav__link">
Display Tools
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/d2d-radar-tools/" title="Radar Tools" class="md-nav__link">
Radar Tools
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/d2d-edit-menus/" title="Editing Menus" class="md-nav__link">
Editing Menus
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/cave-localization/" title="Change Localization" class="md-nav__link">
Change Localization
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-toggle md-nav__toggle" data-md-toggle="nav-5" type="checkbox" id="nav-5">
<label class="md-nav__link" for="nav-5">
EDEX User Manual
</label>
<nav class="md-nav" data-md-component="collapsible" data-md-level="1">
<label class="md-nav__title" for="nav-5">
EDEX User Manual
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../edex/distributed-computing/" title="Distributed EDEX" class="md-nav__link">
Distributed EDEX
</a>
</li>
<li class="md-nav__item">
<a href="../../install/start-edex/" title="EDEX Start and Stop" class="md-nav__link">
EDEX Start and Stop
</a>
</li>
<li class="md-nav__item">
<a href="../../edex/ldm/" title="LDM Feeds" class="md-nav__link">
LDM Feeds
</a>
</li>
<li class="md-nav__item">
<a href="../../edex/data-distribution-files/" title="Data Distribution Files" class="md-nav__link">
Data Distribution Files
</a>
</li>
<li class="md-nav__item">
<a href="../../edex/new-grid/" title="Ingest a New Grid" class="md-nav__link">
Ingest a New Grid
</a>
</li>
<li class="md-nav__item">
<a href="../../edex/data-purge/" title="Purging and Retention" class="md-nav__link">
Purging and Retention
</a>
</li>
<li class="md-nav__item">
<a href="../../edex/edex-users/" title="Monitor Users" class="md-nav__link">
Monitor Users
</a>
</li>
<li class="md-nav__item">
<a href="../../edex/data-plugins/" title="Data Plugins" class="md-nav__link">
Data Plugins
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-toggle md-nav__toggle" data-md-toggle="nav-6" type="checkbox" id="nav-6">
<label class="md-nav__link" for="nav-6">
Supported Data Types
</label>
<nav class="md-nav" data-md-component="collapsible" data-md-level="1">
<label class="md-nav__title" for="nav-6">
Supported Data Types
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../cave/d2d-grids/" title="Gridded Model Display" class="md-nav__link">
Gridded Model Display
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/d2d-pointdata-surface-obs/" title="Surface Obs" class="md-nav__link">
Surface Obs
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/d2d-satellite/" title="Satellite Imagery" class="md-nav__link">
Satellite Imagery
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/d2d-radar/" title="NEXRAD Radar" class="md-nav__link">
NEXRAD Radar
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/d2d-uair/" title="Upper Air" class="md-nav__link">
Upper Air
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/d2d-hydro/" title="NCEP/Hydro" class="md-nav__link">
NCEP/Hydro
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/d2d-map-resources/" title="Map Overlays" class="md-nav__link">
Map Overlays
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--active md-nav__item--nested">
<input class="md-toggle md-nav__toggle" data-md-toggle="nav-7" type="checkbox" id="nav-7" checked>
<label class="md-nav__link" for="nav-7">
Python API
</label>
<nav class="md-nav" data-md-component="collapsible" data-md-level="1">
<label class="md-nav__title" for="nav-7">
Python API
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../python-awips-data-access/" title="Overview" class="md-nav__link">
Overview
</a>
</li>
<li class="md-nav__item">
<a href="../maps-database/" title="Maps Database" class="md-nav__link">
Maps Database
</a>
</li>
<li class="md-nav__item">
<a href="../awips-grids-and-cartopy/" title="AWIPS Grids and Cartopy" class="md-nav__link">
AWIPS Grids and Cartopy
</a>
</li>
<li class="md-nav__item">
<a href="../satellite-imagery/" title="Satellite Imagery" class="md-nav__link">
Satellite Imagery
</a>
</li>
<li class="md-nav__item">
<a href="../nexrad-level-3-radar/" title="NEXRAD Level 3 Radar" class="md-nav__link">
NEXRAD Level 3 Radar
</a>
</li>
<li class="md-nav__item">
<a href="../upper-air-bufr-soundings/" title="Upper air BUFR Soundings" class="md-nav__link">
Upper air BUFR Soundings
</a>
</li>
<li class="md-nav__item">
<a href="../model-sounding-data/" title="Model Sounding Data" class="md-nav__link">
Model Sounding Data
</a>
</li>
<li class="md-nav__item md-nav__item--active">
<input class="md-toggle md-nav__toggle" data-md-toggle="toc" type="checkbox" id="toc">
<label class="md-nav__link md-nav__link--active" for="toc">
Map Resources and Topography
</label>
<a href="./" title="Map Resources and Topography" class="md-nav__link md-nav__link--active">
Map Resources and Topography
</a>
<nav class="md-nav md-nav--secondary">
<label class="md-nav__title" for="toc">Table of contents</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#notes" title="Notes" class="md-nav__link">
Notes
</a>
</li>
<li class="md-nav__item">
<a href="#setup" title="Setup" class="md-nav__link">
Setup
</a>
</li>
<li class="md-nav__item">
<a href="#request-county-boundaries-for-a-wfo" title="Request County Boundaries for a WFO" class="md-nav__link">
Request County Boundaries for a WFO
</a>
</li>
<li class="md-nav__item">
<a href="#create-a-merged-cwa-with-cascaded_union" title="Create a merged CWA with cascaded_union" class="md-nav__link">
Create a merged CWA with cascaded_union
</a>
</li>
<li class="md-nav__item">
<a href="#wfo-boundary-spatial-filter-for-interstates" title="WFO boundary spatial filter for interstates" class="md-nav__link">
WFO boundary spatial filter for interstates
</a>
</li>
<li class="md-nav__item">
<a href="#nearby-cities" title="Nearby cities" class="md-nav__link">
Nearby cities
</a>
</li>
<li class="md-nav__item">
<a href="#lakes" title="Lakes" class="md-nav__link">
Lakes
</a>
</li>
<li class="md-nav__item">
<a href="#major-rivers" title="Major Rivers" class="md-nav__link">
Major Rivers
</a>
</li>
<li class="md-nav__item">
<a href="#topography" title="Topography" class="md-nav__link">
Topography
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../surface-obs-plot-metpy/" title="Surface Obs Plot with MetPy" class="md-nav__link">
Surface Obs Plot with MetPy
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-toggle md-nav__toggle" data-md-toggle="nav-8" type="checkbox" id="nav-8">
<label class="md-nav__link" for="nav-8">
Development
</label>
<nav class="md-nav" data-md-component="collapsible" data-md-level="1">
<label class="md-nav__title" for="nav-8">
Development
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../dev/awips-development-environment/" title="AWIPS Development Environment (ADE)" class="md-nav__link">
AWIPS Development Environment (ADE)
</a>
</li>
<li class="md-nav__item">
<a href="../../dev/build-nsharp-macos/" title="Building NSHARP for macOS" class="md-nav__link">
Building NSHARP for macOS
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-toggle md-nav__toggle" data-md-toggle="nav-9" type="checkbox" id="nav-9">
<label class="md-nav__link" for="nav-9">
Appendix
</label>
<nav class="md-nav" data-md-component="collapsible" data-md-level="1">
<label class="md-nav__title" for="nav-9">
Appendix
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../appendix/appendix-grid-parameters/" title="AWIPS Grid Parameters" class="md-nav__link">
AWIPS Grid Parameters
</a>
</li>
<li class="md-nav__item">
<a href="../../appendix/appendix-acronyms/" title="Acronyms and Abbreviations" class="md-nav__link">
Acronyms and Abbreviations
</a>
</li>
<li class="md-nav__item">
<a href="../../appendix/appendix-cots/" title="COTS and FOSS" class="md-nav__link">
COTS and FOSS
</a>
</li>
<li class="md-nav__item">
<a href="../../appendix/appendix-wsr88d/" title="WSR-88D Product Table" class="md-nav__link">
WSR-88D Product Table
</a>
</li>
<li class="md-nav__item">
<a href="../../cave/cave-keyboard-shortcuts/" title="Keyboard Shortcuts" class="md-nav__link">
Keyboard Shortcuts
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--secondary">
<label class="md-nav__title" for="toc">Table of contents</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#notes" title="Notes" class="md-nav__link">
Notes
</a>
</li>
<li class="md-nav__item">
<a href="#setup" title="Setup" class="md-nav__link">
Setup
</a>
</li>
<li class="md-nav__item">
<a href="#request-county-boundaries-for-a-wfo" title="Request County Boundaries for a WFO" class="md-nav__link">
Request County Boundaries for a WFO
</a>
</li>
<li class="md-nav__item">
<a href="#create-a-merged-cwa-with-cascaded_union" title="Create a merged CWA with cascaded_union" class="md-nav__link">
Create a merged CWA with cascaded_union
</a>
</li>
<li class="md-nav__item">
<a href="#wfo-boundary-spatial-filter-for-interstates" title="WFO boundary spatial filter for interstates" class="md-nav__link">
WFO boundary spatial filter for interstates
</a>
</li>
<li class="md-nav__item">
<a href="#nearby-cities" title="Nearby cities" class="md-nav__link">
Nearby cities
</a>
</li>
<li class="md-nav__item">
<a href="#lakes" title="Lakes" class="md-nav__link">
Lakes
</a>
</li>
<li class="md-nav__item">
<a href="#major-rivers" title="Major Rivers" class="md-nav__link">
Major Rivers
</a>
</li>
<li class="md-nav__item">
<a href="#topography" title="Topography" class="md-nav__link">
Topography
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content">
<article class="md-content__inner md-typeset">
<a href="https://github.com/Unidata/awips2/edit/master/docs/python/map-resources-and-topography.md" title="Edit this page" class="md-icon md-content__icon">edit</a>
<h1>Map Resources and Topography</h1>
<p>The <a href="http://python-awips.readthedocs.io"><b>python-awips</b></a> package provides access to the entire AWIPS Maps Database for use in Python GIS applications. Map objects are returned as <a href="http://toblerity.org/shapely/manual.html"><b>Shapely</b></a> geometries (<em>Polygon</em>, <em>Point</em>, <em>MultiLineString</em>, etc.) and can be plotted by Matplotlib, Cartopy, MetPy, and other packages. </p>
<p>Each map database table has a geometry field called <code>the_geom</code>, which can be used to spatially select map resources for any column of type geometry. </p>
<blockquote>
<p>See the <a href="http://unidata.github.io/awips2/python/maps-database/#mapdatacwa"><b>Maps Database Reference Page</b></a> for available database tables, column names, and types. </p>
</blockquote>
<h2 id="notes">Notes<a class="headerlink" href="#notes" title="Permanent link"></a></h2>
<ul>
<li>This notebook requires: <strong>python-awips, numpy, matplotplib, cartopy, shapely</strong></li>
<li>Use datatype <strong>maps</strong> and <strong>addIdentifier('table', &lt;postgres maps schema&gt;)</strong> to define the map table:
DataAccessLayer.changeEDEXHost("edex-cloud.unidata.ucar.edu")
request = DataAccessLayer.newDataRequest('maps')
request.addIdentifier('table', 'mapdata.county')</li>
<li>Use <strong>request.setLocationNames()</strong> and <strong>request.addIdentifier()</strong> to spatially filter a map resource. In the example below, WFO ID <strong>BOU</strong> (Boulder, Colorado) is used to query counties within the BOU county watch area (CWA) <pre><code>request.addIdentifier('geomField', 'the_geom')
request.addIdentifier('inLocation', 'true')
request.addIdentifier('locationField', 'cwa')
request.setLocationNames('BOU')
request.addIdentifier('cwa', 'BOU')
</code></pre>
</li>
</ul>
<blockquote>
<p>Note the geometry definition of <code>the_geom</code> for each data type, which can be <strong>Point</strong>, <strong>MultiPolygon</strong>, or <strong>MultiLineString</strong>.</p>
</blockquote>
<h2 id="setup">Setup<a class="headerlink" href="#setup" title="Permanent link"></a></h2>
<pre><code class="python">from __future__ import print_function
from awips.dataaccess import DataAccessLayer
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import numpy as np
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
from cartopy.feature import ShapelyFeature,NaturalEarthFeature
from shapely.geometry import Polygon
from shapely.ops import cascaded_union
# Standard map plot
def make_map(bbox, projection=ccrs.PlateCarree()):
fig, ax = plt.subplots(figsize=(12,12),
subplot_kw=dict(projection=projection))
ax.set_extent(bbox)
ax.coastlines(resolution='50m')
gl = ax.gridlines(draw_labels=True)
gl.xlabels_top = gl.ylabels_right = False
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
return fig, ax
# Server, Data Request Type, and Database Table
DataAccessLayer.changeEDEXHost(&quot;edex-cloud.unidata.ucar.edu&quot;)
request = DataAccessLayer.newDataRequest('maps')
request.addIdentifier('table', 'mapdata.county')
</code></pre>
<h2 id="request-county-boundaries-for-a-wfo">Request County Boundaries for a WFO<a class="headerlink" href="#request-county-boundaries-for-a-wfo" title="Permanent link"></a></h2>
<ul>
<li>Use <strong>request.setParameters()</strong> to define fields to be returned by the request.</li>
</ul>
<pre><code class="python"># Define a WFO ID for location
# tie this ID to the mapdata.county column &quot;cwa&quot; for filtering
request.setLocationNames('BOU')
request.addIdentifier('cwa', 'BOU')
# enable location filtering (inLocation)
# locationField is tied to the above cwa definition (BOU)
request.addIdentifier('geomField', 'the_geom')
request.addIdentifier('inLocation', 'true')
request.addIdentifier('locationField', 'cwa')
# This is essentially the same as &quot;'&quot;select count(*) from mapdata.cwa where cwa='BOU';&quot; (=1)
# Get response and create dict of county geometries
response = DataAccessLayer.getGeometryData(request, [])
counties = np.array([])
for ob in response:
counties = np.append(counties,ob.getGeometry())
print(&quot;Using &quot; + str(len(counties)) + &quot; county MultiPolygons&quot;)
%matplotlib inline
# All WFO counties merged to a single Polygon
merged_counties = cascaded_union(counties)
envelope = merged_counties.buffer(2)
boundaries=[merged_counties]
# Get bounds of this merged Polygon to use as buffered map extent
bounds = merged_counties.bounds
bbox=[bounds[0]-1,bounds[2]+1,bounds[1]-1.5,bounds[3]+1.5]
fig, ax = make_map(bbox=bbox)
# Plot political/state boundaries handled by Cartopy
political_boundaries = NaturalEarthFeature(category='cultural',
name='admin_0_boundary_lines_land',
scale='50m', facecolor='none')
states = NaturalEarthFeature(category='cultural',
name='admin_1_states_provinces_lines',
scale='50m', facecolor='none')
ax.add_feature(political_boundaries, linestyle='-', edgecolor='black')
ax.add_feature(states, linestyle='-', edgecolor='black',linewidth=2)
# Plot CWA counties
for i, geom in enumerate(counties):
cbounds = Polygon(geom)
intersection = cbounds.intersection
geoms = (intersection(geom)
for geom in counties
if cbounds.intersects(geom))
shape_feature = ShapelyFeature(geoms,ccrs.PlateCarree(),
facecolor='none', linestyle=&quot;-&quot;,edgecolor='#86989B')
ax.add_feature(shape_feature)
</code></pre>
<pre><code>Using 25 county MultiPolygons
</code></pre>
<p><img alt="png" src="../../images/map_4_1.png" /></p>
<h2 id="create-a-merged-cwa-with-cascaded_union">Create a merged CWA with cascaded_union<a class="headerlink" href="#create-a-merged-cwa-with-cascaded_union" title="Permanent link"></a></h2>
<pre><code class="python"># Plot CWA envelope
for i, geom in enumerate(boundaries):
gbounds = Polygon(geom)
intersection = gbounds.intersection
geoms = (intersection(geom)
for geom in boundaries
if gbounds.intersects(geom))
shape_feature = ShapelyFeature(geoms,ccrs.PlateCarree(),
facecolor='none', linestyle=&quot;-&quot;,linewidth=3.,edgecolor='#cc5000')
ax.add_feature(shape_feature)
fig
</code></pre>
<p><img alt="png" src="../../images/map_6_0.png" /></p>
<h2 id="wfo-boundary-spatial-filter-for-interstates">WFO boundary spatial filter for interstates<a class="headerlink" href="#wfo-boundary-spatial-filter-for-interstates" title="Permanent link"></a></h2>
<p>Using the previously-defined <strong>envelope=merged_counties.buffer(2)</strong> in <strong>newDataRequest()</strong> to request geometries which fall inside the buffered boundary. </p>
<pre><code class="python">request = DataAccessLayer.newDataRequest('maps', envelope=envelope)
request.addIdentifier('table', 'mapdata.interstate')
request.addIdentifier('geomField', 'the_geom')
request.addIdentifier('locationField', 'hwy_type')
request.addIdentifier('hwy_type', 'I') # I (interstate), U (US highway), or S (state highway)
request.setParameters('name')
interstates = DataAccessLayer.getGeometryData(request, [])
print(&quot;Using &quot; + str(len(interstates)) + &quot; interstate MultiLineStrings&quot;)
# Plot interstates
for ob in interstates:
shape_feature = ShapelyFeature(ob.getGeometry(),ccrs.PlateCarree(),
facecolor='none', linestyle=&quot;-&quot;,edgecolor='orange')
ax.add_feature(shape_feature)
fig
</code></pre>
<pre><code>Using 223 interstate MultiLineStrings
</code></pre>
<p><img alt="png" src="../../images/map_8_1.png" /></p>
<blockquote>
<p>Road type from <code>select distinct(hwy_type) from mapdata.interstate;</code></p>
<pre><code> I - Interstates
U - US Highways
S - State Highways
</code></pre>
</blockquote>
<h2 id="nearby-cities">Nearby cities<a class="headerlink" href="#nearby-cities" title="Permanent link"></a></h2>
<p>Request the city table and filter by population and progressive disclosure level:</p>
<p><strong>Warning</strong>: the <code>prog_disc</code> field is not entirely understood and values appear to change significantly depending on WFO site. </p>
<pre><code class="python">request = DataAccessLayer.newDataRequest('maps', envelope=envelope)
request.addIdentifier('table', 'mapdata.city')
request.addIdentifier('geomField', 'the_geom')
request.setParameters('name','population','prog_disc')
cities = DataAccessLayer.getGeometryData(request, [])
print(&quot;Found &quot; + str(len(cities)) + &quot; city Points&quot;)
</code></pre>
<pre><code>Found 1201 city Points
</code></pre>
<pre><code class="python">citylist = []
cityname = []
# For BOU, progressive disclosure values above 50 and pop above 5000 looks good
for ob in cities:
if ((ob.getNumber(&quot;prog_disc&quot;)&gt;50) and int(ob.getString(&quot;population&quot;)) &gt; 5000):
citylist.append(ob.getGeometry())
cityname.append(ob.getString(&quot;name&quot;))
print(&quot;Using &quot; + str(len(cityname)) + &quot; city Points&quot;)
# Plot city markers
ax.scatter([point.x for point in citylist],
[point.y for point in citylist],
transform=ccrs.Geodetic(),marker=&quot;+&quot;,facecolor='black')
# Plot city names
for i, txt in enumerate(cityname):
ax.annotate(txt, (citylist[i].x,citylist[i].y),
xytext=(3,3), textcoords=&quot;offset points&quot;)
fig
</code></pre>
<pre><code>Using 57 city Points
</code></pre>
<p><img alt="png" src="../../images/map_11_1.png" /></p>
<h2 id="lakes">Lakes<a class="headerlink" href="#lakes" title="Permanent link"></a></h2>
<pre><code class="python">request = DataAccessLayer.newDataRequest('maps', envelope=envelope)
request.addIdentifier('table', 'mapdata.lake')
request.addIdentifier('geomField', 'the_geom')
request.setParameters('name')
# Get lake geometries
response = DataAccessLayer.getGeometryData(request, [])
lakes = np.array([])
for ob in response:
lakes = np.append(lakes,ob.getGeometry())
print(&quot;Using &quot; + str(len(lakes)) + &quot; lake MultiPolygons&quot;)
# Plot lakes
for i, geom in enumerate(lakes):
cbounds = Polygon(geom)
intersection = cbounds.intersection
geoms = (intersection(geom)
for geom in lakes
if cbounds.intersects(geom))
shape_feature = ShapelyFeature(geoms,ccrs.PlateCarree(),
facecolor='blue', linestyle=&quot;-&quot;,edgecolor='#20B2AA')
ax.add_feature(shape_feature)
fig
</code></pre>
<pre><code>Using 208 lake MultiPolygons
</code></pre>
<p><img alt="png" src="../../images/map_13_1.png" /></p>
<h2 id="major-rivers">Major Rivers<a class="headerlink" href="#major-rivers" title="Permanent link"></a></h2>
<pre><code class="python">request = DataAccessLayer.newDataRequest('maps', envelope=envelope)
request.addIdentifier('table', 'mapdata.majorrivers')
request.addIdentifier('geomField', 'the_geom')
request.setParameters('pname')
rivers = DataAccessLayer.getGeometryData(request, [])
print(&quot;Using &quot; + str(len(rivers)) + &quot; river MultiLineStrings&quot;)
# Plot rivers
for ob in rivers:
shape_feature = ShapelyFeature(ob.getGeometry(),ccrs.PlateCarree(),
facecolor='none', linestyle=&quot;:&quot;,edgecolor='#20B2AA')
ax.add_feature(shape_feature)
fig
</code></pre>
<pre><code>Using 758 river MultiLineStrings
</code></pre>
<p><img alt="png" src="../../images/map_15_1.png" /></p>
<h2 id="topography">Topography<a class="headerlink" href="#topography" title="Permanent link"></a></h2>
<p>Spatial envelopes are required for topo requests, which can become slow to download and render for large (CONUS) maps.</p>
<pre><code class="python">import numpy.ma as ma
request = DataAccessLayer.newDataRequest()
request.setDatatype(&quot;topo&quot;)
request.addIdentifier(&quot;group&quot;, &quot;/&quot;)
request.addIdentifier(&quot;dataset&quot;, &quot;full&quot;)
request.setEnvelope(envelope)
gridData = DataAccessLayer.getGridData(request)
print(gridData)
print(&quot;Number of grid records: &quot; + str(len(gridData)))
print(&quot;Sample grid data shape:\n&quot; + str(gridData[0].getRawData().shape) + &quot;\n&quot;)
print(&quot;Sample grid data:\n&quot; + str(gridData[0].getRawData()) + &quot;\n&quot;)
</code></pre>
<pre><code>[&lt;awips.dataaccess.PyGridData.PyGridData object at 0x1174adf50&gt;]
Number of grid records: 1
Sample grid data shape:
(778, 1058)
Sample grid data:
[[ 1694. 1693. 1688. ..., 757. 761. 762.]
[ 1701. 1701. 1701. ..., 758. 760. 762.]
[ 1703. 1703. 1703. ..., 760. 761. 762.]
...,
[ 1767. 1741. 1706. ..., 769. 762. 768.]
[ 1767. 1746. 1716. ..., 775. 765. 761.]
[ 1781. 1753. 1730. ..., 766. 762. 759.]]
</code></pre>
<pre><code class="python">grid=gridData[0]
topo=ma.masked_invalid(grid.getRawData())
lons, lats = grid.getLatLonCoords()
print(topo.min())
print(topo.max())
# Plot topography
cs = ax.contourf(lons, lats, topo, 80, cmap=plt.get_cmap('terrain'),alpha=0.1)
cbar = fig.colorbar(cs, extend='both', shrink=0.5, orientation='horizontal')
cbar.set_label(&quot;topography height in meters&quot;)
fig
</code></pre>
<pre><code>623.0
4328.0
</code></pre>
<p><img alt="png" src="../../images/map_18_1.png" /></p>
</article>
</div>
</div>
</main>
<footer class="md-footer">
<div class="md-footer-nav">
<nav class="md-footer-nav__inner md-grid">
<a href="../model-sounding-data/" title="Model Sounding Data" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev">
<div class="md-flex__cell md-flex__cell--shrink">
<i class="md-icon md-icon--arrow-back md-footer-nav__button"></i>
</div>
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
<span class="md-flex__ellipsis">
<span class="md-footer-nav__direction">
Previous
</span>
Model Sounding Data
</span>
</div>
</a>
<a href="../surface-obs-plot-metpy/" title="Surface Obs Plot with MetPy" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next">
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
<span class="md-flex__ellipsis">
<span class="md-footer-nav__direction">
Next
</span>
Surface Obs Plot with MetPy
</span>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<i class="md-icon md-icon--arrow-forward md-footer-nav__button"></i>
</div>
</a>
</nav>
</div>
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-footer-copyright">
<div class="md-footer-copyright__highlight">
Copyright &copy; 2017 Unidata Program Center.
</div>
powered by
<a href="http://www.mkdocs.org" title="MkDocs">MkDocs</a>
and
<a href="http://squidfunk.github.io/mkdocs-material/" title="Material for MkDocs">
Material for MkDocs</a>
</div>
<div class="md-footer-social">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<a href="http://www.unidata.ucar.edu/software/awips2" class="md-footer-social__link fa fa-globe"></a>
<a href="https://github.com/Unidata/awips2" class="md-footer-social__link fa fa-github-alt"></a>
<a href="https://twitter.com/Unidata" class="md-footer-social__link fa fa-twitter"></a>
<a href="https://facebook.com/Unidata" class="md-footer-social__link fa fa-facebook"></a>
</div>
</div>
</div>
</footer>
</div>
<script src="../../assets/javascripts/application-0b7df094bf.js"></script>
<script>app.initialize({url:{base:"../.."}})</script>
</body>
</html>