Sha256: 875ac2180efb180c9c34f886c2bdbdb97742258e26067ae20e9f12d80796e7e5

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

require_relative "point"

module OGR
  # NOTE: {{#type}} will return :wkbPoint (read: 2D instead of 2.5D) until a Z
  # value is set.
  class Point25D < Point
    # @param [FFI::Pointer] geometry_ptr
    def initialize(geometry_ptr = nil, spatial_reference: nil)
      geometry_ptr ||= OGR::Geometry.create(:wkbPoint25D)
      super(geometry_ptr, spatial_reference: spatial_reference)
    end

    # @return [Float]
    def z
      return if empty?

      FFI::OGR::API.OGR_G_GetZ(@c_pointer, 0)
    end

    # @return [Array<Float, Float, Float>] [x, y, z].
    def point
      return [] if empty?

      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, 0, x_ptr, y_ptr, z_ptr)

      [x_ptr.read_double, y_ptr.read_double, z_ptr.read_double]
    end

    # @param x [Number]
    # @param y [Number]
    # @param z [Number]
    def set_point(x, y, z)
      FFI::OGR::API.OGR_G_SetPoint(@c_pointer, 0, x, y, z)
    end

    # Adds a point to a LineString or Point geometry.
    #
    # @param x [Float]
    # @param y [Float]
    # @param z [Float]
    def add_point(x, y, z)
      FFI::OGR::API.OGR_G_AddPoint(@c_pointer, x, y, z)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ffi-gdal-1.1.0 lib/ogr/geometries/point_25d.rb
ffi-gdal-1.0.4 lib/ogr/geometries/point_25d.rb
ffi-gdal-1.0.3 lib/ogr/geometries/point_25d.rb