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
@@ -1,120 +1,163 @@
|
|
1
1
|
require_relative '../ffi/ogr'
|
2
2
|
require_relative 'feature_definition_extensions'
|
3
|
-
require_relative '
|
3
|
+
require_relative 'field_definition'
|
4
|
+
require_relative 'geometry_field_definition'
|
4
5
|
|
5
6
|
module OGR
|
6
7
|
class FeatureDefinition
|
7
8
|
include FeatureDefinitionExtensions
|
8
9
|
|
9
|
-
# @
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
10
|
+
# @return [FFI::Pointer] C pointer of the C FeatureDefn.
|
11
|
+
attr_reader :c_pointer
|
12
|
+
|
13
|
+
# @param name_or_pointer [String, FFI::Pointer] When given a String, it will
|
14
|
+
# create a new FeatureDefinition with that name. When given an
|
15
|
+
# FFI::Pointer, the new object will simply wrap the C FeatureDefinition
|
16
|
+
# at that address.
|
17
|
+
def initialize(name_or_pointer)
|
18
|
+
@c_pointer = if name_or_pointer.is_a? String
|
19
|
+
FFI::OGR::API.OGR_FD_Create(name_or_pointer)
|
20
|
+
else
|
21
|
+
name_or_pointer
|
22
|
+
end
|
23
|
+
|
24
|
+
if !@c_pointer.is_a?(FFI::Pointer) || @c_pointer.null?
|
25
|
+
fail OGR::InvalidFeatureDefinition, "Unable to create #{self.class.name} from #{name_or_pointer}"
|
26
|
+
end
|
27
|
+
|
28
|
+
close_me = -> { FFI::OGR::API.OGR_FD_Destroy(@c_pointer) }
|
23
29
|
ObjectSpace.define_finalizer self, close_me
|
24
30
|
end
|
25
31
|
|
26
|
-
def
|
27
|
-
@
|
32
|
+
def release!
|
33
|
+
FFI::OGR::API.OGR_FD_Release(@c_pointer)
|
28
34
|
end
|
29
35
|
|
30
36
|
# @return [String]
|
31
37
|
def name
|
32
|
-
FFI::
|
38
|
+
FFI::OGR::API.OGR_FD_GetName(@c_pointer)
|
33
39
|
end
|
34
40
|
|
35
41
|
# @return [Fixnum]
|
36
42
|
def field_count
|
37
|
-
FFI::
|
43
|
+
FFI::OGR::API.OGR_FD_GetFieldCount(@c_pointer)
|
38
44
|
end
|
39
45
|
|
40
46
|
# @param index [Fixnum]
|
41
|
-
# @return [OGR::
|
42
|
-
def
|
43
|
-
|
44
|
-
|
47
|
+
# @return [OGR::FieldDefinition]
|
48
|
+
def field_definition(index)
|
49
|
+
field_definition_ptr =
|
50
|
+
FFI::OGR::API.OGR_FD_GetFieldDefn(@c_pointer, index)
|
51
|
+
return nil if field_definition_ptr.null?
|
45
52
|
|
46
|
-
OGR::
|
53
|
+
OGR::FieldDefinition.new(field_definition_ptr, nil)
|
54
|
+
end
|
55
|
+
|
56
|
+
# @param field_definition [OGR::FieldDefinition, FFI::Pointer]
|
57
|
+
def add_field_definition(field_definition)
|
58
|
+
field_definition_ptr = GDAL._pointer(OGR::FieldDefinition, field_definition)
|
59
|
+
|
60
|
+
if field_definition_ptr.nil?
|
61
|
+
fail OGR::InvalidFieldDefinition, "Unable to add OGR::FieldDefinition: '#{field_definition}'"
|
62
|
+
end
|
63
|
+
|
64
|
+
FFI::OGR::API.OGR_FD_AddFieldDefn(@c_pointer, field_definition_ptr)
|
65
|
+
end
|
66
|
+
|
67
|
+
# @param index [Fixnum] Index of the field definition to delete.
|
68
|
+
# @return [Boolean]
|
69
|
+
def delete_field_definition(index)
|
70
|
+
ogr_err = FFI::OGR::API.OGR_FD_DeleteFieldDefn(
|
71
|
+
@c_pointer,
|
72
|
+
index)
|
73
|
+
|
74
|
+
ogr_err.handle_result "Unable to delete field definition at index #{index}"
|
47
75
|
end
|
48
76
|
|
49
77
|
# @param name [String]
|
50
|
-
# @return [Fixnum]
|
78
|
+
# @return [Fixnum] nil if no match found
|
51
79
|
def field_index(name)
|
52
|
-
FFI::
|
80
|
+
result = FFI::OGR::API.OGR_FD_GetFieldIndex(@c_pointer, name)
|
81
|
+
|
82
|
+
result < 0 ? nil : result
|
53
83
|
end
|
54
84
|
|
55
|
-
# @return [FFI::
|
85
|
+
# @return [FFI::OGR::API::WKBGeometryType]
|
56
86
|
def geometry_type
|
57
|
-
FFI::
|
87
|
+
FFI::OGR::API.OGR_FD_GetGeomType(@c_pointer)
|
58
88
|
end
|
59
89
|
|
60
|
-
# @param new_type [FFI::
|
90
|
+
# @param new_type [FFI::OGR::API::WKBGeometryType]
|
61
91
|
def geometry_type=(new_type)
|
62
|
-
FFI::
|
92
|
+
FFI::OGR::API.OGR_FD_SetGeomType(@c_pointer, new_type)
|
63
93
|
end
|
64
94
|
|
65
95
|
# @return [Boolean]
|
66
96
|
def geometry_ignored?
|
67
|
-
FFI::
|
97
|
+
FFI::OGR::API.OGR_FD_IsGeometryIgnored(@c_pointer)
|
68
98
|
end
|
69
99
|
|
70
100
|
# @param ignore [Boolean]
|
71
|
-
def ignore_geometry!(ignore)
|
72
|
-
FFI::
|
101
|
+
def ignore_geometry!(ignore = true)
|
102
|
+
FFI::OGR::API.OGR_FD_SetGeometryIgnored(@c_pointer, ignore)
|
73
103
|
end
|
74
104
|
|
75
105
|
# @return [Boolean]
|
76
106
|
def style_ignored?
|
77
|
-
FFI::
|
107
|
+
FFI::OGR::API.OGR_FD_IsStyleIgnored(@c_pointer)
|
78
108
|
end
|
79
109
|
|
80
110
|
# @param ignore [Boolean]
|
81
|
-
def ignore_style!(ignore)
|
82
|
-
FFI::
|
111
|
+
def ignore_style!(ignore = true)
|
112
|
+
FFI::OGR::API.OGR_FD_SetStyleIgnored(@c_pointer, ignore)
|
83
113
|
end
|
84
114
|
|
85
115
|
# @return [Fixnum]
|
86
116
|
def geometry_field_count
|
87
|
-
FFI::
|
117
|
+
FFI::OGR::API.OGR_FD_GetGeomFieldCount(@c_pointer)
|
88
118
|
end
|
89
119
|
|
90
120
|
# @param index [Fixnum]
|
91
|
-
# @return [OGR::
|
121
|
+
# @return [OGR::GeometryFieldDefinition]
|
92
122
|
def geometry_field_definition(index)
|
93
|
-
|
94
|
-
|
123
|
+
geometry_field_definition_ptr =
|
124
|
+
FFI::OGR::API.OGR_FD_GetGeomFieldDefn(@c_pointer, index)
|
125
|
+
return nil if geometry_field_definition_ptr.null?
|
95
126
|
|
96
|
-
OGR::
|
127
|
+
OGR::GeometryFieldDefinition.new(geometry_field_definition_ptr)
|
97
128
|
end
|
98
129
|
|
99
130
|
# @param name [String]
|
100
131
|
# @return [Fixnum]
|
101
132
|
def geometry_field_index(name)
|
102
|
-
FFI::
|
133
|
+
result = FFI::OGR::API.OGR_FD_GetGeomFieldIndex(@c_pointer, name)
|
134
|
+
|
135
|
+
result < 0 ? nil : result
|
103
136
|
end
|
104
137
|
|
105
|
-
# @param
|
106
|
-
|
107
|
-
|
108
|
-
|
138
|
+
# @param geometry_field_definition [OGR::GeometryFieldDefinition, FFI::Pointer]
|
139
|
+
def add_geometry_field_definition(geometry_field_definition)
|
140
|
+
geometry_field_definition_ptr = GDAL._pointer(OGR::GeometryFieldDefinition,
|
141
|
+
geometry_field_definition)
|
142
|
+
FFI::OGR::API.OGR_FD_AddGeomFieldDefn(@c_pointer,
|
143
|
+
geometry_field_definition_ptr)
|
144
|
+
end
|
145
|
+
|
146
|
+
# @param index [Fixnum]
|
147
|
+
# @return [Boolean]
|
148
|
+
def delete_geometry_field_definition(index)
|
149
|
+
ogr_err = FFI::OGR::API.OGR_FD_DeleteGeomFieldDefn(@c_pointer,
|
150
|
+
index)
|
151
|
+
|
152
|
+
ogr_err.handle_result "Unable to delete geometry field definition at index #{index}"
|
109
153
|
end
|
110
154
|
|
111
|
-
# @param
|
155
|
+
# @param other_feature_definition [OGR::Feature, FFI::Pointer]
|
112
156
|
# @return [Boolean]
|
113
|
-
def same?(
|
114
|
-
fd_ptr = GDAL._pointer(OGR::FeatureDefinition,
|
157
|
+
def same?(other_feature_definition)
|
158
|
+
fd_ptr = GDAL._pointer(OGR::FeatureDefinition, other_feature_definition)
|
115
159
|
|
116
|
-
FFI::
|
160
|
+
FFI::OGR::API.OGR_FD_IsSame(@c_pointer, fd_ptr)
|
117
161
|
end
|
118
|
-
alias_method :==, :same?
|
119
162
|
end
|
120
163
|
end
|
@@ -2,35 +2,58 @@ require 'json'
|
|
2
2
|
|
3
3
|
module OGR
|
4
4
|
module FeatureDefinitionExtensions
|
5
|
+
# @return [Array<OGR::FieldDefinition>]
|
6
|
+
def field_definitions
|
7
|
+
return [] if field_count.zero?
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
field_count.times.map do |i|
|
10
|
+
field_definition(i)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [Array<OGR::GeometryFieldDefinition>]
|
15
|
+
def geometry_field_definitions
|
16
|
+
return [] if geometry_field_count.zero?
|
17
|
+
|
18
|
+
geometry_field_count.times.map do |i|
|
19
|
+
geometry_field_definition(i)
|
10
20
|
end
|
11
21
|
end
|
12
22
|
|
13
23
|
# @param name [String]
|
14
|
-
# @return [OGR::
|
15
|
-
def
|
16
|
-
|
24
|
+
# @return [OGR::FieldDefinition]
|
25
|
+
def field_definition_by_name(name)
|
26
|
+
i = field_index(name)
|
27
|
+
return unless i
|
28
|
+
|
29
|
+
field_definition(i)
|
30
|
+
end
|
31
|
+
|
32
|
+
# @param name [String]
|
33
|
+
# @return [OGR::GeometryFieldDefinition]
|
34
|
+
def geometry_field_definition_by_name(name)
|
35
|
+
g = geometry_field_index(name)
|
36
|
+
return unless g
|
37
|
+
|
38
|
+
geometry_field_definition(g)
|
17
39
|
end
|
18
40
|
|
19
41
|
# @return [Hash]
|
20
|
-
def as_json
|
42
|
+
def as_json(_options = nil)
|
21
43
|
{
|
22
44
|
field_count: field_count,
|
23
|
-
|
45
|
+
field_definitions: field_definitions.map(&:as_json),
|
24
46
|
geometry_field_count: geometry_field_count,
|
25
47
|
geometry_type: geometry_type,
|
26
|
-
|
27
|
-
is_style_ignored: style_ignored
|
48
|
+
is_geometry_ignored: geometry_ignored?,
|
49
|
+
is_style_ignored: style_ignored?,
|
50
|
+
name: name
|
28
51
|
}
|
29
52
|
end
|
30
53
|
|
31
54
|
# @return [String]
|
32
|
-
def to_json
|
33
|
-
as_json.to_json
|
55
|
+
def to_json(options = nil)
|
56
|
+
as_json(options).to_json
|
34
57
|
end
|
35
58
|
end
|
36
59
|
end
|
@@ -2,30 +2,81 @@ require 'json'
|
|
2
2
|
|
3
3
|
module OGR
|
4
4
|
module FeatureExtensions
|
5
|
-
|
6
|
-
#
|
5
|
+
# @return [Array] Uses each FieldDefinition to determine the field type at
|
6
|
+
# each index and returns maps the field as that value type.
|
7
7
|
def fields
|
8
|
-
|
9
|
-
|
8
|
+
field_count.times.map do |i|
|
9
|
+
case field_definition(i).type
|
10
|
+
when :OFTInteger then field_as_integer(i)
|
11
|
+
when :OFTIntegerList then field_as_integer_list(i)
|
12
|
+
when :OFTReal then field_as_double(i)
|
13
|
+
when :OFTRealList then field_as_double_list(i)
|
14
|
+
when :OFTString then field_as_string(i)
|
15
|
+
when :OFTStringList then field_as_string_list(i)
|
16
|
+
when :OFTWideString then field_as_string(i)
|
17
|
+
when :OFTWideStringList then field_as_string_list(i)
|
18
|
+
when :OFTBinary then field_as_binary(i)
|
19
|
+
when :OFTDate, :OFTTime, :OFTDateTime then field_as_date_time(i)
|
20
|
+
when :OFTInteger64 then field_as_integer(i)
|
21
|
+
when :OFTInteger64List then field_as_integer_lsit(i)
|
22
|
+
when :OFTMaxType then field_as_date_time(i)
|
23
|
+
else fail "not sure about field type: #{fd.type}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [Array<OGR::Geometry>]
|
29
|
+
def geometry_fields
|
30
|
+
geometry_field_count.times.map do |i|
|
31
|
+
geometry_field(i)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# TODO: this seems really wonky...
|
36
|
+
def valid_raw_field?(index, raw_field)
|
37
|
+
field_def = field_definition(index)
|
38
|
+
|
39
|
+
case field_def.type
|
40
|
+
when :OFTInteger then !raw_field[:integer].nil?
|
41
|
+
when :OFTIntegerList then !raw_field[:integer_list].nil?
|
42
|
+
when :OFTInteger64 then !raw_field[:integer64].nil?
|
43
|
+
when :OFTInteger64List then !raw_field[:integer64_list].nil?
|
44
|
+
when :OFTReal then !raw_field[:real].nil?
|
45
|
+
when :OFTRealList then !raw_field[:real_list].nil?
|
46
|
+
when :OFTString then !raw_field[:string].nil?
|
47
|
+
when :OFTStringList then !raw_field[:string_list].nil?
|
48
|
+
when :OFTBinary then !raw_field[:binary].nil?
|
49
|
+
when :OFTDate then !raw_field[:date].nil?
|
50
|
+
else
|
51
|
+
fail OGR::Failure, "Not sure how to set raw type: #{field_def.type}"
|
10
52
|
end
|
11
53
|
end
|
12
54
|
|
13
55
|
# @return [Hash]
|
14
|
-
def as_json
|
56
|
+
def as_json(options = nil)
|
57
|
+
fields_with_nested_json = fields.map do |f|
|
58
|
+
{
|
59
|
+
field_definition: f[:field_definition].as_json(options),
|
60
|
+
value_as_string: f[:value_as_string]
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
15
64
|
{
|
16
|
-
definition: definition,
|
65
|
+
definition: definition.as_json(options),
|
17
66
|
fid: fid,
|
18
67
|
field_count: field_count,
|
19
|
-
fields:
|
20
|
-
geometry: geometry.as_json,
|
68
|
+
fields: fields_with_nested_json,
|
69
|
+
geometry: geometry ? geometry.as_json(options) : nil,
|
21
70
|
geometry_field_count: geometry_field_count,
|
22
|
-
|
71
|
+
geometry_field_definitions: geometry_field_definitions.map(&:as_json),
|
72
|
+
style_string: style_string,
|
73
|
+
style_table: style_table ? style_table.as_json(options) : nil
|
23
74
|
}
|
24
75
|
end
|
25
76
|
|
26
77
|
# @return [String]
|
27
|
-
def to_json
|
28
|
-
as_json.to_json
|
78
|
+
def to_json(options = nil)
|
79
|
+
as_json(options).to_json
|
29
80
|
end
|
30
81
|
end
|
31
82
|
end
|
data/lib/ogr/field.rb
CHANGED
@@ -1,91 +1,212 @@
|
|
1
|
-
|
2
|
-
require_relative 'field_extensions'
|
1
|
+
require 'date'
|
3
2
|
|
4
3
|
module OGR
|
5
4
|
class Field
|
6
|
-
|
7
|
-
|
8
|
-
# @param name [String]
|
9
|
-
# @param type [FFI::GDAL::OGRFieldType]
|
10
|
-
# @return [OGR::Field]
|
11
|
-
def self.create(name, type)
|
12
|
-
field_ptr = FFI::GDAL.OGR_Fld_Create(name, type)
|
13
|
-
return nil if field_ptr.null?
|
5
|
+
# @return [FFI::OGR::Point]
|
6
|
+
attr_reader :c_struct
|
14
7
|
|
15
|
-
|
8
|
+
# @param ogr_field_struct [FFI::OGR::Point, FFI::Pointer]
|
9
|
+
def initialize(ogr_field_struct = nil)
|
10
|
+
@c_struct = ogr_field_struct || ::FFI::OGR::Field.new
|
16
11
|
end
|
17
12
|
|
18
|
-
# @
|
19
|
-
def
|
20
|
-
@
|
13
|
+
# @return [FFI::Pointer]
|
14
|
+
def c_pointer
|
15
|
+
@c_struct.to_ptr
|
21
16
|
end
|
22
17
|
|
23
|
-
|
24
|
-
|
18
|
+
# @return [Fixnum]
|
19
|
+
def integer
|
20
|
+
@c_struct[:integer]
|
25
21
|
end
|
22
|
+
alias_method :to_i, :integer
|
26
23
|
|
27
|
-
|
28
|
-
|
24
|
+
# @param new_int [Fixnum]
|
25
|
+
def integer=(new_int)
|
26
|
+
@c_struct[:integer] = new_int
|
29
27
|
end
|
30
28
|
|
31
|
-
# @return [
|
32
|
-
def
|
33
|
-
|
29
|
+
# @return [Bignum]
|
30
|
+
def integer64
|
31
|
+
@c_struct[:integer64]
|
34
32
|
end
|
35
33
|
|
36
|
-
# @param
|
37
|
-
def
|
38
|
-
|
34
|
+
# @param new_int64 [Bignum]
|
35
|
+
def integer64=(new_int64)
|
36
|
+
@c_struct[:integer64] = new_int64
|
39
37
|
end
|
40
38
|
|
41
|
-
# @return [
|
42
|
-
def
|
43
|
-
|
39
|
+
# @return [Float]
|
40
|
+
def real
|
41
|
+
@c_struct[:real]
|
44
42
|
end
|
43
|
+
alias_method :to_f, :real
|
45
44
|
|
46
|
-
# @param
|
47
|
-
def
|
48
|
-
|
45
|
+
# @param new_real [Float]
|
46
|
+
def real=(new_real)
|
47
|
+
@c_struct[:real] = new_real
|
49
48
|
end
|
50
49
|
|
51
|
-
#
|
52
|
-
def
|
53
|
-
|
50
|
+
# TODO: This blows up when another value type has been set.
|
51
|
+
def string
|
52
|
+
return '' if @c_struct[:string] && @c_struct[:string].null?
|
53
|
+
|
54
|
+
@c_struct[:string].read_string
|
54
55
|
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
FFI::GDAL.OGR_Fld_SetPrecision(@field_pointer, new_value)
|
57
|
+
def string=(new_string)
|
58
|
+
@c_struct[:string] = FFI::MemoryPointer.from_string(new_string)
|
59
59
|
end
|
60
60
|
|
61
|
-
# @return [
|
62
|
-
def
|
63
|
-
|
61
|
+
# @return [Array<Fixnum>]
|
62
|
+
def integer_list
|
63
|
+
il = @c_struct[:integer_list]
|
64
|
+
return [] if il[:count].zero?
|
65
|
+
|
66
|
+
il[:list].read_array_of_int(il[:count])
|
64
67
|
end
|
65
68
|
|
66
|
-
# @param
|
67
|
-
def
|
68
|
-
FFI::
|
69
|
+
# @param new_integer_list [Array<Fixnum>]
|
70
|
+
def integer_list=(new_integer_list)
|
71
|
+
list_ptr = FFI::MemoryPointer.new(:int, new_integer_list.size)
|
72
|
+
list_ptr.write_array_of_int(new_integer_list)
|
73
|
+
|
74
|
+
il = FFI::OGR::FieldTypes::IntegerList.new
|
75
|
+
il[:count] = new_integer_list.size
|
76
|
+
il[:list] = list_ptr
|
77
|
+
|
78
|
+
@c_struct[:integer_list] = il
|
69
79
|
end
|
70
80
|
|
71
|
-
# @return [
|
72
|
-
def
|
73
|
-
|
81
|
+
# @return [Array<Bignum>]
|
82
|
+
def integer64_list
|
83
|
+
il = @c_struct[:integer_list]
|
84
|
+
return [] if il[:count].zero?
|
85
|
+
|
86
|
+
il[:list].read_array_of_int64(il[:count])
|
87
|
+
end
|
88
|
+
alias_method :to_bignum, :integer64_list
|
89
|
+
|
90
|
+
# @param new_integer64_list [Array<Bignum>]
|
91
|
+
def integer64_list=(new_integer64_list)
|
92
|
+
list_ptr = FFI::MemoryPointer.new(:int64, new_integer64_list.size)
|
93
|
+
list_ptr.write_array_of_int64(new_integer64_list)
|
94
|
+
|
95
|
+
il = FFI::OGR::FieldTypes::Integer64List.new
|
96
|
+
il[:count] = new_integer64_list.size
|
97
|
+
il[:list] = list_ptr
|
98
|
+
|
99
|
+
@c_struct[:integer64_list] = il
|
100
|
+
end
|
101
|
+
alias_method :bignum_list=, :integer64_list=
|
102
|
+
|
103
|
+
# @return [Array<Float>]
|
104
|
+
def real_list
|
105
|
+
rl = @c_struct[:real_list]
|
106
|
+
return [] if rl[:count].zero?
|
107
|
+
|
108
|
+
rl[:list].read_array_of_double(rl[:count])
|
109
|
+
end
|
110
|
+
alias_method :float_list, :real_list
|
111
|
+
|
112
|
+
# @param new_real_list [Array<Float>]
|
113
|
+
def real_list=(new_real_list)
|
114
|
+
list_ptr = FFI::MemoryPointer.new(:double, new_real_list.size)
|
115
|
+
list_ptr.write_array_of_double(new_real_list)
|
116
|
+
|
117
|
+
rl = FFI::OGR::FieldTypes::RealList.new
|
118
|
+
rl[:count] = new_real_list.size
|
119
|
+
rl[:list] = list_ptr
|
120
|
+
|
121
|
+
@c_struct[:real_list] = rl
|
74
122
|
end
|
123
|
+
alias_method :float_list=, :real_list=
|
75
124
|
|
76
|
-
# @
|
77
|
-
def
|
78
|
-
|
125
|
+
# @return [Array<String>]
|
126
|
+
def string_list
|
127
|
+
sl = @c_struct[:string_list]
|
128
|
+
return [] if sl[:count].zero?
|
129
|
+
|
130
|
+
sl[:list].read_array_of_pointer(sl[:count]).map(&:read_string)
|
131
|
+
end
|
132
|
+
|
133
|
+
# @param new_string_list [Array<String>]
|
134
|
+
def string_list=(new_string_list)
|
135
|
+
list_ptr = GDAL._string_array_to_pointer(new_string_list)
|
136
|
+
|
137
|
+
sl = FFI::OGR::FieldTypes::StringList.new
|
138
|
+
sl[:count] = new_string_list.size
|
139
|
+
sl[:list] = list_ptr
|
140
|
+
|
141
|
+
@c_struct[:string_list] = sl
|
79
142
|
end
|
80
143
|
|
81
|
-
# @return [
|
82
|
-
|
83
|
-
|
144
|
+
# @return [String] 8-bit, unsigned data (uchar). Unpack with
|
145
|
+
# String#unpack('C*').
|
146
|
+
def binary
|
147
|
+
b = @c_struct[:binary]
|
148
|
+
|
149
|
+
b[:count] > 0 ? b[:data].read_bytes(b[:count]) : ''
|
84
150
|
end
|
85
151
|
|
86
|
-
# @param
|
87
|
-
|
88
|
-
|
152
|
+
# @param new_binary [String] Binary string of 8-bit, unsigned data (uchar).
|
153
|
+
# Pack with Array#pack('C*').
|
154
|
+
def binary=(new_binary)
|
155
|
+
data = FFI::MemoryPointer.new(:uchar, new_binary.length)
|
156
|
+
data.put_bytes(0, new_binary)
|
157
|
+
|
158
|
+
b = FFI::OGR::FieldTypes::Binary.new
|
159
|
+
b[:data] = data
|
160
|
+
b[:count] = new_binary.length
|
161
|
+
|
162
|
+
@c_struct[:binary] = b
|
163
|
+
end
|
164
|
+
|
165
|
+
# @return [Hash]
|
166
|
+
def set
|
167
|
+
{ marker1: @c_struct[:set][:marker1], marker2: @c_struct[:set][:marker2] }
|
168
|
+
end
|
169
|
+
|
170
|
+
# @param new_set [Hash{marker1 => Fixnum, marker2 => Fixnum}]
|
171
|
+
def set=(new_set)
|
172
|
+
set = FFI::OGR::FieldTypes::Set.new
|
173
|
+
set[:marker1] = new_set[:marker1]
|
174
|
+
set[:marker2] = new_set[:marker2]
|
175
|
+
|
176
|
+
@c_struct[:set] = set
|
177
|
+
end
|
178
|
+
|
179
|
+
# @return [DateTime]
|
180
|
+
def date
|
181
|
+
c_date = @c_struct[:date]
|
182
|
+
return if c_date[:year].zero? || c_date[:month].zero? || c_date[:day].zero?
|
183
|
+
|
184
|
+
formatted_tz = OGR._format_time_zone_for_ruby(c_date[:tz_flag].to_i)
|
185
|
+
|
186
|
+
DateTime.new(c_date[:year],
|
187
|
+
c_date[:month],
|
188
|
+
c_date[:day],
|
189
|
+
c_date[:hour],
|
190
|
+
c_date[:minute],
|
191
|
+
c_date[:second],
|
192
|
+
formatted_tz)
|
193
|
+
end
|
194
|
+
|
195
|
+
# @param new_date [Date, Time, DateTime]
|
196
|
+
def date=(new_date)
|
197
|
+
time = new_date.to_time
|
198
|
+
zone = OGR._format_time_zone_for_ogr(time.zone)
|
199
|
+
|
200
|
+
date = FFI::OGR::FieldTypes::Date.new
|
201
|
+
date[:year] = time.year
|
202
|
+
date[:month] = time.month
|
203
|
+
date[:day] = time.day
|
204
|
+
date[:hour] = time.hour
|
205
|
+
date[:minute] = time.min
|
206
|
+
date[:second] = time.sec
|
207
|
+
date[:tz_flag] = zone
|
208
|
+
|
209
|
+
@c_struct[:date] = date
|
89
210
|
end
|
90
211
|
end
|
91
212
|
end
|