Class: GeoRuby::SimpleFeatures::MultiLineString

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

Overview

Represents a group of line strings (see LineString).

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) ⇒ MultiLineString

Returns a new instance of MultiLineString.



10
11
12
# File 'lib/geo_ruby/simple_features/multi_line_string.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_sequences, srid = DEFAULT_SRID, with_z = false, with_m = false) ⇒ Object

Creates a new multi line string from sequences of points : (((x,y)…(x,y)),((x,y)…(x,y)))



60
61
62
63
64
# File 'lib/geo_ruby/simple_features/multi_line_string.rb', line 60

def self.from_coordinates(point_sequences,srid=DEFAULT_SRID,with_z=false,with_m=false)
  multi_line_string = new(srid,with_z,with_m)
  multi_line_string.concat(point_sequences.collect {|points| LineString.from_coordinates(points,srid,with_z,with_m) })
  multi_line_string
end

.from_line_strings(line_strings, srid = DEFAULT_SRID, with_z = false, with_m = false) ⇒ Object

Creates a new multi line string from an array of line strings



53
54
55
56
57
# File 'lib/geo_ruby/simple_features/multi_line_string.rb', line 53

def self.from_line_strings(line_strings,srid=DEFAULT_SRID,with_z=false,with_m=false)
  multi_line_string = new(srid,with_z,with_m)
  multi_line_string.concat(line_strings)
  multi_line_string
end

Instance Method Details

#as_json(options = {}) ⇒ Object



40
41
42
43
# File 'lib/geo_ruby/simple_features/multi_line_string.rb', line 40

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

#binary_geometry_typeObject

:nodoc:



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

def binary_geometry_type #:nodoc:
  5
end

#pointsObject



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

def points
  geometries.map(&:points).flatten
end

#text_geometry_typeObject

WKT geometry type



28
29
30
# File 'lib/geo_ruby/simple_features/multi_line_string.rb', line 28

def text_geometry_type #:nodoc:
  "MULTILINESTRING"
end

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

Text representation of a multi line string



23
24
25
# File 'lib/geo_ruby/simple_features/multi_line_string.rb', line 23

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

#to_coordinatesObject



36
37
38
# File 'lib/geo_ruby/simple_features/multi_line_string.rb', line 36

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

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

simple geojson representation TODO add CRS / SRID support?



47
48
49
# File 'lib/geo_ruby/simple_features/multi_line_string.rb', line 47

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

#to_line_string(join = true) ⇒ Object



32
33
34
# File 'lib/geo_ruby/simple_features/multi_line_string.rb', line 32

def to_line_string(join = true)
  LineString.from_points(points)
end