A sample app using MongoDB's $geoIntersects query operator
JavaScript CSS
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
public Minor UI changes Oct 23, 2013
routes
.gitignore
Gruntfile.js Initial commit Oct 22, 2013
README.md
app.js
getDb.js Initial commit Oct 22, 2013
package.json
routeToLineString.js Initial commit Oct 22, 2013

README.md

Geo-Neighborhoods

A live version of this app can be found at: http://geo-neighborhood.cfapps.io

The Data

City of Chicago neighborhood boundaries were found here: http://www.cityofchicago.org/city/en/depts/doit/dataset/boundaries_-_neighborhoods.html

I converted the data to GeoJSON format using ogr2ogr, a command line tool available with GDAL:

ogr2ogr -f "GeoJSON" -t_srs crs:84 neighborhoods.json Neighborhoods_2012b.shp

The -t_srs crs:84 specifies a projection to use. If you leave this part off, you won't be dealing with degrees in your output document.

The resulting file is a single GeoJSON object of the FeatureCollection type, which looks like:

{
  "type": "FeatureCollection",
  "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },

  "features": [ {a neighborhood as a GeoJSON feature},...],
}

I saved just the features array as a separate file, then imported it into MongoDB using mongoimport

mongoimport --db Chicago --collection neighborhoods --jsonArray neighborhoods-formatted.json

NOTE: The neighborhoods of Streeterville and O'Hare are defined as MultiPolygons, an unsupported GeoJSON type in MongoDB. I converted these to separate documents, each with it's own single polygon.

While it's not required for $geoIntersects, adding a 2dsphere index will boost query performance. Open up the mongo shell and run the following command:

db.neighborhoods.ensureIndex({geometry: "2dshere"});