Technology

Building a Geospatial Application with Cloudant to Show Colorado Ski Areas

30 Jul 2014 4:19pm, by

Editor’s note: The use of geodata has traditionally been the domain of geographic information specialists. But increasingly, geodata is proving useful for developers looking to add deeper functionality to their apps. This was evident when I attended the Esri User Conference earlier this month. Developers are finding all kinds of new ways to use geodata. But from our perpsective, more examples are needed to show how geodata can add more context and illuminate information that could not be seen before. Cloudant’s contribution here is just one example of how databases are being used to integrate geodata into apps. We look forward to more contributions that highlight geodata projects and provide guides for all of us to use.

The aim of this post is to provide the building blocks to query and present geospatial data from Cloudant in third-party applications. Specifically, we will discuss how to integrate Leaflet with Cloudant to build this site. Leaflet is an open-source JavaScript library for mobile-friendly interactive maps.

skiing

Building Blocks

The site is built using Leaflet Vector Layers and Leaflet Draw. You can find all the code here. Leaflet Vector Layers pulls vector features from geo web service providers including ArcGIS Server, Arc2Earth, CartoDB, and Geocommons. Leaflet Draw is a vector drawing and editing plugin for Leaflet.

We used the existing dataset from GeoIQ, which includes GeoJSON data for ski areas in the Colorado area of the Rocky Mountains:

After updating the data to Cloudant, create the database through the Cloudant administration user interface. (Note: If new to Cloudant, register and let support@cloudant.com know that you want to be on the geospatial cluster.)

dashboard

We use the following Cloudant design document to index the GeoJSON as an R*Tree secondary spatial index.

The design document above is created within Cloudant with an HTTP POST request:

I used a simple Python script to load the remaining GeoJSON feature collection for Colorado ski areas:

The script above uses the Python requests to pull a GeoJSON feature collection and parse it as individual documents to be indexed in the Cloudant Spatial Index.

The Cloudant Geo OpenSearch API wrapped within Leaflet Vector Layers adds a datasource that is comparable to editing index.html to set up a region of interest.

Leaflet Vector Layers will provide radius, bounding box, and polygon queries of your data.

Norman Barker is the Director of Geo at Cloudant, an IBM Company. He has been developing geospatial programs for more than 10 years and leads the development of distributed geospatial indexes for Cloudant. His primary interest is in how to use unstructured geospatial data.

Feature image via Flickr Creative Commons.

A newsletter digest of the week’s most important stories & analyses.