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
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gdal/internal_helpers'
|
3
|
+
require 'ogr/spatial_reference'
|
4
|
+
require 'gdal/dataset'
|
5
|
+
|
6
|
+
RSpec.describe GDAL::InternalHelpers do
|
7
|
+
subject(:tester) do
|
8
|
+
module Tester
|
9
|
+
include GDAL::InternalHelpers
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '._pointer' do
|
14
|
+
context 'variable is a kind of the klass that was passed in' do
|
15
|
+
let(:variable) { OGR::SpatialReference.new }
|
16
|
+
|
17
|
+
it "returns the variable's pointer with autorelease = true" do
|
18
|
+
expect(variable.c_pointer).to receive(:autorelease=).with(true)
|
19
|
+
expect(subject._pointer(OGR::SpatialReference, variable)).to eq variable.c_pointer
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'variable is an FFI::Pointer' do
|
24
|
+
let(:variable) { FFI::MemoryPointer.new(:pointer) }
|
25
|
+
|
26
|
+
it 'returns the pointer with autorelease = true' do
|
27
|
+
expect(variable).to receive(:autorelease=).with(true)
|
28
|
+
expect(subject._pointer(GDAL::Dataset, variable)).to eq variable
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'variable is nil' do
|
33
|
+
it 'returns nil' do
|
34
|
+
expect(subject._pointer(GDAL::Dataset, nil, false)).to be_nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '._string_array_to_pointer' do
|
40
|
+
context 'an array' do
|
41
|
+
let(:array) { ['one', 2, 3.0, :four] }
|
42
|
+
|
43
|
+
it 'returns a pointer that contains the array values as strings' do
|
44
|
+
pointer = subject._string_array_to_pointer(array)
|
45
|
+
expect(pointer).to be_an FFI::MemoryPointer
|
46
|
+
expect(pointer.get_array_of_string(0)).to eq %w[one 2 3.0 four]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'not an array' do
|
51
|
+
it 'raises an error about no responding to #map' do
|
52
|
+
expect do
|
53
|
+
subject._string_array_to_pointer('blarg')
|
54
|
+
end.to raise_exception NoMethodError
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '._gdal_data_type_to_ffi' do
|
60
|
+
context 'data type is :GDT_Byte' do
|
61
|
+
subject { tester._gdal_data_type_to_ffi(:GDT_Byte) }
|
62
|
+
it { is_expected.to eq :uchar }
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'data type is :GDT_UInt16' do
|
66
|
+
subject { tester._gdal_data_type_to_ffi(:GDT_UInt16) }
|
67
|
+
it { is_expected.to eq :uint16 }
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'data type is :GDT_Int16' do
|
71
|
+
subject { tester._gdal_data_type_to_ffi(:GDT_Int16) }
|
72
|
+
it { is_expected.to eq :int16 }
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'data type is :GDT_UInt32' do
|
76
|
+
subject { tester._gdal_data_type_to_ffi(:GDT_UInt32) }
|
77
|
+
it { is_expected.to eq :uint32 }
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'data type is :GDT_Int32' do
|
81
|
+
subject { tester._gdal_data_type_to_ffi(:GDT_Int32) }
|
82
|
+
it { is_expected.to eq :int32 }
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'data type is :GDT_Float32' do
|
86
|
+
subject { tester._gdal_data_type_to_ffi(:GDT_Float32) }
|
87
|
+
it { is_expected.to eq :float }
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'data type is :GDT_Float64' do
|
91
|
+
subject { tester._gdal_data_type_to_ffi(:GDT_Float64) }
|
92
|
+
it { is_expected.to eq :double }
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'data type is not one listed' do
|
96
|
+
subject { tester._gdal_data_type_to_ffi(:blargh) }
|
97
|
+
it { is_expected.to eq :float }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '._supported?' do
|
102
|
+
context 'function is supported' do
|
103
|
+
subject { tester._supported?(:GDALAllRegister) }
|
104
|
+
it { is_expected.to eq true }
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'function is not supported' do
|
108
|
+
subject { tester._supported?(:darrells) }
|
109
|
+
it { is_expected.to eq false }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gdal/driver'
|
3
|
+
require 'gdal/raster_band_classifier'
|
4
|
+
|
5
|
+
RSpec.describe GDAL::RasterBandClassifier do
|
6
|
+
let(:driver) { GDAL::Driver.by_name('MEM') }
|
7
|
+
|
8
|
+
let(:dataset) do
|
9
|
+
driver.create_dataset 'test dataset', 640, 480
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:raster_band) do
|
13
|
+
band = dataset.raster_band 1
|
14
|
+
new_values = band.to_na.indgen!
|
15
|
+
band.write_array(new_values)
|
16
|
+
band
|
17
|
+
end
|
18
|
+
|
19
|
+
subject(:classifier) { described_class.new(raster_band) }
|
20
|
+
|
21
|
+
describe '#add_range' do
|
22
|
+
context 'range param is a Range' do
|
23
|
+
it 'adds the hash to the list of @ranges' do
|
24
|
+
expect do
|
25
|
+
subject.add_range 0..10, 1
|
26
|
+
end.to change { subject.ranges.size }.by 1
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'range param is not a Range' do
|
31
|
+
it 'raises a RuntimeError' do
|
32
|
+
expect do
|
33
|
+
subject.add_range [1, 2, 3], 1
|
34
|
+
end.to raise_exception RuntimeError
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#add_ranges' do
|
40
|
+
let(:ranges) do
|
41
|
+
[
|
42
|
+
{ range: 0..10, map_to: 1000 },
|
43
|
+
{ range: 10..100, map_to: 1 }
|
44
|
+
]
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'adds a list of ranges to @ranges' do
|
48
|
+
expect do
|
49
|
+
subject.add_ranges(ranges)
|
50
|
+
end.to change { subject.ranges.size }.by ranges.size
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#equal_count_ranges' do
|
55
|
+
context 'band type is :GDT_Byte' do
|
56
|
+
subject { classifier.equal_count_ranges(4) }
|
57
|
+
|
58
|
+
it 'is an Array of Hashes' do
|
59
|
+
expect(subject).to be_an Array
|
60
|
+
expect(subject.first).to be_a Hash
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'has map_to values that are between 1 and 4' do
|
64
|
+
map_to_values = subject.map { |range| range[:map_to] }.uniq
|
65
|
+
expect(map_to_values).to contain_exactly(1, 2, 3, 4)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'band type is :GDT_Float32' do
|
70
|
+
let(:raster_band) do
|
71
|
+
band = float_dataset.raster_band 1
|
72
|
+
new_values = band.to_na.indgen!
|
73
|
+
band.write_array(new_values)
|
74
|
+
band
|
75
|
+
end
|
76
|
+
|
77
|
+
let(:float_dataset) do
|
78
|
+
driver.create_dataset 'test dataset', 640, 480, data_type: :GDT_Float32
|
79
|
+
end
|
80
|
+
|
81
|
+
subject { classifier.equal_count_ranges(4) }
|
82
|
+
|
83
|
+
it 'is an Array of Hashes' do
|
84
|
+
expect(subject).to be_an Array
|
85
|
+
expect(subject.first).to be_a Hash
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'has map_to values that are between 1 and 4' do
|
89
|
+
map_to_values = subject.map { |range| range[:map_to] }.uniq
|
90
|
+
expect(map_to_values).to contain_exactly(1.0, 2.0, 3.0, 4.0)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#classify!' do
|
96
|
+
before do
|
97
|
+
ranges = subject.equal_count_ranges(10)
|
98
|
+
subject.add_ranges(ranges)
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'no_data_value is set' do
|
102
|
+
before do
|
103
|
+
raster_band.no_data_value = 0
|
104
|
+
subject.classify!
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'has a max value equal to the number of ranges' do
|
108
|
+
min_max = raster_band.min_max
|
109
|
+
expect(min_max[:max]).to eq 10
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'has a min value of 1' do
|
113
|
+
min_max = raster_band.min_max
|
114
|
+
expect(min_max[:min]).to eq 1
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'no_data_value is not set' do
|
119
|
+
before do
|
120
|
+
subject.classify!
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'has a max value equal to the number of ranges' do
|
124
|
+
min_max = raster_band.min_max
|
125
|
+
expect(min_max[:max]).to eq 10
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'has a min value of 0' do
|
129
|
+
min_max = raster_band.min_max
|
130
|
+
expect(min_max[:min]).to eq 0
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gdal/virtual_dataset'
|
3
|
+
require 'gdal/dataset'
|
4
|
+
|
5
|
+
RSpec.describe GDAL::VirtualDataset do
|
6
|
+
subject(:virtual_dataset) { described_class.new(300, 200) }
|
7
|
+
|
8
|
+
describe '#initialize' do
|
9
|
+
it { is_expected.to be_a GDAL::VirtualDataset }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#flush_cache' do
|
13
|
+
it 'does something' do
|
14
|
+
subject.flush_cache
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#to_xml' do
|
19
|
+
it 'returns a String' do
|
20
|
+
expect(subject.to_xml).to be_a String
|
21
|
+
expect(subject.to_xml.size).to be > 0
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#add_band' do
|
26
|
+
context 'valid data type' do
|
27
|
+
it "lets you add a real dataset's raster band to it" do
|
28
|
+
expect(subject.add_band(:GDT_Byte)).to eq 0
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ogr/data_source'
|
3
|
+
|
4
|
+
RSpec.describe OGR::DataSource do
|
5
|
+
context 'Memory datasource' do
|
6
|
+
subject(:data_source) do
|
7
|
+
OGR::Driver.by_name('Memory').create_data_source('test')
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#can_create_layer?' do
|
11
|
+
subject { data_source.can_create_layer? }
|
12
|
+
it { is_expected.to eq true }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#can_delete_layer?' do
|
16
|
+
subject { data_source.can_delete_layer? }
|
17
|
+
it { is_expected.to eq true }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#can_create_geometry_field_after_create_layer?' do
|
21
|
+
subject { data_source.can_create_geometry_field_after_create_layer? }
|
22
|
+
it { is_expected.to eq true }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#supports_curve_geometries?' do
|
26
|
+
subject { data_source.supports_curve_geometries? }
|
27
|
+
it { is_expected.to eq false }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,209 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ogr/data_source'
|
3
|
+
require 'ogr/spatial_reference'
|
4
|
+
|
5
|
+
RSpec.describe OGR::DataSource do
|
6
|
+
describe '.open' do
|
7
|
+
context 'not a data source' do
|
8
|
+
it 'raises an OGR::OpenFailure' do
|
9
|
+
expect do
|
10
|
+
described_class.open('blarg', 'r')
|
11
|
+
end.to raise_exception OGR::OpenFailure
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:driver) { OGR::Driver.by_name 'Memory' }
|
17
|
+
|
18
|
+
subject(:data_source) do
|
19
|
+
driver.create_data_source('spec')
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#name' do
|
23
|
+
subject { data_source.name }
|
24
|
+
it { is_expected.to eq 'spec' }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#driver' do
|
28
|
+
subject { data_source.driver.name }
|
29
|
+
it { is_expected.to eq 'Memory' }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#layer_count' do
|
33
|
+
subject { data_source.layer_count }
|
34
|
+
it { is_expected.to be_zero }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#layer' do
|
38
|
+
context 'no layers' do
|
39
|
+
subject { data_source.layer(0) }
|
40
|
+
it { is_expected.to be_nil }
|
41
|
+
end
|
42
|
+
|
43
|
+
context '1 layer' do
|
44
|
+
before { data_source.create_layer 'unknown layer' }
|
45
|
+
subject { data_source.layer(0) }
|
46
|
+
it { is_expected.to be_a OGR::Layer }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#layer_by_name' do
|
51
|
+
context 'no layers' do
|
52
|
+
subject { data_source.layer_by_name 'meow' }
|
53
|
+
it { is_expected.to be_nil }
|
54
|
+
end
|
55
|
+
|
56
|
+
context '1 layer' do
|
57
|
+
before { data_source.create_layer 'unknown layer' }
|
58
|
+
subject { data_source.layer_by_name 'unknown layer' }
|
59
|
+
it { is_expected.to be_a OGR::Layer }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#create_layer' do
|
64
|
+
context 'cannot create layer' do
|
65
|
+
before do
|
66
|
+
expect(subject).to receive(:can_create_layer?).and_return false
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'raises an OGR::UnsupportedOperation' do
|
70
|
+
expect { subject.create_layer('test') }.to raise_exception OGR::UnsupportedOperation
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'can create layer' do
|
75
|
+
context 'geometry type is :wkbUnknown' do
|
76
|
+
it 'adds a new OGR::Layer to @layers' do
|
77
|
+
expect do
|
78
|
+
data_source.create_layer('unknown layer')
|
79
|
+
end.to change { data_source.layers.size }.by 1
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'has a layer that is the given geometry type' do
|
83
|
+
layer = data_source.create_layer('unknown layer', geometry_type: :wkbUnknown)
|
84
|
+
expect(layer.geometry_type).to eq :wkbUnknown
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'geometry type is *not* :wkbUnknown' do
|
89
|
+
it 'adds a new OGR::Layer to @layers' do
|
90
|
+
expect do
|
91
|
+
data_source.create_layer('polygon layer', geometry_type: :wkbPolygon)
|
92
|
+
end.to change { data_source.layers.size }.by 1
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'has a layer that is the given geometry type' do
|
96
|
+
layer = data_source.create_layer('polygon layer', geometry_type: :wkbPolygon)
|
97
|
+
expect(layer.geometry_type).to eq :wkbPolygon
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'spatial reference is passed in' do
|
102
|
+
let(:spatial_reference) { OGR::SpatialReference.new_from_epsg(4326) }
|
103
|
+
|
104
|
+
it 'adds a new OGR::Layer to @layers' do
|
105
|
+
expect do
|
106
|
+
data_source.create_layer('polygon layer', spatial_reference: spatial_reference)
|
107
|
+
end.to change { data_source.layers.size }.by 1
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'has a layer that uses that spatial reference' do
|
111
|
+
layer = data_source.create_layer('polygon layer', spatial_reference: spatial_reference)
|
112
|
+
expect(layer.spatial_reference.to_wkt).to eq spatial_reference.to_wkt
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe '#copy_layer' do
|
119
|
+
let!(:unknown_layer) { subject.create_layer 'unknown layer' }
|
120
|
+
|
121
|
+
it 'adds a new OGR::Layer to @layers' do
|
122
|
+
expect do
|
123
|
+
subject.copy_layer(unknown_layer, 'meow layer')
|
124
|
+
end.to change { subject.layers.size }.by 1
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'makes a copy of the layer' do
|
128
|
+
copied_layer = subject.copy_layer(unknown_layer, 'meow layer')
|
129
|
+
expect(copied_layer.geometry_type).to eq unknown_layer.geometry_type
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '#delete_layer' do
|
134
|
+
context 'deleting not supported' do
|
135
|
+
before do
|
136
|
+
expect(subject).to receive(:can_delete_layer?).and_return false
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'raises an OGR::UnsupportedOperation' do
|
140
|
+
expect { subject.delete_layer(0) }.to raise_exception OGR::UnsupportedOperation
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'deleting is supported' do
|
145
|
+
context 'no layers' do
|
146
|
+
it 'raises a OGR::Failure' do
|
147
|
+
expect do
|
148
|
+
data_source.delete_layer(0)
|
149
|
+
end.to raise_exception OGR::Failure
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context '1 layer' do
|
154
|
+
before { data_source.create_layer 'unknown layer' }
|
155
|
+
subject { data_source.delete_layer(0) }
|
156
|
+
it { is_expected.to eq true }
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe '#style_table' do
|
162
|
+
context 'no associated style table' do
|
163
|
+
subject { data_source.style_table }
|
164
|
+
it { is_expected.to be_nil }
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe '#style_table=' do
|
169
|
+
context 'no style table associated' do
|
170
|
+
let(:style_table) do
|
171
|
+
st = OGR::StyleTable.new
|
172
|
+
st.add_style('test', '#123456')
|
173
|
+
st
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'assigns the new style table' do
|
177
|
+
subject.style_table = style_table
|
178
|
+
expect(subject.style_table.find('test')).to eq '#123456'
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe '#test_capability' do
|
184
|
+
context 'supported capabilities to check' do
|
185
|
+
let(:capabilities) do
|
186
|
+
%w[ODsCCreateLayer ODsCDeleteLayer ODsCCreateGeomFieldAfterCreateLayer ODsCCurveGeometries]
|
187
|
+
end
|
188
|
+
|
189
|
+
# I don't get why these return false...
|
190
|
+
it 'returns false' do
|
191
|
+
capabilities.each do |capability|
|
192
|
+
expect(subject.test_capability(capability)).to eq false
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context 'unsupported capabilities to check' do
|
198
|
+
it 'returns false' do
|
199
|
+
expect(subject.test_capability('meow')).to eq false
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe '#sync_to_disk' do
|
205
|
+
it 'returns true' do
|
206
|
+
expect(subject.sync_to_disk).to eq true
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ogr/driver'
|
3
|
+
|
4
|
+
RSpec.describe OGR::Driver do
|
5
|
+
context 'Memory driver' do
|
6
|
+
subject(:driver) { OGR::Driver.by_name('Memory') }
|
7
|
+
|
8
|
+
describe '#can_create_data_source?' do
|
9
|
+
subject { driver.can_create_data_source? }
|
10
|
+
it { is_expected.to eq true }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#can_delete_data_source?' do
|
14
|
+
subject { driver.can_delete_data_source? }
|
15
|
+
it { is_expected.to eq false }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|