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_json, #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.



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

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

Instance Attribute Details

#centerObject Also known as: c

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



50
51
52
53
54
55
# File 'lib/geo_ruby/simple_features/circle.rb', line 50

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



43
44
45
46
47
48
# File 'lib/geo_ruby/simple_features/circle.rb', line 43

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



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

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

#bounding_boxObject



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

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)


38
39
40
# File 'lib/geo_ruby/simple_features/circle.rb', line 38

def contains_point?(point)
  @center.euclidian_distance(point) <= radius
end

#diameterObject



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

def diameter
  radius * 2
end

#m_rangeObject



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

def m_range
  fail NotImplementedError
end

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



31
32
33
34
35
# File 'lib/geo_ruby/simple_features/circle.rb', line 31

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