A Plethora of Spatial – PostGIS, MongoDB, and Lucene Spatial



Presented by:

Steven Pousty

@TheSteve0 on Twitter, IRC, Smugmug, Instagram, Ingress, and Github


  1. A little about Spatial DataStores
  2. Some JEE
  3. Compare and Contrast


  1. You write Java code
  2. You will ask questions

Types of Spatial datastores

TYPERelationalDocumentFull Text indexGraph
EXAMPLE PostGIS, MySQL, SQLServer, Oracle, & SpatiaLite MongoDB, Couchbase Lucene/Solr/ElasticSearch Neo4J
USE-CASE Use for almost everything Document storage and search Full text Indexing Relationships between "things"

Start With PostGIS


Basic Notes on PostGIS

  • A spatial extension to PostgreSQL
  • Been around for at least 10 years
  • Full OGC Spec for MM-SQL
  • A metric ton of integration with other spatial software
  • THE standard in the FOSS GIS community


  • Extremely Powerful and Flexible
  • Has Hibernate integration
  • Well Known Technology


  • Steep Learning Curve
  • All the same baggage as PostgreSQL
  • No good scaling story

On to Mongo


A bit about MongoDB

  • A document is just a bunch of attributes and values - think of it like HashMap
  • Very simple spatial functionality
  • Defaults to data units from GPS devices
  • Schemaless
  • Really good at fast writes - but you give up immediate consistency
  • Easy to horizontally scale


  • Simple to learn
  • Easy to setup
  • Benefits of NoSQL


  • Limited Spatial - only a few query types
  • No stored procedures or DB error protection
  • Newer technology

Finally Lucene


A bit about Lucene

  • 2 steps - create an Index and then Search it
  • Most spatial functionality comes from Spatial4j
  • Very simple Spatial functionality
  • Schemaless
  • Index is just files on disk
  • Also part of Solr and ElasticSearch


  • Simple to learn
  • Just files on disk
  • Great textual and spatial search


  • Limited Spatial - only a few query types
  • Not really geared towards frequently updated data
  • No on the fly field querying


  • Context Dependency Injection - allows you to make classes availble whenever you need them and let the calling class decide which class it wants
  • JAX-RS - the antiSOAP (three cheers). Makes it super easy to write REST like architectures

Let's look at some code

Build a spatial checkin service for national parks in US and Canada

MongoDB - JEE using CDI and JAX-RS

The full map front end app can be found here Parks App - it may take a while to spin the application back up if nobody has visited in a while

We use LeafletJS for the nice map interactions and OpenStreetMap for the map tiles.


Git Repos to Try

  1. PostGIS
  2. MongoDB with a blog post
  3. Lucene Indexer and Search with a blog post
  4. All of these are easy to try with 'rhc app create myapp jbosseap {mongodb|postgresql}' on OpenShift


NameWhen to use
PostGISNeed, or forsee needing, full spatial power. Want power of RDBMS and updates with transactions. Want more mature technolgy
MongoDBApp just uses simple spatial queries. Frequent data updates. Need horizontal scalability
LuceneApp just uses simple spatial queries. Infrequent updates. Less moving parts. Advanced Full Text search

Let's wrap it up

  1. More than Google maps is available for you in Java Land
  2. Easy to build really interesting apps
  3. OpenShift makes it easy to explore and build with these stacks

Come hang out with us:
#openshift on freenode irc