Class: Terraformer::MultiLineString

Inherits:
Geometry show all
Defined in:
lib/terraformer/multi_line_string.rb

Constant Summary

Constants inherited from Geometry

Geometry::MULTI_REGEX

Instance Attribute Summary

Attributes inherited from Geometry

#coordinates, #crs

Instance Method Summary collapse

Methods inherited from Geometry

#convex_hull, #each_coordinate, #geographic?, #get, #intersects?, iter_coordinate, #map_coordinate, #mercator?, #to_feature, #to_geographic, #to_hash, #to_mercator

Methods included from Geometry::ClassMethods

#arrays_intersect_arrays?, #coordinates_contain_point?, #edge_intersects_edge?, #line_contains_point?

Methods inherited from Primitive

#bbox, #envelope, #to_json, #type

Constructor Details

#initialize(*args) ⇒ MultiLineString

Returns a new instance of MultiLineString.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/terraformer/multi_line_string.rb', line 5

def initialize *args

  case
  when LineString === args[0]
    self.coordinates = args.map &:coordinates
  else
    super *args
  end

  # must be an array of arrays of coordinates
  unless Array === coordinates &&
         Array === coordinates[0] &&
         Terraformer::Coordinate === coordinates[0][0]
    raise ArgumentError.new 'invalid coordinates for Terraformer::MultiLineString'
  end
end

Instance Method Details

#==(obj) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/terraformer/multi_line_string.rb', line 30

def == obj
  super obj do |o|
    lses = line_strings.sort {|a,b| a.first_coordinate <=> b.first_coordinate }
    olses = o.line_strings.sort {|a,b| a.first_coordinate <=> b.first_coordinate }
    lses == olses
  end
end

#contains?(obj) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/terraformer/multi_line_string.rb', line 38

def contains? obj
  case obj
  when Point
    line_strings.any? {|ls| ls.contains? obj}
  when MultiPoint
    obj.points.all? {|p| line_strings.any? {|ls| ls.contains? p}}
  when LineString
    line_strings.any? {|ls| ls == obj or ls.coordinates.slice_exists? obj.coordinates}
  when MultiLineString
    obj.line_strings.all? do |ols|
      line_strings.any? do |ls|
        ls == ols or ls.coordinates.slice_exists? ols.coordinates
      end
    end
  else
    raise ArgumentError.new "unsupported type: #{obj.type rescue obj.class}"
  end
end

#first_coordinateObject



22
23
24
# File 'lib/terraformer/multi_line_string.rb', line 22

def first_coordinate
  coordinates[0][0]
end

#line_stringsObject



26
27
28
# File 'lib/terraformer/multi_line_string.rb', line 26

def line_strings
  coordinates.map {|ls| LineString.new ls}
end

#within?(obj) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/terraformer/multi_line_string.rb', line 57

def within? obj
  case obj
  when MultiLineString
    obj.contains? self
  when Polygon
    obj.contains? self
  when MultiPolygon
    obj.contains? self
  else
    raise ArgumentError.new "unsupported type: #{obj.type rescue obj.class}"
  end
end