require "geo_ruby/simple_features/geometry" module GeoRuby module SimpleFeatures #Represents a line string as an array of points (see Point). class LineString < Geometry #the list of points forming the line string attr_reader :points def initialize(srid= DEFAULT_SRID ) super(srid) @points=[] end #tests if the line string is closed def is_closed #a bit naive... @points.first == @points.last end #add a point to the end of the line string def <<(point) @points << point end #add points to the end of the line string def concat(points) @points.concat points end #number of points of the line string def length @points.length end #accesses the nth point in the line string def [](n) @points[n] end #replaces the nth point in the line string def []=(n,point) @points[n]=point end #iterates over the points in the line string def each(&proc) @points.each(&proc) end #iterates over the points, passing their indices to the bloc def each_index(&proc) @points.each_index(&proc) end #inserts points at the nth position def insert(n,*point) @points.insert(n,*point) end #gets the indices of point def index(point) @points.index(point) end #Removes a slice of points def remove(*slice) @points.slice(*slice) end #Tests the equality of line strings def ==(other_line_string) if(other_line_string.class != self.class or other_line_string.length != self.length) false else index=0 while index