Module: OGR::GeometryTypes::Curve
- Included in:
- LineString, MultiLineString
- Defined in:
- lib/ogr/geometry_types/curve.rb,
lib/ogr/extensions/geometry_types/curve/extensions.rb
Defined Under Namespace
Modules: Extensions
Instance Method Summary collapse
-
#add_point(x, y, z = 0) ⇒ Object
Adds a point to a LineString or Point geometry.
-
#length ⇒ Float
Computes the length for this geometry.
-
#point(number) ⇒ Array<Float, Float, Float>
(also: #get_point)
- x, y
-
if 2d or [x, y, z] if 3d.
- #point_count=(new_count) ⇒ Object
-
#points ⇒ Array<Array<Float>>
(also: #get_points, #point_values)
An array of (x, y) or (x, y, z) points.
- #set_point(index, x, y, z = nil) ⇒ Object
- #x(point_number) ⇒ Float
- #y(point_number) ⇒ Float
- #z(point_number) ⇒ Float
Instance Method Details
#add_point(x, y, z = 0) ⇒ Object
Adds a point to a LineString or Point geometry.
43 44 45 46 47 48 49 |
# File 'lib/ogr/geometry_types/curve.rb', line 43 def add_point(x, y, z = 0) if coordinate_dimension == 3 FFI::OGR::API.OGR_G_AddPoint(@c_pointer, x, y, z) else FFI::OGR::API.OGR_G_AddPoint_2D(@c_pointer, x, y) end end |
#length ⇒ Float
Computes the length for this geometry. Computes area for Curve or MultiCurve objects.
103 104 105 |
# File 'lib/ogr/geometry_types/curve.rb', line 103 def length FFI::OGR::API.OGR_G_Length(@c_pointer) end |
#point(number) ⇒ Array<Float, Float, Float> Also known as: get_point
Returns [x, y] if 2d or [x, y, z] if 3d.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ogr/geometry_types/curve.rb', line 23 def point(number) x_ptr = FFI::MemoryPointer.new(:double) y_ptr = FFI::MemoryPointer.new(:double) z_ptr = FFI::MemoryPointer.new(:double) FFI::OGR::API.OGR_G_GetPoint(@c_pointer, number, x_ptr, y_ptr, z_ptr) if coordinate_dimension == 2 [x_ptr.read_double, y_ptr.read_double] else [x_ptr.read_double, y_ptr.read_double, z_ptr.read_double] end end |
#point_count=(new_count) ⇒ Object
95 96 97 |
# File 'lib/ogr/geometry_types/curve.rb', line 95 def point_count=(new_count) FFI::OGR::API.OGR_G_SetPointCount(@c_pointer, new_count) end |
#points ⇒ Array<Array<Float>> Also known as: get_points, point_values
Returns An array of (x, y) or (x, y, z) points.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ogr/geometry_types/curve.rb', line 64 def points x_stride = FFI::Type::DOUBLE.size y_stride = FFI::Type::DOUBLE.size z_stride = coordinate_dimension == 3 ? FFI::Type::DOUBLE.size : 0 buffer_size = point_count x_buffer = FFI::MemoryPointer.new(:buffer_out, buffer_size) y_buffer = FFI::MemoryPointer.new(:buffer_out, buffer_size) z_buffer = FFI::MemoryPointer.new(:buffer_out, buffer_size) if coordinate_dimension == 3 num_points = FFI::OGR::API.OGR_G_GetPoints(@c_pointer, x_buffer, x_stride, y_buffer, y_stride, z_buffer, z_stride) log "Got different number of points than point_count in #point_values" unless num_points == point_count x_array = x_buffer.read_array_of_double(buffer_size) y_array = y_buffer.read_array_of_double(buffer_size) if z_buffer z_array = z_buffer.read_array_of_double(buffer_size) [x_array, y_array, z_array].transpose else [x_array, y_array].transpose end end |
#set_point(index, x, y, z = nil) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/ogr/geometry_types/curve.rb', line 55 def set_point(index, x, y, z = nil) if is_3d? FFI::OGR::API.OGR_G_SetPoint(@c_pointer, index, x, y, z) else FFI::OGR::API.OGR_G_SetPoint_2D(@c_pointer, index, x, y) end end |
#x(point_number) ⇒ Float
7 8 9 |
# File 'lib/ogr/geometry_types/curve.rb', line 7 def x(point_number) FFI::OGR::API.OGR_G_GetX(@c_pointer, point_number) end |