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, with_z = false, with_m = false) ⇒ Object
creates a new GeometryCollection from an array of geometries.
Instance Method Summary collapse
-
#==(other_collection) ⇒ 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.
-
#to_json(options = {}) ⇒ Object
(also: #as_geojson)
simple geojson representation TODO add CRS / SRID support?.
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) ⇒ 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, with_z = false, with_m = false) ⇒ Object
creates a new GeometryCollection from an array of geometries
141 142 143 144 145 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 141 def self.from_geometries(geometries,srid=DEFAULT_SRID,with_z=false,with_m=false) geometry_collection = new(srid,with_z,with_m) geometry_collection.concat(geometries) geometry_collection end |
Instance Method Details
#==(other_collection) ⇒ 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_collection) if(other_collection.class != self.class) false elsif length != other_collection.length false else index=0 while index<length return false if self[index] != other_collection[index] index+=1 end true end end |
#as_json(options = {}) ⇒ Object
105 106 107 108 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 105 def as_json( = {}) {:type => 'GeometryCollection', :geometries => self.geometries} end |
#binary_geometry_type ⇒ Object
WKB geometry type of the collection
91 92 93 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 91 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 |
# 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
126 127 128 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 126 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
118 119 120 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 118 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
122 123 124 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 122 def georss_w3cgeo_representation()#:nodoc: self[0].georss_w3cgeo_representation() end |
#kml_representation(options = {}) ⇒ Object
outputs the geometry in kml format
131 132 133 134 135 136 137 138 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 131 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
101 102 103 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 101 def text_geometry_type #:nodoc: "GEOMETRYCOLLECTION" end |
#text_representation(allow_z = true, allow_m = true) ⇒ Object
Text representation of a geometry collection
96 97 98 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 96 def text_representation(allow_z=true,allow_m=true) #:nodoc: @geometries.collect{|geometry| geometry.as_ewkt(false,allow_z,allow_m)}.join(",") end |
#to_json(options = {}) ⇒ Object Also known as: as_geojson
simple geojson representation TODO add CRS / SRID support?
112 113 114 |
# File 'lib/geo_ruby/simple_features/geometry_collection.rb', line 112 def to_json( = {}) as_json().to_json() end |