Class GeoRuby::SimpleFeatures::LineString
In: lib/geo_ruby/simple_features/line_string.rb
Parent: Geometry

Represents a line string as an array of points (see Point).

Methods

Attributes

points  [R]  the list of points forming the line string

Public Class methods

Creates a new line string. Accept a sequence of points as argument : ((x,y)…(x,y))

[Source]

     # File lib/geo_ruby/simple_features/line_string.rb, line 153
153:       def self.from_coordinates(points,srid=DEFAULT_SRID,with_z=false,with_m=false)
154:         line_string = new(srid,with_z,with_m)
155:         line_string.concat( points.collect{|point_coords| Point.from_coordinates(point_coords,srid,with_z,with_m)  } )
156:         line_string
157:       end

Creates a new line string. Accept an array of points as argument

[Source]

     # File lib/geo_ruby/simple_features/line_string.rb, line 146
146:       def self.from_points(points,srid=DEFAULT_SRID,with_z=false,with_m=false)
147:         line_string = new(srid,with_z,with_m)
148:         line_string.concat(points)
149:         line_string
150:       end

[Source]

    # File lib/geo_ruby/simple_features/line_string.rb, line 10
10:       def initialize(srid= DEFAULT_SRID,with_z=false,with_m=false)
11:         super(srid,with_z,with_m)
12:         @points=[]
13:       end

Public Instance methods

Tests the equality of line strings

[Source]

    # File lib/geo_ruby/simple_features/line_string.rb, line 65
65:       def ==(other_line_string)
66:         if(other_line_string.class != self.class or 
67:              other_line_string.length != self.length)
68:           false
69:         else
70:           index=0
71:           while index<length
72:             return false if self[index] != other_line_string[index]
73:             index+=1
74:           end
75:           true
76:         end
77:       end

Bounding box in 2D/3D. Returns an array of 2 points

[Source]

    # File lib/geo_ruby/simple_features/line_string.rb, line 27
27:       def bounding_box
28:         max_x, min_x, max_y, min_y = -Float::MAX, Float::MAX, -Float::MAX, Float::MAX
29:         if(with_z)
30:           max_z, min_z = -Float::MAX,Float::MAX
31:           each do |point|
32:             max_y = point.y if point.y > max_y
33:             min_y = point.y if point.y < min_y
34:             max_x = point.x if point.x > max_x
35:             min_x = point.x if point.x < min_x 
36:             max_z = point.z if point.z > max_z
37:             min_z = point.z if point.z < min_z 
38:           end
39:           [Point.from_x_y_z(min_x,min_y,min_z),Point.from_x_y_z(max_x,max_y,max_z)]
40:         else
41:           each do |point|
42:             max_y = point.y if point.y > max_y
43:             min_y = point.y if point.y < min_y
44:             max_x = point.x if point.x > max_x
45:             min_x = point.x if point.x < min_x 
46:           end
47:           [Point.from_x_y(min_x,min_y),Point.from_x_y(max_x,max_y)]
48:         end
49:       end

tests if the line string is closed

[Source]

    # File lib/geo_ruby/simple_features/line_string.rb, line 21
21:       def is_closed
22:         #a bit naive...
23:         @points.first == @points.last
24:       end

[Source]

    # File lib/geo_ruby/simple_features/line_string.rb, line 51
51:       def m_range
52:         if with_m
53:           max_m, min_m = -Float::MAX, Float::MAX
54:           each do |point|
55:             max_m = point.m if point.m > max_m
56:             min_m = point.m if point.m < min_m
57:           end
58:           [min_m,max_m]
59:         else
60:           [0,0]
61:         end
62:       end

Delegate the unknown methods to the points array

[Source]

    # File lib/geo_ruby/simple_features/line_string.rb, line 16
16:       def method_missing(method_name,*args,&b)
17:         @points.send(method_name,*args,&b)
18:       end

[Validate]