Class: NSWTopo::GeoJSON::MultiLineString
- Inherits:
-
Object
- Object
- NSWTopo::GeoJSON::MultiLineString
show all
- Includes:
- StraightSkeleton
- Defined in:
- lib/nswtopo/gis/geojson/multi_line_string.rb
Constant Summary
StraightSkeleton::DEFAULT_ROUNDING_ANGLE
Instance Method Summary
collapse
Instance Method Details
#buffer(*margins, **options) ⇒ Object
26
27
28
|
# File 'lib/nswtopo/gis/geojson/multi_line_string.rb', line 26
def buffer(*margins, **options)
MultiLineString.new(@coordinates + @coordinates.map(&:reverse), @properties).offset(*margins, **options)
end
|
#dissolve_points ⇒ Object
49
50
51
|
# File 'lib/nswtopo/gis/geojson/multi_line_string.rb', line 49
def dissolve_points
MultiPoint.new @coordinates.flatten(1), @properties
end
|
#freeze! ⇒ Object
6
7
8
9
|
# File 'lib/nswtopo/gis/geojson/multi_line_string.rb', line 6
def freeze!
each { }
freeze
end
|
#nodes ⇒ Object
15
16
17
|
# File 'lib/nswtopo/gis/geojson/multi_line_string.rb', line 15
def nodes
Nodes.new self
end
|
#offset(*margins, **options) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/nswtopo/gis/geojson/multi_line_string.rb', line 19
def offset(*margins, **options)
linestrings = margins.inject nodes do |nodes, margin|
nodes.progress limit: margin, **options.slice(:rounding_angle, :cutoff_angle)
end.readout
MultiLineString.new linestrings, @properties
end
|
#path_length ⇒ Object
11
12
13
|
# File 'lib/nswtopo/gis/geojson/multi_line_string.rb', line 11
def path_length
sum(&:path_length)
end
|
#samples(interval) ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/nswtopo/gis/geojson/multi_line_string.rb', line 39
def samples(interval)
sampled = flat_map do |linestring|
distance = linestring.path_length
linestring.sample_at(interval) do |point, along, angle|
[point, (2 * along - distance).abs - distance]
end
end.sort_by(&:last).map(&:first)
MultiPoint.new sampled, @properties
end
|
#smooth(margin, **options) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/nswtopo/gis/geojson/multi_line_string.rb', line 30
def smooth(margin, **options)
linestrings = nodes.tap do |nodes|
nodes.progress **options.slice(:rounding_angle).merge(limit: margin)
nodes.progress **options.slice(:rounding_angle, :cutoff_angle).merge(limit: -2 * margin)
nodes.progress **options.slice(:rounding_angle, :cutoff_angle).merge(limit: margin)
end.readout
MultiLineString.new linestrings, @properties
end
|
#subdivide(count) ⇒ Object
53
54
55
56
57
58
59
60
|
# File 'lib/nswtopo/gis/geojson/multi_line_string.rb', line 53
def subdivide(count)
subdivided = flat_map do |linestring|
linestring.each_cons(2).each_slice(count).map do |pairs|
pairs.inject { |part, (p0, p1)| part << p1 }
end
end
MultiLineString.new subdivided, @properties
end
|
#to_multipolygon ⇒ Object
72
73
74
75
76
77
78
79
80
|
# File 'lib/nswtopo/gis/geojson/multi_line_string.rb', line 72
def to_multipolygon
unclaimed, exterior_rings = partition(&:interior?)
exterior_rings.sort_by(&:signed_area).map(&:to_polygon).map do |polygon|
interior_rings, unclaimed = unclaimed.partition do |ring|
polygon.contains? ring.first
end
interior_rings.inject(polygon, &:add_ring)
end.inject(empty_polygons, &:+)
end
|
#to_polygon ⇒ Object
68
69
70
|
# File 'lib/nswtopo/gis/geojson/multi_line_string.rb', line 68
def to_polygon
Polygon.new @coordinates, @properties
end
|
#trim(amount) ⇒ Object
62
63
64
65
66
|
# File 'lib/nswtopo/gis/geojson/multi_line_string.rb', line 62
def trim(amount)
map do |feature|
feature.trim amount
end.reject(&:empty?).inject(empty_linestrings, &:+)
end
|