Class: GeoRuby::SimpleFeatures::Envelope
- Inherits:
-
Object
- Object
- GeoRuby::SimpleFeatures::Envelope
- Defined in:
- lib/geo_ruby/simple_features/envelope.rb
Overview
Contains the bounding box of a geometry
Instance Attribute Summary collapse
-
#lower_corner ⇒ Object
Returns the value of attribute lower_corner.
-
#srid ⇒ Object
Returns the value of attribute srid.
-
#upper_corner ⇒ Object
Returns the value of attribute upper_corner.
-
#with_z ⇒ Object
Returns the value of attribute with_z.
-
#zoom ⇒ Object
Zoom level.
Class Method Summary collapse
-
.from_coordinates(points, srid = DEFAULT_SRID, with_z = false) ⇒ Object
Creates a new envelope.
-
.from_points(points, srid = DEFAULT_SRID, with_z = false) ⇒ Object
Creates a new envelope.
Instance Method Summary collapse
-
#==(other_envelope) ⇒ Object
Tests the equality of line strings.
-
#as_georss(options = {}) ⇒ Object
georss serialization: Dialect can be passed as option
:dialect
and set to:simple
(default):w3cgeo
or:gml
. -
#as_kml(options = {}) ⇒ Object
Sends back a latlonaltbox.
-
#center ⇒ Object
Sends back the center of the envelope.
-
#extend(envelope) ⇒ Object
Merges the argument with the current evelope and sends back a new envelope without changing the current one.
-
#extend!(envelope) ⇒ Object
Merges the argument with the current evelope.
-
#georss_gml_representation(options = {}) ⇒ Object
georss gml representation.
-
#georss_simple_representation(options = {}) ⇒ Object
georss simple representation.
-
#georss_w3cgeo_representation(options = {}) ⇒ Object
georss w3c representation : outputs the first point of the line.
-
#initialize(srid = DEFAULT_SRID, with_z = false) ⇒ Envelope
constructor
Creates a enw Envelope with
lower_corner
as the first element of the corners array andupper_corner
as the second element. -
#kml_representation(options = {}) ⇒ Object
:nodoc:.
Constructor Details
#initialize(srid = DEFAULT_SRID, with_z = false) ⇒ Envelope
Creates a enw Envelope with lower_corner
as the first element of the corners array and upper_corner
as the second element
10 11 12 13 |
# File 'lib/geo_ruby/simple_features/envelope.rb', line 10 def initialize(srid = DEFAULT_SRID, with_z = false) @srid = srid @with_z = with_z end |
Instance Attribute Details
#lower_corner ⇒ Object
Returns the value of attribute lower_corner.
5 6 7 |
# File 'lib/geo_ruby/simple_features/envelope.rb', line 5 def lower_corner @lower_corner end |
#srid ⇒ Object
Returns the value of attribute srid.
6 7 8 |
# File 'lib/geo_ruby/simple_features/envelope.rb', line 6 def srid @srid end |
#upper_corner ⇒ Object
Returns the value of attribute upper_corner.
5 6 7 |
# File 'lib/geo_ruby/simple_features/envelope.rb', line 5 def upper_corner @upper_corner end |
#with_z ⇒ Object
Returns the value of attribute with_z.
6 7 8 |
# File 'lib/geo_ruby/simple_features/envelope.rb', line 6 def with_z @with_z end |
#zoom ⇒ Object
Zoom level
58 59 60 |
# File 'lib/geo_ruby/simple_features/envelope.rb', line 58 def zoom @zoom end |
Class Method Details
.from_coordinates(points, srid = DEFAULT_SRID, with_z = false) ⇒ Object
Creates a new envelope. Accept a sequence of point coordinates as argument : ((x,y),(x,y))
167 168 169 170 171 |
# File 'lib/geo_ruby/simple_features/envelope.rb', line 167 def self.from_coordinates(points, srid = DEFAULT_SRID, with_z = false) e = Envelope.new(srid, with_z) e.lower_corner, e.upper_corner = points.collect { |point_coords| Point.from_coordinates(point_coords, srid, with_z) } e end |
.from_points(points, srid = DEFAULT_SRID, with_z = false) ⇒ Object
Creates a new envelope. Accept an array of 2 points as argument
159 160 161 162 163 164 |
# File 'lib/geo_ruby/simple_features/envelope.rb', line 159 def self.from_points(points, srid = DEFAULT_SRID, with_z = false) fail 'Not an array' unless points.class == Array e = Envelope.new(srid, with_z) e.lower_corner, e.upper_corner = points e end |
Instance Method Details
#==(other_envelope) ⇒ Object
Tests the equality of line strings
72 73 74 75 76 77 78 |
# File 'lib/geo_ruby/simple_features/envelope.rb', line 72 def ==(other_envelope) if other_envelope.class != self.class false else upper_corner == other_envelope.upper_corner && lower_corner == other_envelope.lower_corner end end |
#as_georss(options = {}) ⇒ Object
georss serialization: Dialect can be passed as option :dialect
and set to :simple
(default) :w3cgeo
or :gml
. Options <tt>:featuretypetag
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/geo_ruby/simple_features/envelope.rb', line 83 def as_georss( = {}) dialect = [:dialect] || :simple case (dialect) when :simple geom_attr = '' if [:featuretypetag] geom_attr += " featuretypetag=\"#{[:featuretypetag]}\"" end if [:relationshiptag] geom_attr += " relationshiptag=\"#{[:relationshiptag]}\"" end geom_attr += " floor=\"#{[:floor]}\"" if [:floor] geom_attr += " radius=\"#{[:radius]}\"" if [:radius] geom_attr += " elev=\"#{[:elev]}\"" if [:elev] georss_simple_representation(.merge(geom_attr: geom_attr)) when :w3cgeo georss_w3cgeo_representation() when :gml georss_gml_representation() end end |
#as_kml(options = {}) ⇒ Object
Sends back a latlonaltbox
133 134 135 136 137 138 139 140 |
# File 'lib/geo_ruby/simple_features/envelope.rb', line 133 def as_kml( = {}) geom_data = '' geom_data = "<altitudeMode>#{[:altitude_mode]}</altitudeMode>\n" if [:altitude_mode] allow_z = with_z && (![:altitude_mode].nil?) && [:atitude_mode] != 'clampToGround' kml_representation(.merge(geom_data: geom_data, allow_z: allow_z)) end |
#center ⇒ Object
Sends back the center of the envelope
53 54 55 |
# File 'lib/geo_ruby/simple_features/envelope.rb', line 53 def center Point.from_x_y((lower_corner.x + upper_corner.x) / 2, (lower_corner.y + upper_corner.y) / 2, srid) end |
#extend(envelope) ⇒ Object
Merges the argument with the current evelope and sends back a new envelope without changing the current one
26 27 28 29 30 31 |
# File 'lib/geo_ruby/simple_features/envelope.rb', line 26 def extend(envelope) e = Envelope.from_points([Point.from_x_y(lower_corner.x, lower_corner.y), Point.from_x_y(upper_corner.x, upper_corner.y)], srid, with_z) e.extend!(envelope) e end |
#extend!(envelope) ⇒ Object
Merges the argument with the current evelope
16 17 18 19 20 21 22 |
# File 'lib/geo_ruby/simple_features/envelope.rb', line 16 def extend!(envelope) lower_corner.x = [lower_corner.x, envelope.lower_corner.x].min lower_corner.y = [lower_corner.y, envelope.lower_corner.y].min upper_corner.x = [upper_corner.x, envelope.upper_corner.x].max upper_corner.y = [upper_corner.y, envelope.upper_corner.y].max self end |
#georss_gml_representation(options = {}) ⇒ Object
georss gml representation
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/geo_ruby/simple_features/envelope.rb', line 121 def georss_gml_representation( = {}) #:nodoc: georss_ns = [:georss_ns] || 'georss' gml_ns = [:gml_ns] || 'gml' result = "<#{georss_ns}:where>\n<#{gml_ns}:Envelope>\n" result += "<#{gml_ns}:LowerCorner>#{lower_corner.y} #{lower_corner.x}"\ "</#{gml_ns}:LowerCorner>" result += "<#{gml_ns}:UpperCorner>#{upper_corner.y} #{upper_corner.x}"\ "</#{gml_ns}:UpperCorner>" result + "</#{gml_ns}:Envelope>\n</#{georss_ns}:where>\n" end |
#georss_simple_representation(options = {}) ⇒ Object
georss simple representation
107 108 109 110 111 |
# File 'lib/geo_ruby/simple_features/envelope.rb', line 107 def georss_simple_representation( = {}) #:nodoc: georss_ns = [:georss_ns] || 'georss' geom_attr = [:geom_attr] "<#{georss_ns}:box#{geom_attr}>#{lower_corner.y} #{lower_corner.x} #{upper_corner.y} #{upper_corner.x}</#{georss_ns}:box>\n" end |
#georss_w3cgeo_representation(options = {}) ⇒ Object
georss w3c representation : outputs the first point of the line
114 115 116 117 118 |
# File 'lib/geo_ruby/simple_features/envelope.rb', line 114 def georss_w3cgeo_representation( = {}) #:nodoc: w3cgeo_ns = [:w3cgeo_ns] || 'geo' point = center "<#{w3cgeo_ns}:lat>#{point.y}</#{w3cgeo_ns}:lat>\n<#{w3cgeo_ns}:long>#{point.x}</#{w3cgeo_ns}:long>\n" end |
#kml_representation(options = {}) ⇒ Object
:nodoc:
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/geo_ruby/simple_features/envelope.rb', line 142 def kml_representation( = {}) #:nodoc: result = "<LatLonAltBox>\n" result += [:geom_data] result += "<north>#{upper_corner.y}</north>\n" result += "<south>#{lower_corner.y}</south>\n" result += "<east>#{upper_corner.x}</east>\n" result += "<west>#{lower_corner.x}</west>\n" if with_z result += "<minAltitude>#{lower_corner.z}</minAltitude>" result += "<maxAltitude>#{upper_corner.z}</maxAltitude>" end result + "</LatLonAltBox>\n" end |