This add-on is operated by SpacialDB

GeoLocation database in seconds via PostGIS


Last Updated: 07 May 2015

This article is a work in progress, or documents a feature that is not yet released to all users. This article is unlisted. Only those with the link can access it.

The SpacialDB add-on is currently in beta.

Table of Contents

What is SpacialDB?

SpacialDB is a cloud based Geospatial database.

SpacialDB Cloud Database

SpacialDB is a Geospatial database service that allows you to create, operate and scale dedicated Geospatial databases in the cloud. Your SpacialDB databases can be used transparently in place of the Heroku-provided PostgreSQL database or a other cloud based databases such as Amazon RDS or Rackspace.

Deploying to Heroku

To use SpacialDB on Heroku, install the SpacialDB add-on:

$ heroku addons:create spacialdb:test

Note: As database provisioning is carried out asynchronously, please wait until the creation and initialization of the database complete. You can monitor the progress of this process by calling heroku config and looking for the value of the SPACIALDB_STATUS variable. Alternatively you can check the provisioning status by clicking the SpacialDB add-on in the Add-ons menu of your application’s Resources.

Connecting to SpacialDB

The SpacialDB add-on will store the database’s credentials in a config vars: SPACIALDB_URL. The URL contains a string of the following syntax:


The parts out of which the URLs are made of are also set for your convenience in the following environment variables:

SPACIALDB_ADAPTER     # coming soon
SPACIALDB_USERNAME    # coming soon
SPACIALDB_PASSWORD    # coming soon
SPACIALDB_HOST        # coming soon
SPACIALDB_PORT        # coming soon
SPACIALDB_NAME        # coming soon

The following example demonstrates use of the connection URL with ActiveRecord’s PostGIS Adapter and GeoRuby:

require 'rubygems'
require 'pg'
require 'active_record'

def establish_active_record_connection(url)
  regex ="(.*):\/\/(.*):(.*)@(.*):([\d]{3,5})\/(.*)")
  matchdata = regex.match(url)

  if matchdata.length == 7
      :adapter => "postgresql",
      :username => matchdata[2],
      :password => matchdata[3],
      :host => matchdata[4],
      :port => Integer(matchdata[5]),
      :database => matchdata[6]

  puts "Connection to SpacialDB established."
rescue => e
  abort "Failed to connect to database: #{e.message}"

Local setup

To try out the basic connection locally you can try saving the above script and setting the SPACIALDB_URL environment variable when running it. For example, if you save the script to a file called test_spacialdb_connection.rb then try this to test your connection:

$ SPACIALDB_URL='postgres://{username}:{password}{port}/{database}' ruby test_spacialdb_connection.rb

Further reading: