Class: Geos::LineString
- Inherits:
-
Geometry
show all
- Includes:
- Enumerable
- Defined in:
- lib/ffi-geos/line_string.rb
Constant Summary
Constants included
from GeomTypes
GeomTypes::GEOS_GEOMETRYCOLLECTION, GeomTypes::GEOS_LINEARRING, GeomTypes::GEOS_LINESTRING, GeomTypes::GEOS_MULTILINESTRING, GeomTypes::GEOS_MULTIPOINT, GeomTypes::GEOS_MULTIPOLYGON, GeomTypes::GEOS_POINT, GeomTypes::GEOS_POLYGON
Instance Attribute Summary
Attributes inherited from Geometry
#ptr
Instance Method Summary
collapse
Methods inherited from Geometry
#==, #area, #boundary, #buffer, #centroid, #clip_by_rect, #contains?, #convex_hull, #coord_seq, #covered_by?, #covers?, #crosses?, #delaunay_triangulation, #difference, #dimensions, #disjoint?, #distance, #empty?, #end_point, #envelope, #eql?, #eql_almost?, #eql_exact?, #extract_unique_points, #frechet_distance, #geom_type, #has_z?, #hausdorff_distance, #initialize, #initialize_copy, #interpolate, #interpolate_normalized, #intersection, #intersects?, #length, #line_merge, #minimum_clearance, #minimum_clearance_line, #minimum_rotated_rectangle, #minimum_width, #nearest_points, #node, #normalize!, #num_coordinates, #num_geometries, #overlaps?, #point_on_surface, #polygonize, #polygonize_cut_edges, #polygonize_full, #precision, #project, #project_normalized, #relate, #relate_boundary_node_rule, #relate_pattern, release, #reverse, #ring?, #shared_paths, #simple?, #simplify, #snap, #srid, #srid=, #start_point, #sym_difference, #to_prepared, #to_s, #topology_preserve_simplify, #touches?, #type_id, #unary_union, #union, #union_cascaded, #valid?, #valid_detail, #valid_reason, #voronoi_diagram, #with_precision, #within?
Methods included from Tools
#bool_result, #bool_to_int, #cast_geometry_ptr, #check_enum_value, #check_geometry, #extract_options!, #pick_srid_according_to_policy, #pick_srid_from_geoms, #symbol_for_enum
Constructor Details
This class inherits a constructor from Geos::Geometry
Instance Method Details
#[](*args) ⇒ Object
Also known as:
slice
36
37
38
39
40
41
42
|
# File 'lib/ffi-geos/line_string.rb', line 36
def [](*args)
if args.length == 1 && args.first.is_a?(Numeric) && args.first >= 0
point_n(args.first)
else
to_a[*args]
end
end
|
#dump_points(cur_path = []) ⇒ Object
77
78
79
|
# File 'lib/ffi-geos/line_string.rb', line 77
def dump_points(cur_path = [])
cur_path.concat(to_a)
end
|
#each ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/ffi-geos/line_string.rb', line 7
def each
if block_given?
num_points.times do |n|
yield point_n(n)
end
self
else
num_points.times.collect { |n|
point_n(n)
}.to_enum
end
end
|
#line_interpolate_point(fraction) ⇒ Object
Also known as:
interpolate_point
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/ffi-geos/line_string.rb', line 103
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
self.end_point
end
end
|
#offset_curve(width, options = {}) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/ffi-geos/line_string.rb', line 45
def offset_curve(width, options = {})
options = Constants::BUFFER_PARAM_DEFAULTS.merge(options)
cast_geometry_ptr(FFIGeos.GEOSOffsetCurve_r(
Geos.current_handle_pointer,
ptr,
width,
options[:quad_segs],
options[:join],
options[:mitre_limit]
), srid_copy: srid)
end
|
#snap_to_grid(*args) ⇒ Object
97
98
99
100
101
|
# File 'lib/ffi-geos/line_string.rb', line 97
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/ffi-geos/line_string.rb', line 81
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
|
#to_linear_ring ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/ffi-geos/line_string.rb', line 64
def to_linear_ring
return Geos.create_linear_ring(coord_seq, srid: pick_srid_according_to_policy(srid)) if closed?
self_cs = coord_seq.to_a
self_cs.push(self_cs[0])
Geos.create_linear_ring(self_cs, srid: pick_srid_according_to_policy(srid))
end
|
#to_polygon ⇒ Object
73
74
75
|
# File 'lib/ffi-geos/line_string.rb', line 73
def to_polygon
to_linear_ring.to_polygon
end
|