ffi-gdal 1.0.0.beta3 → 1.0.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +62 -0
- data/Gemfile +1 -1
- data/History.md +53 -28
- data/README.md +6 -0
- data/Rakefile +23 -1
- data/examples/extract_and_colorize.rb +21 -22
- data/examples/geometries.rb +2 -2
- data/examples/gridding.rb +106 -0
- data/examples/ogr_layer_to_layer.rb +1 -1
- data/examples/points.txt +127 -0
- data/examples/testing_gdal.rb +3 -4
- data/ffi-gdal.gemspec +3 -2
- data/lib/ext/error_symbols.rb +2 -57
- data/lib/ext/ffi_library_function_checks.rb +26 -0
- data/lib/ext/float_ext.rb +2 -2
- data/lib/ext/narray_ext.rb +2 -0
- data/lib/ext/numeric_as_data_type.rb +19 -0
- data/lib/ext/to_bool.rb +4 -4
- data/lib/ffi/cpl/conv.rb +132 -0
- data/lib/ffi/cpl/error.rb +67 -0
- data/lib/ffi/cpl/hash_set.rb +39 -0
- data/lib/ffi/cpl/http.rb +25 -0
- data/lib/ffi/cpl/http_result.rb +18 -0
- data/lib/ffi/cpl/list.rb +38 -0
- data/lib/ffi/cpl/mime_part.rb +11 -0
- data/lib/ffi/cpl/minixml.rb +47 -0
- data/lib/ffi/cpl/port.rb +23 -0
- data/lib/ffi/cpl/quad_tree.rb +51 -0
- data/lib/ffi/{ogr/ogr_envelope.rb → cpl/rect_obj.rb} +3 -3
- data/lib/ffi/cpl/string.rb +95 -0
- data/lib/ffi/cpl/vsi.rb +115 -0
- data/lib/ffi/cpl/xml_node.rb +6 -6
- data/lib/ffi/gdal/alg.rb +385 -0
- data/lib/ffi/gdal/{gdal_color_entry.rb → color_entry.rb} +1 -2
- data/lib/ffi/gdal/exceptions.rb +6 -0
- data/lib/ffi/gdal/{gdal_gcp.rb → gcp.rb} +1 -3
- data/lib/ffi/gdal/{gdal_h.rb → gdal.rb} +253 -252
- data/lib/ffi/gdal/grid.rb +58 -0
- data/lib/ffi/gdal/{gdal_grid_data_metrics_options.rb → grid_data_metrics_options.rb} +1 -2
- data/lib/ffi/gdal/{gdal_grid_inverse_distance_to_a_power_options.rb → grid_inverse_distance_to_a_power_options.rb} +1 -2
- data/lib/ffi/gdal/{gdal_grid_moving_average_options.rb → grid_moving_average_options.rb} +1 -2
- data/lib/ffi/gdal/{gdal_grid_nearest_neighbor_options.rb → grid_nearest_neighbor_options.rb} +1 -2
- data/lib/ffi/gdal/matching.rb +20 -0
- data/lib/ffi/gdal/{gdal_rpc_info.rb → rpc_info.rb} +1 -2
- data/lib/ffi/gdal/{gdal_transformer_info.rb → transformer_info.rb} +1 -2
- data/lib/ffi/gdal/version.rb +1 -1
- data/lib/ffi/gdal/vrt.rb +92 -0
- data/lib/ffi/gdal/{gdal_warp_options.rb → warp_options.rb} +8 -4
- data/lib/ffi/gdal/warper.rb +70 -0
- data/lib/ffi/gdal.rb +56 -69
- data/lib/ffi/ogr/api.rb +567 -0
- data/lib/ffi/ogr/{ogr_contour_writer_info.rb → contour_writer_info.rb} +2 -3
- data/lib/ffi/ogr/core.rb +181 -0
- data/lib/ffi/ogr/envelope.rb +12 -0
- data/lib/ffi/ogr/{ogr_envelope_3d.rb → envelope_3d.rb} +2 -2
- data/lib/ffi/ogr/featurestyle.rb +29 -0
- data/lib/ffi/ogr/field.rb +63 -0
- data/lib/ffi/ogr/geocoding.rb +30 -0
- data/lib/ffi/ogr/srs_api.rb +407 -0
- data/lib/ffi/ogr/style_param.rb +13 -0
- data/lib/ffi/ogr/{ogr_style_value.rb → style_value.rb} +4 -3
- data/lib/ffi/ogr.rb +7 -7
- data/lib/ffi-gdal.rb +7 -145
- data/lib/gdal/color_entry.rb +18 -14
- data/lib/gdal/color_entry_mixins/extensions.rb +32 -0
- data/lib/gdal/color_interpretation.rb +2 -2
- data/lib/gdal/color_table.rb +37 -32
- data/lib/gdal/color_table_mixins/extensions.rb +48 -0
- data/lib/gdal/cpl_error_handler.rb +119 -0
- data/lib/gdal/data_type.rb +7 -7
- data/lib/gdal/dataset.rb +131 -238
- data/lib/gdal/dataset_mixins/algorithm_methods.rb +182 -0
- data/lib/gdal/dataset_mixins/extensions.rb +542 -0
- data/lib/gdal/dataset_mixins/matching.rb +26 -0
- data/lib/gdal/driver.rb +68 -92
- data/lib/gdal/driver_mixins/extensions.rb +93 -0
- data/lib/gdal/exceptions.rb +32 -4
- data/lib/gdal/geo_transform.rb +63 -43
- data/lib/gdal/geo_transform_mixins/extensions.rb +57 -0
- data/lib/gdal/grid.rb +144 -0
- data/lib/gdal/grid_types/data_metrics_base.rb +14 -0
- data/lib/gdal/grid_types/inverse_distance_to_a_power.rb +19 -0
- data/lib/gdal/grid_types/metric_average_distance.rb +12 -0
- data/lib/gdal/grid_types/metric_average_distance_pts.rb +12 -0
- data/lib/gdal/grid_types/metric_count.rb +12 -0
- data/lib/gdal/grid_types/metric_maximum.rb +12 -0
- data/lib/gdal/grid_types/metric_minimum.rb +12 -0
- data/lib/gdal/grid_types/metric_range.rb +12 -0
- data/lib/gdal/grid_types/moving_average.rb +19 -0
- data/lib/gdal/grid_types/nearest_neighbor.rb +19 -0
- data/lib/gdal/grid_types.rb +22 -0
- data/lib/gdal/internal_helpers.rb +94 -0
- data/lib/gdal/major_object.rb +4 -7
- data/lib/gdal/options.rb +14 -7
- data/lib/gdal/raster_attribute_table.rb +38 -47
- data/lib/gdal/raster_attribute_table_mixins/extensions.rb +41 -0
- data/lib/gdal/raster_band.rb +193 -227
- data/lib/gdal/raster_band_classifier.rb +107 -0
- data/lib/gdal/raster_band_mixins/algorithm_methods.rb +292 -0
- data/lib/gdal/raster_band_mixins/extensions.rb +238 -0
- data/lib/gdal/rpc_info.rb +35 -0
- data/lib/gdal/transformer.rb +15 -0
- data/lib/gdal/transformers/approximate_transformer.rb +48 -0
- data/lib/gdal/transformers/base_general_image_projection_transformer.rb +45 -0
- data/lib/gdal/transformers/gcp_transformer.rb +55 -0
- data/lib/gdal/transformers/general_image_projection_transformer.rb +31 -0
- data/lib/gdal/transformers/general_image_projection_transformer2.rb +52 -0
- data/lib/gdal/transformers/general_image_projection_transformer3.rb +25 -0
- data/lib/gdal/transformers/geolocation_transformer.rb +42 -0
- data/lib/gdal/transformers/reprojection_transformer.rb +39 -0
- data/lib/gdal/transformers/rpc_transformer.rb +56 -0
- data/lib/gdal/transformers/tps_transformer.rb +40 -0
- data/lib/gdal/virtual_dataset.rb +96 -0
- data/lib/gdal/warp_operation.rb +20 -23
- data/lib/gdal.rb +17 -0
- data/lib/ogr/coordinate_transformation.rb +16 -41
- data/lib/ogr/data_source.rb +103 -58
- data/lib/ogr/data_source_extensions.rb +5 -6
- data/lib/ogr/data_source_mixins/capability_methods.rb +27 -0
- data/lib/ogr/driver.rb +61 -33
- data/lib/ogr/driver_mixins/capability_methods.rb +16 -0
- data/lib/ogr/envelope.rb +29 -18
- data/lib/ogr/envelope_extensions.rb +70 -49
- data/lib/ogr/error_handling.rb +46 -0
- data/lib/ogr/exceptions.rb +58 -12
- data/lib/ogr/feature.rb +334 -86
- data/lib/ogr/feature_definition.rb +94 -51
- data/lib/ogr/feature_definition_extensions.rb +36 -13
- data/lib/ogr/feature_extensions.rb +62 -11
- data/lib/ogr/field.rb +175 -54
- data/lib/ogr/field_definition.rb +110 -0
- data/lib/ogr/{field_extensions.rb → field_definition_extensions.rb} +4 -5
- data/lib/ogr/{geocoding_session.rb → geocoder.rb} +14 -13
- data/lib/ogr/geometries/geometry_collection.rb +13 -0
- data/lib/ogr/geometries/line_string.rb +35 -0
- data/lib/ogr/geometries/linear_ring.rb +11 -0
- data/lib/ogr/geometries/multi_line_string.rb +16 -0
- data/lib/ogr/geometries/multi_point.rb +14 -0
- data/lib/ogr/geometries/multi_polygon.rb +21 -0
- data/lib/ogr/geometries/none_geometry.rb +13 -0
- data/lib/ogr/geometries/point.rb +65 -0
- data/lib/ogr/geometries/point_extensions.rb +32 -0
- data/lib/ogr/geometries/polygon.rb +14 -0
- data/lib/ogr/geometries/unknown_geometry.rb +10 -0
- data/lib/ogr/geometry.rb +270 -242
- data/lib/ogr/geometry_extensions.rb +8 -9
- data/lib/ogr/geometry_field_definition.rb +99 -0
- data/lib/ogr/geometry_field_definition_extensions.rb +19 -0
- data/lib/ogr/geometry_types/container.rb +75 -0
- data/lib/ogr/geometry_types/curve.rb +25 -28
- data/lib/ogr/geometry_types/surface.rb +13 -4
- data/lib/ogr/internal_helpers.rb +57 -0
- data/lib/ogr/layer.rb +60 -181
- data/lib/ogr/layer_mixins/capability_methods.rb +102 -0
- data/lib/ogr/layer_mixins/extensions.rb +59 -0
- data/lib/ogr/layer_mixins/ogr_feature_methods.rb +127 -0
- data/lib/ogr/layer_mixins/ogr_field_methods.rb +143 -0
- data/lib/ogr/layer_mixins/ogr_layer_method_methods.rb +163 -0
- data/lib/ogr/layer_mixins/ogr_query_filter_methods.rb +89 -0
- data/lib/ogr/layer_mixins/ogr_sql_methods.rb +48 -0
- data/lib/ogr/spatial_reference.rb +108 -589
- data/lib/ogr/spatial_reference_extensions.rb +29 -3
- data/lib/ogr/spatial_reference_mixins/coordinate_system_getter_setters.rb +494 -0
- data/lib/ogr/spatial_reference_mixins/exporters.rb +134 -0
- data/lib/ogr/spatial_reference_mixins/importers.rb +243 -0
- data/lib/ogr/spatial_reference_mixins/morphers.rb +25 -0
- data/lib/ogr/spatial_reference_mixins/parameter_getter_setters.rb +122 -0
- data/lib/ogr/spatial_reference_mixins/type_checks.rb +62 -0
- data/lib/ogr/style_table.rb +53 -5
- data/lib/ogr/style_table_extensions.rb +21 -5
- data/lib/ogr/style_tool.rb +118 -0
- data/lib/ogr.rb +8 -0
- data/spec/ffi-gdal_spec.rb +1 -2
- data/spec/integration/{color_table_info_spec.rb → gdal/color_table_info_spec.rb} +12 -12
- data/spec/integration/{dataset_info_spec.rb → gdal/dataset_info_spec.rb} +2 -6
- data/spec/integration/{driver_info_spec.rb → gdal/driver_info_spec.rb} +5 -5
- data/spec/integration/{geo_transform_info_spec.rb → gdal/geo_transform_info_spec.rb} +1 -14
- data/spec/integration/{raster_attribute_table_info_spec.rb → gdal/raster_attribute_table_info_spec.rb} +1 -2
- data/spec/integration/{raster_band_info_spec.rb → gdal/raster_band_info_spec.rb} +30 -42
- data/spec/integration/ogr/layer_spec.rb +97 -0
- data/spec/spec_helper.rb +94 -5
- data/spec/support/integration_help.rb +1 -0
- data/spec/support/shared_contexts.rb +26 -0
- data/spec/support/shared_examples/{major_object_examples.rb → gdal/major_object_examples.rb} +5 -5
- data/spec/support/shared_examples/ogr/a_25D_geometry.rb +7 -0
- data/spec/support/shared_examples/ogr/a_container_geometry.rb +47 -0
- data/spec/support/shared_examples/ogr/a_geometry.rb +404 -0
- data/spec/support/shared_examples/ogr/a_line_string.rb +16 -0
- data/spec/support/test_style_table.txt +3 -0
- data/spec/unit/ext/error_symbols_spec.rb +41 -53
- data/spec/unit/ext/numeric_as_data_type_spec.rb +113 -0
- data/spec/unit/ffi/gdal_spec.rb +70 -0
- data/spec/unit/gdal/color_entry_spec.rb +5 -0
- data/spec/unit/gdal/color_interpretation_spec.rb +5 -0
- data/spec/unit/gdal/{color_table_extensions_spec.rb → color_table_mixins/extensions_spec.rb} +3 -3
- data/spec/unit/gdal/color_table_spec.rb +14 -16
- data/spec/unit/gdal/data_type_spec.rb +10 -17
- data/spec/unit/gdal/dataset_spec.rb +4 -7
- data/spec/unit/gdal/driver_mixins/extensions_spec.rb +22 -0
- data/spec/unit/gdal/driver_spec.rb +49 -0
- data/spec/unit/gdal/environment_methods_spec.rb +6 -0
- data/spec/unit/gdal/geo_transform_spec.rb +276 -0
- data/spec/unit/gdal/grid_spec.rb +5 -0
- data/spec/unit/gdal/internal_helpers_spec.rb +112 -0
- data/spec/unit/gdal/major_object_spec.rb +6 -0
- data/spec/unit/gdal/options_spec.rb +5 -0
- data/spec/unit/gdal/raster_attribute_table_spec.rb +5 -0
- data/spec/unit/gdal/raster_band_classifier_spec.rb +134 -0
- data/spec/unit/gdal/raster_band_spec.rb +5 -0
- data/spec/unit/gdal/rpc_info_spec.rb +5 -0
- data/spec/unit/gdal/version_info_spec.rb +6 -0
- data/spec/unit/gdal/virtual_dataset_spec.rb +32 -0
- data/spec/unit/gdal/warp_operation_spec.rb +5 -0
- data/spec/unit/ogr/data_source_mixins/capability_methods_spec.rb +30 -0
- data/spec/unit/ogr/data_source_spec.rb +209 -0
- data/spec/unit/ogr/driver_mixins/capability_methods_spec.rb +18 -0
- data/spec/unit/ogr/driver_spec.rb +150 -0
- data/spec/unit/ogr/envelope_spec.rb +322 -0
- data/spec/unit/ogr/feature_definition_spec.rb +313 -0
- data/spec/unit/ogr/feature_spec.rb +379 -0
- data/spec/unit/ogr/field_definition_spec.rb +135 -0
- data/spec/unit/ogr/field_spec.rb +193 -0
- data/spec/unit/ogr/geometries/geometry_collection_spec.rb +186 -0
- data/spec/unit/ogr/geometries/line_string_spec.rb +105 -0
- data/spec/unit/ogr/{linear_ring_spec.rb → geometries/linear_ring_spec.rb} +10 -31
- data/spec/unit/ogr/geometries/multi_line_string_spec.rb +14 -0
- data/spec/unit/ogr/geometries/multi_point_spec.rb +14 -0
- data/spec/unit/ogr/geometries/multi_polygon_spec.rb +41 -0
- data/spec/unit/ogr/geometries/none_geometry_spec.rb +12 -0
- data/spec/unit/ogr/{point_spec.rb → geometries/point_spec.rb} +19 -25
- data/spec/unit/ogr/geometries/polygon_spec.rb +17 -0
- data/spec/unit/ogr/geometries/unknown_geometry_spec.rb +10 -0
- data/spec/unit/ogr/geometry_field_definition_spec.rb +87 -0
- data/spec/unit/ogr/geometry_spec.rb +542 -0
- data/spec/unit/ogr/internal_helpers_spec.rb +57 -0
- data/spec/unit/ogr/layer_mixins/capability_methods_spec.rb +88 -0
- data/spec/unit/ogr/layer_mixins/ogr_feature_methods_spec.rb +145 -0
- data/spec/unit/ogr/layer_mixins/ogr_field_methods_spec.rb +432 -0
- data/spec/unit/ogr/layer_mixins/ogr_layer_method_methods_spec.rb +20 -0
- data/spec/unit/ogr/layer_mixins/ogr_query_filter_methods_spec.rb +42 -0
- data/spec/unit/ogr/layer_mixins/ogr_sql_methods_spec.rb +12 -0
- data/spec/unit/ogr/layer_spec.rb +66 -67
- data/spec/unit/ogr/spatial_reference_mixins/coordinate_system_getter_setters_spec.rb +46 -0
- data/spec/unit/ogr/spatial_reference_mixins/exporters_spec.rb +139 -0
- data/spec/unit/ogr/spatial_reference_mixins/importers_spec.rb +38 -0
- data/spec/unit/ogr/spatial_reference_mixins/morphers_spec.rb +36 -0
- data/spec/unit/ogr/spatial_reference_mixins/parameter_getter_setters_spec.rb +102 -0
- data/spec/unit/ogr/spatial_reference_mixins/type_checks_spec.rb +157 -0
- data/spec/unit/ogr/spatial_reference_spec.rb +42 -0
- data/spec/unit/ogr/style_table_spec.rb +132 -0
- data/spec/unit/ogr/style_tool_spec.rb +157 -0
- data/spec/unit/version_info_spec.rb +1 -1
- metadata +285 -75
- data/lib/ffi/cpl/conv_h.rb +0 -143
- data/lib/ffi/cpl/error_h.rb +0 -63
- data/lib/ffi/cpl/minixml_h.rb +0 -14
- data/lib/ffi/cpl/string_h.rb +0 -81
- data/lib/ffi/cpl/vsi_h.rb +0 -112
- data/lib/ffi/gdal/alg_h.rb +0 -127
- data/lib/ffi/gdal/grid_h.rb +0 -51
- data/lib/ffi/gdal/warper_h.rb +0 -48
- data/lib/ffi/ogr/api_h.rb +0 -553
- data/lib/ffi/ogr/core_h.rb +0 -148
- data/lib/ffi/ogr/featurestyle_h.rb +0 -22
- data/lib/ffi/ogr/geocoding_h.rb +0 -21
- data/lib/ffi/ogr/ogr_field.rb +0 -50
- data/lib/ffi/ogr/ogr_style_param.rb +0 -12
- data/lib/ffi/ogr/srs_api_h.rb +0 -325
- data/lib/gdal/color_entry_extensions.rb +0 -30
- data/lib/gdal/color_table_extensions.rb +0 -47
- data/lib/gdal/dataset_extensions.rb +0 -496
- data/lib/gdal/driver_extensions.rb +0 -56
- data/lib/gdal/geo_transform_extensions.rb +0 -90
- data/lib/gdal/raster_attribute_table_extensions.rb +0 -40
- data/lib/gdal/raster_band_extensions.rb +0 -198
- data/lib/ogr/geometry_types/collection.rb +0 -45
- data/lib/ogr/layer_extensions.rb +0 -55
- data/lib/ogr/line_string.rb +0 -7
- data/lib/ogr/linear_ring.rb +0 -6
- data/lib/ogr/multi_line_string.rb +0 -9
- data/lib/ogr/multi_point.rb +0 -7
- data/lib/ogr/multi_polygon.rb +0 -14
- data/lib/ogr/point.rb +0 -89
- data/lib/ogr/polygon.rb +0 -9
data/lib/ogr/envelope.rb
CHANGED
@@ -5,76 +5,87 @@ module OGR
|
|
5
5
|
class Envelope
|
6
6
|
include EnvelopeExtensions
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
# @return [FFI::OGR::Envelope, FFI::OGR::Envelope3D] The C struct that this
|
9
|
+
# object wraps.
|
10
|
+
attr_reader :c_struct
|
11
|
+
|
12
|
+
# @param envelope_struct [FFI::OGR::Envelope]
|
13
|
+
def initialize(envelope_struct = nil, three_d: false)
|
14
|
+
@c_struct = envelope_struct
|
15
|
+
@c_struct ||= three_d ? FFI::OGR::Envelope3D.new : FFI::OGR::Envelope.new
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [FFI::Pointer] Pointer to the C struct.
|
19
|
+
def c_pointer
|
20
|
+
@c_struct.to_ptr
|
10
21
|
end
|
11
22
|
|
12
23
|
# @return [Float]
|
13
24
|
def x_min
|
14
|
-
@
|
25
|
+
@c_struct[:min_x]
|
15
26
|
end
|
16
27
|
|
17
28
|
# @param new_x_min [Float]
|
18
29
|
def x_min=(new_x_min)
|
19
|
-
@
|
30
|
+
@c_struct[:min_x] = new_x_min
|
20
31
|
end
|
21
32
|
|
22
33
|
# @return [Float]
|
23
34
|
def x_max
|
24
|
-
@
|
35
|
+
@c_struct[:max_x]
|
25
36
|
end
|
26
37
|
|
27
38
|
# @param new_x_max [Float]
|
28
39
|
def x_max=(new_x_max)
|
29
|
-
@
|
40
|
+
@c_struct[:max_x] = new_x_max
|
30
41
|
end
|
31
42
|
|
32
43
|
# @return [Float]
|
33
44
|
def y_min
|
34
|
-
@
|
45
|
+
@c_struct[:min_y]
|
35
46
|
end
|
36
47
|
|
37
48
|
# @param new_y_min [Float]
|
38
49
|
def y_min=(new_y_min)
|
39
|
-
@
|
50
|
+
@c_struct[:min_y] = new_y_min
|
40
51
|
end
|
41
52
|
|
42
53
|
# @return [Float]
|
43
54
|
def y_max
|
44
|
-
@
|
55
|
+
@c_struct[:max_y]
|
45
56
|
end
|
46
57
|
|
47
58
|
# @param new_y_max [Float]
|
48
59
|
def y_max=(new_y_max)
|
49
|
-
@
|
60
|
+
@c_struct[:max_y] = new_y_max
|
50
61
|
end
|
51
62
|
|
52
63
|
# @return [Float, nil]
|
53
64
|
def z_min
|
54
|
-
return nil unless @
|
65
|
+
return nil unless @c_struct.is_a? FFI::OGR::Envelope3D
|
55
66
|
|
56
|
-
@
|
67
|
+
@c_struct[:min_z]
|
57
68
|
end
|
58
69
|
|
59
70
|
# @param new_z_min [Float]
|
60
71
|
def z_min=(new_z_min)
|
61
|
-
return nil unless @
|
72
|
+
return nil unless @c_struct.is_a? FFI::OGR::Envelope3D
|
62
73
|
|
63
|
-
@
|
74
|
+
@c_struct[:min_z] = new_z_min
|
64
75
|
end
|
65
76
|
|
66
77
|
# @return [Float, nil]
|
67
78
|
def z_max
|
68
|
-
return nil unless @
|
79
|
+
return nil unless @c_struct.is_a? FFI::OGR::Envelope3D
|
69
80
|
|
70
|
-
@
|
81
|
+
@c_struct[:max_z]
|
71
82
|
end
|
72
83
|
|
73
84
|
# @param new_z_max [Float]
|
74
85
|
def z_max=(new_z_max)
|
75
|
-
return nil unless @
|
86
|
+
return nil unless @c_struct.is_a? FFI::OGR::Envelope3D
|
76
87
|
|
77
|
-
@
|
88
|
+
@c_struct[:max_z] = new_z_max
|
78
89
|
end
|
79
90
|
end
|
80
91
|
end
|
@@ -2,56 +2,39 @@ require 'json'
|
|
2
2
|
|
3
3
|
module OGR
|
4
4
|
module EnvelopeExtensions
|
5
|
+
# @return [Float] x_max - x_min
|
6
|
+
def x_size
|
7
|
+
x_max - x_min
|
8
|
+
end
|
9
|
+
|
10
|
+
# @return [Float] y_max - y_min
|
11
|
+
def y_size
|
12
|
+
y_max - y_min
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [Float] z_max - z_min
|
16
|
+
def z_size
|
17
|
+
return unless z_max && z_min
|
18
|
+
|
19
|
+
z_max - z_min
|
20
|
+
end
|
5
21
|
|
6
22
|
# Adapted from "Advanced Geospatial Python Modeling". Calculates the
|
7
|
-
# pixel locations of these geospatial coordinates
|
23
|
+
# pixel locations of these geospatial coordinates according to the given
|
24
|
+
# GeoTransform.
|
8
25
|
#
|
9
26
|
# @param geo_transform [GDAL::GeoTransform]
|
10
|
-
# @
|
11
|
-
|
12
|
-
def world_to_pixel(geo_transform, value_type=:integer)
|
27
|
+
# @return [Hash{x_min => Fixnum, y_min => Fixnum, x_max => Fixnum, y_max => Fixnum}]
|
28
|
+
def world_to_pixels(geo_transform)
|
13
29
|
min_values = geo_transform.world_to_pixel(x_min, y_max)
|
14
30
|
max_values = geo_transform.world_to_pixel(x_max, y_min)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
{
|
23
|
-
x_origin: min_values[:x].to_f.abs,
|
24
|
-
y_origin: min_values[:y].to_f.abs,
|
25
|
-
x_max: max_values[:x].to_f.abs,
|
26
|
-
y_max: max_values[:y].to_f.abs,
|
27
|
-
pixel_count: pixel_count.to_i.abs,
|
28
|
-
line_count: line_count.to_i.abs,
|
29
|
-
pixel_width: pixel_width.to_f,
|
30
|
-
pixel_height: pixel_height.to_f
|
31
|
-
}
|
32
|
-
when :integer
|
33
|
-
{
|
34
|
-
x_origin: min_values[:x].to_i.abs,
|
35
|
-
y_origin: min_values[:y].to_i.abs,
|
36
|
-
x_max: max_values[:x].to_i.abs,
|
37
|
-
y_max: max_values[:y].to_i.abs,
|
38
|
-
pixel_count: pixel_count.to_i.abs,
|
39
|
-
line_count: line_count.to_i.abs,
|
40
|
-
pixel_width: pixel_width.to_f,
|
41
|
-
pixel_height: pixel_height.to_f
|
42
|
-
}
|
43
|
-
else
|
44
|
-
{
|
45
|
-
x_origin: min_values[:x].abs,
|
46
|
-
y_origin: min_values[:y].abs,
|
47
|
-
x_max: max_values[:x].abs,
|
48
|
-
y_max: max_values[:y].abs,
|
49
|
-
pixel_count: pixel_count.to_i.abs,
|
50
|
-
line_count: line_count.to_i.abs,
|
51
|
-
pixel_width: pixel_width.to_f,
|
52
|
-
pixel_height: pixel_height.to_f
|
53
|
-
}
|
54
|
-
end
|
31
|
+
|
32
|
+
{
|
33
|
+
x_min: min_values[:pixel].round.to_i,
|
34
|
+
y_min: min_values[:line].round.to_i,
|
35
|
+
x_max: max_values[:pixel].round.to_i,
|
36
|
+
y_max: max_values[:line].round.to_i
|
37
|
+
}
|
55
38
|
end
|
56
39
|
|
57
40
|
# Compares min/max X and min/max Y to the other envelope. The envelopes are
|
@@ -64,8 +47,46 @@ module OGR
|
|
64
47
|
x_max == other_envelope.x_max && y_max == other_envelope.y_max
|
65
48
|
end
|
66
49
|
|
50
|
+
# Stolen from http://www.gdal.org/ogr__core_8h_source.html.
|
51
|
+
#
|
52
|
+
# @param other_envelope [OGR::Envelope] The Envelope to merge self with.
|
53
|
+
# @return [OGR::Envelope]
|
54
|
+
def merge(other_envelope)
|
55
|
+
new_envelope = OGR::Envelope.new
|
56
|
+
new_envelope.x_min = [x_min, other_envelope.x_min].min
|
57
|
+
new_envelope.x_max = [x_max, other_envelope.x_max].max
|
58
|
+
new_envelope.y_min = [y_min, other_envelope.y_min].min
|
59
|
+
new_envelope.y_max = [y_max, other_envelope.y_max].max
|
60
|
+
|
61
|
+
new_envelope
|
62
|
+
end
|
63
|
+
|
64
|
+
# Stolen from http://www.gdal.org/ogr__core_8h_source.html.
|
65
|
+
#
|
66
|
+
# @param other_envelope [OGR::Envelope] The Envelope to check intersection
|
67
|
+
# with.
|
68
|
+
# @return [OGR::Envelope]
|
69
|
+
def intersects?(other_envelope)
|
70
|
+
x_min <= other_envelope.x_max &&
|
71
|
+
x_max >= other_envelope.x_min &&
|
72
|
+
y_min <= other_envelope.y_max &&
|
73
|
+
y_max >= other_envelope.y_min
|
74
|
+
end
|
75
|
+
|
76
|
+
# Stolen from http://www.gdal.org/ogr__core_8h_source.html.
|
77
|
+
#
|
78
|
+
# @param other_envelope [OGR::Envelope] The Envelope to check containment
|
79
|
+
# with.
|
80
|
+
# @return [OGR::Envelope]
|
81
|
+
def contains?(other_envelope)
|
82
|
+
x_min <= other_envelope.x_min &&
|
83
|
+
y_min <= other_envelope.y_min &&
|
84
|
+
x_max >= other_envelope.x_max &&
|
85
|
+
y_max >= other_envelope.y_max
|
86
|
+
end
|
87
|
+
|
67
88
|
# @return [Hash]
|
68
|
-
def as_json
|
89
|
+
def as_json(_options = nil)
|
69
90
|
json = {
|
70
91
|
x_min: x_min,
|
71
92
|
x_max: x_max,
|
@@ -73,16 +94,16 @@ module OGR
|
|
73
94
|
y_max: y_max
|
74
95
|
}
|
75
96
|
|
76
|
-
if @
|
77
|
-
json.merge!(
|
97
|
+
if @c_struct.is_a? FFI::GDAL::OGREnvelope3D
|
98
|
+
json.merge!(z_min: z_min, z_max: z_max)
|
78
99
|
end
|
79
100
|
|
80
101
|
json
|
81
102
|
end
|
82
103
|
|
83
104
|
# @return [String]
|
84
|
-
def to_json
|
85
|
-
as_json.to_json
|
105
|
+
def to_json(options = nil)
|
106
|
+
as_json(options).to_json
|
86
107
|
end
|
87
108
|
|
88
109
|
def to_a
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require_relative 'exceptions'
|
2
|
+
|
3
|
+
module OGR
|
4
|
+
# OGR returns errors as Integers--not as part of the GDAL/CPLErr error
|
5
|
+
# handling callback interface. This hacks together a facility for sort of
|
6
|
+
# doing that with OGR.
|
7
|
+
#
|
8
|
+
# Unlike the OGR API, ffi-gdal defines an Enum for the OGRERR types, which
|
9
|
+
# in turns causes OGR to return Symbols on errors (the #defines for those can
|
10
|
+
# be found here: http://www.gdal.org/ogr__core_8h.html). This maps those
|
11
|
+
# Symbols to Ruby exceptions (or lack thereof). The sad part of this
|
12
|
+
# solution is that any function that returns an OGRErr needs to assign that
|
13
|
+
# Symbol to a variable, then call #handle_result to get that
|
14
|
+
# Symbol-to-Exception mapping to take place.
|
15
|
+
module ErrorHandling
|
16
|
+
def handle_result(msg = nil)
|
17
|
+
error_class_map(self).call(msg)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# @param [Symbol] error_class
|
23
|
+
# @return [Proc]
|
24
|
+
def error_class_map(error_class)
|
25
|
+
{
|
26
|
+
OGRERR_NONE: ->(_) { true },
|
27
|
+
OGRERR_NOT_ENOUGH_DATA: ->(msg) { raise_exception(OGR::NotEnoughData, msg) },
|
28
|
+
OGRERR_NOT_ENOUGH_MEMORY: ->(msg) { raise_exception(::NoMemoryError, msg) },
|
29
|
+
OGRERR_UNSUPPORTED_GEOMETRY_TYPE: ->(msg) { raise_exception(OGR::UnsupportedGeometryType, msg) },
|
30
|
+
OGRERR_UNSUPPORTED_OPERATION: ->(msg) { raise_exception(OGR::UnsupportedOperation, msg) },
|
31
|
+
OGRERR_CORRUPT_DATA: ->(msg) { raise_exception(OGR::CorruptData, msg) },
|
32
|
+
OGRERR_FAILURE: ->(msg) { raise_exception(OGR::Failure, msg) },
|
33
|
+
OGRERR_UNSUPPORTED_SRS: ->(msg) { raise_exception(OGR::UnsupportedSRS, msg) },
|
34
|
+
OGRERR_INVALID_HANDLE: ->(msg) { raise_exception(OGR::InvalidHandle, msg) }
|
35
|
+
}.fetch(error_class) { fail "Unknown OGRERR type: #{self}" }
|
36
|
+
end
|
37
|
+
|
38
|
+
# Exists solely to strip off the top 4 lines of the backtrace so it doesn't
|
39
|
+
# look like the problem is coming from here.
|
40
|
+
def raise_exception(exception, message)
|
41
|
+
e = exception.new(message)
|
42
|
+
e.set_backtrace(caller(4))
|
43
|
+
fail(e)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/ogr/exceptions.rb
CHANGED
@@ -1,35 +1,81 @@
|
|
1
1
|
module OGR
|
2
|
-
class
|
3
|
-
|
4
|
-
|
2
|
+
class CorruptData < RuntimeError
|
3
|
+
end
|
4
|
+
|
5
|
+
class CreateFailure < RuntimeError
|
6
|
+
end
|
7
|
+
|
8
|
+
class DriverNotFound < RuntimeError
|
9
|
+
def initialize(driver, msg = nil)
|
10
|
+
message =
|
11
|
+
if msg
|
12
|
+
msg
|
13
|
+
elsif driver.is_a? String
|
14
|
+
"Driver not found with name '#{driver}'."
|
15
|
+
elsif driver.is_a? Fixnum
|
16
|
+
"Driver at index #{driver} not found."
|
17
|
+
end
|
18
|
+
|
5
19
|
super(message)
|
6
20
|
end
|
7
21
|
end
|
8
22
|
|
9
|
-
class
|
23
|
+
class Failure < StandardError
|
10
24
|
end
|
11
25
|
|
12
|
-
class
|
26
|
+
class InvalidDataSource < StandardError
|
13
27
|
end
|
14
28
|
|
15
|
-
class
|
29
|
+
class InvalidFeature < StandardError
|
16
30
|
end
|
17
31
|
|
18
|
-
class
|
32
|
+
class InvalidFeatureDefinition < StandardError
|
19
33
|
end
|
20
34
|
|
21
|
-
class
|
35
|
+
class InvalidFieldDefinition < StandardError
|
22
36
|
end
|
23
37
|
|
24
|
-
class
|
38
|
+
class InvalidGeometry < StandardError
|
25
39
|
end
|
26
40
|
|
27
|
-
class
|
41
|
+
class InvalidGeometryFieldDefinition < StandardError
|
28
42
|
end
|
29
43
|
|
30
|
-
class
|
44
|
+
class InvalidHandle < RuntimeError
|
31
45
|
end
|
32
46
|
|
33
|
-
class
|
47
|
+
class InvalidLayer < StandardError
|
48
|
+
end
|
49
|
+
|
50
|
+
class InvalidStyleTable < StandardError
|
51
|
+
end
|
52
|
+
|
53
|
+
class InvalidSpatialReference < StandardError
|
54
|
+
end
|
55
|
+
|
56
|
+
class NotEnoughData < RuntimeError
|
57
|
+
end
|
58
|
+
|
59
|
+
class OpenFailure < RuntimeError
|
60
|
+
def initialize(file, msg = nil)
|
61
|
+
message = msg || "Unable to open file '#{file}'. Perhaps an unsupported file format?"
|
62
|
+
super(message)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class ReadOnlyObject < StandardError
|
67
|
+
def initialize(msg = nil)
|
68
|
+
message = msg || "The object you're accessing is read-only. Probably because it's internally managed by OGR."
|
69
|
+
super(message)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class UnsupportedGeometryType < StandardError
|
74
|
+
end
|
75
|
+
|
76
|
+
class UnsupportedOperation < StandardError
|
77
|
+
end
|
78
|
+
|
79
|
+
class UnsupportedSRS < StandardError
|
34
80
|
end
|
35
81
|
end
|