Sha256: 455fa4b79a3d3d8dc24f6df733fce35aaaeb498b656e6b6c4a7655419c949627

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

require 'json'

module OGR
  module LayerExtensions

    # @return [Array<OGR::Feature>]
    def features
      feature_list = 0.upto(feature_count - 1).map do |i|
        feature(i)
      end

      @features = feature_list
    end

    # @return [OGR::Geometry] A convex hull geometry derived from a LineString
    #   that connects the 4 bounding box points (from the extent).
    def geometry_from_extent
      sr = spatial_reference
      geometry = OGR::Geometry.create(:wkbLineString)
      geometry.spatial_reference = sr

      geometry.add_point(extent.x_min, extent.y_min)
      geometry.add_point(extent.x_min, extent.y_max)
      geometry.add_point(extent.x_max, extent.y_max)
      geometry.add_point(extent.x_max, extent.y_min)
      geometry.add_point(extent.x_min, extent.y_min)

      geometry.convex_hull
    end

    # @return [Hash]
    def as_json
      {
        layer: {
          extent: extent.as_json,
          feature_count: feature_count,
          feature_definition: feature_definition.as_json,
          features: features.map(&:as_json),
          fid_column: fid_column,
          geometry_column: geometry_column,
          geometry_type: geometry_type,
          name: name,
          spatial_reference: spatial_reference.as_json,
          style_table: style_table ? style_table.as_json : nil
        },
        metadata: nil #all_metadata
      }
    end

    # @return [String]
    def to_json
      as_json.to_json
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ffi-gdal-1.0.0.beta3 lib/ogr/layer_extensions.rb
ffi-gdal-1.0.0.beta1 lib/ogr/layer_extensions.rb