SlideShare a Scribd company logo
1 of 50
GIS Applications in Ruby/Rails 101
Introduction
hence I love maps and mapping.
I work at Research Solutions Africa
(RSA) as a location analyst this is just
telling people more about a place that
they don’t know especially businesses.
On most platforms @kamalogudah
About Me
What I am Supposed to Do
What my Friends think I do
What My Boss Think I will Do
What I am doing
Agenda
 What is GIS/Spatial
Programming?
 Important GIS/Spatial Terms
 Tools in the GIS/spatial stack
 How you get started
 What’s next?
GIS in Ruby is Hard… Though possible
But
GIS?
Definition of Terms
• GIS: Geographical Information System
• Layers: just like the layers in Photoshop,
but they're georeferenced.
• Projection: algorithm for flatting the
globe
• Geometry: the core data type in a
Geospatial application
Spatial Programming?
 Exposing physical space as a first-order
programming concept.
 Has Rich, built-in support for shapes,
space, and the relationship of physical
objects to one another.
 Describes objects spatially eg Locations
on the earth, shapes of buildings etc.
Coordinate System
 Coordinate system defines the location
of a point on a planar or spherical surface.
 Geographic coordinate system is a 3D
reference system that locates points on the
Earth’s surface.
 A point has two coordinate values:
latitude and longitude which measure
angles.

Types of Coordinate System
1. Geocentric coordinate systems are 3D coordinate
systems with the origin located at the earth's center.
Geocentric coordinates measure X, Y, and Z distances
from the center of the earth.
Types of Coordinate System
2. Geographic coordinate systems are the familiar
latitude-longitude systems identifying points on the
earth's surface in terms of degrees. most common, eg
"WGS 84". used by GPS and most mapping apps.
Types of Coordinate System
 3.Projected coordinate systems involve taking a
portion of the earth's surface and "flattening" it.
Planar and generally Cartesian for easy display and
computation; introduces distortion.
Spatial Database
Spatial Data Types
Store shapes like points,lines, and
polygons in geometry columns.
Represents a binary representation of
a shapes in a db row (with location).
Geometry Hierarchy
Geometry
Spatial Functions
Spatial functions (in SQL) help query
spatial properties and relationships.
Normal Db has functions for
manipulating data in a query.
These include mathematical functions,
date, functions to work on Strings.
A spatial Db adds more to these “base
functions” these include those to operate
on geometries.
Spatial Functions
1. Conversion. Text representation of a point
(ST_AsText), (ST_GeomFromText).
2. Retrieval. Length of a road? (ST_Length),
perimeter of a Kenya (ST_Perimeter).
3. Comparison. Is Nairobi next to Turkana?
(ST_Touches), ST_Contains.
4. Generation. Calculate a 20km exclusion limit
around a point (ST_Buffer), Consolidate
Nairobi, Machakos, Kiambu and Kajiado
counties (ST_Union)
Spatial Index
Indexes make using a spatial db for
large data sets possible.
 Otherwise, any search for a feature
would require a “sequential scan” of
every record in the database.
 Indexing speeds up searching by
organizing the data into a search tree.
This can be quickly traversed to find a
particular record.
Indexing Example
R-Tree Hierarchy
Bounding boxes
PostGIS Anatomy.
 There are more than 700+ PostGIS functions.
 One table (spatial_ref_sys) and two views
(geometry_columns and
geography_columns).
 Spatial_ref_sys. Defines the spatial reference
systems known to the database (SRID).
 They are known by an ID number, such as
4326 (for WGS 84 Lat/Lon)
Geometry Columns
The geometry_columns view defines
the dimension, geometry, and spatial
reference system for each spatial table
in the PostGIS database that contains a
geometry type.
Geometry_columns
Geography Column
• The geography_columns view defines
the dimension, geometry, each spatial
table in the PostGIS database that
contains a geography type.
GIS STACK
1. Database – PostgreSQL with
PostGIS extension (Preferably
and works).
Ruby
 rgeo --- a geospatial data library for Ruby.
 rgeo-shapefile --- RGeo component for reading ESRI
shapefiles
 rgeo-geojson --- RGeo component for reading and writing
GeoJSON
 Rgeo-activerecord –- is an optional RGeo module providing
spatial extensions for ActiveRecord.
 squeel --- ActiveRecord enhancement for query writing
 activerecord-postgis-adapter --- ActiveRecord adapter for
PostGIS
 ruby geocoder --- Integration with geocoding services
CLIENT SIDE
 heatmap.js --- A heatmap implementation for
Javascript
 thermo.js --- Another heatmap implementation for
Javascript
 heatcanvas.js --- Yet another heatmap
implementation for Javascript
 OpenLayers --- An open-source map/visualization
tool; an alternative to Google Maps.
 Mapbox, Leafletjs etc.
OTHERS
libgeos --- C library for geometric
analysis
libproj --- C library for coordinate
transforms
libgdal --- C library for rasters
 rails new rubyconf --database=postgresql

Create new app

 In Gemfile add activerecord-postgis-adapter
Configure Database
encoding: unicode
pool: <%=
ENV.fetch("RAILS_MAX_THREADS
") { 5 } %>
username: <your_username>
password: <your_password>
encoding: unicode
pool: <%=
ENV.fetch("RAILS_MAX_THREADS
") { 5 } %>
username: <your_username>
password: <your_password>
Configure Database
class CreateCountries < ActiveRecord::Migration[5.1]
def change
create_table :countries do |t|
t.string :name, :unique => true
t.string :iso_code, :unique => true
t.multi_polygon :geom, :srid => 4326
#t.timestamps null: false
end
change_table :countries do |t|
t.index :geom, using: :gist
end
end
end
Create Model
class CreateCountries < ActiveRecord::Migration[5.1]
def change
create_table :countries do |t|
t.string :name, :unique => true
t.string :iso_code, :unique => true
t.multi_polygon :geom, :srid => 4326
#t.timestamps null: false
end
change_table :countries do |t|
t.index :geom, using: :gist
end
end
end
Create Model
Importing Shapefile Data
def up
from_shp_sql = `shp2pgsql -c -g geom -W LATIN1 -s 4326
#{Rails.root.join('db', 'shpfiles', 'KEN_adm0.shp')} countries_ref `
Country.transaction do
execute from_shp_sql
execute <<-SQL
insert into countries(name, iso_code, geom)
select name_engli, iso, geom from countries_ref
SQL
drop_table :countries_ref
end
end
def down
Country.delete_all
End
end….
Importing Shapefile Data
def up
from_shp_sql = `shp2pgsql -c -g geom -W LATIN1 -s 4326
#{Rails.root.join('db', 'shpfiles', 'KEN_adm0.shp')} countries_ref `
Country.transaction do
execute from_shp_sql
execute <<-SQL
insert into countries(name, iso_code, geom)
select name_engli, iso, geom from countries_ref
SQL
drop_table :countries_ref
end
end
def down
Country.delete_all
End
end….
include Featurable
featurable :geom, [:name]
end
Alter Model
Featurable Module
Concerns/Featurable.rb
module Featurable
extend ActiveSupport::Concern
module ClassMethods
def featurable geom_attr_name, property_names = []
define_method :to_feature do
factory = RGeo::GeoJSON::EntityFactory.instance
property_names = Array(property_names)
properties = property_names.inject({}) do |hash, property_name|
hash[property_name.to_sym] = read_attribute(property_name)
hash
end
factory.feature read_attribute(geom_attr_name), self.id, properties
end
end
RGeo::GeoJSON::EntityFactory.instanc
e
features = models.map(&:to_feature)
factory.feature_collection features
end
end
end
Featurable continued
The End…

More Related Content

What's hot

Database gis fundamentals
Database gis fundamentalsDatabase gis fundamentals
Database gis fundamentalsSumant Diwakar
 
Defination of gis and components of arc gis
Defination of gis and components of arc gisDefination of gis and components of arc gis
Defination of gis and components of arc gisSreedhar Siddhu
 
Finding Meaning in Points, Areas and Surfaces: Spatial Analysis in R
Finding Meaning in Points, Areas and Surfaces: Spatial Analysis in RFinding Meaning in Points, Areas and Surfaces: Spatial Analysis in R
Finding Meaning in Points, Areas and Surfaces: Spatial Analysis in RRevolution Analytics
 
Hive query optimization infinity
Hive query optimization infinityHive query optimization infinity
Hive query optimization infinityShashwat Shriparv
 
Geographic Information System unit 1
Geographic Information System   unit 1Geographic Information System   unit 1
Geographic Information System unit 1sridevi5983
 
Lecture 1b introduction to arc gis
Lecture 1b  introduction to arc gisLecture 1b  introduction to arc gis
Lecture 1b introduction to arc gisAbir Mohammad
 
Data Models - GIS I
Data Models - GIS IData Models - GIS I
Data Models - GIS IJohn Reiser
 
ePOM - Intro to Ocean Data Science - Raster and Vector Data Formats
ePOM - Intro to Ocean Data Science - Raster and Vector Data FormatsePOM - Intro to Ocean Data Science - Raster and Vector Data Formats
ePOM - Intro to Ocean Data Science - Raster and Vector Data FormatsGiuseppe Masetti
 
Terminology and Basic Questions About GIS
Terminology and Basic Questions About GISTerminology and Basic Questions About GIS
Terminology and Basic Questions About GISMrinmoy Majumder
 
Gis Tutorial Purnawan
Gis Tutorial PurnawanGis Tutorial Purnawan
Gis Tutorial PurnawanKodok Ngorex
 
An introduction to Hadoop for large scale data analysis
An introduction to Hadoop for large scale data analysisAn introduction to Hadoop for large scale data analysis
An introduction to Hadoop for large scale data analysisAbhijit Sharma
 
Difference between gis and cad
Difference between gis and cadDifference between gis and cad
Difference between gis and cadSumant Diwakar
 
TYBSC IT PGIS Unit I Chapter I- Introduction to Geographic Information Systems
TYBSC IT PGIS Unit I  Chapter I- Introduction to Geographic Information SystemsTYBSC IT PGIS Unit I  Chapter I- Introduction to Geographic Information Systems
TYBSC IT PGIS Unit I Chapter I- Introduction to Geographic Information SystemsArti Parab Academics
 
Geo CO - RTD Denver
Geo CO - RTD DenverGeo CO - RTD Denver
Geo CO - RTD DenverMike Giddens
 

What's hot (20)

Database gis fundamentals
Database gis fundamentalsDatabase gis fundamentals
Database gis fundamentals
 
Defination of gis and components of arc gis
Defination of gis and components of arc gisDefination of gis and components of arc gis
Defination of gis and components of arc gis
 
Types of GIS Data
Types of GIS DataTypes of GIS Data
Types of GIS Data
 
Finding Meaning in Points, Areas and Surfaces: Spatial Analysis in R
Finding Meaning in Points, Areas and Surfaces: Spatial Analysis in RFinding Meaning in Points, Areas and Surfaces: Spatial Analysis in R
Finding Meaning in Points, Areas and Surfaces: Spatial Analysis in R
 
Hive query optimization infinity
Hive query optimization infinityHive query optimization infinity
Hive query optimization infinity
 
Geographic Information System unit 1
Geographic Information System   unit 1Geographic Information System   unit 1
Geographic Information System unit 1
 
Lecture 1b introduction to arc gis
Lecture 1b  introduction to arc gisLecture 1b  introduction to arc gis
Lecture 1b introduction to arc gis
 
Data Models - GIS I
Data Models - GIS IData Models - GIS I
Data Models - GIS I
 
ePOM - Intro to Ocean Data Science - Raster and Vector Data Formats
ePOM - Intro to Ocean Data Science - Raster and Vector Data FormatsePOM - Intro to Ocean Data Science - Raster and Vector Data Formats
ePOM - Intro to Ocean Data Science - Raster and Vector Data Formats
 
Introduction to GIS
Introduction to GISIntroduction to GIS
Introduction to GIS
 
Terminology and Basic Questions About GIS
Terminology and Basic Questions About GISTerminology and Basic Questions About GIS
Terminology and Basic Questions About GIS
 
Info Grafix
Info GrafixInfo Grafix
Info Grafix
 
Gis Tutorial Purnawan
Gis Tutorial PurnawanGis Tutorial Purnawan
Gis Tutorial Purnawan
 
Día 3
Día 3Día 3
Día 3
 
An introduction to Hadoop for large scale data analysis
An introduction to Hadoop for large scale data analysisAn introduction to Hadoop for large scale data analysis
An introduction to Hadoop for large scale data analysis
 
Difference between gis and cad
Difference between gis and cadDifference between gis and cad
Difference between gis and cad
 
GIS Data Types
GIS Data TypesGIS Data Types
GIS Data Types
 
TYBSC IT PGIS Unit I Chapter I- Introduction to Geographic Information Systems
TYBSC IT PGIS Unit I  Chapter I- Introduction to Geographic Information SystemsTYBSC IT PGIS Unit I  Chapter I- Introduction to Geographic Information Systems
TYBSC IT PGIS Unit I Chapter I- Introduction to Geographic Information Systems
 
Geo CO - RTD Denver
Geo CO - RTD DenverGeo CO - RTD Denver
Geo CO - RTD Denver
 
Spatial data for GIS
Spatial data for GISSpatial data for GIS
Spatial data for GIS
 

Similar to Gis and Ruby 101 at Ruby Conf Kenya 2017 by Kamal Ogudah

ADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtap
ADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtapADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtap
ADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtapVikas Jagtap
 
Databases Basics and Spacial Matrix - Discussig Geographic Potentials of Data...
Databases Basics and Spacial Matrix - Discussig Geographic Potentials of Data...Databases Basics and Spacial Matrix - Discussig Geographic Potentials of Data...
Databases Basics and Spacial Matrix - Discussig Geographic Potentials of Data...Jerin John
 
Components of gis
Components of gisComponents of gis
Components of gisPramoda Raj
 
Giving MongoDB a Way to Play with the GIS Community
Giving MongoDB a Way to Play with the GIS CommunityGiving MongoDB a Way to Play with the GIS Community
Giving MongoDB a Way to Play with the GIS CommunityMongoDB
 
2017 RM-URISA Track: Spatial SQL - The Best Kept Secret in the Geospatial World
2017 RM-URISA Track:  Spatial SQL - The Best Kept Secret in the Geospatial World2017 RM-URISA Track:  Spatial SQL - The Best Kept Secret in the Geospatial World
2017 RM-URISA Track: Spatial SQL - The Best Kept Secret in the Geospatial WorldGIS in the Rockies
 
Adelaide Ruby Meetup PostGIS Notes
Adelaide Ruby Meetup PostGIS NotesAdelaide Ruby Meetup PostGIS Notes
Adelaide Ruby Meetup PostGIS Noteschris-teague
 
Spot db consistency checking and optimization in spatial database
Spot db  consistency checking and optimization in spatial databaseSpot db  consistency checking and optimization in spatial database
Spot db consistency checking and optimization in spatial databasePratik Udapure
 
Gis fandamentals -1
Gis fandamentals -1Gis fandamentals -1
Gis fandamentals -1RJRANJEET1
 
Introduction to arc gis
Introduction to arc gisIntroduction to arc gis
Introduction to arc gisMohamed Hamed
 
Building a Spatial Database in PostgreSQL
Building a Spatial Database in PostgreSQLBuilding a Spatial Database in PostgreSQL
Building a Spatial Database in PostgreSQLKudos S.A.S
 
Postgres Vision 2018: PostGIS and Spatial Extensions
Postgres Vision 2018: PostGIS and Spatial ExtensionsPostgres Vision 2018: PostGIS and Spatial Extensions
Postgres Vision 2018: PostGIS and Spatial ExtensionsEDB
 
Unit 4 Data Input and Analysis.pptx
Unit 4 Data Input and Analysis.pptxUnit 4 Data Input and Analysis.pptx
Unit 4 Data Input and Analysis.pptxe20ag004
 
Leicester 2010 notes
Leicester 2010 notesLeicester 2010 notes
Leicester 2010 notesJoanne Cook
 

Similar to Gis and Ruby 101 at Ruby Conf Kenya 2017 by Kamal Ogudah (20)

Gis Xke
Gis XkeGis Xke
Gis Xke
 
ADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtap
ADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtapADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtap
ADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtap
 
Databases Basics and Spacial Matrix - Discussig Geographic Potentials of Data...
Databases Basics and Spacial Matrix - Discussig Geographic Potentials of Data...Databases Basics and Spacial Matrix - Discussig Geographic Potentials of Data...
Databases Basics and Spacial Matrix - Discussig Geographic Potentials of Data...
 
Spatial Databases
Spatial DatabasesSpatial Databases
Spatial Databases
 
Unit3 slides
Unit3 slidesUnit3 slides
Unit3 slides
 
Components of gis
Components of gisComponents of gis
Components of gis
 
GIS_Intro_March_2014
GIS_Intro_March_2014GIS_Intro_March_2014
GIS_Intro_March_2014
 
Giving MongoDB a Way to Play with the GIS Community
Giving MongoDB a Way to Play with the GIS CommunityGiving MongoDB a Way to Play with the GIS Community
Giving MongoDB a Way to Play with the GIS Community
 
2017 RM-URISA Track: Spatial SQL - The Best Kept Secret in the Geospatial World
2017 RM-URISA Track:  Spatial SQL - The Best Kept Secret in the Geospatial World2017 RM-URISA Track:  Spatial SQL - The Best Kept Secret in the Geospatial World
2017 RM-URISA Track: Spatial SQL - The Best Kept Secret in the Geospatial World
 
Au09 Presentation Ut118 1
Au09 Presentation Ut118 1Au09 Presentation Ut118 1
Au09 Presentation Ut118 1
 
Geographic information system
Geographic information systemGeographic information system
Geographic information system
 
Adelaide Ruby Meetup PostGIS Notes
Adelaide Ruby Meetup PostGIS NotesAdelaide Ruby Meetup PostGIS Notes
Adelaide Ruby Meetup PostGIS Notes
 
Spot db consistency checking and optimization in spatial database
Spot db  consistency checking and optimization in spatial databaseSpot db  consistency checking and optimization in spatial database
Spot db consistency checking and optimization in spatial database
 
Gis fandamentals -1
Gis fandamentals -1Gis fandamentals -1
Gis fandamentals -1
 
Introduction to arc gis
Introduction to arc gisIntroduction to arc gis
Introduction to arc gis
 
Building a Spatial Database in PostgreSQL
Building a Spatial Database in PostgreSQLBuilding a Spatial Database in PostgreSQL
Building a Spatial Database in PostgreSQL
 
Postgres Vision 2018: PostGIS and Spatial Extensions
Postgres Vision 2018: PostGIS and Spatial ExtensionsPostgres Vision 2018: PostGIS and Spatial Extensions
Postgres Vision 2018: PostGIS and Spatial Extensions
 
Unit 4 Data Input and Analysis.pptx
Unit 4 Data Input and Analysis.pptxUnit 4 Data Input and Analysis.pptx
Unit 4 Data Input and Analysis.pptx
 
Data_Sources
Data_SourcesData_Sources
Data_Sources
 
Leicester 2010 notes
Leicester 2010 notesLeicester 2010 notes
Leicester 2010 notes
 

More from Michael Kimathi

Soni pi at rubycongkenya2017 by rishi jain
Soni pi at rubycongkenya2017 by rishi jainSoni pi at rubycongkenya2017 by rishi jain
Soni pi at rubycongkenya2017 by rishi jainMichael Kimathi
 
Coopetition slides at ruby conference kenya 2017 by james corey
Coopetition slides at ruby conference kenya 2017 by james coreyCoopetition slides at ruby conference kenya 2017 by james corey
Coopetition slides at ruby conference kenya 2017 by james coreyMichael Kimathi
 
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar BatsovRuby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar BatsovMichael Kimathi
 
Opal,The Journey from Javascript to Ruby at Ruby Conf Kenya 2017 by Bozhidar ...
Opal,The Journey from Javascript to Ruby at Ruby Conf Kenya 2017 by Bozhidar ...Opal,The Journey from Javascript to Ruby at Ruby Conf Kenya 2017 by Bozhidar ...
Opal,The Journey from Javascript to Ruby at Ruby Conf Kenya 2017 by Bozhidar ...Michael Kimathi
 
How GitHub Builds Software at Ruby Conference Kenya 2017 by Mike McQuaid
How GitHub Builds Software at Ruby Conference Kenya 2017 by Mike McQuaidHow GitHub Builds Software at Ruby Conference Kenya 2017 by Mike McQuaid
How GitHub Builds Software at Ruby Conference Kenya 2017 by Mike McQuaidMichael Kimathi
 
Helping Yourself With_Open_Source_Software at Ruby Conference Kenya 2017 by M...
Helping Yourself With_Open_Source_Software at Ruby Conference Kenya 2017 by M...Helping Yourself With_Open_Source_Software at Ruby Conference Kenya 2017 by M...
Helping Yourself With_Open_Source_Software at Ruby Conference Kenya 2017 by M...Michael Kimathi
 
Metaprogamming the Ruby Way by Joannah Nanjekye at Ruby ConfKE2017
Metaprogamming the Ruby Way by Joannah Nanjekye at  Ruby ConfKE2017Metaprogamming the Ruby Way by Joannah Nanjekye at  Ruby ConfKE2017
Metaprogamming the Ruby Way by Joannah Nanjekye at Ruby ConfKE2017Michael Kimathi
 
Scaling Rails with Ruby-prof -- Ruby Conf Kenya 2017 by Ben Hughes
Scaling Rails with Ruby-prof -- Ruby Conf Kenya 2017 by Ben Hughes Scaling Rails with Ruby-prof -- Ruby Conf Kenya 2017 by Ben Hughes
Scaling Rails with Ruby-prof -- Ruby Conf Kenya 2017 by Ben Hughes Michael Kimathi
 
Techpreneurship Triathon at Ruby Conference Kenya 2017 by Bernard Banta
Techpreneurship Triathon at Ruby Conference Kenya 2017 by Bernard BantaTechpreneurship Triathon at Ruby Conference Kenya 2017 by Bernard Banta
Techpreneurship Triathon at Ruby Conference Kenya 2017 by Bernard BantaMichael Kimathi
 
The Curious Case of Wikipedia Parsing at Ruby Conference Kenya 2017 by victor...
The Curious Case of Wikipedia Parsing at Ruby Conference Kenya 2017 by victor...The Curious Case of Wikipedia Parsing at Ruby Conference Kenya 2017 by victor...
The Curious Case of Wikipedia Parsing at Ruby Conference Kenya 2017 by victor...Michael Kimathi
 
When The Whole World is Your Database at Ruby Conference Kenya by Victor Shep...
When The Whole World is Your Database at Ruby Conference Kenya by Victor Shep...When The Whole World is Your Database at Ruby Conference Kenya by Victor Shep...
When The Whole World is Your Database at Ruby Conference Kenya by Victor Shep...Michael Kimathi
 
Building Communities by Michael Kimathi Ruby Conference Kenya 2017
Building Communities by Michael Kimathi Ruby Conference Kenya 2017Building Communities by Michael Kimathi Ruby Conference Kenya 2017
Building Communities by Michael Kimathi Ruby Conference Kenya 2017Michael Kimathi
 
Leveling Up Through OSS by William Wanyama Ruby ConfKKE 2017
Leveling Up Through OSS by William Wanyama Ruby ConfKKE 2017Leveling Up Through OSS by William Wanyama Ruby ConfKKE 2017
Leveling Up Through OSS by William Wanyama Ruby ConfKKE 2017Michael Kimathi
 
Education shaping innovation ecosystem by prof. felix musau
Education shaping innovation ecosystem by prof. felix musauEducation shaping innovation ecosystem by prof. felix musau
Education shaping innovation ecosystem by prof. felix musauMichael Kimathi
 

More from Michael Kimathi (14)

Soni pi at rubycongkenya2017 by rishi jain
Soni pi at rubycongkenya2017 by rishi jainSoni pi at rubycongkenya2017 by rishi jain
Soni pi at rubycongkenya2017 by rishi jain
 
Coopetition slides at ruby conference kenya 2017 by james corey
Coopetition slides at ruby conference kenya 2017 by james coreyCoopetition slides at ruby conference kenya 2017 by james corey
Coopetition slides at ruby conference kenya 2017 by james corey
 
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar BatsovRuby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
Ruby 4.0 To Infinity and Beyond at Ruby Conference Kenya 2017 by Bozhidar Batsov
 
Opal,The Journey from Javascript to Ruby at Ruby Conf Kenya 2017 by Bozhidar ...
Opal,The Journey from Javascript to Ruby at Ruby Conf Kenya 2017 by Bozhidar ...Opal,The Journey from Javascript to Ruby at Ruby Conf Kenya 2017 by Bozhidar ...
Opal,The Journey from Javascript to Ruby at Ruby Conf Kenya 2017 by Bozhidar ...
 
How GitHub Builds Software at Ruby Conference Kenya 2017 by Mike McQuaid
How GitHub Builds Software at Ruby Conference Kenya 2017 by Mike McQuaidHow GitHub Builds Software at Ruby Conference Kenya 2017 by Mike McQuaid
How GitHub Builds Software at Ruby Conference Kenya 2017 by Mike McQuaid
 
Helping Yourself With_Open_Source_Software at Ruby Conference Kenya 2017 by M...
Helping Yourself With_Open_Source_Software at Ruby Conference Kenya 2017 by M...Helping Yourself With_Open_Source_Software at Ruby Conference Kenya 2017 by M...
Helping Yourself With_Open_Source_Software at Ruby Conference Kenya 2017 by M...
 
Metaprogamming the Ruby Way by Joannah Nanjekye at Ruby ConfKE2017
Metaprogamming the Ruby Way by Joannah Nanjekye at  Ruby ConfKE2017Metaprogamming the Ruby Way by Joannah Nanjekye at  Ruby ConfKE2017
Metaprogamming the Ruby Way by Joannah Nanjekye at Ruby ConfKE2017
 
Scaling Rails with Ruby-prof -- Ruby Conf Kenya 2017 by Ben Hughes
Scaling Rails with Ruby-prof -- Ruby Conf Kenya 2017 by Ben Hughes Scaling Rails with Ruby-prof -- Ruby Conf Kenya 2017 by Ben Hughes
Scaling Rails with Ruby-prof -- Ruby Conf Kenya 2017 by Ben Hughes
 
Techpreneurship Triathon at Ruby Conference Kenya 2017 by Bernard Banta
Techpreneurship Triathon at Ruby Conference Kenya 2017 by Bernard BantaTechpreneurship Triathon at Ruby Conference Kenya 2017 by Bernard Banta
Techpreneurship Triathon at Ruby Conference Kenya 2017 by Bernard Banta
 
The Curious Case of Wikipedia Parsing at Ruby Conference Kenya 2017 by victor...
The Curious Case of Wikipedia Parsing at Ruby Conference Kenya 2017 by victor...The Curious Case of Wikipedia Parsing at Ruby Conference Kenya 2017 by victor...
The Curious Case of Wikipedia Parsing at Ruby Conference Kenya 2017 by victor...
 
When The Whole World is Your Database at Ruby Conference Kenya by Victor Shep...
When The Whole World is Your Database at Ruby Conference Kenya by Victor Shep...When The Whole World is Your Database at Ruby Conference Kenya by Victor Shep...
When The Whole World is Your Database at Ruby Conference Kenya by Victor Shep...
 
Building Communities by Michael Kimathi Ruby Conference Kenya 2017
Building Communities by Michael Kimathi Ruby Conference Kenya 2017Building Communities by Michael Kimathi Ruby Conference Kenya 2017
Building Communities by Michael Kimathi Ruby Conference Kenya 2017
 
Leveling Up Through OSS by William Wanyama Ruby ConfKKE 2017
Leveling Up Through OSS by William Wanyama Ruby ConfKKE 2017Leveling Up Through OSS by William Wanyama Ruby ConfKKE 2017
Leveling Up Through OSS by William Wanyama Ruby ConfKKE 2017
 
Education shaping innovation ecosystem by prof. felix musau
Education shaping innovation ecosystem by prof. felix musauEducation shaping innovation ecosystem by prof. felix musau
Education shaping innovation ecosystem by prof. felix musau
 

Recently uploaded

꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Callshivangimorya083
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service LucknowAminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknowmakika9823
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxJohnnyPlasten
 
Predicting Employee Churn: A Data-Driven Approach Project Presentation
Predicting Employee Churn: A Data-Driven Approach Project PresentationPredicting Employee Churn: A Data-Driven Approach Project Presentation
Predicting Employee Churn: A Data-Driven Approach Project PresentationBoston Institute of Analytics
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSAishani27
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptxthyngster
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...shivangimorya083
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改atducpo
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxEmmanuel Dauda
 

Recently uploaded (20)

꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service LucknowAminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptx
 
Predicting Employee Churn: A Data-Driven Approach Project Presentation
Predicting Employee Churn: A Data-Driven Approach Project PresentationPredicting Employee Churn: A Data-Driven Approach Project Presentation
Predicting Employee Churn: A Data-Driven Approach Project Presentation
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICS
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptx
 

Gis and Ruby 101 at Ruby Conf Kenya 2017 by Kamal Ogudah

  • 1. GIS Applications in Ruby/Rails 101
  • 3. hence I love maps and mapping. I work at Research Solutions Africa (RSA) as a location analyst this is just telling people more about a place that they don’t know especially businesses. On most platforms @kamalogudah About Me
  • 4. What I am Supposed to Do
  • 5. What my Friends think I do
  • 6. What My Boss Think I will Do
  • 7. What I am doing
  • 8.
  • 9. Agenda  What is GIS/Spatial Programming?  Important GIS/Spatial Terms  Tools in the GIS/spatial stack  How you get started  What’s next?
  • 10. GIS in Ruby is Hard… Though possible But
  • 11. GIS?
  • 12. Definition of Terms • GIS: Geographical Information System • Layers: just like the layers in Photoshop, but they're georeferenced. • Projection: algorithm for flatting the globe • Geometry: the core data type in a Geospatial application
  • 13.
  • 15.  Exposing physical space as a first-order programming concept.  Has Rich, built-in support for shapes, space, and the relationship of physical objects to one another.  Describes objects spatially eg Locations on the earth, shapes of buildings etc.
  • 16. Coordinate System  Coordinate system defines the location of a point on a planar or spherical surface.  Geographic coordinate system is a 3D reference system that locates points on the Earth’s surface.  A point has two coordinate values: latitude and longitude which measure angles. 
  • 17. Types of Coordinate System 1. Geocentric coordinate systems are 3D coordinate systems with the origin located at the earth's center. Geocentric coordinates measure X, Y, and Z distances from the center of the earth.
  • 18. Types of Coordinate System 2. Geographic coordinate systems are the familiar latitude-longitude systems identifying points on the earth's surface in terms of degrees. most common, eg "WGS 84". used by GPS and most mapping apps.
  • 19. Types of Coordinate System  3.Projected coordinate systems involve taking a portion of the earth's surface and "flattening" it. Planar and generally Cartesian for easy display and computation; introduces distortion.
  • 21. Spatial Data Types Store shapes like points,lines, and polygons in geometry columns. Represents a binary representation of a shapes in a db row (with location).
  • 24. Spatial Functions Spatial functions (in SQL) help query spatial properties and relationships. Normal Db has functions for manipulating data in a query. These include mathematical functions, date, functions to work on Strings. A spatial Db adds more to these “base functions” these include those to operate on geometries.
  • 25. Spatial Functions 1. Conversion. Text representation of a point (ST_AsText), (ST_GeomFromText). 2. Retrieval. Length of a road? (ST_Length), perimeter of a Kenya (ST_Perimeter). 3. Comparison. Is Nairobi next to Turkana? (ST_Touches), ST_Contains. 4. Generation. Calculate a 20km exclusion limit around a point (ST_Buffer), Consolidate Nairobi, Machakos, Kiambu and Kajiado counties (ST_Union)
  • 26. Spatial Index Indexes make using a spatial db for large data sets possible.  Otherwise, any search for a feature would require a “sequential scan” of every record in the database.  Indexing speeds up searching by organizing the data into a search tree. This can be quickly traversed to find a particular record.
  • 30. PostGIS Anatomy.  There are more than 700+ PostGIS functions.  One table (spatial_ref_sys) and two views (geometry_columns and geography_columns).  Spatial_ref_sys. Defines the spatial reference systems known to the database (SRID).  They are known by an ID number, such as 4326 (for WGS 84 Lat/Lon)
  • 31. Geometry Columns The geometry_columns view defines the dimension, geometry, and spatial reference system for each spatial table in the PostGIS database that contains a geometry type.
  • 33. Geography Column • The geography_columns view defines the dimension, geometry, each spatial table in the PostGIS database that contains a geography type.
  • 35. 1. Database – PostgreSQL with PostGIS extension (Preferably and works).
  • 36. Ruby  rgeo --- a geospatial data library for Ruby.  rgeo-shapefile --- RGeo component for reading ESRI shapefiles  rgeo-geojson --- RGeo component for reading and writing GeoJSON  Rgeo-activerecord –- is an optional RGeo module providing spatial extensions for ActiveRecord.  squeel --- ActiveRecord enhancement for query writing  activerecord-postgis-adapter --- ActiveRecord adapter for PostGIS  ruby geocoder --- Integration with geocoding services
  • 37. CLIENT SIDE  heatmap.js --- A heatmap implementation for Javascript  thermo.js --- Another heatmap implementation for Javascript  heatcanvas.js --- Yet another heatmap implementation for Javascript  OpenLayers --- An open-source map/visualization tool; an alternative to Google Maps.  Mapbox, Leafletjs etc.
  • 38. OTHERS libgeos --- C library for geometric analysis libproj --- C library for coordinate transforms libgdal --- C library for rasters
  • 39.
  • 40.  rails new rubyconf --database=postgresql  Create new app   In Gemfile add activerecord-postgis-adapter
  • 41. Configure Database encoding: unicode pool: <%= ENV.fetch("RAILS_MAX_THREADS ") { 5 } %> username: <your_username> password: <your_password>
  • 42. encoding: unicode pool: <%= ENV.fetch("RAILS_MAX_THREADS ") { 5 } %> username: <your_username> password: <your_password> Configure Database
  • 43. class CreateCountries < ActiveRecord::Migration[5.1] def change create_table :countries do |t| t.string :name, :unique => true t.string :iso_code, :unique => true t.multi_polygon :geom, :srid => 4326 #t.timestamps null: false end change_table :countries do |t| t.index :geom, using: :gist end end end Create Model
  • 44. class CreateCountries < ActiveRecord::Migration[5.1] def change create_table :countries do |t| t.string :name, :unique => true t.string :iso_code, :unique => true t.multi_polygon :geom, :srid => 4326 #t.timestamps null: false end change_table :countries do |t| t.index :geom, using: :gist end end end Create Model
  • 45. Importing Shapefile Data def up from_shp_sql = `shp2pgsql -c -g geom -W LATIN1 -s 4326 #{Rails.root.join('db', 'shpfiles', 'KEN_adm0.shp')} countries_ref ` Country.transaction do execute from_shp_sql execute <<-SQL insert into countries(name, iso_code, geom) select name_engli, iso, geom from countries_ref SQL drop_table :countries_ref end end def down Country.delete_all End end….
  • 46. Importing Shapefile Data def up from_shp_sql = `shp2pgsql -c -g geom -W LATIN1 -s 4326 #{Rails.root.join('db', 'shpfiles', 'KEN_adm0.shp')} countries_ref ` Country.transaction do execute from_shp_sql execute <<-SQL insert into countries(name, iso_code, geom) select name_engli, iso, geom from countries_ref SQL drop_table :countries_ref end end def down Country.delete_all End end….
  • 47. include Featurable featurable :geom, [:name] end Alter Model
  • 48. Featurable Module Concerns/Featurable.rb module Featurable extend ActiveSupport::Concern module ClassMethods def featurable geom_attr_name, property_names = [] define_method :to_feature do factory = RGeo::GeoJSON::EntityFactory.instance property_names = Array(property_names) properties = property_names.inject({}) do |hash, property_name| hash[property_name.to_sym] = read_attribute(property_name) hash end factory.feature read_attribute(geom_attr_name), self.id, properties end end