Files

GeoRuby::SimpleFeatures::LineString

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

Attributes

points[R]

the list of points forming the line string

Public Class Methods

from_coordinates(points,srid=DEFAULT_SRID,with_z=false,with_m=false) click to toggle source

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

# File lib/geo_ruby/simple_features/line_string.rb, line 158
def self.from_coordinates(points,srid=DEFAULT_SRID,with_z=false,with_m=false)
  line_string = new(srid,with_z,with_m)
  line_string.concat( points.collect{|point_coords| Point.from_coordinates(point_coords,srid,with_z,with_m)  } )
  line_string
end
from_points(points,srid=DEFAULT_SRID,with_z=false,with_m=false) click to toggle source

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

# File lib/geo_ruby/simple_features/line_string.rb, line 151
def self.from_points(points,srid=DEFAULT_SRID,with_z=false,with_m=false)
  line_string = new(srid,with_z,with_m)
  line_string.concat(points)
  line_string
end
new(srid= DEFAULT_SRID,with_z=false,with_m=false) click to toggle source
# File lib/geo_ruby/simple_features/line_string.rb, line 10
def initialize(srid= DEFAULT_SRID,with_z=false,with_m=false)
  super(srid,with_z,with_m)
  @points=[]
end

Public Instance Methods

==(other_line_string) click to toggle source

Tests the equality of line strings

# File lib/geo_ruby/simple_features/line_string.rb, line 65
def ==(other_line_string)
  if(other_line_string.class != self.class or 
       other_line_string.length != self.length)
    false
  else
    index=0
    while index<length
      return false if self[index] != other_line_string[index]
      index+=1
    end
    true
  end
end
bounding_box() click to toggle source

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

# File lib/geo_ruby/simple_features/line_string.rb, line 27
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 |point|
      max_y = point.y if point.y > max_y
      min_y = point.y if point.y < min_y
      max_x = point.x if point.x > max_x
      min_x = point.x if point.x < min_x 
      max_z = point.z if point.z > max_z
      min_z = point.z if point.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 |point|
      max_y = point.y if point.y > max_y
      min_y = point.y if point.y < min_y
      max_x = point.x if point.x > max_x
      min_x = point.x if point.x < min_x 
    end
    [Point.from_x_y(min_x,min_y),Point.from_x_y(max_x,max_y)]
  end
end
is_closed() click to toggle source

tests if the line string is closed

# File lib/geo_ruby/simple_features/line_string.rb, line 21
def is_closed
  #a bit naive...

  @points.first == @points.last
end
m_range() click to toggle source
# File lib/geo_ruby/simple_features/line_string.rb, line 51
def m_range
  if with_m
    max_m, min_m = -Float::MAX, Float::MAX
    each do |point|
      max_m = point.m if point.m > max_m
      min_m = point.m if point.m < min_m
    end
    [min_m,max_m]
  else
    [0,0]
  end
end
method_missing(method_name,*args,&b) click to toggle source

Delegate the unknown methods to the points array

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.