mysql spatial extensions and ruby

41
Using MySQL’s Spatial Extensions (with Ruby) Seth Fitzsimmons <[email protected]>

Upload: mojodna

Post on 08-Jul-2015

1.735 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: MySQL Spatial Extensions And Ruby

Using MySQL’sSpatial Extensions

(with Ruby)

Seth Fitzsimmons<[email protected]>

Page 2: MySQL Spatial Extensions And Ruby

MySQL Spatial Extensions

Page 3: MySQL Spatial Extensions And Ruby

GeoRuby

Page 4: MySQL Spatial Extensions And Ruby

MySQL Spatial Extensions

+GeoRuby

Page 5: MySQL Spatial Extensions And Ruby

What’s the problem?

Page 6: MySQL Spatial Extensions And Ruby

Storing Spatial Data

Page 7: MySQL Spatial Extensions And Ruby

Where does this data come from?

Page 8: MySQL Spatial Extensions And Ruby

What is this data?

Page 9: MySQL Spatial Extensions And Ruby

Raster Data

Page 10: MySQL Spatial Extensions And Ruby

Vector Data

Page 11: MySQL Spatial Extensions And Ruby

Earthly Complications

Page 12: MySQL Spatial Extensions And Ruby

[katamari]

http://flickr.com/photos/ethanhein/1555066117/

Page 13: MySQL Spatial Extensions And Ruby

Latitude & Longitude

Page 14: MySQL Spatial Extensions And Ruby

Projections

Page 15: MySQL Spatial Extensions And Ruby
Page 16: MySQL Spatial Extensions And Ruby
Page 17: MySQL Spatial Extensions And Ruby

I maps

Page 18: MySQL Spatial Extensions And Ruby
Page 19: MySQL Spatial Extensions And Ruby

SRIDs

Page 20: MySQL Spatial Extensions And Ruby

File Types

Page 21: MySQL Spatial Extensions And Ruby

Simpler Formats

Page 22: MySQL Spatial Extensions And Ruby

Google Earth

Page 23: MySQL Spatial Extensions And Ruby

qgis

Page 24: MySQL Spatial Extensions And Ruby

GRASS

Page 25: MySQL Spatial Extensions And Ruby

OGR

Page 26: MySQL Spatial Extensions And Ruby

MapServer / GeoServer

Page 27: MySQL Spatial Extensions And Ruby

WMS / WFS

Page 28: MySQL Spatial Extensions And Ruby

Geocoding

Page 29: MySQL Spatial Extensions And Ruby

Reverse Geocoding

Page 30: MySQL Spatial Extensions And Ruby

How is this data represented in

MySQL?

Page 31: MySQL Spatial Extensions And Ruby

OGC Simple Features for SQL

Page 32: MySQL Spatial Extensions And Ruby

MySQL-specifics

Page 33: MySQL Spatial Extensions And Ruby

How is this data queried?

Page 34: MySQL Spatial Extensions And Ruby

๏Dimension(g)

๏Envelope(g)

๏GeometryType(g)

๏SRID(g)

๏X(g)

๏Y(g)

๏EndPoint(ls)

๏GLength(ls)

๏NumPoints(ls)

๏StartPoint(ls)

๏ IsClosed(mls)

๏Area(poly)

๏ExteriorRing(poly)

๏ InteriorRingN(poly,N)

๏NumInteriorRings(poly)

๏GeometryN(gc,N)

๏NumGeometries(gc)

๏MBRContains(g1,g2)

๏MBRDisjoint(g1,g2)

๏MBREqual(g1,g2)

๏MBRIntersects(g1,g2)

๏MBROverlaps(g1,g2)

๏MBRTouches(g1,g2)

๏MBRWithin(g1,g2)

Page 35: MySQL Spatial Extensions And Ruby

MoreMySQL-specifics

Page 36: MySQL Spatial Extensions And Ruby

WKT,WKB,WTF?

Page 37: MySQL Spatial Extensions And Ruby

ActiveRecord with GeoRuby

Page 38: MySQL Spatial Extensions And Ruby

loc = Location.find(:first)loc.geom.x # => point's x coordinateloc.geom.y # => point's y coordinateloc.geom.srid # => point's SRIDloc.geom.as_kml # => KML representation

loc.geom.ellipsoidal_distance(loc2) # => ellipsoidal distance from loc2loc.geom.euclidian_distance(loc2) # => euclidean distance from loc2loc.geom.spherical_distance(loc2) # => spherical distance from loc2

loc.geom.x = -43.2253 # set location's longitudeloc.save!

state = State.find(:first)state.geom.envelope # => bounding boxstate.geom.rings.first.points # => points making up the outer LinearRingstate.geom.as_georss # => GeoRSS representation

Page 39: MySQL Spatial Extensions And Ruby

create_table "locations", :options => 'ENGINE=MyISAM' do |t| t.string "name" t.column "geom", :geometry, :null => false t.datetime "created_at" t.datetime "updated_at"end

add_index "locations", ["geom"], :name => "geom", :spatial => true

Page 40: MySQL Spatial Extensions And Ruby

Exposure