Looking at the increasing NoSQL movement and considering that databases like MongoDB offers a new perspective in flexible data storage for GIS. What is the best way to store lines and polygons in JSON documents to take advantage of 2d indexes and spatial functions?
Here's an example of a line and a polygon:
One thing to note is that MongoDB's support for spatial datatypes is horrendously bad for any serious spatial lookup, and this applies across the board with NoSQL last time I checked. I dislike GeoCouch quite a bit less, but it also still has a way to go.
GeoJSON is a fantastic format but to take advantage of the limited (POINT-ONLY) spatial indexes in Mongo you'd need a spatially indexed collection holding nothing but a record for each of the polygon's points with an additional value for the record ID of your spatial record living in another collection, then use a bounding box query to get record IDs from one and select from the other, effectively emulating a join.
You could go hacky and just do the corners of the bounding box as points for your records, but then bounding box searches may fail and all in all it forces some pretty inefficient design patterns and inappropriately pushes all kinds of responsibilities to the developer.
As a reference implementation, you may want to refer to this code which was presented at the Esri Developer Summit this year.
I have not been happy at all with the spatial support on the various NoSQL databases. They only go far enough for dumb point cloud lookup, which makes sense considering most apps using this are only dropping pushpins onto a Google map on a browser somewhere. PostGIS is still going to be the best open-source workhorse for managing spatial information for the foreseeable future.
This is simply not true,
"to take advantage of spatial indexes in Mongo, you'd need a spatially indexed collection holding nothing but a record for each of the polygon's points, with an additional value for the record ID of your spatial record living in another collection, then use a bounding box query to get record IDs from one [collection] and select [record data] from the other [collection], effectively emulating a join."
I have USGS point data stored in a single Mongo collection with records that look like this:
I am able to do bounding box queries on this data that return the entire record (without the need for another collection) just fine.
Mongo also provides the ability to do nearest neighbor searches, as well as point in polygon searches. This is well documented at mongodb.org
|show 3 more comments|