Class: Geos::LineString
- Inherits:
-
Object
- Object
- Geos::LineString
- Defined in:
- lib/geos/yaml/syck.rb,
lib/geos/line_string.rb
Instance Method Summary collapse
- #as_geojson(options = {}) ⇒ Object (also: #to_geojsonable)
- #as_json(options = {}) ⇒ Object (also: #to_jsonable)
-
#dump_points(cur_path = []) ⇒ Object
Dumps points similarly to the PostGIS
ST_DumpPointsfunction. - #line_interpolate_point(fraction) ⇒ Object (also: #interpolate_point)
- #snap_to_grid(*args) ⇒ Object
- #snap_to_grid!(*args) ⇒ Object
Instance Method Details
#as_geojson(options = {}) ⇒ Object Also known as: to_geojsonable
11 12 13 |
# File 'lib/geos/line_string.rb', line 11 def as_geojson( = {}) self.coord_seq.to_geojsonable() end |
#as_json(options = {}) ⇒ Object Also known as: to_jsonable
6 7 8 |
# File 'lib/geos/line_string.rb', line 6 def as_json( = {}) self.coord_seq.as_json() end |
#dump_points(cur_path = []) ⇒ Object
Dumps points similarly to the PostGIS ST_DumpPoints function.
17 18 19 |
# File 'lib/geos/line_string.rb', line 17 def dump_points(cur_path = []) cur_path.concat(self.to_a) end |
#line_interpolate_point(fraction) ⇒ Object Also known as: interpolate_point
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# 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 |
#snap_to_grid(*args) ⇒ Object
61 62 63 64 65 |
# 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) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# 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 |