Class: GeoRuby::SimpleFeatures::Circle

Inherits:
Geometry
  • Object
show all
Defined in:
lib/geo_ruby/simple_features/circle.rb

Overview

Represents a point. It is in 3D if the Z coordinate is not nil.

Instance Attribute Summary collapse

Attributes inherited from Geometry

#srid, #with_m, #with_z

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Geometry

#as_ewkb, #as_ewkt, #as_georss, #as_hex_ewkb, #as_hex_wkb, #as_kml, #as_wkb, #as_wkt, #envelope, from_ewkb, from_ewkt, from_geojson, from_georss, from_georss_with_tags, from_hex_ewkb, from_kml

Constructor Details

#initialize(srid = DEFAULT_SRID, with_z = false, with_m = false) ⇒ Circle

Returns a new instance of Circle.



8
9
10
# File 'lib/geo_ruby/simple_features/circle.rb', line 8

def initialize(srid = DEFAULT_SRID, with_z = false, with_m = false)
  super(srid, with_z, with_m)
end

Instance Attribute Details

#centerObject

Returns the value of attribute center.



5
6
7
# File 'lib/geo_ruby/simple_features/circle.rb', line 5

def center
  @center
end

#radiusObject Also known as: r

Returns the value of attribute radius.



5
6
7
# File 'lib/geo_ruby/simple_features/circle.rb', line 5

def radius
  @radius
end

Class Method Details

.from_coordinates(center, r, srid = DEFAULT_SRID) ⇒ Object



47
48
49
50
51
52
# File 'lib/geo_ruby/simple_features/circle.rb', line 47

def from_coordinates(center, r, srid = DEFAULT_SRID)
  circle = new(srid)
  circle.center = Point.from_coordinates(center)
  circle.radius = r
  circle
end

.from_x_y_r(x, y, r, srid = DEFAULT_SRID) ⇒ Object



40
41
42
43
44
45
# File 'lib/geo_ruby/simple_features/circle.rb', line 40

def from_x_y_r(x, y, r, srid = DEFAULT_SRID)
  circle = new(srid)
  circle.center = Point.from_x_y(x, y, srid)
  circle.radius = r
  circle
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
24
# File 'lib/geo_ruby/simple_features/circle.rb', line 21

def ==(other)
  return false unless other.is_a?(Circle)
  @center == other.center and @radius == other.radius
end

#bounding_boxObject



12
13
14
15
# File 'lib/geo_ruby/simple_features/circle.rb', line 12

def bounding_box
  [Point.from_x_y(@center.x - @r, @center.y - @r),
   Point.from_x_y(@center.x + @r, @center.y + @r)]
end

#contains_point?(point) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/geo_ruby/simple_features/circle.rb', line 33

def contains_point?(point)
  dist = Mongoid::Spacial.distance(@center.to_coordinates,
            point.to_coordinates, :spherical => true, :unit => :m)
  dist <= @radius
end

#m_rangeObject

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/geo_ruby/simple_features/circle.rb', line 17

def m_range
  raise NotImplementedError
end

#to_json(options = {}) ⇒ Object Also known as: as_geojson



26
27
28
29
30
# File 'lib/geo_ruby/simple_features/circle.rb', line 26

def to_json(options = {})
  {:type => 'Circle',
   :coordinates => @center.to_coordinates,
   :radius => @radius}.to_json(options)
end