Ruby gem to store, query, and visualize map data without all the complexity
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


MapPLZ is a framework to make mapping quick and easy in your favorite language.

Getting started

MapPLZ consumes many many types of geodata. It can process data for a script or dump it into a database.

Here's how you can add some data:

mapstore =

# a point
mapstore << [lat, lng]
mapstore << { lat: 40, lng: -70 }
mapstore.add( [lng, lat], lonlat: true )

# multiple points
mapstore << [point1, point2]

# a line or polygon
mapstore << [[point1, point2, point3]]
mapstore << [[point1, point2, point3, point1]]
mapstore << { path: [point1, point2], label: 'hello world' }

# GeoJSON string or hash
mapstore << { type: "Feature", geometry: { type: "Point", coordinates: [lng, lat] } }

Include properties along with the geo data:

# an array of attributes
pt1 = mapstore << [lat, lng, color, cost]
pt2 = mapstore << [lat, lng, color2, cost2]
# = [color, cost]

# a hash or JSON string of attributes
mapstore << [lat, lng, { color: 'red', cost: 10 }]

# GeoJSON properties
mapstore << { type: "Feature", geometry: { type: "Point", properties: { name: "Bella" }, coordinates: [lng, lat] } }

MapPLZ can read GeoJSON files and some CSVs.

@mapstore <'test.csv')
@mapstore <'test.geojson')

If you have gdal installed, you can import files in formats parseable by the ogr2ogr command line tool.

@mapstore <'test.shp')

Export HTML and GeoJSON

You can output the entire dataset anytime as GeoJSON:

@mapper =
@mapper << mapplz_content

Each mapped item can be exported as GeoJSON or WKT

pt = @mapper << { lat: 40, lng: -70 }

You can add interactive, HTML+JavaScript maps which use Leaflet.js

require 'mapplz'

@mapper =
@mapper << geo_stuff
@mapper.embed_html # a map embed snippet
@mapper.render_html # a full HTML page

This extends the Leaflet-Rails plugin. Set Leaflet defaults directly:

Leaflet.tile_layer = 'http://{s}{z}/{x}/{y}.png'

You can pass options to render_html, including new default styles for lines and shapes:

@mapper.render_html(max_zoom: 18, fillColor: '#00f')

You can also add styles as you enter data into MapPLZ.

@mapper << { path: [point1, point2], color: 'red', opacity: 0.8 }

All of these would appear as clickable map features with popups:

@mapper << [40, -70, 'hello popup']
@mapper << { lat: 40, lng: -80, label: 'hello popup' }
@mapper << { path: [point1, point2], color: 'red', label: 'the red line' }


All of these are valid ways to query geodata:

# return all

# with a value
mapplz.where('layer = ?', name_of_layer)

# get a count
mapplz.count('layer = ?', name_of_layer)

# near a point
mapplz.near([lat, lng])
mapplz.near([lat, lng], max: 10)

# in an area
mapplz.inside([point1, point2, point3, point1])

Queries are returned as an array of GeoItems, which each can be exported as GeoJSON or WKT

my_features = @mapper.where('points > 10')
collection = { type: 'FeatureCollection', features: { |feature| JSON.parse(feature.to_geojson) } }


If you want to store geodata in a database, you can use Postgres/PostGIS or MongoDB. SQLite/Spatialite support is written but untested.

MapPLZ simplifies geodata management and queries.

# setting the database

# updating records
pt = mapstore << [lat, lng]
pt[:name] = "Sears Tower"
pt[:lat] += 1!

Database Setup

# MongoDB
require 'mongo'
mongo_client =
database = mongo_client['mapplz']
collection = database['geoitems']
collection.create_index(geo: Mongo::GEO2DSPHERE)
mapstore =

# PostGIS
# before you start, install PostGIS and create a table
# here's my schema:
# CREATE TABLE mapplz (id SERIAL PRIMARY KEY, properties JSON, geom public.geometry)

require 'pg'
conn = PG.connect(dbname: 'your_db')
mapstore =


You can make a map super quickly by using the MapPLZ language. A MapPLZ map can be described using as simply as this:

mymap = """map
    "The Statue of Liberty"
    [40, -70]
@mapper << mymap


Free BSD License