Class: GeoRuby::SimpleFeatures::MultiPolygon

Inherits:
GeometryCollection show all
Defined in:
lib/geo_ruby/simple_features/multi_polygon.rb

Overview

Represents a group of polygons (see Polygon).

Instance Attribute Summary

Attributes inherited from GeometryCollection

#geometries

Attributes inherited from Geometry

#srid, #with_m, #with_z

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GeometryCollection

#==, #binary_representation, #bounding_box, from_geometries, #georss_gml_representation, #georss_simple_representation, #georss_w3cgeo_representation, #kml_representation, #m_range, #method_missing

Methods inherited from Geometry

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

Constructor Details

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

Returns a new instance of MultiPolygon.



10
11
12
# File 'lib/geo_ruby/simple_features/multi_polygon.rb', line 10

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class GeoRuby::SimpleFeatures::GeometryCollection

Class Method Details

.from_coordinates(point_sequence_sequences, srid = DEFAULT_SRID, with_z = false, with_m = false) ⇒ Object

Creates a multi polygon from sequences of points : ((((x,y)…(x,y)),((x,y)…(x,y)),((x,y)…(x,y)))



58
59
60
61
62
# File 'lib/geo_ruby/simple_features/multi_polygon.rb', line 58

def self.from_coordinates(point_sequence_sequences,srid= DEFAULT_SRID,with_z=false,with_m=false)
  multi_polygon = new(srid,with_z,with_m)
  multi_polygon.concat( point_sequence_sequences.collect {|point_sequences| Polygon.from_coordinates(point_sequences,srid,with_z,with_m) } )
  multi_polygon
end

.from_polygons(polygons, srid = DEFAULT_SRID, with_z = false, with_m = false) ⇒ Object

Creates a multi polygon from an array of polygons



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

def self.from_polygons(polygons,srid=DEFAULT_SRID,with_z=false,with_m=false)
  multi_polygon = new(srid,with_z,with_m)
  multi_polygon.concat(polygons)
  multi_polygon
end

Instance Method Details

#as_json(options = {}) ⇒ Object



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

def as_json(options = {})
  {:type => 'MultiPolygon',
   :coordinates => self.to_coordinates}
end

#binary_geometry_typeObject

:nodoc:



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

def binary_geometry_type #:nodoc:
  6
end

#pointsObject



18
19
20
21
22
# File 'lib/geo_ruby/simple_features/multi_polygon.rb', line 18

def points
  @points ||= geometries.inject([]) do |arr, r|
    arr.concat(r.rings.map(&:points).flatten)
  end
end

#text_geometry_typeObject

WKT geometry type



30
31
32
# File 'lib/geo_ruby/simple_features/multi_polygon.rb', line 30

def text_geometry_type #:nodoc:
  "MULTIPOLYGON"
end

#text_representation(allow_z = true, allow_m = true) ⇒ Object

Text representation of a MultiPolygon



25
26
27
# File 'lib/geo_ruby/simple_features/multi_polygon.rb', line 25

def text_representation(allow_z=true,allow_m=true) #:nodoc:
  @geometries.map {|polygon| "(" + polygon.text_representation(allow_z,allow_m) + ")"}.join(",")
end

#to_coordinatesObject



34
35
36
# File 'lib/geo_ruby/simple_features/multi_polygon.rb', line 34

def to_coordinates
  geometries.map{|polygon| polygon.to_coordinates}
end

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

simple geojson representation TODO add CRS / SRID support?



45
46
47
# File 'lib/geo_ruby/simple_features/multi_polygon.rb', line 45

def to_json(options = {})
  as_json(options).to_json(options)
end