Skip to content

Instantly share code, notes, and snippets.

@pirelenito
Created April 7, 2011 16:21
Show Gist options
  • Select an option

  • Save pirelenito/908126 to your computer and use it in GitHub Desktop.

Select an option

Save pirelenito/908126 to your computer and use it in GitHub Desktop.
Getting started with RGeo
require 'rgeo'
# factory = RGeo::Geos.factory()
# factory = RGeo::Geographic.spherical_factory()
factory = RGeo::Geographic.simple_mercator_factory()
p1 = factory.point 0, 0
p2 = factory.point 0, 2
p3 = factory.point 2, 2
p4 = factory.point 2, 0
p5 = factory.point 4, 4
p6 = factory.point 4, 6
p7 = factory.point 6, 6
p8 = factory.point 6, 4
linear_ring = factory.linear_ring [p1,p2,p3,p4]
polygon = factory.polygon linear_ring
linear_ring2 = factory.linear_ring [p5,p6,p7,p8]
polygon2 = factory.polygon linear_ring2
multi_polygon = factory.multi_polygon [polygon, polygon2]
point = factory.point 1, 1
point2 = factory.point 5, 5
point3 = factory.point 10, 10
multi_point = factory.multi_point [point, point2, point3]
puts polygon.intersection point
puts polygon2.intersection point2
puts multi_polygon.intersection multi_point
zero = factory.point 0,0
um = factory.point 1,0
puts um.distance zero
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment