Class: GeoScript::Geom::LineString

Inherits:
JTSLineString
  • Object
show all
Includes:
GeoScript::Geom
Defined in:
lib/geoscript/geom/linestring.rb

Constant Summary

Constants included from GeoScript::Geom

GEOM_FACTORY, PREP_FACTORY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GeoScript::Geom

buffer, enhance, from_wkt, get_bounds, prepare, simplify, to_wkt

Constructor Details

#initialize(*coords) ⇒ LineString

Returns a new instance of LineString.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/geoscript/geom/linestring.rb', line 11

def initialize(*coords)
  if coords.size == 1
    if coords.first.kind_of? JTSLineString
    elsif coords.kind_of? Array
      if coords.first.kind_of? Array
        l = []
        coords.first.each do |coord|
          l << Coordinate.new(coord[0], coord[1])
          l.last.z = coord[2] if coord[2]
        end
        if l.size > 0
          ls = GEOM_FACTORY.create_line_string l.to_java(com.vividsolutions.jts.geom.Coordinate)
        end
      end
    end
  else
    l = []
    coords.each do |coord|
      l << Coordinate.new(coord[0], coord[1])
      l.last.z = coord[2] if coord[2]
    end
    if l.size > 0
      ls = GEOM_FACTORY.create_line_string l.to_java(com.vividsolutions.jts.geom.Coordinate)
    end
  end

  if ls
    super(ls.coordinate_sequence, GEOM_FACTORY)
  else
    raise 'LineString could not be created. Check inputs.'
  end
end

Instance Attribute Details

#boundsObject

Returns the value of attribute bounds.



9
10
11
# File 'lib/geoscript/geom/linestring.rb', line 9

def bounds
  @bounds
end

Instance Method Details

#buffer(dist) ⇒ Object



44
45
46
# File 'lib/geoscript/geom/linestring.rb', line 44

def buffer(dist)
  Polygon.new super
end

#to_jsonObject



56
57
58
# File 'lib/geoscript/geom/linestring.rb', line 56

def to_json
  IO.write_json self
end

#to_wkbObject



52
53
54
# File 'lib/geoscript/geom/linestring.rb', line 52

def to_wkb
  IO.write_wkb self
end

#to_wktObject



48
49
50
# File 'lib/geoscript/geom/linestring.rb', line 48

def to_wkt
  IO.write_wkt self
end