ffi-gdal 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.prettierrc.yml +4 -0
- data/.rubocop.yml +9 -5
- data/.rubocop_todo.yml +5 -11
- data/.solargraph.yml +13 -0
- data/Changelog-0.x.md +229 -174
- data/Changelog.md +15 -5
- data/Dockerfile.gdal2 +1 -1
- data/Gemfile +12 -2
- data/README.md +13 -10
- data/Rakefile +6 -6
- data/bin/bundle +12 -12
- data/bin/rake +6 -6
- data/bin/rspec +6 -6
- data/bin/rubocop +6 -6
- data/examples/extract_and_colorize.rb +15 -15
- data/examples/geometries.rb +12 -12
- data/examples/gridding.rb +17 -17
- data/examples/ogr_layer_to_layer.rb +3 -3
- data/examples/raster_erasing.rb +9 -9
- data/examples/remove_small_polygons.rb +11 -11
- data/examples/testing_gdal.rb +20 -20
- data/examples/warping.rb +13 -13
- data/ffi-gdal.gemspec +15 -26
- data/lib/ext/ffi_library_function_checks.rb +3 -3
- data/lib/ext/narray_ext.rb +1 -1
- data/lib/ext/to_bool.rb +2 -2
- data/lib/ffi/cpl/conv.rb +2 -2
- data/lib/ffi/cpl/error.rb +1 -1
- data/lib/ffi/cpl/hash_set.rb +2 -2
- data/lib/ffi/cpl/http.rb +3 -3
- data/lib/ffi/cpl/http_result.rb +2 -2
- data/lib/ffi/cpl/list.rb +1 -1
- data/lib/ffi/cpl/mime_part.rb +1 -1
- data/lib/ffi/cpl/minixml.rb +2 -2
- data/lib/ffi/cpl/port.rb +1 -1
- data/lib/ffi/cpl/progress.rb +2 -2
- data/lib/ffi/cpl/quad_tree.rb +3 -3
- data/lib/ffi/cpl/rect_obj.rb +1 -1
- data/lib/ffi/cpl/string.rb +1 -1
- data/lib/ffi/cpl/vsi.rb +2 -2
- data/lib/ffi/cpl/xml_node.rb +1 -1
- data/lib/ffi/cpl.rb +11 -11
- data/lib/ffi/extensions/gdal/extensions/all.rb +2 -2
- data/lib/ffi/extensions/gdal/extensions.rb +2 -2
- data/lib/ffi/extensions/rttopo/gbox.rb +1 -1
- data/lib/ffi/extensions/rttopo/geom.rb +2 -2
- data/lib/ffi/extensions/rttopo.rb +3 -3
- data/lib/ffi/gdal/alg.rb +2 -2
- data/lib/ffi/gdal/color_entry.rb +1 -1
- data/lib/ffi/gdal/gcp.rb +1 -1
- data/lib/ffi/gdal/gdal.rb +3 -3
- data/lib/ffi/gdal/grid.rb +2 -2
- data/lib/ffi/gdal/grid_data_metrics_options.rb +1 -1
- data/lib/ffi/gdal/grid_inverse_distance_to_a_power_options.rb +1 -1
- data/lib/ffi/gdal/grid_moving_average_options.rb +1 -1
- data/lib/ffi/gdal/grid_nearest_neighbor_options.rb +1 -1
- data/lib/ffi/gdal/matching.rb +2 -2
- data/lib/ffi/gdal/rpc_info.rb +1 -1
- data/lib/ffi/gdal/transformer_info.rb +1 -1
- data/lib/ffi/gdal/version.rb +1 -1
- data/lib/ffi/gdal/vrt.rb +2 -2
- data/lib/ffi/gdal/warp_options.rb +1 -1
- data/lib/ffi/gdal/warper.rb +2 -2
- data/lib/ffi/gdal.rb +22 -22
- data/lib/ffi/ogr/api.rb +3 -3
- data/lib/ffi/ogr/contour_writer_info.rb +1 -1
- data/lib/ffi/ogr/core.rb +9 -9
- data/lib/ffi/ogr/envelope.rb +1 -1
- data/lib/ffi/ogr/envelope_3d.rb +1 -1
- data/lib/ffi/ogr/featurestyle.rb +1 -1
- data/lib/ffi/ogr/field.rb +1 -1
- data/lib/ffi/ogr/geocoding.rb +2 -2
- data/lib/ffi/ogr/srs_api.rb +63 -63
- data/lib/ffi/ogr/style_param.rb +2 -2
- data/lib/ffi/ogr/style_value.rb +1 -1
- data/lib/ffi/ogr.rb +11 -11
- data/lib/ffi-gdal.rb +8 -8
- data/lib/gdal/color_table.rb +6 -6
- data/lib/gdal/dataset/accessors.rb +101 -0
- data/lib/gdal/{dataset_mixins → dataset}/algorithm_methods.rb +1 -1
- data/lib/gdal/dataset/class_methods.rb +69 -0
- data/lib/gdal/dataset/internal_functions.rb +22 -0
- data/lib/gdal/{dataset_mixins → dataset}/matching.rb +1 -1
- data/lib/gdal/dataset/raster_band_methods.rb +181 -0
- data/lib/gdal/{dataset_mixins → dataset}/warp_methods.rb +1 -1
- data/lib/gdal/dataset.rb +21 -359
- data/lib/gdal/driver.rb +10 -10
- data/lib/gdal/environment_methods.rb +1 -1
- data/lib/gdal/extensions/all.rb +1 -1
- data/lib/gdal/extensions/color_entry/extensions.rb +2 -2
- data/lib/gdal/extensions/color_table/extensions.rb +2 -2
- data/lib/gdal/extensions/dataset/extensions.rb +11 -11
- data/lib/gdal/extensions/driver/extensions.rb +7 -7
- data/lib/gdal/extensions/geo_transform/extensions.rb +2 -2
- data/lib/gdal/extensions/gridder.rb +8 -8
- data/lib/gdal/extensions/gridder_options.rb +6 -6
- data/lib/gdal/extensions/raster_attribute_table/extensions.rb +1 -1
- data/lib/gdal/extensions/raster_band/algorithm_extensions.rb +4 -4
- data/lib/gdal/extensions/raster_band/coloring_extensions.rb +1 -1
- data/lib/gdal/extensions/raster_band/extensions.rb +3 -3
- data/lib/gdal/extensions/raster_band/io_extensions.rb +4 -4
- data/lib/gdal/extensions/raster_band_classifier.rb +3 -3
- data/lib/gdal/geo_transform.rb +1 -1
- data/lib/gdal/grid.rb +6 -6
- data/lib/gdal/grid_algorithms/metric_average_distance.rb +1 -1
- data/lib/gdal/grid_algorithms/metric_average_distance_pts.rb +1 -1
- data/lib/gdal/grid_algorithms/metric_count.rb +1 -1
- data/lib/gdal/grid_algorithms/metric_maximum.rb +1 -1
- data/lib/gdal/grid_algorithms/metric_minimum.rb +1 -1
- data/lib/gdal/grid_algorithms/metric_range.rb +1 -1
- data/lib/gdal/grid_algorithms.rb +9 -9
- data/lib/gdal/internal_helpers.rb +3 -3
- data/lib/gdal/logger.rb +1 -1
- data/lib/gdal/major_object.rb +6 -6
- data/lib/gdal/options.rb +2 -2
- data/lib/gdal/raster_attribute_table.rb +5 -5
- data/lib/gdal/raster_band.rb +24 -24
- data/lib/gdal/rpc_info.rb +2 -2
- data/lib/gdal/transformer.rb +1 -1
- data/lib/gdal/transformers/general_image_projection_transformer.rb +1 -1
- data/lib/gdal/transformers/general_image_projection_transformer2.rb +1 -1
- data/lib/gdal/transformers/general_image_projection_transformer3.rb +1 -1
- data/lib/gdal/version_info.rb +9 -9
- data/lib/gdal/virtual_dataset.rb +4 -4
- data/lib/gdal/warp_operation.rb +2 -2
- data/lib/gdal/warp_options.rb +2 -2
- data/lib/gdal.rb +17 -17
- data/lib/ogr/coordinate_transformation.rb +5 -5
- data/lib/ogr/data_source.rb +9 -9
- data/lib/ogr/driver.rb +9 -9
- data/lib/ogr/envelope.rb +1 -1
- data/lib/ogr/error_handling.rb +1 -1
- data/lib/ogr/extensions/all.rb +1 -1
- data/lib/ogr/extensions/data_source/capability_methods.rb +4 -4
- data/lib/ogr/extensions/data_source/data_source_extensions.rb +1 -1
- data/lib/ogr/extensions/driver/capability_methods.rb +3 -3
- data/lib/ogr/extensions/envelope/extensions.rb +1 -1
- data/lib/ogr/extensions/feature/extensions.rb +1 -1
- data/lib/ogr/extensions/feature_definition/extensions.rb +1 -1
- data/lib/ogr/extensions/geometries/point/extensions.rb +1 -1
- data/lib/ogr/extensions/geometry/container_mixins.rb +10 -10
- data/lib/ogr/extensions/geometry/ewkb_io_extensions.rb +3 -3
- data/lib/ogr/extensions/geometry/ewkb_record.rb +4 -4
- data/lib/ogr/extensions/geometry/extensions.rb +4 -7
- data/lib/ogr/extensions/geometry/rttopo_extensions.rb +2 -2
- data/lib/ogr/extensions/geometry/wkb_record.rb +3 -3
- data/lib/ogr/extensions/geometry_types/curve/extensions.rb +2 -2
- data/lib/ogr/extensions/layer/capability_methods.rb +17 -17
- data/lib/ogr/extensions/layer/extensions.rb +1 -1
- data/lib/ogr/extensions/spatial_reference/extensions.rb +1 -1
- data/lib/ogr/extensions/spatial_reference/initializers.rb +2 -2
- data/lib/ogr/extensions/style_table/extensions.rb +1 -1
- data/lib/ogr/feature.rb +15 -15
- data/lib/ogr/feature_definition.rb +2 -2
- data/lib/ogr/field.rb +5 -5
- data/lib/ogr/field_definition.rb +1 -1
- data/lib/ogr/geocoder.rb +1 -1
- data/lib/ogr/geometries/geometry_collection.rb +2 -2
- data/lib/ogr/geometries/geometry_collection_25d.rb +1 -1
- data/lib/ogr/geometries/line_string.rb +1 -1
- data/lib/ogr/geometries/line_string_25d.rb +1 -1
- data/lib/ogr/geometries/linear_ring.rb +2 -2
- data/lib/ogr/geometries/multi_line_string.rb +2 -2
- data/lib/ogr/geometries/multi_line_string_25d.rb +1 -1
- data/lib/ogr/geometries/multi_point.rb +1 -1
- data/lib/ogr/geometries/multi_point_25d.rb +1 -1
- data/lib/ogr/geometries/multi_polygon.rb +2 -2
- data/lib/ogr/geometries/multi_polygon_25d.rb +1 -1
- data/lib/ogr/geometries/point_25d.rb +1 -1
- data/lib/ogr/geometries/polygon.rb +2 -2
- data/lib/ogr/geometries/polygon_25d.rb +1 -1
- data/lib/ogr/geometry.rb +11 -11
- data/lib/ogr/geometry_types/container.rb +1 -1
- data/lib/ogr/geometry_types/curve.rb +1 -1
- data/lib/ogr/internal_helpers.rb +4 -4
- data/lib/ogr/layer.rb +8 -8
- data/lib/ogr/layer_mixins/ogr_feature_methods.rb +9 -9
- data/lib/ogr/layer_mixins/ogr_field_methods.rb +15 -15
- data/lib/ogr/layer_mixins/ogr_sql_methods.rb +2 -2
- data/lib/ogr/spatial_reference.rb +19 -19
- data/lib/ogr/spatial_reference_mixins/coordinate_system_getter_setters.rb +4 -4
- data/lib/ogr/spatial_reference_mixins/exporters.rb +9 -9
- data/lib/ogr/spatial_reference_mixins/importers.rb +2 -2
- data/lib/ogr/spatial_reference_mixins/morphers.rb +2 -2
- data/lib/ogr/spatial_reference_mixins/parameter_getter_setters.rb +1 -1
- data/lib/ogr/style_table.rb +3 -3
- data/lib/ogr/style_tool.rb +1 -1
- data/lib/ogr.rb +33 -33
- data/rakelib/docker.rake +2 -2
- metadata +11 -145
data/lib/ogr/geometry.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
3
|
+
require_relative "../ogr"
|
4
|
+
require_relative "../gdal"
|
5
5
|
|
6
6
|
module OGR
|
7
7
|
module Geometry
|
@@ -213,7 +213,7 @@ module OGR
|
|
213
213
|
FFI::OGR::API.OGR_G_GetEnvelope3D(@c_pointer, envelope)
|
214
214
|
when 0 then return nil
|
215
215
|
else
|
216
|
-
raise
|
216
|
+
raise "Unknown envelope dimension."
|
217
217
|
end
|
218
218
|
|
219
219
|
return if envelope.null?
|
@@ -268,7 +268,7 @@ module OGR
|
|
268
268
|
# @param file_path [String] The text file to write to.
|
269
269
|
# @param prefix [String] The prefix to put on each line of output.
|
270
270
|
def dump_readable(file_path = nil, prefix: nil)
|
271
|
-
file_ptr = file_path ? FFI::CPL::Conv.CPLOpenShared(file_path,
|
271
|
+
file_ptr = file_path ? FFI::CPL::Conv.CPLOpenShared(file_path, "w", false) : nil
|
272
272
|
FFI::OGR::API.OGR_G_DumpReadable(@c_pointer, file_ptr, prefix)
|
273
273
|
FFI::CPL::Conv.CPLCloseShared(file_ptr) if file_ptr
|
274
274
|
end
|
@@ -363,7 +363,7 @@ module OGR
|
|
363
363
|
def ring?
|
364
364
|
FFI::OGR::API.OGR_G_IsRing(@c_pointer)
|
365
365
|
rescue GDAL::Error => e
|
366
|
-
return false if e.message.include?
|
366
|
+
return false if e.message.include? "IllegalArgumentException"
|
367
367
|
|
368
368
|
raise
|
369
369
|
end
|
@@ -467,7 +467,7 @@ module OGR
|
|
467
467
|
|
468
468
|
return if coord_trans_ptr.nil? || coord_trans_ptr.null?
|
469
469
|
|
470
|
-
OGR::ErrorHandling.handle_ogr_err(
|
470
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to transform geometry") do
|
471
471
|
FFI::OGR::API.OGR_G_Transform(@c_pointer, coord_trans_ptr)
|
472
472
|
end
|
473
473
|
end
|
@@ -489,7 +489,7 @@ module OGR
|
|
489
489
|
new_spatial_ref_ptr = GDAL._pointer(OGR::SpatialReference, new_spatial_ref, autorelease: false)
|
490
490
|
return if new_spatial_ref_ptr.null?
|
491
491
|
|
492
|
-
OGR::ErrorHandling.handle_ogr_err(
|
492
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to transform geometry") do
|
493
493
|
FFI::OGR::API.OGR_G_TransformTo(@c_pointer, new_spatial_ref_ptr)
|
494
494
|
end
|
495
495
|
end
|
@@ -552,7 +552,7 @@ module OGR
|
|
552
552
|
# @param wkb_data [String] Binary WKB data.
|
553
553
|
# @raise [OGR::Failure]
|
554
554
|
def import_from_wkb(wkb_data)
|
555
|
-
OGR::ErrorHandling.handle_ogr_err(
|
555
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to import geometry from WKB") do
|
556
556
|
FFI::OGR::API.OGR_G_ImportFromWkb(@c_pointer, wkb_data, wkb_data.length)
|
557
557
|
end
|
558
558
|
end
|
@@ -592,7 +592,7 @@ module OGR
|
|
592
592
|
# @raise [OGR::Failure]
|
593
593
|
def to_wkt
|
594
594
|
GDAL._cpl_read_and_free_string do |output_ptr|
|
595
|
-
OGR::ErrorHandling.handle_ogr_err(
|
595
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to export to WKT") do
|
596
596
|
FFI::OGR::API.OGR_G_ExportToWkt(@c_pointer, output_ptr)
|
597
597
|
end
|
598
598
|
end
|
@@ -602,7 +602,7 @@ module OGR
|
|
602
602
|
# @raise [OGR::Failure]
|
603
603
|
def to_iso_wkt
|
604
604
|
GDAL._cpl_read_and_free_string do |output_ptr|
|
605
|
-
OGR::ErrorHandling.handle_ogr_err(
|
605
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to export to WKT") do
|
606
606
|
FFI::OGR::API.OGR_G_ExportToIsoWkt(@c_pointer, output_ptr)
|
607
607
|
end
|
608
608
|
end
|
@@ -683,7 +683,7 @@ module OGR
|
|
683
683
|
|
684
684
|
linear_ring.spatial_reference = line_string.spatial_reference.clone if line_string.spatial_reference
|
685
685
|
|
686
|
-
linear_ring.import_from_wkt(line_string.to_wkt.tr(
|
686
|
+
linear_ring.import_from_wkt(line_string.to_wkt.tr("LINESTRING", "LINEARRING"))
|
687
687
|
linear_ring.close_rings! if close_rings
|
688
688
|
|
689
689
|
linear_ring
|
@@ -75,7 +75,7 @@ module OGR
|
|
75
75
|
x_buffer, x_stride, y_buffer,
|
76
76
|
y_stride, z_buffer, z_stride)
|
77
77
|
|
78
|
-
log
|
78
|
+
log "Got different number of points than point_count in #point_values" unless num_points == point_count
|
79
79
|
|
80
80
|
x_array = x_buffer.read_array_of_double(buffer_size)
|
81
81
|
y_array = y_buffer.read_array_of_double(buffer_size)
|
data/lib/ogr/internal_helpers.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "time"
|
4
4
|
|
5
5
|
module OGR
|
6
6
|
module InternalHelpers
|
@@ -15,8 +15,8 @@ module OGR
|
|
15
15
|
# @param flag [String] 'w' for writing, 'r' for reading.
|
16
16
|
def _boolean_access_flag(flag)
|
17
17
|
case flag
|
18
|
-
when
|
19
|
-
when
|
18
|
+
when "w" then true
|
19
|
+
when "r" then false
|
20
20
|
else raise "Invalid access_flag '#{flag}'. Use 'r' or 'w'."
|
21
21
|
end
|
22
22
|
end
|
@@ -33,7 +33,7 @@ module OGR
|
|
33
33
|
case time_zone
|
34
34
|
when 0 then nil
|
35
35
|
when 1 then (Time.now.getlocal.utc_offset / 3600).to_s
|
36
|
-
when 100 then
|
36
|
+
when 100 then "+0"
|
37
37
|
else raise "Unable to process time zone: #{time_zone}"
|
38
38
|
end
|
39
39
|
end
|
data/lib/ogr/layer.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
3
|
+
require_relative "../ogr"
|
4
|
+
require_relative "../gdal"
|
5
|
+
require_relative "layer_mixins/ogr_feature_methods"
|
6
|
+
require_relative "layer_mixins/ogr_field_methods"
|
7
|
+
require_relative "layer_mixins/ogr_layer_method_methods"
|
8
|
+
require_relative "layer_mixins/ogr_query_filter_methods"
|
9
|
+
require_relative "layer_mixins/ogr_sql_methods"
|
10
10
|
|
11
11
|
module OGR
|
12
12
|
class Layer
|
@@ -42,7 +42,7 @@ module OGR
|
|
42
42
|
# TODO: This seems to occasionally lead to: 28352 illegal hardware
|
43
43
|
# instruction, and sometimes full crashes.
|
44
44
|
def sync_to_disk
|
45
|
-
OGR::ErrorHandling.handle_ogr_err(
|
45
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to sync layer to disk") do
|
46
46
|
FFI::OGR::API.OGR_L_SyncToDisk(@c_pointer)
|
47
47
|
end
|
48
48
|
end
|
@@ -27,12 +27,12 @@ module OGR
|
|
27
27
|
# @param feature [OGR::Feature] [description]
|
28
28
|
# @raise [OGR::Failure]
|
29
29
|
def create_feature(feature)
|
30
|
-
unless test_capability(
|
30
|
+
unless test_capability("SequentialWrite")
|
31
31
|
raise OGR::UnsupportedOperation,
|
32
|
-
|
32
|
+
"This layer does not support feature creation."
|
33
33
|
end
|
34
34
|
|
35
|
-
OGR::ErrorHandling.handle_ogr_err(
|
35
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to create feature") do
|
36
36
|
FFI::OGR::API.OGR_L_CreateFeature(@c_pointer, feature.c_pointer)
|
37
37
|
end
|
38
38
|
end
|
@@ -43,9 +43,9 @@ module OGR
|
|
43
43
|
# @raise [OGR::Failure] When trying to delete a feature with an ID that
|
44
44
|
# does not exist.
|
45
45
|
def delete_feature(feature_id)
|
46
|
-
unless test_capability(
|
46
|
+
unless test_capability("DeleteFeature")
|
47
47
|
raise OGR::UnsupportedOperation,
|
48
|
-
|
48
|
+
"This layer does not support feature deletion."
|
49
49
|
end
|
50
50
|
|
51
51
|
OGR::ErrorHandling.handle_ogr_err("Unable to delete feature with ID '#{feature_id}'") do
|
@@ -67,12 +67,12 @@ module OGR
|
|
67
67
|
# @param new_feature [OGR::Feature, FFI::Pointer]
|
68
68
|
# @raise [OGR::Failure]
|
69
69
|
def feature=(new_feature)
|
70
|
-
raise OGR::UnsupportedOperation,
|
70
|
+
raise OGR::UnsupportedOperation, "#feature= not supported by this Layer" unless test_capability("RandomWrite")
|
71
71
|
|
72
72
|
new_feature_ptr = GDAL._pointer(OGR::Feature, new_feature)
|
73
73
|
raise OGR::InvalidFeature if new_feature_ptr.nil? || new_feature_ptr.null?
|
74
74
|
|
75
|
-
OGR::ErrorHandling.handle_ogr_err(
|
75
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to set feature") do
|
76
76
|
FFI::OGR::API.OGR_L_SetFeature(@c_pointer, new_feature_ptr)
|
77
77
|
end
|
78
78
|
end
|
@@ -81,9 +81,9 @@ module OGR
|
|
81
81
|
# be <= +feature_count+, but no checking is done to ensure.
|
82
82
|
# @return [OGR::Feature, nil]
|
83
83
|
def feature(index)
|
84
|
-
unless test_capability(
|
84
|
+
unless test_capability("RandomRead")
|
85
85
|
raise OGR::UnsupportedOperation,
|
86
|
-
|
86
|
+
"#feature(index) not supported by this Layer"
|
87
87
|
end
|
88
88
|
|
89
89
|
# This feature needs to be Destroyed.
|
@@ -12,14 +12,14 @@ module OGR
|
|
12
12
|
# different form, depending on the limitations of the format driver.
|
13
13
|
# @raise [OGR::Failure]
|
14
14
|
def create_field(field_definition, approx_ok: false)
|
15
|
-
unless test_capability(
|
15
|
+
unless test_capability("CreateField")
|
16
16
|
raise OGR::UnsupportedOperation,
|
17
|
-
|
17
|
+
"This layer does not support field creation."
|
18
18
|
end
|
19
19
|
|
20
20
|
field_definition_ptr = GDAL._pointer(OGR::FieldDefinition, field_definition)
|
21
21
|
|
22
|
-
OGR::ErrorHandling.handle_ogr_err(
|
22
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to create field") do
|
23
23
|
FFI::OGR::API.OGR_L_CreateField(@c_pointer, field_definition_ptr, approx_ok)
|
24
24
|
end
|
25
25
|
end
|
@@ -28,12 +28,12 @@ module OGR
|
|
28
28
|
#
|
29
29
|
# @raise [OGR::Failure]
|
30
30
|
def delete_field(field_id)
|
31
|
-
unless test_capability(
|
31
|
+
unless test_capability("DeleteField")
|
32
32
|
raise OGR::UnsupportedOperation,
|
33
|
-
|
33
|
+
"This driver does not support field deletion."
|
34
34
|
end
|
35
35
|
|
36
|
-
OGR::ErrorHandling.handle_ogr_err(
|
36
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to delete field") do
|
37
37
|
FFI::OGR::API.OGR_L_DeleteField(@c_pointer, field_id)
|
38
38
|
end
|
39
39
|
end
|
@@ -42,9 +42,9 @@ module OGR
|
|
42
42
|
# which they should be reordered. I.e. [0, 2, 3, 1, 4].
|
43
43
|
# @raise [OGR::Failure]
|
44
44
|
def reorder_fields(*new_order)
|
45
|
-
unless test_capability(
|
45
|
+
unless test_capability("ReorderFields")
|
46
46
|
raise OGR::UnsupportedOperation,
|
47
|
-
|
47
|
+
"This driver does not support field reordering."
|
48
48
|
end
|
49
49
|
|
50
50
|
return false if new_order.empty? || new_order.any? { |i| i > feature_definition.field_count }
|
@@ -63,9 +63,9 @@ module OGR
|
|
63
63
|
# @param new_position [Integer]
|
64
64
|
# @raise [OGR::Failure]
|
65
65
|
def reorder_field(old_position, new_position)
|
66
|
-
unless test_capability(
|
66
|
+
unless test_capability("ReorderFields")
|
67
67
|
raise OGR::UnsupportedOperation,
|
68
|
-
|
68
|
+
"This driver does not support field reordering."
|
69
69
|
end
|
70
70
|
|
71
71
|
OGR::ErrorHandling.handle_ogr_err("Unable to reorder field: #{old_position} to #{new_position}") do
|
@@ -80,8 +80,8 @@ module OGR
|
|
80
80
|
# ALTER_WIDTH_PRECISION_FLAG, or ALTER_ALL_FLAG.
|
81
81
|
# @raise [OGR::Failure]
|
82
82
|
def alter_field_definition(field_index, new_field_definition, flags)
|
83
|
-
unless test_capability(
|
84
|
-
raise OGR::UnsupportedOperation,
|
83
|
+
unless test_capability("AlterFieldDefn")
|
84
|
+
raise OGR::UnsupportedOperation, "This layer does not support field definition altering."
|
85
85
|
end
|
86
86
|
|
87
87
|
new_field_definition_ptr = GDAL._pointer(OGR::FieldDefinition, new_field_definition)
|
@@ -116,13 +116,13 @@ module OGR
|
|
116
116
|
# @param approx_ok [Boolean]
|
117
117
|
# @raise [OGR::Failure]
|
118
118
|
def create_geometry_field(geometry_field_def, approx_ok: false)
|
119
|
-
unless test_capability(
|
120
|
-
raise OGR::UnsupportedOperation,
|
119
|
+
unless test_capability("CreateGeomField")
|
120
|
+
raise OGR::UnsupportedOperation, "This layer does not support geometry field creation"
|
121
121
|
end
|
122
122
|
|
123
123
|
geometry_field_definition_ptr = GDAL._pointer(OGR::GeometryFieldDefinition, geometry_field_def)
|
124
124
|
|
125
|
-
OGR::ErrorHandling.handle_ogr_err(
|
125
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to create geometry field") do
|
126
126
|
FFI::OGR::API.OGR_L_CreateGeomField(
|
127
127
|
@c_pointer,
|
128
128
|
geometry_field_definition_ptr,
|
@@ -43,11 +43,11 @@ module OGR
|
|
43
43
|
|
44
44
|
# @raise [OGR::Failure]
|
45
45
|
def transact
|
46
|
-
raise OGR::UnsupportedOperation,
|
46
|
+
raise OGR::UnsupportedOperation, "This layer does not support transactions." unless supports_transactions?
|
47
47
|
|
48
48
|
ogr_err = yield
|
49
49
|
|
50
|
-
OGR::ErrorHandling.handle_ogr_err(
|
50
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to set geometry directly on feature") do
|
51
51
|
ogr_err
|
52
52
|
end
|
53
53
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
10
|
-
require_relative
|
3
|
+
require_relative "../ogr"
|
4
|
+
require_relative "../gdal"
|
5
|
+
require_relative "spatial_reference_mixins/coordinate_system_getter_setters"
|
6
|
+
require_relative "spatial_reference_mixins/exporters"
|
7
|
+
require_relative "spatial_reference_mixins/importers"
|
8
|
+
require_relative "spatial_reference_mixins/morphers"
|
9
|
+
require_relative "spatial_reference_mixins/parameter_getter_setters"
|
10
|
+
require_relative "spatial_reference_mixins/type_checks"
|
11
11
|
|
12
12
|
module OGR
|
13
13
|
# Represents a geographic coordinate system. There are two primary types:
|
@@ -46,7 +46,7 @@ module OGR
|
|
46
46
|
|
47
47
|
list = pointer_array.map(&:read_string).sort
|
48
48
|
|
49
|
-
strip_underscores ? list.map! { |l| l.tr(
|
49
|
+
strip_underscores ? list.map! { |l| l.tr("_", " ") } : list
|
50
50
|
end
|
51
51
|
|
52
52
|
# @deprecated This was removed in GDAL 3.0.
|
@@ -141,13 +141,13 @@ module OGR
|
|
141
141
|
def initialize(spatial_reference_or_wkt = nil)
|
142
142
|
pointer =
|
143
143
|
case spatial_reference_or_wkt.class.name
|
144
|
-
when
|
144
|
+
when "OGR::SpatialReference"
|
145
145
|
# This is basically getting a reference to the SpatialReference that
|
146
146
|
# was passed in, thus when this SpatialReference gets garbage-collected,
|
147
147
|
# it shouldn't release anything.
|
148
148
|
ptr = spatial_reference_or_wkt.c_pointer
|
149
149
|
ptr.autorelease = false
|
150
|
-
when
|
150
|
+
when "String", "NilClass"
|
151
151
|
# FWIW, the docs say:
|
152
152
|
# Note that newly created objects are given a reference count of one.
|
153
153
|
#
|
@@ -157,7 +157,7 @@ module OGR
|
|
157
157
|
|
158
158
|
# We're instantiating a new SR, so we can use .destroy.
|
159
159
|
FFI::AutoPointer.new(ptr, SpatialReference.method(:release))
|
160
|
-
when
|
160
|
+
when "FFI::AutoPointer", "FFI::Pointer", "FFI::MemoryPointer"
|
161
161
|
# If we got a pointer, we don't know who owns the data, so don't
|
162
162
|
# touch anything about autorelease/AutoPointer.
|
163
163
|
spatial_reference_or_wkt
|
@@ -165,7 +165,7 @@ module OGR
|
|
165
165
|
log "Dunno what to do with #{spatial_reference_or_wkt.inspect}"
|
166
166
|
end
|
167
167
|
|
168
|
-
raise OGR::CreateFailure,
|
168
|
+
raise OGR::CreateFailure, "Unable to create SpatialReference." if pointer.nil? || pointer.null?
|
169
169
|
|
170
170
|
@c_pointer = pointer
|
171
171
|
end
|
@@ -201,28 +201,28 @@ module OGR
|
|
201
201
|
other_spatial_ref_ptr = GDAL._pointer(OGR::SpatialReference, other_spatial_ref)
|
202
202
|
raise OGR::InvalidSpatialReference if other_spatial_ref_ptr.nil? || other_spatial_ref_ptr.null?
|
203
203
|
|
204
|
-
OGR::ErrorHandling.handle_ogr_err(
|
204
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to copy GEOGCS") do
|
205
205
|
FFI::OGR::SRSAPI.OSRCopyGeogCSFrom(@c_pointer, other_spatial_ref_ptr)
|
206
206
|
end
|
207
207
|
end
|
208
208
|
|
209
209
|
# @raise [OGR::Failure]
|
210
210
|
def validate
|
211
|
-
OGR::ErrorHandling.handle_ogr_err(
|
211
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to validate") do
|
212
212
|
FFI::OGR::SRSAPI.OSRValidate(@c_pointer)
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
216
216
|
# @raise [OGR::Failure]
|
217
217
|
def fixup_ordering!
|
218
|
-
OGR::ErrorHandling.handle_ogr_err(
|
218
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to fixup ordering") do
|
219
219
|
FFI::OGR::SRSAPI.OSRFixupOrdering(@c_pointer)
|
220
220
|
end
|
221
221
|
end
|
222
222
|
|
223
223
|
# @raise [OGR::Failure]
|
224
224
|
def fixup!
|
225
|
-
OGR::ErrorHandling.handle_ogr_err(
|
225
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to fixup") do
|
226
226
|
FFI::OGR::SRSAPI.OSRFixup(@c_pointer)
|
227
227
|
end
|
228
228
|
end
|
@@ -231,7 +231,7 @@ module OGR
|
|
231
231
|
#
|
232
232
|
# @raise [OGR::Failure]
|
233
233
|
def strip_ct_parameters!
|
234
|
-
OGR::ErrorHandling.handle_ogr_err(
|
234
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to strip coordinate transformation parameters") do
|
235
235
|
FFI::OGR::SRSAPI.OSRStripCTParms(@c_pointer)
|
236
236
|
end
|
237
237
|
end
|
@@ -240,7 +240,7 @@ module OGR
|
|
240
240
|
#
|
241
241
|
# @raise [OGR::Failure]
|
242
242
|
def auto_identify_epsg!
|
243
|
-
OGR::ErrorHandling.handle_ogr_err(
|
243
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to determine SRS from EPSG") do
|
244
244
|
FFI::OGR::SRSAPI.OSRAutoIdentifyEPSG(@c_pointer)
|
245
245
|
end
|
246
246
|
end
|
@@ -50,7 +50,7 @@ module OGR
|
|
50
50
|
# @param definition [String]
|
51
51
|
# @raise [OGR::Failure]
|
52
52
|
def set_from_user_input(definition) # rubocop:disable Naming/AccessorMethodName
|
53
|
-
OGR::ErrorHandling.handle_ogr_err(
|
53
|
+
OGR::ErrorHandling.handle_ogr_err("Invalid projection info given.") do
|
54
54
|
FFI::OGR::SRSAPI.OSRSetFromUserInput(@c_pointer, definition)
|
55
55
|
end
|
56
56
|
end
|
@@ -60,7 +60,7 @@ module OGR
|
|
60
60
|
def towgs84
|
61
61
|
coefficients = FFI::MemoryPointer.new(:double, 7)
|
62
62
|
|
63
|
-
OGR::ErrorHandling.handle_ogr_err(
|
63
|
+
OGR::ErrorHandling.handle_ogr_err("No TOWGS84 node available") do
|
64
64
|
FFI::OGR::SRSAPI.OSRGetTOWGS84(@c_pointer, coefficients, 7)
|
65
65
|
end
|
66
66
|
|
@@ -77,7 +77,7 @@ module OGR
|
|
77
77
|
# @raise [OGR::Failure]
|
78
78
|
def set_towgs84(x_distance: nil, y_distance: nil, z_distance: 0.0,
|
79
79
|
x_rotation: 0.0, y_rotation: 0.0, z_rotation: 0.0, scaling_factor: 0.0)
|
80
|
-
OGR::ErrorHandling.handle_ogr_err(
|
80
|
+
OGR::ErrorHandling.handle_ogr_err("No existing DATUM node") do
|
81
81
|
FFI::OGR::SRSAPI.OSRSetTOWGS84(
|
82
82
|
@c_pointer,
|
83
83
|
x_distance, y_distance, z_distance,
|
@@ -488,7 +488,7 @@ module OGR
|
|
488
488
|
# @param false_northing [Float]
|
489
489
|
# @raise [OGR::Failure]
|
490
490
|
def set_transverse_mercator(center_lat, center_long, scale, false_easting, false_northing)
|
491
|
-
msg =
|
491
|
+
msg = "Unable to set transverse mercator: " \
|
492
492
|
"#{center_lat}, #{center_long}, #{scale}, #{false_easting}, #{false_northing}"
|
493
493
|
|
494
494
|
OGR::ErrorHandling.handle_ogr_err(msg) do
|
@@ -10,7 +10,7 @@ module OGR
|
|
10
10
|
datum_name = FFI::MemoryPointer.new(:string, 32)
|
11
11
|
units = FFI::MemoryPointer.new(:string, 32)
|
12
12
|
|
13
|
-
OGR::ErrorHandling.handle_ogr_err(
|
13
|
+
OGR::ErrorHandling.handle_ogr_err("Required parameters (name, datum name, units) are not defined") do
|
14
14
|
FFI::OGR::SRSAPI.OSRExportToERM(@c_pointer, projection_name, datum_name, units)
|
15
15
|
end
|
16
16
|
|
@@ -25,7 +25,7 @@ module OGR
|
|
25
25
|
# @raise [OGR::Failure]
|
26
26
|
def to_mapinfo
|
27
27
|
GDAL._cpl_read_and_free_string do |return_ptr_ptr|
|
28
|
-
OGR::ErrorHandling.handle_ogr_err(
|
28
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to export to MapInfo") do
|
29
29
|
FFI::OGR::SRSAPI.OSRExportToMICoordSys(@c_pointer, return_ptr_ptr)
|
30
30
|
end
|
31
31
|
end
|
@@ -41,7 +41,7 @@ module OGR
|
|
41
41
|
prj_params_ptr_ptr = GDAL._pointer_pointer(:double)
|
42
42
|
prj_params_ptr_ptr.autorelease = false
|
43
43
|
|
44
|
-
OGR::ErrorHandling.handle_ogr_err(
|
44
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to export to PCI") do
|
45
45
|
FFI::OGR::SRSAPI.OSRExportToPCI(@c_pointer, proj_ptr_ptr, units_ptr_ptr, prj_params_ptr_ptr)
|
46
46
|
end
|
47
47
|
|
@@ -66,7 +66,7 @@ module OGR
|
|
66
66
|
# @raise [GDAL::UnsupportedOperation] If empty definition.
|
67
67
|
def to_proj4
|
68
68
|
GDAL._cpl_read_and_free_string do |proj4_ptr_ptr|
|
69
|
-
OGR::ErrorHandling.handle_ogr_err(
|
69
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to export to PROJ.4") do
|
70
70
|
FFI::OGR::SRSAPI.OSRExportToProj4(@c_pointer, proj4_ptr_ptr)
|
71
71
|
end
|
72
72
|
end
|
@@ -81,7 +81,7 @@ module OGR
|
|
81
81
|
prj_params_ptr_ptr = GDAL._pointer_pointer(:double)
|
82
82
|
prj_params_ptr_ptr.autorelease = false
|
83
83
|
|
84
|
-
OGR::ErrorHandling.handle_ogr_err(
|
84
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to export to USGS GCTP") do
|
85
85
|
FFI::OGR::SRSAPI.OSRExportToUSGS(@c_pointer, proj_sys_ptr, zone_ptr, prj_params_ptr_ptr, datum_ptr)
|
86
86
|
end
|
87
87
|
|
@@ -106,7 +106,7 @@ module OGR
|
|
106
106
|
# @raise [OGR::Failure]
|
107
107
|
def to_wkt
|
108
108
|
GDAL._cpl_read_and_free_string do |wkt_ptr_ptr|
|
109
|
-
OGR::ErrorHandling.handle_ogr_err(
|
109
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to export to WKT") do
|
110
110
|
FFI::OGR::SRSAPI.OSRExportToWkt(@c_pointer, wkt_ptr_ptr)
|
111
111
|
end
|
112
112
|
end
|
@@ -117,10 +117,10 @@ module OGR
|
|
117
117
|
# @raise [OGR::Failure]
|
118
118
|
# @return [String]
|
119
119
|
def to_pretty_wkt(simplify: false)
|
120
|
-
return +
|
120
|
+
return +"" if @c_pointer.null?
|
121
121
|
|
122
122
|
GDAL._cpl_read_and_free_string do |wkt_ptr_ptr|
|
123
|
-
OGR::ErrorHandling.handle_ogr_err(
|
123
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to export to pretty WKT") do
|
124
124
|
FFI::OGR::SRSAPI.OSRExportToPrettyWkt(@c_pointer, wkt_ptr_ptr, simplify)
|
125
125
|
end
|
126
126
|
end
|
@@ -130,7 +130,7 @@ module OGR
|
|
130
130
|
# @raise [OGR::Failure]
|
131
131
|
def to_xml
|
132
132
|
GDAL._cpl_read_and_free_string do |xml_ptr_ptr|
|
133
|
-
OGR::ErrorHandling.handle_ogr_err(
|
133
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to export to XML (GML)") do
|
134
134
|
FFI::OGR::SRSAPI.OSRExportToXML(@c_pointer, xml_ptr_ptr, nil)
|
135
135
|
end
|
136
136
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "../error_handling"
|
4
4
|
|
5
5
|
module OGR
|
6
6
|
module SpatialReferenceMixins
|
@@ -124,7 +124,7 @@ module OGR
|
|
124
124
|
object = new(spatial_reference_or_wkt)
|
125
125
|
ogr_err = yield object.c_pointer
|
126
126
|
|
127
|
-
OGR::ErrorHandling.handle_ogr_err(
|
127
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to build SpatialReference") do
|
128
128
|
ogr_err
|
129
129
|
end
|
130
130
|
|
@@ -8,7 +8,7 @@ module OGR
|
|
8
8
|
# @return [OGR::SpatialReference] If successful, returns self.
|
9
9
|
# @raise [OGR::Failure]
|
10
10
|
def morph_to_esri!
|
11
|
-
OGR::ErrorHandling.handle_ogr_err(
|
11
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to morph self to ESRI") do
|
12
12
|
FFI::OGR::SRSAPI.OSRMorphToESRI(@c_pointer)
|
13
13
|
end
|
14
14
|
|
@@ -20,7 +20,7 @@ module OGR
|
|
20
20
|
# @return [OGR::SpatialReference] If successful, returns self.
|
21
21
|
# @raise [OGR::Failure]
|
22
22
|
def morph_from_esri!
|
23
|
-
OGR::ErrorHandling.handle_ogr_err(
|
23
|
+
OGR::ErrorHandling.handle_ogr_err("Unable to morph self from ESRI") do
|
24
24
|
FFI::OGR::SRSAPI.OSRMorphFromESRI(@c_pointer)
|
25
25
|
end
|
26
26
|
|
@@ -74,7 +74,7 @@ module OGR
|
|
74
74
|
# @raise [OGR::Failure]
|
75
75
|
def set_linear_units_and_update_parameters(unit_label, transform_to_meters)
|
76
76
|
msg = "Unable to set linear units to #{unit_label} (transform to meters? #{transform_to_meters}) and update" \
|
77
|
-
|
77
|
+
"parameters"
|
78
78
|
|
79
79
|
OGR::ErrorHandling.handle_ogr_err(msg) do
|
80
80
|
FFI::OGR::SRSAPI.OSRSetLinearUnitsAndUpdateParameters(@c_pointer, unit_label, transform_to_meters.to_f)
|
data/lib/ogr/style_table.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
3
|
+
require_relative "../gdal"
|
4
|
+
require_relative "../ogr"
|
5
5
|
|
6
6
|
module OGR
|
7
7
|
class StyleTable
|
@@ -25,7 +25,7 @@ module OGR
|
|
25
25
|
FFI::AutoPointer.new(pointer, StyleTable.method(:release))
|
26
26
|
end
|
27
27
|
|
28
|
-
raise
|
28
|
+
raise "Unable to create StyleTable" if @c_pointer.null?
|
29
29
|
end
|
30
30
|
|
31
31
|
def destroy!
|