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,150 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ogr/driver'
|
3
|
+
|
4
|
+
RSpec.describe OGR::Driver do
|
5
|
+
describe '.count' do
|
6
|
+
subject { described_class.count }
|
7
|
+
it { is_expected.to be_a Fixnum }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.by_name' do
|
11
|
+
it 'can return an OGR::Driver' do
|
12
|
+
expect(described_class.by_name('Memory')).to be_a OGR::Driver
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '.at_index' do
|
17
|
+
context 'valid index' do
|
18
|
+
it 'returns an OGR::Driver' do
|
19
|
+
expect(described_class.at_index(0)).to be_a OGR::Driver
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'invalid index' do
|
24
|
+
it 'raises an OGR::DriverNotFound' do
|
25
|
+
expect { described_class.at_index(123_456) }.
|
26
|
+
to raise_exception OGR::DriverNotFound
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '.names' do
|
32
|
+
it 'returns an Array of Strings' do
|
33
|
+
expect(described_class.names).to be_an Array
|
34
|
+
expect(described_class.names.first).to be_a String
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
subject(:memory_driver) { described_class.by_name('Memory') }
|
39
|
+
let(:shapefile_driver) { described_class.by_name('ESRI Shapefile') }
|
40
|
+
|
41
|
+
describe '#name' do
|
42
|
+
subject { memory_driver.name }
|
43
|
+
it { is_expected.to eq 'Memory' }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#open' do
|
47
|
+
context 'data source at path does not exist' do
|
48
|
+
context 'with write flag' do
|
49
|
+
it 'raises an OGR::InvalidDataSource' do
|
50
|
+
expect { subject.open('spec source', 'w') }.
|
51
|
+
to raise_exception OGR::InvalidDataSource
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'with read flag' do
|
56
|
+
it 'raises an OGR::InvalidDataSource' do
|
57
|
+
expect { subject.open('spec source', 'r') }.
|
58
|
+
to raise_exception OGR::InvalidDataSource
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'data source at path exists' do
|
64
|
+
let(:shapefile_path) do
|
65
|
+
'spec/support/shapefiles/states_21basic/states.shp'
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'with write flag' do
|
69
|
+
it 'returns an OGR::DataSource' do
|
70
|
+
data_source = shapefile_driver.open(shapefile_path, 'w')
|
71
|
+
expect(data_source).to be_a OGR::DataSource
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'with read flag' do
|
76
|
+
it 'returns an OGR::DataSource' do
|
77
|
+
data_source = shapefile_driver.open(shapefile_path, 'r')
|
78
|
+
expect(data_source).to be_a OGR::DataSource
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'using a driver that does not support the file type' do
|
83
|
+
it 'raises an OGR::InvalidDataSource' do
|
84
|
+
expect { memory_driver.open(shapefile_path, 'r') }.
|
85
|
+
to raise_exception OGR::InvalidDataSource
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#create_data_source' do
|
92
|
+
context 'creation not supported' do
|
93
|
+
before do
|
94
|
+
expect(subject).to receive(:can_create_data_source?).and_return false
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'raises an OGR::UnsupportedOperation' do
|
98
|
+
expect { subject.create_data_source('test') }.to raise_exception OGR::UnsupportedOperation
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'creation supported' do
|
103
|
+
context 'block given' do
|
104
|
+
it 'yields the new DataSource to the block' do
|
105
|
+
expect do |b|
|
106
|
+
subject.create_data_source('test source', &b)
|
107
|
+
end.to yield_with_args OGR::DataSource
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'no block given' do
|
112
|
+
it 'returns the new data source' do
|
113
|
+
expect(subject.create_data_source('test source')).
|
114
|
+
to be_a OGR::DataSource
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe '#delete_data_source' do
|
121
|
+
context 'does not support deleting' do
|
122
|
+
context 'data source does not exist' do
|
123
|
+
it "raises a OGR::UnsupportedOperation (Memory driver doesn't support)" do
|
124
|
+
expect { subject.delete_data_source('we no here') }.to raise_exception OGR::UnsupportedOperation
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe '#copy_data_source' do
|
131
|
+
context 'source data source does not exist' do
|
132
|
+
it 'raises an OGR::InvalidDataSource' do
|
133
|
+
expect do
|
134
|
+
subject.copy_data_source('not a pointer', 'bobo')
|
135
|
+
end.to raise_exception OGR::InvalidDataSource
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context 'source data source exists' do
|
140
|
+
let(:data_source) do
|
141
|
+
subject.create_data_source('datasource1')
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'returns the new OGR::DataSource' do
|
145
|
+
expect(subject.copy_data_source(data_source, 'datasource2')).
|
146
|
+
to be_a OGR::DataSource
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,322 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ogr/envelope'
|
3
|
+
require 'gdal/geo_transform'
|
4
|
+
|
5
|
+
RSpec.describe OGR::Envelope do
|
6
|
+
describe '#x_min' do
|
7
|
+
context 'default value' do
|
8
|
+
subject { described_class.new.x_min }
|
9
|
+
it { is_expected.to eq(0.0) }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#x_min= + #x_min' do
|
14
|
+
it 'sets the x_min value' do
|
15
|
+
subject.x_min = 123
|
16
|
+
expect(subject.x_min).to eq 123.0
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#x_max' do
|
21
|
+
context 'default value' do
|
22
|
+
subject { described_class.new.x_max }
|
23
|
+
it { is_expected.to eq(0.0) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#x_max= + #x_max' do
|
28
|
+
it 'sets the x_max value' do
|
29
|
+
subject.x_max = 123
|
30
|
+
expect(subject.x_max).to eq 123.0
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#y_min' do
|
35
|
+
context 'default value' do
|
36
|
+
subject { described_class.new.y_min }
|
37
|
+
it { is_expected.to eq(0.0) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#y_min= + #y_min' do
|
42
|
+
it 'sets the y_min value' do
|
43
|
+
subject.y_min = 123
|
44
|
+
expect(subject.y_min).to eq 123.0
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#y_max' do
|
49
|
+
context 'default value' do
|
50
|
+
subject { described_class.new.y_max }
|
51
|
+
it { is_expected.to eq(0.0) }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#y_max= + #y_max' do
|
56
|
+
it 'sets the y_max value' do
|
57
|
+
subject.y_max = 123
|
58
|
+
expect(subject.y_max).to eq 123.0
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context '2d' do
|
63
|
+
describe '#z_min' do
|
64
|
+
context 'default value' do
|
65
|
+
subject { described_class.new.z_min }
|
66
|
+
it { is_expected.to be_nil }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#z_min= + #z_min' do
|
71
|
+
it 'sets the z_min value' do
|
72
|
+
subject.z_min = 123
|
73
|
+
expect(subject.z_min).to be_nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#z_max' do
|
78
|
+
context 'default value' do
|
79
|
+
subject { described_class.new.z_max }
|
80
|
+
it { is_expected.to be_nil }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#z_max= + #z_max' do
|
85
|
+
it 'sets the z_max value' do
|
86
|
+
subject.z_max = 123
|
87
|
+
expect(subject.z_max).to be_nil
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context '3d' do
|
93
|
+
subject { described_class.new(three_d: true) }
|
94
|
+
|
95
|
+
describe '#z_min' do
|
96
|
+
context 'default value' do
|
97
|
+
subject { described_class.new.z_min }
|
98
|
+
it { is_expected.to be_nil }
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '#z_min= + #z_min' do
|
103
|
+
it 'sets the z_min value' do
|
104
|
+
subject.z_min = 123
|
105
|
+
expect(subject.z_min).to eq 123.0
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '#z_max' do
|
110
|
+
context 'default value' do
|
111
|
+
subject { described_class.new.z_max }
|
112
|
+
it { is_expected.to be_nil }
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#z_max= + #z_max' do
|
117
|
+
it 'sets the z_max value' do
|
118
|
+
subject.z_max = 123
|
119
|
+
expect(subject.z_max).to eq 123.0
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#world_to_pixels' do
|
125
|
+
let(:geo_transform) do
|
126
|
+
GDAL::GeoTransform.from_world_file('spec/support/worldfiles/SR_50M/SR_50M', '.tfw')
|
127
|
+
end
|
128
|
+
|
129
|
+
before do
|
130
|
+
subject.x_min = 10
|
131
|
+
subject.x_max = 20
|
132
|
+
subject.y_min = -10
|
133
|
+
subject.y_max = 0
|
134
|
+
end
|
135
|
+
|
136
|
+
context 'as integers' do
|
137
|
+
it 'returns a Hash of translated values' do
|
138
|
+
result = subject.world_to_pixels(geo_transform)
|
139
|
+
expect(result).to eq(
|
140
|
+
x_min: 5700,
|
141
|
+
y_min: -2700,
|
142
|
+
x_max: 6000,
|
143
|
+
y_max: -3000
|
144
|
+
)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe '#==' do
|
150
|
+
subject do
|
151
|
+
envelope = described_class.new
|
152
|
+
envelope.x_min = 10
|
153
|
+
envelope.y_min = -100
|
154
|
+
envelope.x_max = 50
|
155
|
+
envelope.y_max = -50
|
156
|
+
|
157
|
+
envelope
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'envelopes are equal' do
|
161
|
+
let(:other_envelope) do
|
162
|
+
envelope = described_class.new
|
163
|
+
envelope.x_min = 10
|
164
|
+
envelope.y_min = -100
|
165
|
+
envelope.x_max = 50
|
166
|
+
envelope.y_max = -50
|
167
|
+
|
168
|
+
envelope
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'returns true' do
|
172
|
+
expect(subject == other_envelope).to eq true
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'envelopes not equal' do
|
177
|
+
let(:other_envelope) do
|
178
|
+
envelope = described_class.new
|
179
|
+
envelope.x_min = 0
|
180
|
+
envelope.y_min = -100
|
181
|
+
envelope.x_max = 50
|
182
|
+
envelope.y_max = -50
|
183
|
+
|
184
|
+
envelope
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'returns false' do
|
188
|
+
expect(subject == other_envelope).to eq false
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
describe '#merge' do
|
194
|
+
subject do
|
195
|
+
envelope = described_class.new
|
196
|
+
envelope.x_min = 10
|
197
|
+
envelope.y_min = -100
|
198
|
+
envelope.x_max = 50
|
199
|
+
envelope.y_max = -50
|
200
|
+
|
201
|
+
envelope
|
202
|
+
end
|
203
|
+
|
204
|
+
let(:other_envelope) do
|
205
|
+
envelope = described_class.new
|
206
|
+
envelope.x_min = 0
|
207
|
+
envelope.y_min = 0
|
208
|
+
envelope.x_max = 500
|
209
|
+
envelope.y_max = 250
|
210
|
+
|
211
|
+
envelope
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'returns a new OGR::Envelope' do
|
215
|
+
expect(subject.merge(other_envelope)).to be_a OGR::Envelope
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'has an x_min that equals the most minimum value between the two envelopes' do
|
219
|
+
expect(subject.merge(other_envelope).x_min).to eq 0
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'has an y_min that equals the most minimum value between the two envelopes' do
|
223
|
+
expect(subject.merge(other_envelope).y_min).to eq(-100)
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'has an x_max that equals the most maximum value between the two envelopes' do
|
227
|
+
expect(subject.merge(other_envelope).x_max).to eq 500
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'has an y_max that equals the most maximum value between the two envelopes' do
|
231
|
+
expect(subject.merge(other_envelope).y_max).to eq 250
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
describe '#intersects?' do
|
236
|
+
subject do
|
237
|
+
envelope = described_class.new
|
238
|
+
envelope.x_min = 0
|
239
|
+
envelope.x_max = 1
|
240
|
+
envelope.y_min = 0
|
241
|
+
envelope.y_max = 1
|
242
|
+
|
243
|
+
envelope
|
244
|
+
end
|
245
|
+
|
246
|
+
context 'envelopes intersect' do
|
247
|
+
let(:other_envelope) do
|
248
|
+
envelope = described_class.new
|
249
|
+
envelope.x_min = 0
|
250
|
+
envelope.x_max = 1
|
251
|
+
envelope.y_min = 0
|
252
|
+
envelope.y_max = 1
|
253
|
+
|
254
|
+
envelope
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'returns true' do
|
258
|
+
expect(subject.intersects?(other_envelope)).to eq true
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
context 'envelopes do not intersect' do
|
263
|
+
let(:other_envelope) do
|
264
|
+
envelope = described_class.new
|
265
|
+
envelope.x_min = 500
|
266
|
+
envelope.y_min = 500
|
267
|
+
envelope.x_max = 1000
|
268
|
+
envelope.y_max = 1000
|
269
|
+
|
270
|
+
envelope
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'returns false' do
|
274
|
+
expect(subject.intersects?(other_envelope)).to eq false
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
describe '#contains?' do
|
280
|
+
subject do
|
281
|
+
envelope = described_class.new
|
282
|
+
envelope.x_min = 0
|
283
|
+
envelope.x_max = 10
|
284
|
+
envelope.y_min = 0
|
285
|
+
envelope.y_max = 10
|
286
|
+
|
287
|
+
envelope
|
288
|
+
end
|
289
|
+
|
290
|
+
context 'subject contains other envelope' do
|
291
|
+
let(:other_envelope) do
|
292
|
+
envelope = described_class.new
|
293
|
+
envelope.x_min = 1
|
294
|
+
envelope.x_max = 9
|
295
|
+
envelope.y_min = 1
|
296
|
+
envelope.y_max = 9
|
297
|
+
|
298
|
+
envelope
|
299
|
+
end
|
300
|
+
|
301
|
+
it 'returns true' do
|
302
|
+
expect(subject.contains?(other_envelope)).to eq true
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
context 'subject does not contain other envelope' do
|
307
|
+
let(:other_envelope) do
|
308
|
+
envelope = described_class.new
|
309
|
+
envelope.x_min = 500
|
310
|
+
envelope.y_min = 500
|
311
|
+
envelope.x_max = 1000
|
312
|
+
envelope.y_max = 1000
|
313
|
+
|
314
|
+
envelope
|
315
|
+
end
|
316
|
+
|
317
|
+
it 'returns false' do
|
318
|
+
expect(subject.contains?(other_envelope)).to eq false
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|