Class: GeoRuby::SimpleFeatures::GeometryCollection
- Defined in:
- lib/geo_ruby/simple_features/geometry_collection.rb
Overview
Represents a collection of arbitrary geometries
Direct Known Subclasses
Instance Attribute Summary collapse
-
#geometries ⇒ Object
readonly
Returns the value of attribute geometries.
Attributes inherited from Geometry
Class Method Summary collapse
-
.from_geometries(geometries, srid = DEFAULT_SRID, z = false, m = false) ⇒ Object
creates a new GeometryCollection from an array of geometries.
Instance Method Summary collapse
-
#==(other) ⇒ Object
tests the equality of geometry collections.
- #as_json(_options = {}) ⇒ Object
-
#binary_geometry_type ⇒ Object
WKB geometry type of the collection.
-
#binary_representation(allow_z = true, allow_m = true) ⇒ Object
Binary representation of the collection.
-
#bounding_box ⇒ Object
Bounding box in 2D/3D.
-
#georss_gml_representation(options) ⇒ Object
georss gml representation : outputs only the first geometry of the collection.
-
#georss_simple_representation(options) ⇒ Object
georss simple representation : outputs only the first geometry of the collection.
-
#georss_w3cgeo_representation(options) ⇒ Object
georss w3c representation : outputs the first point of the outer ring.
-
#initialize(srid = DEFAULT_SRID, with_z = false, with_m = false) ⇒ GeometryCollection
constructor
A new instance of GeometryCollection.
-
#kml_representation(options = {}) ⇒ Object
outputs the geometry in kml format.
- #m_range ⇒ Object
-
#method_missing(method_name, *args, &b) ⇒ Object
Delegate the unknown methods to the geometries array.
-
#text_geometry_type ⇒ Object
WKT geometry type.
-
#text_representation(allow_z = true, allow_m = true) ⇒ Object
Text representation of a geometry collection.
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, #to_json
Constructor Details
#initialize(srid = DEFAULT_SRID, with_z = false, with_m = false) ⇒ GeometryCollection
Returns a new instance of GeometryCollection.
9 10 11 12 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 9 def initialize(srid = DEFAULT_SRID, with_z = false, with_m = false) super(srid, with_z, with_m) @geometries = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &b) ⇒ Object
Delegate the unknown methods to the geometries array
15 16 17 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 15 def method_missing(method_name, *args, &b) @geometries.send(method_name, *args, &b) end |
Instance Attribute Details
#geometries ⇒ Object (readonly)
Returns the value of attribute geometries.
7 8 9 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 7 def geometries @geometries end |
Class Method Details
.from_geometries(geometries, srid = DEFAULT_SRID, z = false, m = false) ⇒ Object
creates a new GeometryCollection from an array of geometries
136 137 138 139 140 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 136 def self.from_geometries(geometries, srid = DEFAULT_SRID, z = false, m = false) geometry_collection = new(srid, z, m) geometry_collection.concat(geometries) geometry_collection end |
Instance Method Details
#==(other) ⇒ Object
tests the equality of geometry collections
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 67 def ==(other) if (other.class != self.class) false elsif length != other.length false else index = 0 while index < length return false if self[index] != other[index] index += 1 end true end end |
#as_json(_options = {}) ⇒ Object
108 109 110 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 108 def as_json( = {}) { type: 'GeometryCollection', geometries: geometries } end |
#binary_geometry_type ⇒ Object
WKB geometry type of the collection
92 93 94 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 92 def binary_geometry_type #:nodoc: 7 end |
#binary_representation(allow_z = true, allow_m = true) ⇒ Object
Binary representation of the collection
83 84 85 86 87 88 89 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 83 def binary_representation(allow_z = true, allow_m = true) #:nodoc: rep = [length].pack('V') # output the list of geometries without outputting the SRID first # and with the same setting regarding Z and M each { |geometry| rep << geometry.as_ewkb(false, allow_z, allow_m) } rep end |
#bounding_box ⇒ Object
Bounding box in 2D/3D. Returns an array of 2 points
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 20 def bounding_box max_x, min_x, max_y, min_y = -Float::MAX, Float::MAX, -Float::MAX, Float::MAX if with_z max_z, min_z = -Float::MAX, Float::MAX each do |geometry| bbox = geometry.bounding_box sw = bbox[0] ne = bbox[1] max_y = ne.y if ne.y > max_y min_y = sw.y if sw.y < min_y max_x = ne.x if ne.x > max_x min_x = sw.x if sw.x < min_x max_z = ne.z if ne.z > max_z min_z = sw.z if sw.z < min_z end [Point.from_x_y_z(min_x, min_y, min_z), Point.from_x_y_z(max_x, max_y, max_z)] else each do |geometry| bbox = geometry.bounding_box sw = bbox[0] ne = bbox[1] max_y = ne.y if ne.y > max_y min_y = sw.y if sw.y < min_y max_x = ne.x if ne.x > max_x min_x = sw.x if sw.x < min_x end [Point.from_x_y(min_x, min_y), Point.from_x_y(max_x, max_y)] end end |
#georss_gml_representation(options) ⇒ Object
georss gml representation : outputs only the first geometry of the collection
121 122 123 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 121 def georss_gml_representation() #:nodoc: self[0].georss_gml_representation() end |
#georss_simple_representation(options) ⇒ Object
georss simple representation : outputs only the first geometry of the collection
113 114 115 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 113 def georss_simple_representation() #:nodoc: self[0].georss_simple_representation() end |
#georss_w3cgeo_representation(options) ⇒ Object
georss w3c representation : outputs the first point of the outer ring
117 118 119 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 117 def georss_w3cgeo_representation() #:nodoc: self[0].georss_w3cgeo_representation() end |
#kml_representation(options = {}) ⇒ Object
outputs the geometry in kml format
126 127 128 129 130 131 132 133 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 126 def kml_representation( = {}) #:nodoc: result = "<MultiGeometry#{[:id_attr]}>\n" [:id_attr] = '' # the subgeometries do not have an ID each do |geometry| result += geometry.kml_representation() end result += "</MultiGeometry>\n" end |
#m_range ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 52 def m_range if with_m max_m, min_m = -Float::MAX, Float::MAX each do |lr| lrmr = lr.m_range max_m = lrmr[1] if lrmr[1] > max_m min_m = lrmr[0] if lrmr[0] < min_m end [min_m, max_m] else [0, 0] end end |
#text_geometry_type ⇒ Object
WKT geometry type
104 105 106 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 104 def text_geometry_type #:nodoc: 'GEOMETRYCOLLECTION' end |
#text_representation(allow_z = true, allow_m = true) ⇒ Object
Text representation of a geometry collection
97 98 99 100 101 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 97 def text_representation(allow_z = true, allow_m = true) #:nodoc: @geometries.collect do |geometry| geometry.as_ewkt(false, allow_z, allow_m) end.join(',') end |