The changewithin.py script pulls daily changes
from OpenStreetMap with requests
, parses them with lxml
, finds the ones that are inside
of a GeoJSON shape (in this case a national park), sorts out the ones that have tags set by the user, and emails a set of users
with mailgun.
This script was forked from the osmlab/changewithin repository and enhanced to assist NPS iteratively explore integrating more OpenStreetMap geo data into the production of Park Tiles. Now the script has been improved to capture ways and nodes, with any tags set in the configuration file. This gives NPS access to all data from the changesets, and the control to tweak the amount of information monitored as they iterate on the Park Tiles data workflow.
- Script detects changes in national park
- Abstracted tag entry to configuration file, enabling user to filter contributions captured by the script, for example, only 'highway' and 'amenity'
- Script now checks for ways and nodes that match tags set in configuration file
- Improved output layout with detected contributions grouped by changeset, then by tag, see example output from February 19, 2014.
The one file that will require editing is config.ini.
This configuration file sets the following:
- email addresses to which the script will send reports
- mailgun api key
- GeoJSON file
- tags for ways that you wish to retrieve with the script that fall within the GeoJSON boundaries
- these tags must be separated by commas only
The email templates for html can be edited within
the file lib.py
.
The report itself contains a summary of changes, then lists each relevant changeset, its ID, then a summary of details by tag. The report will automatically generate a section for each tag entered in the configuration file. If there are no changes with a certain tag for that changeset, it will not appear. Furhter details also include the user who made the change and their comment, individual element IDs for building footprint and address changes that link to their history, and a map thumbnail that is centered on the location where the edits were made.
Geographic areas for the script to run against are stored in the folder /boundaries/
.
Since there aren't frequent changes in national parks at the moment, the script runs on a larger area surrounding Olympic National Park to display the change detetion capabilities.
As this screenshot shows, olympic-park-large.geojson
extends beyond the boundaries of Olympic National Park.
The actual park, stored in this repository as olympic-park.geojson
, will return less results since there are infrequent contributions to parks on OSM.
You can also run the script against urban areas. Add nyc.geojson
to the configuration file to see the relatively larger amount of contributions captured.
You can configure a remote URL containing GeoJSON data. US Census places and counties are available from Code for America, referenced by GEOID. To find the GEOID for a county or place, start with one of these Census lookup tools:
- http://www.census.gov/geo/reference/codes/countylookup.html
- http://www.census.gov/geo/reference/codes/placelookup.html
Each GEOID combines the state FIPS code (two digits) and ANSI code. For example, to find the GEOID of New York City, select New York State via the Place Lookup tool above and look for "New York City" on the page. Its ANSI code is 51000 and New York's state FIPS code is 36. Therefore, New York City's GEOID is 3651000 and its GeoJSON URL is:
Example GeoJSON URLs for L.A. County, Washington DC, and Oakland CA:
- http://forever.codeforamerica.org/Census-API/by-geoid/06037.json
- http://forever.codeforamerica.org/Census-API/by-geoid/11001.json
- http://forever.codeforamerica.org/Census-API/by-geoid/0653000.json
cURL typically comes pre-installed.
For Mac use homebrew and one of:
brew install wget
brew install curl
For Ubuntu/Linux one of:
apt-get install wget
apt-get install curl
Requires Python with lxml, requests, pystache, PIL, and ModestMaps.
Optionally set up virtualenv:
virtualenv --no-site-packages venv-changewithin
source venv-changewithin/bin/activate
Install libraries needed for fast XML processing and Python extensions. For Ubuntu/Linux:
apt-get install python-dev libxml2-dev libxslt1-dev
Install Python packages:
pip install -r requirements.txt
python changewithin.py
Assuming the above installation, edit your cron table (crontab -e
) to run the script once a day at 7:00am.
0 7 * * * ~/path/to/changewithin/bin/python ~/path/to/changewithin/changewithin.py