ffi-gdal 1.0.0.beta3 → 1.0.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +62 -0
- data/Gemfile +1 -1
- data/History.md +53 -28
- data/README.md +6 -0
- data/Rakefile +23 -1
- data/examples/extract_and_colorize.rb +21 -22
- data/examples/geometries.rb +2 -2
- data/examples/gridding.rb +106 -0
- data/examples/ogr_layer_to_layer.rb +1 -1
- data/examples/points.txt +127 -0
- data/examples/testing_gdal.rb +3 -4
- data/ffi-gdal.gemspec +3 -2
- data/lib/ext/error_symbols.rb +2 -57
- data/lib/ext/ffi_library_function_checks.rb +26 -0
- data/lib/ext/float_ext.rb +2 -2
- data/lib/ext/narray_ext.rb +2 -0
- data/lib/ext/numeric_as_data_type.rb +19 -0
- data/lib/ext/to_bool.rb +4 -4
- data/lib/ffi/cpl/conv.rb +132 -0
- data/lib/ffi/cpl/error.rb +67 -0
- data/lib/ffi/cpl/hash_set.rb +39 -0
- data/lib/ffi/cpl/http.rb +25 -0
- data/lib/ffi/cpl/http_result.rb +18 -0
- data/lib/ffi/cpl/list.rb +38 -0
- data/lib/ffi/cpl/mime_part.rb +11 -0
- data/lib/ffi/cpl/minixml.rb +47 -0
- data/lib/ffi/cpl/port.rb +23 -0
- data/lib/ffi/cpl/quad_tree.rb +51 -0
- data/lib/ffi/{ogr/ogr_envelope.rb → cpl/rect_obj.rb} +3 -3
- data/lib/ffi/cpl/string.rb +95 -0
- data/lib/ffi/cpl/vsi.rb +115 -0
- data/lib/ffi/cpl/xml_node.rb +6 -6
- data/lib/ffi/gdal/alg.rb +385 -0
- data/lib/ffi/gdal/{gdal_color_entry.rb → color_entry.rb} +1 -2
- data/lib/ffi/gdal/exceptions.rb +6 -0
- data/lib/ffi/gdal/{gdal_gcp.rb → gcp.rb} +1 -3
- data/lib/ffi/gdal/{gdal_h.rb → gdal.rb} +253 -252
- data/lib/ffi/gdal/grid.rb +58 -0
- data/lib/ffi/gdal/{gdal_grid_data_metrics_options.rb → grid_data_metrics_options.rb} +1 -2
- data/lib/ffi/gdal/{gdal_grid_inverse_distance_to_a_power_options.rb → grid_inverse_distance_to_a_power_options.rb} +1 -2
- data/lib/ffi/gdal/{gdal_grid_moving_average_options.rb → grid_moving_average_options.rb} +1 -2
- data/lib/ffi/gdal/{gdal_grid_nearest_neighbor_options.rb → grid_nearest_neighbor_options.rb} +1 -2
- data/lib/ffi/gdal/matching.rb +20 -0
- data/lib/ffi/gdal/{gdal_rpc_info.rb → rpc_info.rb} +1 -2
- data/lib/ffi/gdal/{gdal_transformer_info.rb → transformer_info.rb} +1 -2
- data/lib/ffi/gdal/version.rb +1 -1
- data/lib/ffi/gdal/vrt.rb +92 -0
- data/lib/ffi/gdal/{gdal_warp_options.rb → warp_options.rb} +8 -4
- data/lib/ffi/gdal/warper.rb +70 -0
- data/lib/ffi/gdal.rb +56 -69
- data/lib/ffi/ogr/api.rb +567 -0
- data/lib/ffi/ogr/{ogr_contour_writer_info.rb → contour_writer_info.rb} +2 -3
- data/lib/ffi/ogr/core.rb +181 -0
- data/lib/ffi/ogr/envelope.rb +12 -0
- data/lib/ffi/ogr/{ogr_envelope_3d.rb → envelope_3d.rb} +2 -2
- data/lib/ffi/ogr/featurestyle.rb +29 -0
- data/lib/ffi/ogr/field.rb +63 -0
- data/lib/ffi/ogr/geocoding.rb +30 -0
- data/lib/ffi/ogr/srs_api.rb +407 -0
- data/lib/ffi/ogr/style_param.rb +13 -0
- data/lib/ffi/ogr/{ogr_style_value.rb → style_value.rb} +4 -3
- data/lib/ffi/ogr.rb +7 -7
- data/lib/ffi-gdal.rb +7 -145
- data/lib/gdal/color_entry.rb +18 -14
- data/lib/gdal/color_entry_mixins/extensions.rb +32 -0
- data/lib/gdal/color_interpretation.rb +2 -2
- data/lib/gdal/color_table.rb +37 -32
- data/lib/gdal/color_table_mixins/extensions.rb +48 -0
- data/lib/gdal/cpl_error_handler.rb +119 -0
- data/lib/gdal/data_type.rb +7 -7
- data/lib/gdal/dataset.rb +131 -238
- data/lib/gdal/dataset_mixins/algorithm_methods.rb +182 -0
- data/lib/gdal/dataset_mixins/extensions.rb +542 -0
- data/lib/gdal/dataset_mixins/matching.rb +26 -0
- data/lib/gdal/driver.rb +68 -92
- data/lib/gdal/driver_mixins/extensions.rb +93 -0
- data/lib/gdal/exceptions.rb +32 -4
- data/lib/gdal/geo_transform.rb +63 -43
- data/lib/gdal/geo_transform_mixins/extensions.rb +57 -0
- data/lib/gdal/grid.rb +144 -0
- data/lib/gdal/grid_types/data_metrics_base.rb +14 -0
- data/lib/gdal/grid_types/inverse_distance_to_a_power.rb +19 -0
- data/lib/gdal/grid_types/metric_average_distance.rb +12 -0
- data/lib/gdal/grid_types/metric_average_distance_pts.rb +12 -0
- data/lib/gdal/grid_types/metric_count.rb +12 -0
- data/lib/gdal/grid_types/metric_maximum.rb +12 -0
- data/lib/gdal/grid_types/metric_minimum.rb +12 -0
- data/lib/gdal/grid_types/metric_range.rb +12 -0
- data/lib/gdal/grid_types/moving_average.rb +19 -0
- data/lib/gdal/grid_types/nearest_neighbor.rb +19 -0
- data/lib/gdal/grid_types.rb +22 -0
- data/lib/gdal/internal_helpers.rb +94 -0
- data/lib/gdal/major_object.rb +4 -7
- data/lib/gdal/options.rb +14 -7
- data/lib/gdal/raster_attribute_table.rb +38 -47
- data/lib/gdal/raster_attribute_table_mixins/extensions.rb +41 -0
- data/lib/gdal/raster_band.rb +193 -227
- data/lib/gdal/raster_band_classifier.rb +107 -0
- data/lib/gdal/raster_band_mixins/algorithm_methods.rb +292 -0
- data/lib/gdal/raster_band_mixins/extensions.rb +238 -0
- data/lib/gdal/rpc_info.rb +35 -0
- data/lib/gdal/transformer.rb +15 -0
- data/lib/gdal/transformers/approximate_transformer.rb +48 -0
- data/lib/gdal/transformers/base_general_image_projection_transformer.rb +45 -0
- data/lib/gdal/transformers/gcp_transformer.rb +55 -0
- data/lib/gdal/transformers/general_image_projection_transformer.rb +31 -0
- data/lib/gdal/transformers/general_image_projection_transformer2.rb +52 -0
- data/lib/gdal/transformers/general_image_projection_transformer3.rb +25 -0
- data/lib/gdal/transformers/geolocation_transformer.rb +42 -0
- data/lib/gdal/transformers/reprojection_transformer.rb +39 -0
- data/lib/gdal/transformers/rpc_transformer.rb +56 -0
- data/lib/gdal/transformers/tps_transformer.rb +40 -0
- data/lib/gdal/virtual_dataset.rb +96 -0
- data/lib/gdal/warp_operation.rb +20 -23
- data/lib/gdal.rb +17 -0
- data/lib/ogr/coordinate_transformation.rb +16 -41
- data/lib/ogr/data_source.rb +103 -58
- data/lib/ogr/data_source_extensions.rb +5 -6
- data/lib/ogr/data_source_mixins/capability_methods.rb +27 -0
- data/lib/ogr/driver.rb +61 -33
- data/lib/ogr/driver_mixins/capability_methods.rb +16 -0
- data/lib/ogr/envelope.rb +29 -18
- data/lib/ogr/envelope_extensions.rb +70 -49
- data/lib/ogr/error_handling.rb +46 -0
- data/lib/ogr/exceptions.rb +58 -12
- data/lib/ogr/feature.rb +334 -86
- data/lib/ogr/feature_definition.rb +94 -51
- data/lib/ogr/feature_definition_extensions.rb +36 -13
- data/lib/ogr/feature_extensions.rb +62 -11
- data/lib/ogr/field.rb +175 -54
- data/lib/ogr/field_definition.rb +110 -0
- data/lib/ogr/{field_extensions.rb → field_definition_extensions.rb} +4 -5
- data/lib/ogr/{geocoding_session.rb → geocoder.rb} +14 -13
- data/lib/ogr/geometries/geometry_collection.rb +13 -0
- data/lib/ogr/geometries/line_string.rb +35 -0
- data/lib/ogr/geometries/linear_ring.rb +11 -0
- data/lib/ogr/geometries/multi_line_string.rb +16 -0
- data/lib/ogr/geometries/multi_point.rb +14 -0
- data/lib/ogr/geometries/multi_polygon.rb +21 -0
- data/lib/ogr/geometries/none_geometry.rb +13 -0
- data/lib/ogr/geometries/point.rb +65 -0
- data/lib/ogr/geometries/point_extensions.rb +32 -0
- data/lib/ogr/geometries/polygon.rb +14 -0
- data/lib/ogr/geometries/unknown_geometry.rb +10 -0
- data/lib/ogr/geometry.rb +270 -242
- data/lib/ogr/geometry_extensions.rb +8 -9
- data/lib/ogr/geometry_field_definition.rb +99 -0
- data/lib/ogr/geometry_field_definition_extensions.rb +19 -0
- data/lib/ogr/geometry_types/container.rb +75 -0
- data/lib/ogr/geometry_types/curve.rb +25 -28
- data/lib/ogr/geometry_types/surface.rb +13 -4
- data/lib/ogr/internal_helpers.rb +57 -0
- data/lib/ogr/layer.rb +60 -181
- data/lib/ogr/layer_mixins/capability_methods.rb +102 -0
- data/lib/ogr/layer_mixins/extensions.rb +59 -0
- data/lib/ogr/layer_mixins/ogr_feature_methods.rb +127 -0
- data/lib/ogr/layer_mixins/ogr_field_methods.rb +143 -0
- data/lib/ogr/layer_mixins/ogr_layer_method_methods.rb +163 -0
- data/lib/ogr/layer_mixins/ogr_query_filter_methods.rb +89 -0
- data/lib/ogr/layer_mixins/ogr_sql_methods.rb +48 -0
- data/lib/ogr/spatial_reference.rb +108 -589
- data/lib/ogr/spatial_reference_extensions.rb +29 -3
- data/lib/ogr/spatial_reference_mixins/coordinate_system_getter_setters.rb +494 -0
- data/lib/ogr/spatial_reference_mixins/exporters.rb +134 -0
- data/lib/ogr/spatial_reference_mixins/importers.rb +243 -0
- data/lib/ogr/spatial_reference_mixins/morphers.rb +25 -0
- data/lib/ogr/spatial_reference_mixins/parameter_getter_setters.rb +122 -0
- data/lib/ogr/spatial_reference_mixins/type_checks.rb +62 -0
- data/lib/ogr/style_table.rb +53 -5
- data/lib/ogr/style_table_extensions.rb +21 -5
- data/lib/ogr/style_tool.rb +118 -0
- data/lib/ogr.rb +8 -0
- data/spec/ffi-gdal_spec.rb +1 -2
- data/spec/integration/{color_table_info_spec.rb → gdal/color_table_info_spec.rb} +12 -12
- data/spec/integration/{dataset_info_spec.rb → gdal/dataset_info_spec.rb} +2 -6
- data/spec/integration/{driver_info_spec.rb → gdal/driver_info_spec.rb} +5 -5
- data/spec/integration/{geo_transform_info_spec.rb → gdal/geo_transform_info_spec.rb} +1 -14
- data/spec/integration/{raster_attribute_table_info_spec.rb → gdal/raster_attribute_table_info_spec.rb} +1 -2
- data/spec/integration/{raster_band_info_spec.rb → gdal/raster_band_info_spec.rb} +30 -42
- data/spec/integration/ogr/layer_spec.rb +97 -0
- data/spec/spec_helper.rb +94 -5
- data/spec/support/integration_help.rb +1 -0
- data/spec/support/shared_contexts.rb +26 -0
- data/spec/support/shared_examples/{major_object_examples.rb → gdal/major_object_examples.rb} +5 -5
- data/spec/support/shared_examples/ogr/a_25D_geometry.rb +7 -0
- data/spec/support/shared_examples/ogr/a_container_geometry.rb +47 -0
- data/spec/support/shared_examples/ogr/a_geometry.rb +404 -0
- data/spec/support/shared_examples/ogr/a_line_string.rb +16 -0
- data/spec/support/test_style_table.txt +3 -0
- data/spec/unit/ext/error_symbols_spec.rb +41 -53
- data/spec/unit/ext/numeric_as_data_type_spec.rb +113 -0
- data/spec/unit/ffi/gdal_spec.rb +70 -0
- data/spec/unit/gdal/color_entry_spec.rb +5 -0
- data/spec/unit/gdal/color_interpretation_spec.rb +5 -0
- data/spec/unit/gdal/{color_table_extensions_spec.rb → color_table_mixins/extensions_spec.rb} +3 -3
- data/spec/unit/gdal/color_table_spec.rb +14 -16
- data/spec/unit/gdal/data_type_spec.rb +10 -17
- data/spec/unit/gdal/dataset_spec.rb +4 -7
- data/spec/unit/gdal/driver_mixins/extensions_spec.rb +22 -0
- data/spec/unit/gdal/driver_spec.rb +49 -0
- data/spec/unit/gdal/environment_methods_spec.rb +6 -0
- data/spec/unit/gdal/geo_transform_spec.rb +276 -0
- data/spec/unit/gdal/grid_spec.rb +5 -0
- data/spec/unit/gdal/internal_helpers_spec.rb +112 -0
- data/spec/unit/gdal/major_object_spec.rb +6 -0
- data/spec/unit/gdal/options_spec.rb +5 -0
- data/spec/unit/gdal/raster_attribute_table_spec.rb +5 -0
- data/spec/unit/gdal/raster_band_classifier_spec.rb +134 -0
- data/spec/unit/gdal/raster_band_spec.rb +5 -0
- data/spec/unit/gdal/rpc_info_spec.rb +5 -0
- data/spec/unit/gdal/version_info_spec.rb +6 -0
- data/spec/unit/gdal/virtual_dataset_spec.rb +32 -0
- data/spec/unit/gdal/warp_operation_spec.rb +5 -0
- data/spec/unit/ogr/data_source_mixins/capability_methods_spec.rb +30 -0
- data/spec/unit/ogr/data_source_spec.rb +209 -0
- data/spec/unit/ogr/driver_mixins/capability_methods_spec.rb +18 -0
- data/spec/unit/ogr/driver_spec.rb +150 -0
- data/spec/unit/ogr/envelope_spec.rb +322 -0
- data/spec/unit/ogr/feature_definition_spec.rb +313 -0
- data/spec/unit/ogr/feature_spec.rb +379 -0
- data/spec/unit/ogr/field_definition_spec.rb +135 -0
- data/spec/unit/ogr/field_spec.rb +193 -0
- data/spec/unit/ogr/geometries/geometry_collection_spec.rb +186 -0
- data/spec/unit/ogr/geometries/line_string_spec.rb +105 -0
- data/spec/unit/ogr/{linear_ring_spec.rb → geometries/linear_ring_spec.rb} +10 -31
- data/spec/unit/ogr/geometries/multi_line_string_spec.rb +14 -0
- data/spec/unit/ogr/geometries/multi_point_spec.rb +14 -0
- data/spec/unit/ogr/geometries/multi_polygon_spec.rb +41 -0
- data/spec/unit/ogr/geometries/none_geometry_spec.rb +12 -0
- data/spec/unit/ogr/{point_spec.rb → geometries/point_spec.rb} +19 -25
- data/spec/unit/ogr/geometries/polygon_spec.rb +17 -0
- data/spec/unit/ogr/geometries/unknown_geometry_spec.rb +10 -0
- data/spec/unit/ogr/geometry_field_definition_spec.rb +87 -0
- data/spec/unit/ogr/geometry_spec.rb +542 -0
- data/spec/unit/ogr/internal_helpers_spec.rb +57 -0
- data/spec/unit/ogr/layer_mixins/capability_methods_spec.rb +88 -0
- data/spec/unit/ogr/layer_mixins/ogr_feature_methods_spec.rb +145 -0
- data/spec/unit/ogr/layer_mixins/ogr_field_methods_spec.rb +432 -0
- data/spec/unit/ogr/layer_mixins/ogr_layer_method_methods_spec.rb +20 -0
- data/spec/unit/ogr/layer_mixins/ogr_query_filter_methods_spec.rb +42 -0
- data/spec/unit/ogr/layer_mixins/ogr_sql_methods_spec.rb +12 -0
- data/spec/unit/ogr/layer_spec.rb +66 -67
- data/spec/unit/ogr/spatial_reference_mixins/coordinate_system_getter_setters_spec.rb +46 -0
- data/spec/unit/ogr/spatial_reference_mixins/exporters_spec.rb +139 -0
- data/spec/unit/ogr/spatial_reference_mixins/importers_spec.rb +38 -0
- data/spec/unit/ogr/spatial_reference_mixins/morphers_spec.rb +36 -0
- data/spec/unit/ogr/spatial_reference_mixins/parameter_getter_setters_spec.rb +102 -0
- data/spec/unit/ogr/spatial_reference_mixins/type_checks_spec.rb +157 -0
- data/spec/unit/ogr/spatial_reference_spec.rb +42 -0
- data/spec/unit/ogr/style_table_spec.rb +132 -0
- data/spec/unit/ogr/style_tool_spec.rb +157 -0
- data/spec/unit/version_info_spec.rb +1 -1
- metadata +285 -75
- data/lib/ffi/cpl/conv_h.rb +0 -143
- data/lib/ffi/cpl/error_h.rb +0 -63
- data/lib/ffi/cpl/minixml_h.rb +0 -14
- data/lib/ffi/cpl/string_h.rb +0 -81
- data/lib/ffi/cpl/vsi_h.rb +0 -112
- data/lib/ffi/gdal/alg_h.rb +0 -127
- data/lib/ffi/gdal/grid_h.rb +0 -51
- data/lib/ffi/gdal/warper_h.rb +0 -48
- data/lib/ffi/ogr/api_h.rb +0 -553
- data/lib/ffi/ogr/core_h.rb +0 -148
- data/lib/ffi/ogr/featurestyle_h.rb +0 -22
- data/lib/ffi/ogr/geocoding_h.rb +0 -21
- data/lib/ffi/ogr/ogr_field.rb +0 -50
- data/lib/ffi/ogr/ogr_style_param.rb +0 -12
- data/lib/ffi/ogr/srs_api_h.rb +0 -325
- data/lib/gdal/color_entry_extensions.rb +0 -30
- data/lib/gdal/color_table_extensions.rb +0 -47
- data/lib/gdal/dataset_extensions.rb +0 -496
- data/lib/gdal/driver_extensions.rb +0 -56
- data/lib/gdal/geo_transform_extensions.rb +0 -90
- data/lib/gdal/raster_attribute_table_extensions.rb +0 -40
- data/lib/gdal/raster_band_extensions.rb +0 -198
- data/lib/ogr/geometry_types/collection.rb +0 -45
- data/lib/ogr/layer_extensions.rb +0 -55
- data/lib/ogr/line_string.rb +0 -7
- data/lib/ogr/linear_ring.rb +0 -6
- data/lib/ogr/multi_line_string.rb +0 -9
- data/lib/ogr/multi_point.rb +0 -7
- data/lib/ogr/multi_polygon.rb +0 -14
- data/lib/ogr/point.rb +0 -89
- data/lib/ogr/polygon.rb +0 -9
data/lib/ogr/feature.rb
CHANGED
@@ -1,210 +1,458 @@
|
|
1
1
|
require_relative '../ffi/ogr'
|
2
2
|
require_relative 'feature_extensions'
|
3
3
|
require_relative 'feature_definition'
|
4
|
-
require_relative '
|
4
|
+
require_relative 'field_definition'
|
5
|
+
require 'date'
|
5
6
|
|
6
7
|
module OGR
|
7
8
|
class Feature
|
8
9
|
include FeatureExtensions
|
9
10
|
|
10
|
-
# @
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
# @return [FFI::Pointer] C pointer of the C Feature.
|
12
|
+
attr_reader :c_pointer
|
13
|
+
|
14
|
+
# @param fd_or_pointer [OGR::FeatureDefinition, FFI::Pointer] Must either be
|
15
|
+
# a FeatureDefinition (i.e. normal Feature creation) or a Pointer (in the
|
16
|
+
# case a handle to a C OGR Feature needs to be wrapped with this object).
|
17
|
+
def initialize(fd_or_pointer)
|
18
|
+
@c_pointer = if fd_or_pointer.is_a? OGR::FeatureDefinition
|
19
|
+
FFI::OGR::API.OGR_F_Create(fd_or_pointer.c_pointer)
|
20
|
+
else
|
21
|
+
fd_or_pointer
|
22
|
+
end
|
23
|
+
|
24
|
+
if !@c_pointer.is_a?(FFI::Pointer) || @c_pointer.null?
|
25
|
+
fail OGR::InvalidFeature, "Unable to create Feature with #{fd_or_pointer}"
|
26
|
+
end
|
16
27
|
|
17
|
-
|
28
|
+
close_me = -> { destroy! }
|
29
|
+
ObjectSpace.define_finalizer self, close_me
|
18
30
|
end
|
19
31
|
|
20
|
-
|
21
|
-
|
22
|
-
@feature_pointer = GDAL._pointer(OGR::Feature, feature)
|
32
|
+
def destroy!
|
33
|
+
return unless @c_pointer
|
23
34
|
|
24
|
-
|
25
|
-
|
35
|
+
FFI::OGR::API.OGR_F_Destroy(@c_pointer)
|
36
|
+
@c_pointer = nil
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [OGR::Feature]
|
40
|
+
# @raise [OGR::Failure] If, for some reason, the clone fails.
|
41
|
+
def clone
|
42
|
+
feature_ptr = FFI::OGR::API.OGR_F_Clone(@c_pointer)
|
43
|
+
fail OGR::Failure, 'Unable to clone feature' if feature_ptr.nil?
|
44
|
+
|
45
|
+
OGR::Feature.new(feature_ptr)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Dumps the feature out to the file in human-readable form.
|
49
|
+
#
|
50
|
+
# @param file_name [String]
|
51
|
+
def dump_readable(file_name)
|
52
|
+
FFI::OGR::API.OGR_F_DumpReadable(@c_pointer, file_name)
|
26
53
|
end
|
27
54
|
|
28
|
-
|
29
|
-
|
55
|
+
# Overwrites the contents of this feature from the geometry and attributes
|
56
|
+
# of the +other_feature+.
|
57
|
+
#
|
58
|
+
# @param _other_feature [OGR::Feature]
|
59
|
+
# @param _be_forgiving [Boolean] +true+ if the operation should continue
|
60
|
+
# despite lacking output fields matching some of the source fields.
|
61
|
+
# @param with_map [Array<Fixnum>]
|
62
|
+
# TODO: Implement +with_map+
|
63
|
+
def set_from!(_other_feature, _be_forgiving = false, with_map: nil)
|
64
|
+
fail NotImplementedError, 'with_map: is not yet supported' if with_map
|
65
|
+
|
66
|
+
ogr_err = FFI::OGR::API.OGR_F_SetFrom(@c_pointer, other_feature_ptr)
|
67
|
+
|
68
|
+
ogr_err.handle_result
|
30
69
|
end
|
31
70
|
|
71
|
+
# This will always be the same as the field count for the feature
|
72
|
+
# definition.
|
73
|
+
#
|
32
74
|
# @return [Fixnum]
|
33
75
|
def field_count
|
34
|
-
FFI::
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
76
|
+
FFI::OGR::API.OGR_F_GetFieldCount(@c_pointer)
|
77
|
+
end
|
78
|
+
|
79
|
+
# @param index [Fixnum]
|
80
|
+
# @param value [String]
|
81
|
+
def set_field_string(index, value)
|
82
|
+
FFI::OGR::API.OGR_F_SetFieldString(@c_pointer, index, value)
|
83
|
+
end
|
84
|
+
|
85
|
+
# @param index [Fixnum]
|
86
|
+
# @param value [Fixnum]
|
87
|
+
def set_field_integer(index, value)
|
88
|
+
FFI::OGR::API.OGR_F_SetFieldInteger(@c_pointer, index, value)
|
89
|
+
end
|
90
|
+
|
91
|
+
# @param index [Fixnum]
|
92
|
+
# @param value [Float]
|
93
|
+
def set_field_double(index, value)
|
94
|
+
FFI::OGR::API.OGR_F_SetFieldDouble(@c_pointer, index, value)
|
95
|
+
end
|
96
|
+
|
97
|
+
# @param index [Fixnum]
|
98
|
+
# @param values [Array<String>]
|
99
|
+
# @raise [GDAL::Error] If index isn't valid
|
100
|
+
def set_field_string_list(index, values)
|
101
|
+
values_ptr = GDAL._string_array_to_pointer(values)
|
102
|
+
|
103
|
+
FFI::OGR::API.OGR_F_SetFieldStringList(
|
104
|
+
@c_pointer,
|
105
|
+
index,
|
106
|
+
values_ptr)
|
107
|
+
end
|
108
|
+
|
109
|
+
# @param index [Fixnum]
|
110
|
+
# @param values [Array<Fixnum>]
|
111
|
+
def set_field_integer_list(index, values)
|
112
|
+
values_ptr = FFI::MemoryPointer.new(:int, values.size)
|
113
|
+
values_ptr.write_array_of_int(values)
|
114
|
+
|
115
|
+
FFI::OGR::API.OGR_F_SetFieldIntegerList(
|
116
|
+
@c_pointer,
|
117
|
+
index,
|
118
|
+
values.size,
|
119
|
+
values_ptr)
|
120
|
+
end
|
121
|
+
|
122
|
+
# @param index [Fixnum]
|
123
|
+
# @param values [Array<Float>]
|
124
|
+
def set_field_double_list(index, values)
|
125
|
+
values_ptr = FFI::MemoryPointer.new(:double, values.size)
|
126
|
+
values_ptr.write_array_of_double(values)
|
127
|
+
|
128
|
+
FFI::OGR::API.OGR_F_SetFieldDoubleList(
|
129
|
+
@c_pointer,
|
130
|
+
index,
|
131
|
+
values.size,
|
132
|
+
values_ptr)
|
133
|
+
end
|
134
|
+
|
135
|
+
# @param index [Fixnum]
|
136
|
+
# @param value [FFI::OGR::Field]
|
137
|
+
def set_field_raw(index, value)
|
138
|
+
raw_field_ptr = FFI::MemoryPointer.new(value)
|
139
|
+
usable_raw_field = FFI::OGR::Field.new(raw_field_ptr)
|
140
|
+
|
141
|
+
unless valid_raw_field?(index, usable_raw_field)
|
142
|
+
fail TypeError,
|
143
|
+
"Raw field is not of required field type: #{field_definition(index).type}"
|
65
144
|
end
|
145
|
+
|
146
|
+
FFI::OGR::API.OGR_F_SetFieldRaw(@c_pointer, index, value)
|
147
|
+
end
|
148
|
+
|
149
|
+
# @param index [Fixnum]
|
150
|
+
# @param value [String]
|
151
|
+
def set_field_binary(index, value)
|
152
|
+
fail TypeError, 'value must be a binary string' unless value.is_a? String
|
153
|
+
|
154
|
+
value_ptr = FFI::MemoryPointer.new(:uchar, value.length)
|
155
|
+
value_ptr.put_bytes(0, value)
|
156
|
+
|
157
|
+
FFI::OGR::API.OGR_F_SetFieldBinary(
|
158
|
+
@c_pointer,
|
159
|
+
index,
|
160
|
+
value.length,
|
161
|
+
value_ptr)
|
162
|
+
end
|
163
|
+
|
164
|
+
# @param index [Fixnum]
|
165
|
+
# @param value [Date, Time, DateTime]
|
166
|
+
def set_field_date_time(index, value)
|
167
|
+
time = value.to_time
|
168
|
+
zone = OGR._format_time_zone_for_ogr(time.zone)
|
169
|
+
|
170
|
+
FFI::OGR::API.OGR_F_SetFieldDateTime(@c_pointer, index,
|
171
|
+
time.year,
|
172
|
+
time.month,
|
173
|
+
time.day,
|
174
|
+
time.hour,
|
175
|
+
time.min,
|
176
|
+
time.sec,
|
177
|
+
zone)
|
66
178
|
end
|
67
179
|
|
68
180
|
# @param index [Fixnum]
|
69
|
-
# @return [OGR::
|
70
|
-
def
|
71
|
-
field_pointer = FFI::
|
181
|
+
# @return [OGR::FieldDefinition]
|
182
|
+
def field_definition(index)
|
183
|
+
field_pointer = FFI::OGR::API.OGR_F_GetFieldDefnRef(@c_pointer, index)
|
72
184
|
return nil if field_pointer.null?
|
73
185
|
|
74
|
-
OGR::
|
186
|
+
OGR::FieldDefinition.new(field_pointer, nil)
|
75
187
|
end
|
76
188
|
|
77
189
|
# @param name [String]
|
78
|
-
# @return [Fixnum]
|
190
|
+
# @return [Fixnum, nil]
|
79
191
|
def field_index(name)
|
80
|
-
FFI::
|
192
|
+
result = FFI::OGR::API.OGR_F_GetFieldIndex(@c_pointer, name)
|
193
|
+
|
194
|
+
result < 0 ? nil : result
|
81
195
|
end
|
82
196
|
|
83
197
|
# @param index [Fixnum]
|
84
198
|
# @return [Boolean]
|
85
199
|
def field_set?(index)
|
86
|
-
FFI::
|
200
|
+
FFI::OGR::API.OGR_F_IsFieldSet(@c_pointer, index)
|
87
201
|
end
|
88
202
|
|
89
203
|
# @param index [Fixnum]
|
90
204
|
def unset_field(index)
|
91
|
-
FFI::
|
205
|
+
FFI::OGR::API.OGR_F_UnsetField(@c_pointer, index)
|
92
206
|
end
|
93
207
|
|
94
208
|
# @return [OGR::FeatureDefinition,nil]
|
95
209
|
def definition
|
96
|
-
|
97
|
-
|
98
|
-
feature_defn_ptr = FFI::GDAL.OGR_F_GetDefnRef(@feature_pointer)
|
210
|
+
feature_defn_ptr = FFI::OGR::API.OGR_F_GetDefnRef(@c_pointer)
|
99
211
|
return nil if feature_defn_ptr.null?
|
100
212
|
|
101
|
-
|
213
|
+
OGR::FeatureDefinition.new(feature_defn_ptr)
|
102
214
|
end
|
103
215
|
|
104
216
|
# @return [OGR::Geometry]
|
105
217
|
def geometry
|
106
|
-
|
107
|
-
|
108
|
-
geometry_ptr = FFI::GDAL.OGR_F_GetGeometryRef(@feature_pointer)
|
218
|
+
geometry_ptr = FFI::OGR::API.OGR_F_GetGeometryRef(@c_pointer)
|
109
219
|
return nil if geometry_ptr.null?
|
110
220
|
|
111
|
-
|
221
|
+
OGR::Geometry.factory(geometry_ptr)
|
112
222
|
end
|
113
223
|
|
114
224
|
# @param new_geometry [OGR::Geometry]
|
115
225
|
# @return +true+ if successful, otherwise raises an OGR exception.
|
116
226
|
def geometry=(new_geometry)
|
117
|
-
ogr_err = FFI::
|
118
|
-
@geometry = new_geometry
|
227
|
+
ogr_err = FFI::OGR::API.OGR_F_SetGeometryDirectly(@c_pointer, new_geometry.c_pointer)
|
119
228
|
|
120
|
-
ogr_err.
|
229
|
+
ogr_err.handle_result
|
230
|
+
end
|
231
|
+
|
232
|
+
# @return [OGR::Geometry]
|
233
|
+
def steal_geometry
|
234
|
+
geometry_ptr = FFI::OGR::API.OGR_F_StealGeometry(@c_pointer)
|
235
|
+
fail OGR::Failure, 'Unable to steal geometry.' if geometry_ptr.nil?
|
236
|
+
|
237
|
+
OGR::Geometry.factory(geometry_ptr)
|
121
238
|
end
|
122
239
|
|
123
240
|
# @return [Fixnum]
|
124
241
|
def fid
|
125
|
-
FFI::
|
242
|
+
FFI::OGR::API.OGR_F_GetFID(@c_pointer)
|
126
243
|
end
|
127
244
|
|
128
245
|
# @param new_fid [Fixnum]
|
129
246
|
# @return +true+ if successful, otherwise raises an OGR exception.
|
130
247
|
def fid=(new_fid)
|
131
|
-
ogr_err = FFI::
|
248
|
+
ogr_err = FFI::OGR::API.OGR_F_SetFID(@c_pointer, new_fid)
|
132
249
|
|
133
|
-
ogr_err.
|
250
|
+
ogr_err.handle_result
|
134
251
|
end
|
135
252
|
|
253
|
+
# The number of Geometries in this feature.
|
254
|
+
#
|
136
255
|
# @return [Fixnum]
|
137
256
|
def geometry_field_count
|
138
|
-
FFI::
|
257
|
+
FFI::OGR::API.OGR_F_GetGeomFieldCount(@c_pointer)
|
258
|
+
end
|
259
|
+
|
260
|
+
# @param index [Fixnum]
|
261
|
+
# @return [OGR::GeometryFieldDefinition] A read-only
|
262
|
+
# OGR::GeometryFieldDefinition.
|
263
|
+
# @raise [OGR::InvalidGeometryFieldDefinition] If there isn't one at
|
264
|
+
# +index+.
|
265
|
+
def geometry_field_definition(index)
|
266
|
+
gfd_ptr = FFI::OGR::API.OGR_F_GetGeomFieldDefnRef(@c_pointer, index)
|
267
|
+
return nil if gfd_ptr.nil?
|
268
|
+
|
269
|
+
gfd = OGR::GeometryFieldDefinition.new(gfd_ptr)
|
270
|
+
gfd.read_only = true
|
271
|
+
|
272
|
+
gfd
|
273
|
+
end
|
274
|
+
|
275
|
+
# @param name [String]
|
276
|
+
# @return [Fixnum]
|
277
|
+
def geometry_field_index(name)
|
278
|
+
FFI::OGR::API.OGR_F_GetGeomFieldIndex(@c_pointer, name)
|
279
|
+
end
|
280
|
+
|
281
|
+
# @param index [Fixnum]
|
282
|
+
# @return [OGR::Geometry, nil] A read-only OGR::Geometry.
|
283
|
+
def geometry_field(index)
|
284
|
+
geometry_ptr = FFI::OGR::API.OGR_F_GetGeomFieldRef(@c_pointer, index)
|
285
|
+
return nil if geometry_ptr.nil? || geometry_ptr.null?
|
286
|
+
|
287
|
+
geometry = OGR::Geometry.factory(geometry_ptr)
|
288
|
+
geometry.read_only = true
|
289
|
+
|
290
|
+
geometry
|
291
|
+
end
|
292
|
+
|
293
|
+
# @param index [Fixnum]
|
294
|
+
# @param geometry [OGR::Geometry]
|
295
|
+
def set_geometry_field(index, geometry)
|
296
|
+
geometry_ptr = GDAL._pointer(OGR::Geometry, geometry)
|
297
|
+
fail OGR::InvalidGeometry if geometry_ptr.nil?
|
298
|
+
|
299
|
+
ogr_err =
|
300
|
+
# FFI::OGR::API.OGR_F_SetGeomFieldDirectly(@c_pointer, index, geometry_ptr)
|
301
|
+
FFI::OGR::API.OGR_F_SetGeomField(@c_pointer, index, geometry_ptr)
|
302
|
+
|
303
|
+
ogr_err.handle_result
|
139
304
|
end
|
140
305
|
|
141
306
|
# @return [Boolean]
|
142
307
|
def equal?(other_feature)
|
143
|
-
FFI::
|
308
|
+
FFI::OGR::API.OGR_F_Equal(@c_pointer, c_pointer_from(other_feature))
|
144
309
|
end
|
145
310
|
alias_method :equals?, :equal?
|
146
311
|
|
147
312
|
# @param index [Fixnum]
|
148
313
|
# @return [Fixnum]
|
149
314
|
def field_as_integer(index)
|
150
|
-
FFI::
|
315
|
+
FFI::OGR::API.OGR_F_GetFieldAsInteger(@c_pointer, index)
|
151
316
|
end
|
152
317
|
|
153
318
|
# @param index [Fixnum]
|
154
319
|
# @return [Array<Fixnum>]
|
155
320
|
def field_as_integer_list(index)
|
156
|
-
|
157
|
-
|
321
|
+
list_size_ptr = FFI::MemoryPointer.new(:int)
|
322
|
+
list_ptr =
|
323
|
+
FFI::OGR::API.OGR_F_GetFieldAsIntegerList(@c_pointer, index, list_size_ptr)
|
324
|
+
return [] if list_ptr.null?
|
158
325
|
|
159
|
-
|
326
|
+
list_ptr.read_array_of_int(list_size_ptr.read_int)
|
160
327
|
end
|
161
328
|
|
162
329
|
# @param index [Fixnum]
|
163
330
|
# @return [Float]
|
164
331
|
def field_as_double(index)
|
165
|
-
FFI::
|
332
|
+
FFI::OGR::API.OGR_F_GetFieldAsDouble(@c_pointer, index)
|
166
333
|
end
|
167
334
|
|
168
335
|
# @param index [Fixnum]
|
169
336
|
# @return [Array<Float>]
|
170
337
|
def field_as_double_list(index)
|
171
|
-
|
172
|
-
|
338
|
+
list_size_ptr = FFI::MemoryPointer.new(:int)
|
339
|
+
list_ptr =
|
340
|
+
FFI::OGR::API.OGR_F_GetFieldAsDoubleList(@c_pointer, index, list_size_ptr)
|
341
|
+
return [] if list_ptr.null?
|
173
342
|
|
174
|
-
|
343
|
+
list_ptr.read_array_of_double(list_size_ptr.read_int)
|
175
344
|
end
|
176
345
|
|
177
346
|
# @param index [Fixnum]
|
178
347
|
# @return [String]
|
179
348
|
def field_as_string(index)
|
180
|
-
FFI::
|
349
|
+
FFI::OGR::API.OGR_F_GetFieldAsString(@c_pointer, index)
|
181
350
|
end
|
182
351
|
|
183
352
|
# @param index [Fixnum]
|
184
353
|
# @return [Array<String>]
|
185
354
|
def field_as_string_list(index)
|
186
|
-
|
187
|
-
|
355
|
+
list_ptr =
|
356
|
+
FFI::OGR::API.OGR_F_GetFieldAsStringList(@c_pointer, index)
|
357
|
+
return [] if list_ptr.null?
|
358
|
+
|
359
|
+
list_ptr.get_array_of_string(0)
|
360
|
+
end
|
361
|
+
|
362
|
+
# @param index [Fixnum]
|
363
|
+
# @return [String]
|
364
|
+
def field_as_binary(index)
|
365
|
+
byte_count_ptr = FFI::MemoryPointer.new(:int)
|
366
|
+
binary_data = FFI::OGR::API.OGR_F_GetFieldAsBinary(
|
367
|
+
@c_pointer,
|
368
|
+
index,
|
369
|
+
byte_count_ptr
|
370
|
+
)
|
371
|
+
|
372
|
+
byte_count = byte_count_ptr.read_int
|
373
|
+
string = byte_count > 0 ? binary_data.read_bytes(byte_count) : ''
|
374
|
+
|
375
|
+
string.unpack('C*')
|
376
|
+
end
|
188
377
|
|
189
|
-
|
378
|
+
def field_as_date_time(index)
|
379
|
+
year_ptr = FFI::MemoryPointer.new(:int)
|
380
|
+
month_ptr = FFI::MemoryPointer.new(:int)
|
381
|
+
day_ptr = FFI::MemoryPointer.new(:int)
|
382
|
+
hour_ptr = FFI::MemoryPointer.new(:int)
|
383
|
+
minute_ptr = FFI::MemoryPointer.new(:int)
|
384
|
+
second_ptr = FFI::MemoryPointer.new(:int)
|
385
|
+
time_zone_flag_ptr = FFI::MemoryPointer.new(:int)
|
386
|
+
|
387
|
+
result = FFI::OGR::API.OGR_F_GetFieldAsDateTime(
|
388
|
+
@c_pointer,
|
389
|
+
index,
|
390
|
+
year_ptr,
|
391
|
+
month_ptr,
|
392
|
+
day_ptr,
|
393
|
+
hour_ptr,
|
394
|
+
minute_ptr,
|
395
|
+
second_ptr,
|
396
|
+
time_zone_flag_ptr
|
397
|
+
)
|
398
|
+
return nil unless result
|
399
|
+
|
400
|
+
formatted_tz = OGR._format_time_zone_for_ruby(time_zone_flag_ptr.read_int)
|
401
|
+
|
402
|
+
if formatted_tz
|
403
|
+
DateTime.new(
|
404
|
+
year_ptr.read_int,
|
405
|
+
month_ptr.read_int,
|
406
|
+
day_ptr.read_int,
|
407
|
+
hour_ptr.read_int,
|
408
|
+
minute_ptr.read_int,
|
409
|
+
second_ptr.read_int,
|
410
|
+
formatted_tz
|
411
|
+
)
|
412
|
+
else
|
413
|
+
DateTime.new(
|
414
|
+
year_ptr.read_int,
|
415
|
+
month_ptr.read_int,
|
416
|
+
day_ptr.read_int,
|
417
|
+
hour_ptr.read_int,
|
418
|
+
minute_ptr.read_int,
|
419
|
+
second_ptr.read_int
|
420
|
+
)
|
421
|
+
end
|
190
422
|
end
|
191
423
|
|
192
424
|
# @return [String]
|
193
425
|
def style_string
|
194
|
-
FFI::
|
426
|
+
FFI::OGR::API.OGR_F_GetStyleString(@c_pointer)
|
195
427
|
end
|
196
428
|
|
197
429
|
# @param new_style [String]
|
198
430
|
def style_string=(new_style)
|
199
|
-
FFI::
|
431
|
+
FFI::OGR::API.OGR_F_SetStyleString(@c_pointer, new_style)
|
432
|
+
end
|
433
|
+
|
434
|
+
# @return [OGR::StyleTable]
|
435
|
+
def style_table
|
436
|
+
style_table_ptr = FFI::OGR::API.OGR_F_GetStyleTable(@c_pointer)
|
437
|
+
return nil if style_table_ptr.nil? || style_table_ptr.null?
|
438
|
+
|
439
|
+
OGR::StyleTable.new(style_table_ptr)
|
440
|
+
end
|
441
|
+
|
442
|
+
# @param new_style_table [OGR::StyleTable]
|
443
|
+
def style_table=(new_style_table)
|
444
|
+
new_style_table_ptr = GDAL._pointer(OGR::StyleTable, new_style_table)
|
445
|
+
fail OGR::InvalidStyleTable unless new_style_table_ptr
|
446
|
+
|
447
|
+
FFI::OGR::API.OGR_F_SetStyleTableDirectly(@c_pointer, new_style_table_ptr)
|
200
448
|
end
|
201
449
|
|
202
450
|
private
|
203
451
|
|
204
|
-
def
|
452
|
+
def c_pointer_from(feature)
|
205
453
|
if feature.is_a? OGR::Feature
|
206
454
|
feature.c_pointer
|
207
|
-
elsif feature.
|
455
|
+
elsif feature.is_a? FFI::Pointer
|
208
456
|
feature
|
209
457
|
end
|
210
458
|
end
|