ffi-gdal 1.0.0.beta16 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dockerignore +17 -0
- data/.github/workflows/codacy.yml +61 -0
- data/.github/workflows/codeql.yml +74 -0
- data/.github/workflows/continuous-integration.yml +36 -0
- data/.github/workflows/dependency-review.yml +20 -0
- data/.github/workflows/specs-in-docker.yml +27 -0
- data/.gitignore +3 -0
- data/.rspec +1 -0
- data/.rubocop.yml +10 -80
- data/.rubocop_todo.yml +23 -40
- data/.ruby-version +1 -1
- data/Changelog-0.x.md +512 -0
- data/Changelog.md +12 -0
- data/Dockerfile.gdal2 +110 -0
- data/Dockerfile.gdal3 +73 -0
- data/README.md +25 -14
- data/Rakefile +0 -8
- data/Tiltfile +91 -0
- data/bin/bundle +123 -0
- data/bin/docker-clean +8 -0
- data/bin/rake +29 -0
- data/bin/rspec +29 -0
- data/bin/rubocop +29 -0
- data/docker-compose.yml +25 -0
- data/examples/extract_and_colorize.rb +0 -13
- data/examples/geometries.rb +14 -14
- data/examples/ogr_layer_to_layer.rb +1 -3
- data/examples/raster_erasing.rb +1 -0
- data/examples/remove_small_polygons.rb +1 -1
- data/examples/testing_gdal.rb +20 -17
- data/examples/warping.rb +9 -7
- data/ffi-gdal.gemspec +12 -6
- data/lib/ext/ffi_library_function_checks.rb +2 -2
- data/lib/ext/to_bool.rb +5 -3
- data/lib/ffi/cpl/conv.rb +27 -25
- data/lib/ffi/cpl/error.rb +19 -20
- data/lib/ffi/cpl/hash_set.rb +4 -4
- data/lib/ffi/cpl/http.rb +3 -3
- data/lib/ffi/cpl/http_result.rb +8 -8
- data/lib/ffi/cpl/list.rb +1 -1
- data/lib/ffi/cpl/mime_part.rb +2 -2
- data/lib/ffi/cpl/minixml.rb +7 -7
- data/lib/ffi/cpl/progress.rb +8 -8
- data/lib/ffi/cpl/quad_tree.rb +14 -14
- data/lib/ffi/cpl/rect_obj.rb +3 -3
- data/lib/ffi/cpl/string.rb +17 -20
- data/lib/ffi/cpl/vsi.rb +13 -13
- data/lib/ffi/cpl/xml_node.rb +3 -3
- data/lib/ffi/extensions/gdal/extensions/all.rb +4 -0
- data/lib/ffi/extensions/gdal/extensions/version.rb +9 -0
- data/lib/ffi/extensions/gdal/extensions.rb +12 -0
- data/lib/ffi/extensions/rttopo/gbox.rb +19 -0
- data/lib/ffi/extensions/rttopo/geom.rb +16 -0
- data/lib/ffi/extensions/rttopo.rb +41 -0
- data/lib/ffi/gdal/alg.rb +277 -277
- data/lib/ffi/gdal/color_entry.rb +3 -3
- data/lib/ffi/gdal/gcp.rb +6 -6
- data/lib/ffi/gdal/gdal.rb +349 -349
- data/lib/ffi/gdal/grid.rb +134 -134
- data/lib/ffi/gdal/grid_data_metrics_options.rb +4 -4
- data/lib/ffi/gdal/grid_inverse_distance_to_a_power_options.rb +9 -9
- data/lib/ffi/gdal/grid_moving_average_options.rb +4 -4
- data/lib/ffi/gdal/grid_nearest_neighbor_options.rb +3 -3
- data/lib/ffi/gdal/matching.rb +3 -3
- data/lib/ffi/gdal/rpc_info.rb +17 -17
- data/lib/ffi/gdal/transformer_info.rb +4 -4
- data/lib/ffi/gdal/version.rb +1 -1
- data/lib/ffi/gdal/vrt.rb +39 -39
- data/lib/ffi/gdal/warp_options.rb +34 -34
- data/lib/ffi/gdal/warper.rb +90 -90
- data/lib/ffi/gdal.rb +2 -31
- data/lib/ffi/ogr/api.rb +175 -167
- data/lib/ffi/ogr/contour_writer_info.rb +4 -4
- data/lib/ffi/ogr/core.rb +107 -107
- data/lib/ffi/ogr/envelope.rb +3 -3
- data/lib/ffi/ogr/envelope_3d.rb +5 -5
- data/lib/ffi/ogr/featurestyle.rb +3 -3
- data/lib/ffi/ogr/field.rb +22 -22
- data/lib/ffi/ogr/geocoding.rb +4 -4
- data/lib/ffi/ogr/srs_api.rb +154 -155
- data/lib/ffi/ogr/style_param.rb +3 -3
- data/lib/ffi/ogr/style_value.rb +4 -4
- data/lib/gdal/color_entry.rb +1 -5
- data/lib/gdal/color_interpretation.rb +7 -3
- data/lib/gdal/color_table.rb +46 -27
- data/lib/gdal/cpl_error_handler.rb +26 -6
- data/lib/gdal/data_type.rb +10 -3
- data/lib/gdal/dataset.rb +171 -85
- data/lib/gdal/dataset_mixins/algorithm_methods.rb +44 -44
- data/lib/gdal/dataset_mixins/matching.rb +1 -1
- data/lib/gdal/dataset_mixins/warp_methods.rb +4 -2
- data/lib/gdal/driver.rb +38 -21
- data/lib/gdal/environment_methods.rb +6 -6
- data/lib/gdal/extensions/all.rb +3 -0
- data/lib/gdal/{color_entry_mixins → extensions/color_entry}/extensions.rb +4 -1
- data/lib/gdal/{color_table_mixins → extensions/color_table}/extensions.rb +3 -0
- data/lib/gdal/extensions/dataset/extensions.rb +205 -0
- data/lib/gdal/{driver_mixins → extensions/driver}/extensions.rb +6 -2
- data/lib/gdal/{geo_transform_mixins → extensions/geo_transform}/extensions.rb +10 -8
- data/lib/gdal/{gridder → extensions/gridder}/point_extracting.rb +7 -5
- data/lib/gdal/{gridder.rb → extensions/gridder.rb} +33 -33
- data/lib/gdal/{gridder_options.rb → extensions/gridder_options.rb} +13 -14
- data/lib/gdal/{raster_attribute_table_mixins → extensions/raster_attribute_table}/extensions.rb +8 -6
- data/lib/gdal/{raster_band_mixins → extensions/raster_band}/algorithm_extensions.rb +8 -6
- data/lib/gdal/{raster_band_mixins → extensions/raster_band}/coloring_extensions.rb +6 -4
- data/lib/gdal/{raster_band_mixins → extensions/raster_band}/extensions.rb +9 -5
- data/lib/gdal/{raster_band_mixins → extensions/raster_band}/io_extensions.rb +18 -14
- data/lib/gdal/{raster_band_classifier.rb → extensions/raster_band_classifier.rb} +3 -5
- data/lib/gdal/geo_transform.rb +1 -6
- data/lib/gdal/grid.rb +3 -2
- data/lib/gdal/grid_algorithms.rb +9 -9
- data/lib/gdal/internal_helpers.rb +46 -9
- data/lib/gdal/major_object.rb +11 -3
- data/lib/gdal/options.rb +26 -32
- data/lib/gdal/raster_attribute_table.rb +63 -37
- data/lib/gdal/raster_band.rb +164 -116
- data/lib/gdal/raster_band_mixins/algorithm_methods.rb +26 -25
- data/lib/gdal/rpc_info.rb +3 -2
- data/lib/gdal/transformers/approximate_transformer.rb +12 -3
- data/lib/gdal/transformers/base_general_image_projection_transformer.rb +15 -2
- data/lib/gdal/transformers/gcp_transformer.rb +27 -19
- data/lib/gdal/transformers/general_image_projection_transformer.rb +8 -6
- data/lib/gdal/transformers/general_image_projection_transformer2.rb +9 -6
- data/lib/gdal/transformers/general_image_projection_transformer3.rb +6 -2
- data/lib/gdal/transformers/geolocation_transformer.rb +12 -4
- data/lib/gdal/transformers/reprojection_transformer.rb +11 -3
- data/lib/gdal/transformers/rpc_transformer.rb +11 -2
- data/lib/gdal/transformers/tps_transformer.rb +12 -4
- data/lib/gdal/version_info.rb +2 -2
- data/lib/gdal/virtual_dataset.rb +2 -0
- data/lib/gdal/warp_operation.rb +65 -54
- data/lib/gdal/warp_options.rb +9 -11
- data/lib/ogr/coordinate_transformation.rb +23 -9
- data/lib/ogr/data_source.rb +68 -37
- data/lib/ogr/driver.rb +18 -17
- data/lib/ogr/envelope.rb +0 -3
- data/lib/ogr/error_handling.rb +22 -24
- data/lib/ogr/extensions/all.rb +3 -0
- data/lib/ogr/{data_source_mixins → extensions/data_source}/capability_methods.rb +2 -0
- data/lib/ogr/extensions/data_source/data_source_extensions.rb +16 -0
- data/lib/ogr/{driver_mixins → extensions/driver}/capability_methods.rb +5 -1
- data/lib/ogr/extensions/envelope/extensions.rb +114 -0
- data/lib/ogr/extensions/feature/extensions.rb +87 -0
- data/lib/ogr/extensions/feature_definition/extensions.rb +43 -0
- data/lib/ogr/extensions/geometries/point/extensions.rb +19 -0
- data/lib/ogr/extensions/geometry/container_mixins.rb +56 -0
- data/lib/ogr/extensions/geometry/ewkb_io_extensions.rb +44 -0
- data/lib/ogr/extensions/geometry/ewkb_record.rb +94 -0
- data/lib/ogr/{geometry_mixins → extensions/geometry}/extensions.rb +16 -9
- data/lib/ogr/extensions/geometry/rttopo_extensions.rb +48 -0
- data/lib/ogr/extensions/geometry/wkb_record.rb +63 -0
- data/lib/ogr/extensions/geometry_types/curve/extensions.rb +68 -0
- data/lib/ogr/{layer_mixins → extensions/layer}/capability_methods.rb +4 -0
- data/lib/ogr/{layer_mixins → extensions/layer}/extensions.rb +11 -6
- data/lib/ogr/extensions/spatial_reference/extensions.rb +38 -0
- data/lib/ogr/extensions/spatial_reference/initializers.rb +138 -0
- data/lib/ogr/extensions/style_table/extensions.rb +31 -0
- data/lib/ogr/feature.rb +173 -88
- data/lib/ogr/feature_definition.rb +53 -45
- data/lib/ogr/field.rb +17 -19
- data/lib/ogr/field_definition.rb +30 -18
- data/lib/ogr/geocoder.rb +11 -4
- data/lib/ogr/geometries/line_string.rb +1 -0
- data/lib/ogr/geometries/line_string_25d.rb +0 -9
- data/lib/ogr/geometries/linear_ring.rb +2 -2
- data/lib/ogr/geometries/point.rb +0 -9
- data/lib/ogr/geometry.rb +116 -49
- data/lib/ogr/geometry_field_definition.rb +31 -15
- data/lib/ogr/geometry_types/container.rb +26 -28
- data/lib/ogr/geometry_types/curve.rb +5 -61
- data/lib/ogr/geometry_types/surface.rb +1 -1
- data/lib/ogr/internal_helpers.rb +2 -2
- data/lib/ogr/layer.rb +12 -10
- data/lib/ogr/layer_mixins/ogr_feature_methods.rb +39 -27
- data/lib/ogr/layer_mixins/ogr_field_methods.rb +66 -50
- data/lib/ogr/layer_mixins/ogr_layer_method_methods.rb +17 -8
- data/lib/ogr/layer_mixins/ogr_query_filter_methods.rb +7 -6
- data/lib/ogr/layer_mixins/ogr_sql_methods.rb +15 -7
- data/lib/ogr/spatial_reference.rb +79 -42
- data/lib/ogr/spatial_reference_mixins/coordinate_system_getter_setters.rb +149 -118
- data/lib/ogr/spatial_reference_mixins/exporters.rb +87 -51
- data/lib/ogr/spatial_reference_mixins/importers.rb +88 -43
- data/lib/ogr/spatial_reference_mixins/morphers.rb +12 -8
- data/lib/ogr/spatial_reference_mixins/parameter_getter_setters.rb +27 -13
- data/lib/ogr/style_table.rb +15 -5
- data/lib/ogr/style_tool.rb +29 -15
- data/lib/ogr.rb +1 -0
- data/rakelib/docker.rake +10 -0
- data/sorbet/rbi/hidden-definitions/errors.txt +21790 -0
- data/tilt/gdal2.yml +22 -0
- data/tilt/gdal3.yml +22 -0
- metadata +116 -280
- data/History.md +0 -360
- data/lib/ext/error_symbols.rb +0 -7
- data/lib/gdal/dataset_mixins/extensions.rb +0 -380
- data/lib/gdal/merger.rb +0 -132
- data/lib/ogr/data_source_extensions.rb +0 -10
- data/lib/ogr/envelope_extensions.rb +0 -110
- data/lib/ogr/feature_definition_extensions.rb +0 -39
- data/lib/ogr/feature_extensions.rb +0 -87
- data/lib/ogr/geometry_mixins/container_mixins.rb +0 -25
- data/lib/ogr/spatial_reference_extensions.rb +0 -34
- data/lib/ogr/style_table_extensions.rb +0 -26
- data/spec/ffi-gdal_spec.rb +0 -24
- data/spec/integration/gdal/color_table_info_spec.rb +0 -78
- data/spec/integration/gdal/dataset_info_spec.rb +0 -342
- data/spec/integration/gdal/driver_info_spec.rb +0 -170
- data/spec/integration/gdal/geo_transform_info_spec.rb +0 -226
- data/spec/integration/gdal/gridder_spec.rb +0 -331
- data/spec/integration/gdal/raster_attribute_table_info_spec.rb +0 -229
- data/spec/integration/gdal/raster_band_algorithms_spec.rb +0 -35
- data/spec/integration/gdal/raster_band_info_spec.rb +0 -320
- data/spec/integration/ogr/layer_spec.rb +0 -95
- data/spec/spec_helper.rb +0 -116
- data/spec/support/images/123.tiff +0 -0
- data/spec/support/images/osgeo/gdal/data/hfa/float-rle.img +0 -0
- data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.lgo +0 -31
- data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.tif +0 -0
- data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.tif.msk +0 -0
- data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.txt +0 -10
- data/spec/support/images/osgeo/geotiff/gdal_eg/cea.tif +0 -0
- data/spec/support/images/osgeo/geotiff/gdal_eg/cea.txt +0 -84
- data/spec/support/images/osgeo/geotiff/zi_imaging/image0.lgo +0 -45
- data/spec/support/images/osgeo/geotiff/zi_imaging/image0.tif +0 -0
- data/spec/support/integration_help.rb +0 -34
- data/spec/support/shapefiles/states_21basic/states.dbf +0 -0
- data/spec/support/shapefiles/states_21basic/states.prj +0 -1
- data/spec/support/shapefiles/states_21basic/states.sbn +0 -0
- data/spec/support/shapefiles/states_21basic/states.sbx +0 -0
- data/spec/support/shapefiles/states_21basic/states.shp +0 -0
- data/spec/support/shapefiles/states_21basic/states.shp.xml +0 -3
- data/spec/support/shapefiles/states_21basic/states.shx +0 -0
- data/spec/support/shared_contexts.rb +0 -28
- data/spec/support/shared_examples/gdal/major_object_examples.rb +0 -55
- data/spec/support/shared_examples/ogr/a_25d_geometry.rb +0 -9
- data/spec/support/shared_examples/ogr/a_container_geometry.rb +0 -49
- data/spec/support/shared_examples/ogr/a_geometry.rb +0 -406
- data/spec/support/shared_examples/ogr/a_line_string.rb +0 -18
- data/spec/support/test_style_table.txt +0 -3
- data/spec/support/worldfiles/SR_50M/SR_50M.VERSION.txt +0 -1
- data/spec/support/worldfiles/SR_50M/SR_50M.prj +0 -1
- data/spec/support/worldfiles/SR_50M/SR_50M.tfw +0 -6
- data/spec/support/worldfiles/SR_50M/SR_50M.tif +0 -0
- data/spec/unit/ext/error_symbols_spec.rb +0 -69
- data/spec/unit/ext/numeric_as_data_type_spec.rb +0 -115
- data/spec/unit/ffi/gdal_spec.rb +0 -73
- data/spec/unit/gdal/color_entry_spec.rb +0 -8
- data/spec/unit/gdal/color_interpretation_spec.rb +0 -8
- data/spec/unit/gdal/color_table_mixins/extensions_spec.rb +0 -62
- data/spec/unit/gdal/color_table_spec.rb +0 -146
- data/spec/unit/gdal/data_type_spec.rb +0 -74
- data/spec/unit/gdal/dataset_mixins/warp_methods_spec.rb +0 -55
- data/spec/unit/gdal/dataset_spec.rb +0 -148
- data/spec/unit/gdal/driver_mixins/extensions_spec.rb +0 -24
- data/spec/unit/gdal/driver_spec.rb +0 -51
- data/spec/unit/gdal/environment_methods_spec.rb +0 -8
- data/spec/unit/gdal/geo_transform_mixins/extensions_spec.rb +0 -69
- data/spec/unit/gdal/geo_transform_spec.rb +0 -265
- data/spec/unit/gdal/grid_spec.rb +0 -98
- data/spec/unit/gdal/gridder/point_extracting_spec.rb +0 -101
- data/spec/unit/gdal/gridder_options_spec.rb +0 -185
- data/spec/unit/gdal/gridder_spec.rb +0 -182
- data/spec/unit/gdal/internal_helpers_spec.rb +0 -278
- data/spec/unit/gdal/major_object_spec.rb +0 -10
- data/spec/unit/gdal/options_spec.rb +0 -33
- data/spec/unit/gdal/raster_attribute_table_spec.rb +0 -7
- data/spec/unit/gdal/raster_band_classifier_spec.rb +0 -260
- data/spec/unit/gdal/raster_band_mixins/extensions_spec.rb +0 -73
- data/spec/unit/gdal/raster_band_mixins/io_extensions_spec.rb +0 -135
- data/spec/unit/gdal/raster_band_spec.rb +0 -8
- data/spec/unit/gdal/rpc_info_spec.rb +0 -8
- data/spec/unit/gdal/version_info_spec.rb +0 -10
- data/spec/unit/gdal/virtual_dataset_spec.rb +0 -34
- data/spec/unit/gdal/warp_operation_spec.rb +0 -8
- data/spec/unit/gdal/warp_options_spec.rb +0 -338
- data/spec/unit/ogr/coordinate_transformation_spec.rb +0 -104
- data/spec/unit/ogr/data_source_mixins/capability_methods_spec.rb +0 -32
- data/spec/unit/ogr/data_source_spec.rb +0 -223
- data/spec/unit/ogr/driver_mixins/capability_methods_spec.rb +0 -20
- data/spec/unit/ogr/driver_spec.rb +0 -152
- data/spec/unit/ogr/envelope_spec.rb +0 -324
- data/spec/unit/ogr/feature_definition_spec.rb +0 -296
- data/spec/unit/ogr/feature_extensions_spec.rb +0 -90
- data/spec/unit/ogr/feature_spec.rb +0 -363
- data/spec/unit/ogr/field_definition_spec.rb +0 -118
- data/spec/unit/ogr/field_spec.rb +0 -195
- data/spec/unit/ogr/geometries/geometry_collection_25d_spec.rb +0 -25
- data/spec/unit/ogr/geometries/geometry_collection_spec.rb +0 -188
- data/spec/unit/ogr/geometries/line_string_25d_spec.rb +0 -25
- data/spec/unit/ogr/geometries/line_string_spec.rb +0 -107
- data/spec/unit/ogr/geometries/linear_ring_spec.rb +0 -92
- data/spec/unit/ogr/geometries/multi_line_string_25d_spec.rb +0 -25
- data/spec/unit/ogr/geometries/multi_line_string_spec.rb +0 -16
- data/spec/unit/ogr/geometries/multi_point_25d_spec.rb +0 -25
- data/spec/unit/ogr/geometries/multi_point_spec.rb +0 -16
- data/spec/unit/ogr/geometries/multi_polygon_25d_spec.rb +0 -25
- data/spec/unit/ogr/geometries/multi_polygon_spec.rb +0 -43
- data/spec/unit/ogr/geometries/none_geometry_spec.rb +0 -14
- data/spec/unit/ogr/geometries/point_25d_spec.rb +0 -25
- data/spec/unit/ogr/geometries/point_spec.rb +0 -307
- data/spec/unit/ogr/geometries/polygon_25d_spec.rb +0 -25
- data/spec/unit/ogr/geometries/polygon_spec.rb +0 -19
- data/spec/unit/ogr/geometries/unknown_geometry_spec.rb +0 -12
- data/spec/unit/ogr/geometry_field_definition_spec.rb +0 -73
- data/spec/unit/ogr/geometry_spec.rb +0 -711
- data/spec/unit/ogr/internal_helpers_spec.rb +0 -70
- data/spec/unit/ogr/layer_mixins/capability_methods_spec.rb +0 -90
- data/spec/unit/ogr/layer_mixins/ogr_feature_methods_spec.rb +0 -155
- data/spec/unit/ogr/layer_mixins/ogr_field_methods_spec.rb +0 -434
- data/spec/unit/ogr/layer_mixins/ogr_layer_method_methods_spec.rb +0 -22
- data/spec/unit/ogr/layer_mixins/ogr_query_filter_methods_spec.rb +0 -44
- data/spec/unit/ogr/layer_mixins/ogr_sql_methods_spec.rb +0 -14
- data/spec/unit/ogr/layer_spec.rb +0 -98
- data/spec/unit/ogr/spatial_reference_mixins/coordinate_system_getter_setters_spec.rb +0 -48
- data/spec/unit/ogr/spatial_reference_mixins/exporters_spec.rb +0 -151
- data/spec/unit/ogr/spatial_reference_mixins/importers_spec.rb +0 -40
- data/spec/unit/ogr/spatial_reference_mixins/morphers_spec.rb +0 -38
- data/spec/unit/ogr/spatial_reference_mixins/parameter_getter_setters_spec.rb +0 -105
- data/spec/unit/ogr/spatial_reference_mixins/type_checks_spec.rb +0 -159
- data/spec/unit/ogr/spatial_reference_spec.rb +0 -44
- data/spec/unit/ogr/style_table_spec.rb +0 -108
- data/spec/unit/ogr/style_tool_spec.rb +0 -159
- data/spec/unit/version_info_spec.rb +0 -50
data/lib/ogr/error_handling.rb
CHANGED
@@ -10,38 +10,36 @@ module OGR
|
|
10
10
|
# Unlike the OGR API, ffi-gdal defines an Enum for the OGRERR types, which
|
11
11
|
# in turns causes OGR to return Symbols on errors (the #defines for those can
|
12
12
|
# be found here: http://www.gdal.org/ogr__core_8h.html). This maps those
|
13
|
-
# Symbols to Ruby exceptions (or lack thereof).
|
14
|
-
# solution is that any function that returns an OGRErr needs to assign that
|
15
|
-
# Symbol to a variable, then call #handle_result to get that
|
16
|
-
# Symbol-to-Exception mapping to take place.
|
13
|
+
# Symbols to Ruby exceptions (or lack thereof).
|
17
14
|
module ErrorHandling
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
ERROR_CLASS_MAP = {
|
16
|
+
OGRERR_NONE: nil,
|
17
|
+
OGRERR_NOT_ENOUGH_DATA: OGR::NotEnoughData,
|
18
|
+
OGRERR_NOT_ENOUGH_MEMORY: ::NoMemoryError,
|
19
|
+
OGRERR_UNSUPPORTED_GEOMETRY_TYPE: OGR::UnsupportedGeometryType,
|
20
|
+
OGRERR_UNSUPPORTED_OPERATION: OGR::UnsupportedOperation,
|
21
|
+
OGRERR_CORRUPT_DATA: OGR::CorruptData,
|
22
|
+
OGRERR_FAILURE: OGR::Failure,
|
23
|
+
OGRERR_UNSUPPORTED_SRS: OGR::UnsupportedSRS,
|
24
|
+
OGRERR_INVALID_HANDLE: OGR::InvalidHandle
|
25
|
+
}.freeze
|
26
|
+
|
27
|
+
# Yields, then expects the result to be a Symbol from FFI::OGR::Core::Err.
|
28
|
+
#
|
29
|
+
# @param msg [String]
|
30
|
+
def self.handle_ogr_err(msg)
|
31
|
+
ogr_err_symbol = yield
|
21
32
|
|
22
|
-
|
33
|
+
klass = ERROR_CLASS_MAP.fetch(ogr_err_symbol) { raise "Unknown OGRERR type: #{self}" }
|
23
34
|
|
24
|
-
|
25
|
-
# @return [Proc]
|
26
|
-
def error_class_map(error_class)
|
27
|
-
{
|
28
|
-
OGRERR_NONE: ->(_msg) { true },
|
29
|
-
OGRERR_NOT_ENOUGH_DATA: ->(msg) { raise_exception(OGR::NotEnoughData, msg) },
|
30
|
-
OGRERR_NOT_ENOUGH_MEMORY: ->(msg) { raise_exception(::NoMemoryError, msg) },
|
31
|
-
OGRERR_UNSUPPORTED_GEOMETRY_TYPE: ->(msg) { raise_exception(OGR::UnsupportedGeometryType, msg) },
|
32
|
-
OGRERR_UNSUPPORTED_OPERATION: ->(msg) { raise_exception(OGR::UnsupportedOperation, msg) },
|
33
|
-
OGRERR_CORRUPT_DATA: ->(msg) { raise_exception(OGR::CorruptData, msg) },
|
34
|
-
OGRERR_FAILURE: ->(msg) { raise_exception(OGR::Failure, msg) },
|
35
|
-
OGRERR_UNSUPPORTED_SRS: ->(msg) { raise_exception(OGR::UnsupportedSRS, msg) },
|
36
|
-
OGRERR_INVALID_HANDLE: ->(msg) { raise_exception(OGR::InvalidHandle, msg) }
|
37
|
-
}.fetch(error_class) { raise "Unknown OGRERR type: #{self}" }
|
35
|
+
raise_exception(klass, msg) if klass
|
38
36
|
end
|
39
37
|
|
40
38
|
# Exists solely to strip off the top 4 lines of the backtrace so it doesn't
|
41
39
|
# look like the problem is coming from here.
|
42
|
-
def raise_exception(exception, message)
|
40
|
+
def self.raise_exception(exception, message)
|
43
41
|
e = exception.new(message)
|
44
|
-
e.set_backtrace(caller(
|
42
|
+
e.set_backtrace(caller(2))
|
45
43
|
raise(e)
|
46
44
|
end
|
47
45
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ogr/data_source'
|
4
|
+
|
5
|
+
module OGR
|
6
|
+
class DataSource
|
7
|
+
module Extensions
|
8
|
+
# @return [Array<OGR::Layer>]
|
9
|
+
def layers
|
10
|
+
@layers = Array.new(layer_count) { |i| layer(i) }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
OGR::DataSource.include(OGR::DataSource::Extensions)
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'ogr/driver'
|
4
|
+
|
3
5
|
module OGR
|
4
6
|
module DriverMixins
|
5
7
|
# Helper methods for testing capabilities of the current driver.
|
@@ -11,8 +13,10 @@ module OGR
|
|
11
13
|
|
12
14
|
# @return [Boolean] +true+ if this driver supports deleting data sources.
|
13
15
|
def can_delete_data_source?
|
14
|
-
test_capability('
|
16
|
+
test_capability('DeleteDataSource')
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
21
|
+
|
22
|
+
OGR::Driver.include(OGR::DriverMixins::CapabilityMethods)
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ogr/envelope'
|
4
|
+
|
5
|
+
module OGR
|
6
|
+
class Envelope
|
7
|
+
module Extensions
|
8
|
+
# @return [Float] x_max - x_min
|
9
|
+
def x_size
|
10
|
+
x_max - x_min
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return [Float] y_max - y_min
|
14
|
+
def y_size
|
15
|
+
y_max - y_min
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [Float] z_max - z_min
|
19
|
+
def z_size
|
20
|
+
return unless z_max && z_min
|
21
|
+
|
22
|
+
z_max - z_min
|
23
|
+
end
|
24
|
+
|
25
|
+
# Adapted from "Advanced Geospatial Python Modeling". Calculates the
|
26
|
+
# pixel locations of these geospatial coordinates according to the given
|
27
|
+
# GeoTransform.
|
28
|
+
#
|
29
|
+
# @param geo_transform [GDAL::GeoTransform]
|
30
|
+
# @return [Hash{x_min => Integer, y_min => Integer, x_max => Integer, y_max => Integer}]
|
31
|
+
def world_to_pixels(geo_transform)
|
32
|
+
min_values = geo_transform.world_to_pixel(x_min, y_max)
|
33
|
+
max_values = geo_transform.world_to_pixel(x_max, y_min)
|
34
|
+
|
35
|
+
{
|
36
|
+
x_min: min_values[:pixel].round.to_i,
|
37
|
+
y_min: min_values[:line].round.to_i,
|
38
|
+
x_max: max_values[:pixel].round.to_i,
|
39
|
+
y_max: max_values[:line].round.to_i
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
# Compares min/max X and min/max Y to the other envelope. The envelopes are
|
44
|
+
# considered equal if those values are the same.
|
45
|
+
#
|
46
|
+
# @param other [OGR::Envelope]
|
47
|
+
# @return [Boolean]
|
48
|
+
def ==(other)
|
49
|
+
x_min == other.x_min && y_min == other.y_min &&
|
50
|
+
x_max == other.x_max && y_max == other.y_max
|
51
|
+
end
|
52
|
+
|
53
|
+
# Stolen from http://www.gdal.org/ogr__core_8h_source.html.
|
54
|
+
#
|
55
|
+
# @param other_envelope [OGR::Envelope] The Envelope to merge self with.
|
56
|
+
# @return [OGR::Envelope]
|
57
|
+
def merge(other_envelope)
|
58
|
+
new_envelope = OGR::Envelope.new
|
59
|
+
new_envelope.x_min = [x_min, other_envelope.x_min].min
|
60
|
+
new_envelope.x_max = [x_max, other_envelope.x_max].max
|
61
|
+
new_envelope.y_min = [y_min, other_envelope.y_min].min
|
62
|
+
new_envelope.y_max = [y_max, other_envelope.y_max].max
|
63
|
+
|
64
|
+
new_envelope
|
65
|
+
end
|
66
|
+
|
67
|
+
# Stolen from http://www.gdal.org/ogr__core_8h_source.html.
|
68
|
+
#
|
69
|
+
# @param other_envelope [OGR::Envelope] The Envelope to check intersection
|
70
|
+
# with.
|
71
|
+
# @return [Boolean]
|
72
|
+
def intersects?(other_envelope)
|
73
|
+
x_min <= other_envelope.x_max &&
|
74
|
+
x_max >= other_envelope.x_min &&
|
75
|
+
y_min <= other_envelope.y_max &&
|
76
|
+
y_max >= other_envelope.y_min
|
77
|
+
end
|
78
|
+
|
79
|
+
# Stolen from http://www.gdal.org/ogr__core_8h_source.html.
|
80
|
+
#
|
81
|
+
# @param other_envelope [OGR::Envelope] The Envelope to check containment
|
82
|
+
# with.
|
83
|
+
# @return [Boolean]
|
84
|
+
def contains?(other_envelope)
|
85
|
+
x_min <= other_envelope.x_min &&
|
86
|
+
y_min <= other_envelope.y_min &&
|
87
|
+
x_max >= other_envelope.x_max &&
|
88
|
+
y_max >= other_envelope.y_max
|
89
|
+
end
|
90
|
+
|
91
|
+
# @return [OGR::Polygon]
|
92
|
+
def to_polygon
|
93
|
+
ring = OGR::LinearRing.new
|
94
|
+
ring.point_count = 5
|
95
|
+
ring.set_point(0, x_min, y_max)
|
96
|
+
ring.set_point(1, x_max, y_max)
|
97
|
+
ring.set_point(2, x_max, y_min)
|
98
|
+
ring.set_point(3, x_min, y_min)
|
99
|
+
ring.set_point(4, x_min, y_max)
|
100
|
+
|
101
|
+
polygon = OGR::Polygon.new
|
102
|
+
polygon.add_geometry(ring)
|
103
|
+
|
104
|
+
polygon
|
105
|
+
end
|
106
|
+
|
107
|
+
def to_a
|
108
|
+
[x_min, y_min, x_max, y_max]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
OGR::Envelope.include(OGR::Envelope::Extensions)
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ogr/feature'
|
4
|
+
|
5
|
+
module OGR
|
6
|
+
class Feature
|
7
|
+
module Extensions
|
8
|
+
# Retrieves the value for each field and yields it.
|
9
|
+
#
|
10
|
+
# @return [Enumerator]
|
11
|
+
# @yieldparam [Number, String, Array]
|
12
|
+
def each_field
|
13
|
+
return enum_for(:each_field) unless block_given?
|
14
|
+
|
15
|
+
field_count.times do |i|
|
16
|
+
yield field(i)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Array] Uses each FieldDefinition to determine the field type at
|
21
|
+
# each index and returns maps the field as that value type.
|
22
|
+
def fields
|
23
|
+
each_field.to_a
|
24
|
+
end
|
25
|
+
|
26
|
+
# Retrieves a field using +index+, but uses its type from the associated
|
27
|
+
# {OGR::FieldDefinition} to determine it's core type to return as. This
|
28
|
+
# saves from having to find out the type then call the associated
|
29
|
+
# +field_as_[type]+ method if you just want the data in it's originally
|
30
|
+
# intended form.
|
31
|
+
#
|
32
|
+
# @param index [Integer] Index of the field to retrieve the data for.
|
33
|
+
# @return [Number, String, Array]
|
34
|
+
# @raise [OGR::UnsupportedFieldType] if the associated FieldDefinition's
|
35
|
+
# type has not yet been mapped here (to know how to return the value).
|
36
|
+
def field(index)
|
37
|
+
field_type = field_definition(index).type
|
38
|
+
|
39
|
+
case field_type
|
40
|
+
when :OFTInteger, :OFTInteger64 then field_as_integer(index)
|
41
|
+
when :OFTIntegerList, :OFTInteger64List then field_as_integer_list(index)
|
42
|
+
when :OFTReal then field_as_double(index)
|
43
|
+
when :OFTRealList then field_as_double_list(index)
|
44
|
+
when :OFTString, :OFTWideString then field_as_string(index)
|
45
|
+
when :OFTStringList, :OFTWideStringList then field_as_string_list(index)
|
46
|
+
when :OFTBinary then field_as_binary(index)
|
47
|
+
when :OFTDate, :OFTTime, :OFTDateTime, :OFTMaxType then field_as_date_time(index)
|
48
|
+
else
|
49
|
+
raise OGR::UnsupportedFieldType,
|
50
|
+
"Don't know how to fetch field for field type: #{field_type}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [Enumerator]
|
55
|
+
# @yieldparam [OGR::GeometryFieldDefinition]
|
56
|
+
def each_geometry_field_definition
|
57
|
+
return enum_for(:each_geometry_field_definition) unless block_given?
|
58
|
+
|
59
|
+
geometry_field_count.times do |i|
|
60
|
+
yield geometry_field_definition(i)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [Array<OGR::GeometryFieldDefinition>]
|
65
|
+
def geometry_field_definitions
|
66
|
+
each_geometry_field_definition.to_a
|
67
|
+
end
|
68
|
+
|
69
|
+
# @return [Enumerator]
|
70
|
+
# @yieldparam [OGR::Geometry]
|
71
|
+
def each_geometry_field
|
72
|
+
return enum_for(:each_geometry_field) unless block_given?
|
73
|
+
|
74
|
+
geometry_field_count.times do |i|
|
75
|
+
yield geometry_field(i)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# @return [Array<OGR::Geometry>]
|
80
|
+
def geometry_fields
|
81
|
+
each_geometry_field.to_a
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
OGR::Feature.include(OGR::Feature::Extensions)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ogr/feature_definition'
|
4
|
+
|
5
|
+
module OGR
|
6
|
+
class FeatureDefinition
|
7
|
+
module Extensions
|
8
|
+
# @return [Array<OGR::FieldDefinition>]
|
9
|
+
def field_definitions
|
10
|
+
return [] if field_count.zero?
|
11
|
+
|
12
|
+
Array.new(field_count) { |i| field_definition(i) }
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [Array<OGR::GeometryFieldDefinition>]
|
16
|
+
def geometry_field_definitions
|
17
|
+
return [] if geometry_field_count.zero?
|
18
|
+
|
19
|
+
Array.new(geometry_field_count) { |i| geometry_field_definition(i) }
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param name [String]
|
23
|
+
# @return [OGR::FieldDefinition]
|
24
|
+
def field_definition_by_name(name)
|
25
|
+
i = field_index(name)
|
26
|
+
return unless i
|
27
|
+
|
28
|
+
field_definition(i)
|
29
|
+
end
|
30
|
+
|
31
|
+
# @param name [String]
|
32
|
+
# @return [OGR::GeometryFieldDefinition]
|
33
|
+
def geometry_field_definition_by_name(name)
|
34
|
+
g = geometry_field_index(name)
|
35
|
+
return unless g
|
36
|
+
|
37
|
+
geometry_field_definition(g)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
OGR::FeatureDefinition.include(OGR::FeatureDefinition::Extensions)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ogr/geometry'
|
4
|
+
|
5
|
+
module OGR
|
6
|
+
class Point
|
7
|
+
module Extensions
|
8
|
+
# Wrapper around {#point_value} to provide API parity with other geometries
|
9
|
+
# that can have multiple points.
|
10
|
+
#
|
11
|
+
# @return [Array<Array<Float, Float>>]
|
12
|
+
def point_values
|
13
|
+
[point]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
OGR::Point.include(OGR::Point::Extensions)
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ogr/geometries/geometry_collection'
|
4
|
+
require 'ogr/geometries/geometry_collection_25d'
|
5
|
+
require 'ogr/geometries/multi_line_string'
|
6
|
+
require 'ogr/geometries/multi_line_string_25d'
|
7
|
+
require 'ogr/geometries/multi_point'
|
8
|
+
require 'ogr/geometries/multi_point_25d'
|
9
|
+
require 'ogr/geometries/multi_polygon'
|
10
|
+
require 'ogr/geometries/multi_polygon_25d'
|
11
|
+
require 'ogr/geometries/polygon'
|
12
|
+
require 'ogr/geometries/polygon_25d'
|
13
|
+
|
14
|
+
module OGR
|
15
|
+
module GeometryMixins
|
16
|
+
module ContainerMixins
|
17
|
+
include Enumerable
|
18
|
+
|
19
|
+
def collection?
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
# Iterates over each geometry in the container geometry. Per `OGR` docs, the
|
24
|
+
# yielded geometry should not be modified; if you need to do something to
|
25
|
+
# that geometry, you should {{#clone}} it. Additionally, the yielded
|
26
|
+
# geometry is only valid until the container changes.
|
27
|
+
#
|
28
|
+
# @yieldparam [OGR::Geometry]
|
29
|
+
# @return [Enumerator]
|
30
|
+
# @see http://gdal.org/1.11/ogr/ogr__api_8h.html#a6bac93150529a5c98811db29e289dd66
|
31
|
+
def each
|
32
|
+
return enum_for(:each) unless block_given?
|
33
|
+
|
34
|
+
geometry_count.times do |i|
|
35
|
+
yield geometry_at(i)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Using prepend here to override the `#collection?` method that's already defined on Geometry.
|
43
|
+
OGR::GeometryCollection.prepend(OGR::GeometryMixins::ContainerMixins)
|
44
|
+
OGR::GeometryCollection25D.prepend(OGR::GeometryMixins::ContainerMixins)
|
45
|
+
|
46
|
+
OGR::MultiPolygon.prepend(OGR::GeometryMixins::ContainerMixins)
|
47
|
+
OGR::MultiPolygon25D.prepend(OGR::GeometryMixins::ContainerMixins)
|
48
|
+
|
49
|
+
OGR::MultiLineString.prepend(OGR::GeometryMixins::ContainerMixins)
|
50
|
+
OGR::MultiLineString25D.prepend(OGR::GeometryMixins::ContainerMixins)
|
51
|
+
|
52
|
+
OGR::MultiPoint.prepend(OGR::GeometryMixins::ContainerMixins)
|
53
|
+
OGR::MultiPoint25D.prepend(OGR::GeometryMixins::ContainerMixins)
|
54
|
+
|
55
|
+
OGR::Polygon.prepend(OGR::GeometryMixins::ContainerMixins)
|
56
|
+
OGR::Polygon25D.prepend(OGR::GeometryMixins::ContainerMixins)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ogr/spatial_reference'
|
4
|
+
require_relative 'ewkb_record'
|
5
|
+
require_relative 'wkb_record'
|
6
|
+
|
7
|
+
module OGR
|
8
|
+
module Geometry
|
9
|
+
# Extends OGR::Geometry with methods that allow creating a Geometry from
|
10
|
+
# EKWB or outputting a Geometry as EWKB (EWKB is the WKB format that PostGIS
|
11
|
+
# uses).
|
12
|
+
module EWKBIOExtensions
|
13
|
+
# Methods to extend OGR::Geometry with.
|
14
|
+
module ClassMethods
|
15
|
+
# @param ewkb_data [String] Binary EWKB string.
|
16
|
+
# @return [OGR::Geometry]
|
17
|
+
def create_from_ewkb(ewkb_data)
|
18
|
+
e = EWKBRecord.read(ewkb_data)
|
19
|
+
|
20
|
+
if e.srid?
|
21
|
+
spatial_ref = OGR::SpatialReference.new.import_from_epsg(e.srid)
|
22
|
+
create_from_wkb(e.to_wkb, spatial_ref)
|
23
|
+
else
|
24
|
+
create_from_wkb(e.to_wkb)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.included(base)
|
30
|
+
base.extend(ClassMethods)
|
31
|
+
end
|
32
|
+
|
33
|
+
# @return [String] Binary string representative of EWKB.
|
34
|
+
def to_ewkb
|
35
|
+
wkb_record = WKBRecord.read(to_wkb)
|
36
|
+
srid = spatial_reference ? spatial_reference.authority_code.to_i : 0
|
37
|
+
|
38
|
+
EWKBRecord.from_wkb_record(wkb_record, srid).to_binary_s
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
OGR::Geometry.include OGR::Geometry::EWKBIOExtensions
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bindata'
|
4
|
+
require 'ffi-gdal'
|
5
|
+
require 'ogr'
|
6
|
+
require_relative 'wkb_record'
|
7
|
+
|
8
|
+
# rubocop:disable Naming/PredicateName
|
9
|
+
module OGR
|
10
|
+
module Geometry
|
11
|
+
# Parses raw EWKB and turns into a data structure. Only really exists for
|
12
|
+
# converting to and from EWKB.
|
13
|
+
#
|
14
|
+
# @see http://trac.osgeo.org/postgis/browser/trunk/doc/ZMSgeoms.txt
|
15
|
+
# @see OGR::Geometry::EWKBRecord
|
16
|
+
class EWKBRecord < BinData::Record
|
17
|
+
uint8 :endianness, assert: -> { [0, 1].include?(value) }
|
18
|
+
|
19
|
+
# Choose the type based on the endianness.
|
20
|
+
choice :wkb_type, selection: :endianness do
|
21
|
+
uint32be 0
|
22
|
+
uint32le 1
|
23
|
+
end
|
24
|
+
|
25
|
+
# Make sure the geometry_type is one OGR knows about.
|
26
|
+
virtual assert: -> { FFI::OGR::Core::WKBGeometryType.symbol_map.value?(geometry_type) }
|
27
|
+
|
28
|
+
# If the wkb_type has the SRID flag set, there's an SRID.
|
29
|
+
choice :srid, onlyif: :has_srid?, selection: :endianness do
|
30
|
+
uint32be 0
|
31
|
+
uint32le 1
|
32
|
+
end
|
33
|
+
|
34
|
+
# The #geometry attribute is just the rest of the data. We don't care what
|
35
|
+
# kind of geom it actually is; that doesn't matter for building EWKB.
|
36
|
+
rest :geometry
|
37
|
+
|
38
|
+
WKB_Z = 0x8000_0000
|
39
|
+
WKB_M = 0x4000_0000
|
40
|
+
WKB_SRID = 0x2000_0000
|
41
|
+
|
42
|
+
# @param wkb_record [OGR::Geometry::WKBRecord]
|
43
|
+
# @param srid [Fixnum]
|
44
|
+
# @return [OGR::Geometry::EWKBRecord]
|
45
|
+
def self.from_wkb_record(wkb_record, srid = 0)
|
46
|
+
ewkb_type_flag = if srid.zero?
|
47
|
+
wkb_record.wkb_type
|
48
|
+
else
|
49
|
+
(wkb_record.wkb_type | WKB_SRID)
|
50
|
+
end
|
51
|
+
|
52
|
+
ewkb_type_flag |= WKB_Z if wkb_record.has_z?
|
53
|
+
|
54
|
+
new(endianness: wkb_record.endianness,
|
55
|
+
wkb_type: ewkb_type_flag,
|
56
|
+
srid: srid,
|
57
|
+
geometry: wkb_record.geometry)
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [Boolean] Is the Z flag set?
|
61
|
+
def has_z?
|
62
|
+
wkb_type & WKB_Z != 0
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return [Boolean] Is the M flag set?
|
66
|
+
def has_m?
|
67
|
+
wkb_type & WKB_M != 0
|
68
|
+
end
|
69
|
+
|
70
|
+
# @return [Boolean] Is the SRID flag set?
|
71
|
+
def has_srid?
|
72
|
+
wkb_type & WKB_SRID != 0
|
73
|
+
end
|
74
|
+
|
75
|
+
# @return [Fixnum] Enum number that matches the FFI::OGR::Core::WKBGeometryType.
|
76
|
+
def geometry_type
|
77
|
+
type = wkb_type & 0x0fff_ffff
|
78
|
+
|
79
|
+
has_z? ? (type | WKB_Z) : type
|
80
|
+
end
|
81
|
+
|
82
|
+
# @return [OGR::Geometry::WKBRecord]
|
83
|
+
def to_wkb_record
|
84
|
+
WKBRecord.from_ewkb_record(self)
|
85
|
+
end
|
86
|
+
|
87
|
+
# @return [String] WKB binary string.
|
88
|
+
def to_wkb
|
89
|
+
to_wkb_record.to_binary_s
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
# rubocop:enable Naming/PredicateName
|
@@ -1,22 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'ogr/geometry'
|
4
4
|
|
5
5
|
module OGR
|
6
6
|
module GeometryMixins
|
7
7
|
module Extensions
|
8
|
-
# @return [
|
8
|
+
# @return [Integer] The number of the UTM zone this geometry belongs to.
|
9
9
|
def utm_zone
|
10
10
|
return unless spatial_reference
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
self_as4326 =
|
13
|
+
if spatial_reference.authority_code == '4326'
|
14
|
+
self
|
15
|
+
else
|
16
|
+
# NOTE: #clone here has overriden Ruby's clone and calls OGR_G_Clone;
|
17
|
+
# it's important to do this and
|
18
|
+
as4326 = clone
|
19
|
+
return unless as4326.transform_to!(OGR::SpatialReference.new.import_from_epsg(4326))
|
18
20
|
|
19
|
-
|
21
|
+
as4326
|
22
|
+
end
|
23
|
+
|
24
|
+
self_as4326.self_as4326.buffer!(0) unless valid?
|
20
25
|
|
21
26
|
return unless self_as4326.point_on_surface.x
|
22
27
|
|
@@ -80,3 +85,5 @@ module OGR
|
|
80
85
|
end
|
81
86
|
end
|
82
87
|
end
|
88
|
+
|
89
|
+
OGR::Geometry.include(OGR::GeometryMixins::Extensions)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ogr'
|
4
|
+
require 'ffi/extensions/rttopo'
|
5
|
+
|
6
|
+
module OGR
|
7
|
+
module Geometry
|
8
|
+
# Methods for {{OGR::Geometry}}s that use rttopo to operate on
|
9
|
+
# themselves.
|
10
|
+
#
|
11
|
+
# @see http://postgis.net/docs/doxygen/2.1/da/de7/librttopo_8h_af8d208cf4c0bb7c9f96c75bddc6c498a.html#af8d208cf4c0bb7c9f96c75bddc6c498a
|
12
|
+
module RttopoExtensions
|
13
|
+
# Uses rttopo's make_valid to make the current geometry valid.
|
14
|
+
#
|
15
|
+
# @return [OGR::Geometry] Returns a new geometry, based on the
|
16
|
+
# rttopo_make_valid call.
|
17
|
+
def make_valid
|
18
|
+
ctx = FFI::Rttopo.rtgeom_init FFI::MemoryPointer::NULL, FFI::MemoryPointer::NULL, FFI::MemoryPointer::NULL
|
19
|
+
geom = FFI::Rttopo.rtgeom_from_wkb(ctx, to_wkb, wkb_size, false)
|
20
|
+
valid_geom = FFI::Rttopo.rtgeom_make_valid(ctx, geom)
|
21
|
+
valid_wkb_size = FFI::MemoryPointer.new(:size_t)
|
22
|
+
valid_wkb_ptr = FFI::Rttopo.rtgeom_to_wkb(ctx, valid_geom, FFI::Rttopo::RTWKB_EXTENDED, valid_wkb_size)
|
23
|
+
valid_wkb = valid_wkb_ptr.read_bytes(valid_wkb_size.read_int)
|
24
|
+
|
25
|
+
FFI::Rttopo.rtfree ctx, geom
|
26
|
+
FFI::Rttopo.rtfree ctx, valid_geom
|
27
|
+
FFI::Rttopo.rtfree ctx, valid_wkb_ptr
|
28
|
+
FFI::Rttopo.rtgeom_finish ctx
|
29
|
+
OGR::Geometry.create_from_wkb(valid_wkb)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
OGR::GeometryCollection25D.include(OGR::Geometry::RttopoExtensions)
|
36
|
+
OGR::LineString.include(OGR::Geometry::RttopoExtensions)
|
37
|
+
OGR::LineString25D.include(OGR::Geometry::RttopoExtensions)
|
38
|
+
OGR::LinearRing.include(OGR::Geometry::RttopoExtensions)
|
39
|
+
OGR::MultiLineString.include(OGR::Geometry::RttopoExtensions)
|
40
|
+
OGR::MultiLineString25D.include(OGR::Geometry::RttopoExtensions)
|
41
|
+
OGR::MultiPoint.include(OGR::Geometry::RttopoExtensions)
|
42
|
+
OGR::MultiPoint25D.include(OGR::Geometry::RttopoExtensions)
|
43
|
+
OGR::MultiPolygon.include(OGR::Geometry::RttopoExtensions)
|
44
|
+
OGR::MultiPolygon25D.include(OGR::Geometry::RttopoExtensions)
|
45
|
+
OGR::Point.include(OGR::Geometry::RttopoExtensions)
|
46
|
+
OGR::Point25D.include(OGR::Geometry::RttopoExtensions)
|
47
|
+
OGR::Polygon.include(OGR::Geometry::RttopoExtensions)
|
48
|
+
OGR::Polygon25D.include(OGR::Geometry::RttopoExtensions)
|