Module: OGR::LayerMixins::OGRQueryFilterMethods

Included in:
OGR::Layer
Defined in:
lib/ogr/layer_mixins/ogr_query_filter_methods.rb

Instance Method Summary collapse

Instance Method Details

#set_attribute_filter(query) ⇒ Object

Sets the attribute query string to be used when fetching Features using #next_feature. Should be in the form of an ‘SQL WHERE` clause. Note that this will generally result in resetting the current reading position.



86
87
88
89
90
# File 'lib/ogr/layer_mixins/ogr_query_filter_methods.rb', line 86

def set_attribute_filter(query) # rubocop:disable Naming/AccessorMethodName
  OGR::ErrorHandling.handle_ogr_err("Unable to set attribute filter: #{query}") do
    FFI::OGR::API.OGR_L_SetAttributeFilter(@c_pointer, query)
  end
end

#set_spatial_filter_ex(geometry_field_index, geometry) ⇒ Object

Only feature which intersect the filter geometry will be returned.

Parameters:

  • geometry_field_index (Integer)

    The spatial filter operates on this geometry field.

  • geometry (OGR::Geometry)

    Use this geometry as the filtering region.



30
31
32
33
34
35
36
# File 'lib/ogr/layer_mixins/ogr_query_filter_methods.rb', line 30

def set_spatial_filter_ex(geometry_field_index, geometry)
  geometry_ptr = GDAL._pointer(OGR::Geometry, geometry)

  FFI::OGR::API.OGR_L_SetSpatialFilterEx(
    @c_pointer, geometry_field_index, geometry_ptr
  )
end

#set_spatial_filter_rectangle(min_x, min_y, max_x, max_y) ⇒ Object

Only features that geometrically intersect the given rectangle will be returned. X/Y values should be in the same coordinate system as the layer as a whole (different from #set_spatial_filter_rectangle_ex). To clear the filter, set #spatial_filter = nil.

Parameters:



47
48
49
50
51
52
53
54
55
# File 'lib/ogr/layer_mixins/ogr_query_filter_methods.rb', line 47

def set_spatial_filter_rectangle(min_x, min_y, max_x, max_y)
  FFI::OGR::API.OGR_L_SetSpatialFilterRect(
    @c_pointer,
    min_x,
    min_y,
    max_x,
    max_y
  )
end

#set_spatial_filter_rectangle_ex(geometry_field_index, min_x, min_y, max_x, max_y) ⇒ Object

Only features that geometrically intersect the given rectangle will be returned. X/Y values should be in the same coordinate system as the layer as the given GeometryFieldDefinition at the given index (different from #set_spatial_filter_rectangle). To clear the filter, set #spatial_filter = nil.

Parameters:



68
69
70
71
72
73
74
75
76
77
# File 'lib/ogr/layer_mixins/ogr_query_filter_methods.rb', line 68

def set_spatial_filter_rectangle_ex(geometry_field_index, min_x, min_y, max_x, max_y)
  FFI::OGR::API.OGR_L_SetSpatialFilterRectEx(
    @c_pointer,
    geometry_field_index,
    min_x,
    min_y,
    max_x,
    max_y
  )
end

#spatial_filterOGR::Geometry

TODO: per the GDAL docs: “The returned pointer is to an internally owned object, and should not be altered or deleted by the caller.”

Returns:



10
11
12
13
14
15
# File 'lib/ogr/layer_mixins/ogr_query_filter_methods.rb', line 10

def spatial_filter
  filter_pointer = FFI::OGR::API.OGR_L_GetSpatialFilter(@c_pointer)
  return nil if filter_pointer.null?

  OGR::Geometry.factory(filter_pointer)
end

#spatial_filter=(new_spatial_filter) ⇒ Object

Parameters:



18
19
20
21
22
# File 'lib/ogr/layer_mixins/ogr_query_filter_methods.rb', line 18

def spatial_filter=(new_spatial_filter)
  spatial_filter_ptr = GDAL._pointer(OGR::Geometry, new_spatial_filter)

  FFI::OGR::API.OGR_L_SetSpatialFilter(@c_pointer, spatial_filter_ptr)
end