class Geos::LineString
Public Instance Methods
as_geojson(options = {})
click to toggle source
# File lib/geos/line_string.rb, line 11 def as_geojson(options = {}) self.coord_seq.to_geojsonable(options) end
Also aliased as: to_geojsonable
as_json(options = {})
click to toggle source
# File lib/geos/line_string.rb, line 6 def as_json(options = {}) self.coord_seq.as_json(options) end
Also aliased as: to_jsonable
dump_points(cur_path = [])
click to toggle source
Dumps points similarly to the PostGIS `ST_DumpPoints` function.
# File lib/geos/line_string.rb, line 17 def dump_points(cur_path = []) cur_path.concat(self.to_a) end
line_interpolate_point(fraction)
click to toggle source
# File lib/geos/line_string.rb, line 67 def line_interpolate_point(fraction) if !fraction.between?(0, 1) raise ArgumentError.new("fraction must be between 0 and 1") end case fraction when 0 self.start_point when 1 self.end_point else length = self.length total_length = 0 segs = self.num_points - 1 segs.times do |i| p1 = self[i] p2 = self[i + 1] seg_length = p1.distance(p2) / length if fraction < total_length + seg_length dseg = (fraction - total_length) / seg_length args = [] args << p1.x + ((p2.x - p1.x) * dseg) args << p1.y + ((p2.y - p1.y) * dseg) args << p1.z + ((p2.z - p1.z) * dseg) if self.has_z? args << { :srid => pick_srid_according_to_policy(self.srid) } unless self.srid == 0 return Geos.create_point(*args) end total_length += seg_length end # if all else fails... self.end_point end end
Also aliased as: interpolate_point
snap_to_grid(*args)
click to toggle source
# File lib/geos/line_string.rb, line 61 def snap_to_grid(*args) ret = self.dup.snap_to_grid!(*args) ret.srid = pick_srid_according_to_policy(self.srid) ret end
snap_to_grid!(*args)
click to toggle source
# File lib/geos/line_string.rb, line 45 def snap_to_grid!(*args) if !self.empty? cs = self.coord_seq.snap_to_grid!(*args) if cs.length == 0 @ptr = Geos.create_empty_line_string(:srid => self.srid).ptr elsif cs.length <= 1 raise Geos::InvalidGeometryError.new("snap_to_grid! produced an invalid number of points in for a LineString - found #{cs.length} - must be 0 or > 1") else @ptr = Geos.create_line_string(cs).ptr end end self end