Class: OGR::Layer

Defined Under Namespace

Modules: Extensions

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OGR::LayerMixins::CapabilityMethods

#can_alter_field_definition?, #can_create_field?, #can_create_geometry_field?, #can_delete_feature?, #can_delete_field?, #can_fast_feature_count?, #can_fast_get_extent?, #can_fast_set_next_by_index?, #can_fast_spatial_filter?, #can_random_read?, #can_random_write?, #can_reorder_fields?, #can_sequential_write?, #strings_are_utf_8?, #supports_curve_geometries?, #supports_transactions?

Methods included from Extensions

#any_geometries_with_z?, #each_feature, #each_feature_pointer, #features, #geometry_from_extent, #point_values

Methods included from OGR::LayerMixins::OGRSQLMethods

#commit_transaction, #fid_column, #geometry_column, #rollback_transaction, #start_transaction

Methods included from OGR::LayerMixins::OGRQueryFilterMethods

#set_attribute_filter, #set_spatial_filter_ex, #set_spatial_filter_rectangle, #set_spatial_filter_rectangle_ex, #spatial_filter, #spatial_filter=

Methods included from OGR::LayerMixins::OGRLayerMethodMethods

#clip, #erase, #identity, #intersection, #symmetrical_difference, #union, #update

Methods included from OGR::LayerMixins::OGRFieldMethods

#alter_field_definition, #create_field, #create_geometry_field, #delete_field, #find_field_index, #reorder_field, #reorder_fields, #set_ignored_fields

Methods included from OGR::LayerMixins::OGRFeatureMethods

#create_feature, #definition, #delete_feature, #feature, #feature=, #feature_count, #features_read, #next_feature, #next_feature_index=, #reset_reading

Methods included from GDAL::MajorObject

#all_metadata, #description, #metadata, #metadata_domain_list, #metadata_item, #null?, #set_metadata_item

Constructor Details

#initialize(layer_ptr) ⇒ Layer

Returns a new instance of Layer.

Parameters:

  • layer_ptr (FFI::Pointer)


29
30
31
# File 'lib/ogr/layer.rb', line 29

def initialize(layer_ptr)
  @c_pointer = layer_ptr
end

Instance Attribute Details

#c_pointerFFI::Pointer (readonly)

Returns C pointer to the C Layer.

Returns:

  • (FFI::Pointer)

    C pointer to the C Layer.



26
27
28
# File 'lib/ogr/layer.rb', line 26

def c_pointer
  @c_pointer
end

Instance Method Details

#extent(force: true) ⇒ OGR::Envelope

Returns:



72
73
74
75
76
77
78
# File 'lib/ogr/layer.rb', line 72

def extent(force: true)
  envelope = FFI::OGR::Envelope.new
  FFI::OGR::API.OGR_L_GetExtent(@c_pointer, envelope, force)
  return nil if envelope.null?

  OGR::Envelope.new(envelope)
end

#extent_by_geometry(geometry_field_index, force: true) ⇒ OGR::Envelope

Returns:



81
82
83
84
85
86
87
# File 'lib/ogr/layer.rb', line 81

def extent_by_geometry(geometry_field_index, force: true)
  envelope = FFI::OGR::Envelope.new
  FFI::OGR::API.OGR_L_GetExtentEx(@c_pointer, geometry_field_index, envelope, force)
  return nil if envelope.null?

  OGR::Envelope.new(envelope)
end

#geometry_typeSymbol

Returns One of OGRwkbGeometryType.

Returns:

  • (Symbol)

    One of OGRwkbGeometryType.



90
91
92
# File 'lib/ogr/layer.rb', line 90

def geometry_type
  FFI::OGR::API.OGR_L_GetGeomType(@c_pointer)
end

#nameString

Returns:



34
35
36
37
38
39
# File 'lib/ogr/layer.rb', line 34

def name
  name, ptr = FFI::OGR::API.OGR_L_GetName(@c_pointer)
  ptr.autorelease = false

  name
end

#spatial_referenceOGR::SpatialReference

NOTE: This SpatialReference is owned by the Layer and should thus not be modified.



64
65
66
67
68
69
# File 'lib/ogr/layer.rb', line 64

def spatial_reference
  spatial_ref_pointer = FFI::OGR::API.OGR_L_GetSpatialRef(@c_pointer)
  return nil if spatial_ref_pointer.null?

  OGR::SpatialReference.new(spatial_ref_pointer)
end

#style_tableOGR::StyleTable?

Returns:



95
96
97
98
99
100
# File 'lib/ogr/layer.rb', line 95

def style_table
  style_table_pointer = FFI::OGR::API.OGR_L_GetStyleTable(@c_pointer)
  return nil if style_table_pointer.null?

  OGR::StyleTable.new(style_table_pointer)
end

#style_table=(new_style_table) ⇒ Object

Parameters:

Raises:



103
104
105
106
107
108
# File 'lib/ogr/layer.rb', line 103

def style_table=(new_style_table)
  style_table_ptr = GDAL._pointer(OGR::StyleTable, new_style_table)
  raise OGR::Failure if style_table_ptr.nil? || style_table_ptr.null?

  FFI::OGR::API.OGR_L_SetStyleTable(@c_pointer, style_table_ptr)
end

#sync_to_diskBoolean

TODO: This seems to occasionally lead to: 28352 illegal hardware

instruction, and sometimes full crashes.

Returns:

  • (Boolean)


44
45
46
47
48
# File 'lib/ogr/layer.rb', line 44

def sync_to_disk
  OGR::ErrorHandling.handle_ogr_err("Unable to sync layer to disk") do
    FFI::OGR::API.OGR_L_SyncToDisk(@c_pointer)
  end
end

#test_capability(capability) ⇒ Boolean

Tests if this layer supports the given capability. Must be in the list of available capabilities. See www.gdal.org/ogr__api_8h.html#a480adc8b839b04597f49583371d366fd.

Parameters:

Returns:

  • (Boolean)

See Also:



56
57
58
# File 'lib/ogr/layer.rb', line 56

def test_capability(capability)
  FFI::OGR::API.OGR_L_TestCapability(@c_pointer, capability.to_s)
end