ffi-gdal 1.0.0.beta5 → 1.0.0.beta6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +7 -3
- data/.rubocop.yml +7 -0
- data/.ruby-version +1 -0
- data/Gemfile +1 -1
- data/History.md +143 -1
- data/README.md +5 -11
- data/Rakefile +2 -60
- data/TODO.md +10 -0
- data/examples/geometries.rb +4 -6
- data/examples/gridding.rb +99 -98
- data/examples/ogr_layer_to_layer.rb +0 -2
- data/examples/raster_erasing.rb +47 -0
- data/examples/remove_small_polygons.rb +62 -0
- data/examples/testing_gdal.rb +0 -3
- data/examples/warping.rb +140 -0
- data/ffi-gdal.gemspec +5 -2
- data/lib/ext/error_symbols.rb +1 -1
- data/lib/ext/ffi_library_function_checks.rb +3 -2
- data/lib/ext/float_ext.rb +2 -2
- data/lib/ext/narray_ext.rb +1 -1
- data/lib/ext/numeric_as_data_type.rb +1 -1
- data/lib/ext/to_bool.rb +2 -2
- data/lib/ffi/cpl/conv.rb +1 -3
- data/lib/ffi/cpl/error.rb +0 -3
- data/lib/ffi/cpl/minixml.rb +17 -21
- data/lib/ffi/cpl/progress.rb +27 -0
- data/lib/ffi/cpl/string.rb +0 -8
- data/lib/ffi/cpl/vsi.rb +0 -1
- data/lib/ffi/cpl/xml_node.rb +0 -1
- data/lib/ffi/cpl.rb +15 -0
- data/lib/ffi/gdal/alg.rb +72 -54
- data/lib/ffi/gdal/gdal.rb +669 -672
- data/lib/ffi/gdal/grid.rb +141 -24
- data/lib/ffi/gdal/grid_data_metrics_options.rb +1 -1
- data/lib/ffi/gdal/grid_moving_average_options.rb +1 -1
- data/lib/ffi/gdal/matching.rb +0 -2
- data/lib/ffi/gdal/transformer_info.rb +1 -1
- data/lib/ffi/gdal/version.rb +1 -1
- data/lib/ffi/gdal/vrt.rb +0 -2
- data/lib/ffi/gdal/warp_options.rb +12 -14
- data/lib/ffi/gdal/warper.rb +61 -6
- data/lib/ffi/gdal.rb +18 -3
- data/lib/ffi/ogr/api.rb +10 -21
- data/lib/ffi/ogr/core.rb +9 -12
- data/lib/ffi/ogr/featurestyle.rb +0 -5
- data/lib/ffi/ogr/geocoding.rb +0 -1
- data/lib/ffi/ogr/srs_api.rb +0 -4
- data/lib/ffi/ogr/style_value.rb +1 -2
- data/lib/ffi/ogr.rb +15 -12
- data/lib/ffi-gdal.rb +5 -3
- data/lib/gdal/color_entry.rb +1 -0
- data/lib/gdal/color_interpretation.rb +2 -2
- data/lib/gdal/color_table.rb +14 -14
- data/lib/gdal/color_table_mixins/extensions.rb +4 -4
- data/lib/gdal/cpl_error_handler.rb +12 -14
- data/lib/gdal/data_type.rb +13 -12
- data/lib/gdal/dataset.rb +170 -94
- data/lib/gdal/dataset_mixins/algorithm_methods.rb +47 -21
- data/lib/gdal/dataset_mixins/extensions.rb +32 -61
- data/lib/gdal/dataset_mixins/matching.rb +0 -2
- data/lib/gdal/dataset_mixins/warp_methods.rb +42 -0
- data/lib/gdal/driver.rb +62 -47
- data/lib/gdal/driver_mixins/extensions.rb +2 -7
- data/lib/gdal/environment_methods.rb +13 -10
- data/lib/gdal/exceptions.rb +24 -2
- data/lib/gdal/geo_transform.rb +10 -16
- data/lib/gdal/geo_transform_mixins/extensions.rb +58 -3
- data/lib/gdal/grid.rb +62 -109
- data/lib/gdal/{grid_types → grid_algorithms}/data_metrics_base.rb +1 -3
- data/lib/gdal/{grid_types → grid_algorithms}/inverse_distance_to_a_power.rb +2 -4
- data/lib/gdal/{grid_types → grid_algorithms}/metric_average_distance.rb +2 -2
- data/lib/gdal/{grid_types → grid_algorithms}/metric_average_distance_pts.rb +2 -2
- data/lib/gdal/{grid_types → grid_algorithms}/metric_count.rb +2 -2
- data/lib/gdal/{grid_types → grid_algorithms}/metric_maximum.rb +2 -2
- data/lib/gdal/{grid_types → grid_algorithms}/metric_minimum.rb +2 -2
- data/lib/gdal/{grid_types → grid_algorithms}/metric_range.rb +2 -2
- data/lib/gdal/{grid_types → grid_algorithms}/moving_average.rb +2 -4
- data/lib/gdal/{grid_types → grid_algorithms}/nearest_neighbor.rb +2 -4
- data/lib/gdal/grid_algorithms.rb +22 -0
- data/lib/gdal/gridder/point_extracting.rb +89 -0
- data/lib/gdal/gridder.rb +294 -0
- data/lib/gdal/gridder_options.rb +273 -0
- data/lib/gdal/internal_helpers.rb +132 -23
- data/lib/gdal/major_object.rb +13 -10
- data/lib/gdal/merger.rb +130 -0
- data/lib/gdal/options.rb +3 -2
- data/lib/gdal/raster_attribute_table.rb +74 -51
- data/lib/gdal/raster_attribute_table_mixins/extensions.rb +21 -3
- data/lib/gdal/raster_band.rb +139 -167
- data/lib/gdal/raster_band_classifier.rb +19 -18
- data/lib/gdal/raster_band_mixins/algorithm_extensions.rb +107 -0
- data/lib/gdal/raster_band_mixins/algorithm_methods.rb +79 -40
- data/lib/gdal/raster_band_mixins/coloring_extensions.rb +84 -0
- data/lib/gdal/raster_band_mixins/extensions.rb +34 -169
- data/lib/gdal/raster_band_mixins/io_extensions.rb +180 -0
- data/lib/gdal/rpc_info.rb +1 -2
- data/lib/gdal/transformer.rb +1 -6
- data/lib/gdal/transformers/approximate_transformer.rb +0 -4
- data/lib/gdal/transformers/base_general_image_projection_transformer.rb +0 -6
- data/lib/gdal/transformers/gcp_transformer.rb +2 -6
- data/lib/gdal/transformers/general_image_projection_transformer.rb +8 -7
- data/lib/gdal/transformers/general_image_projection_transformer2.rb +1 -1
- data/lib/gdal/transformers/geolocation_transformer.rb +0 -4
- data/lib/gdal/transformers/reprojection_transformer.rb +0 -8
- data/lib/gdal/transformers/rpc_transformer.rb +0 -4
- data/lib/gdal/transformers/tps_transformer.rb +1 -3
- data/lib/gdal/version_info.rb +7 -8
- data/lib/gdal/virtual_dataset.rb +2 -4
- data/lib/gdal/warp_operation.rb +17 -14
- data/lib/gdal/warp_options.rb +132 -0
- data/lib/gdal.rb +41 -2
- data/lib/ogr/coordinate_transformation.rb +79 -32
- data/lib/ogr/data_source.rb +17 -14
- data/lib/ogr/data_source_extensions.rb +1 -5
- data/lib/ogr/driver.rb +11 -14
- data/lib/ogr/envelope.rb +1 -1
- data/lib/ogr/envelope_extensions.rb +23 -6
- data/lib/ogr/error_handling.rb +3 -3
- data/lib/ogr/exceptions.rb +6 -0
- data/lib/ogr/feature.rb +25 -38
- data/lib/ogr/feature_definition.rb +6 -8
- data/lib/ogr/feature_definition_extensions.rb +2 -6
- data/lib/ogr/feature_extensions.rb +71 -41
- data/lib/ogr/field.rb +16 -15
- data/lib/ogr/field_definition.rb +4 -4
- data/lib/ogr/geocoder.rb +5 -5
- data/lib/ogr/geometries/geometry_collection.rb +4 -1
- data/lib/ogr/geometries/geometry_collection_25d.rb +12 -0
- data/lib/ogr/geometries/line_string.rb +30 -8
- data/lib/ogr/geometries/line_string_25d.rb +21 -0
- data/lib/ogr/geometries/linear_ring.rb +10 -1
- data/lib/ogr/geometries/multi_line_string.rb +2 -1
- data/lib/ogr/geometries/multi_line_string_25d.rb +13 -0
- data/lib/ogr/geometries/multi_point.rb +2 -1
- data/lib/ogr/geometries/multi_point_25d.rb +14 -0
- data/lib/ogr/geometries/multi_polygon.rb +3 -2
- data/lib/ogr/geometries/multi_polygon_25d.rb +13 -0
- data/lib/ogr/geometries/point.rb +20 -23
- data/lib/ogr/geometries/point_25d.rb +48 -0
- data/lib/ogr/geometries/polygon.rb +4 -1
- data/lib/ogr/geometries/polygon_25d.rb +14 -0
- data/lib/ogr/geometry.rb +125 -93
- data/lib/ogr/geometry_field_definition.rb +7 -5
- data/lib/ogr/geometry_mixins/container_mixins.rb +23 -0
- data/lib/ogr/geometry_mixins/extensions.rb +111 -0
- data/lib/ogr/geometry_types/container.rb +10 -3
- data/lib/ogr/geometry_types/curve.rb +68 -23
- data/lib/ogr/geometry_types/surface.rb +0 -9
- data/lib/ogr/internal_helpers.rb +3 -3
- data/lib/ogr/layer.rb +4 -5
- data/lib/ogr/layer_mixins/extensions.rb +242 -17
- data/lib/ogr/layer_mixins/ogr_feature_methods.rb +11 -11
- data/lib/ogr/layer_mixins/ogr_field_methods.rb +6 -11
- data/lib/ogr/layer_mixins/ogr_layer_method_methods.rb +18 -18
- data/lib/ogr/layer_mixins/ogr_query_filter_methods.rb +0 -2
- data/lib/ogr/layer_mixins/ogr_sql_methods.rb +1 -1
- data/lib/ogr/spatial_reference.rb +12 -37
- data/lib/ogr/spatial_reference_mixins/coordinate_system_getter_setters.rb +53 -55
- data/lib/ogr/spatial_reference_mixins/exporters.rb +18 -49
- data/lib/ogr/spatial_reference_mixins/parameter_getter_setters.rb +10 -29
- data/lib/ogr/style_table.rb +2 -2
- data/lib/ogr/style_table_extensions.rb +3 -1
- data/lib/ogr/style_tool.rb +8 -14
- data/lib/ogr.rb +39 -1
- data/spec/ffi-gdal_spec.rb +18 -1
- data/spec/integration/gdal/color_table_info_spec.rb +49 -33
- data/spec/integration/gdal/dataset_info_spec.rb +294 -45
- data/spec/integration/gdal/driver_info_spec.rb +139 -31
- data/spec/integration/gdal/geo_transform_info_spec.rb +197 -26
- data/spec/integration/gdal/gridder_spec.rb +329 -0
- data/spec/integration/gdal/raster_attribute_table_info_spec.rb +216 -11
- data/spec/integration/gdal/raster_band_algorithms_spec.rb +33 -0
- data/spec/integration/gdal/raster_band_info_spec.rb +240 -271
- data/spec/integration/ogr/layer_spec.rb +3 -1
- data/spec/spec_helper.rb +15 -6
- data/spec/support/images/osgeo/gdal/data/hfa/float-rle.img +0 -0
- data/spec/support/images/osgeo/geotiff/GeogToWGS84GeoKey/GeogToWGS84GeoKey5.lgo +31 -0
- 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 +10 -0
- data/spec/support/images/osgeo/geotiff/gdal_eg/cea.tif +0 -0
- data/spec/support/images/osgeo/geotiff/gdal_eg/cea.txt +84 -0
- data/spec/support/images/osgeo/geotiff/zi_imaging/image0.lgo +45 -0
- data/spec/support/images/osgeo/geotiff/zi_imaging/image0.tif +0 -0
- data/spec/support/integration_help.rb +32 -2
- data/spec/support/shared_examples/gdal/major_object_examples.rb +0 -6
- data/spec/support/shared_examples/ogr/a_geometry.rb +1 -1
- data/spec/unit/ffi/gdal_spec.rb +1 -1
- data/spec/unit/gdal/color_entry_spec.rb +1 -0
- data/spec/unit/gdal/color_interpretation_spec.rb +1 -0
- data/spec/unit/gdal/dataset_spec.rb +53 -2
- data/spec/unit/gdal/geo_transform_mixins/extensions_spec.rb +67 -0
- data/spec/unit/gdal/geo_transform_spec.rb +1 -1
- data/spec/unit/gdal/grid_spec.rb +83 -0
- data/spec/unit/gdal/gridder/point_extracting_spec.rb +99 -0
- data/spec/unit/gdal/gridder_options_spec.rb +183 -0
- data/spec/unit/gdal/gridder_spec.rb +140 -0
- data/spec/unit/gdal/internal_helpers_spec.rb +166 -2
- data/spec/unit/gdal/major_object_spec.rb +2 -0
- data/spec/unit/gdal/options_spec.rb +1 -0
- data/spec/unit/gdal/raster_band_classifier_spec.rb +70 -12
- data/spec/unit/gdal/raster_band_mixins/extensions_spec.rb +71 -0
- data/spec/unit/gdal/raster_band_mixins/io_extensions_spec.rb +133 -0
- data/spec/unit/gdal/raster_band_spec.rb +1 -0
- data/spec/unit/gdal/rpc_info_spec.rb +1 -0
- data/spec/unit/gdal/version_info_spec.rb +2 -0
- data/spec/unit/gdal/warp_operation_spec.rb +1 -0
- data/spec/unit/ogr/coordinate_transformation_spec.rb +102 -0
- data/spec/unit/ogr/data_source_spec.rb +12 -0
- data/spec/unit/ogr/feature_extensions_spec.rb +88 -0
- data/spec/unit/ogr/feature_spec.rb +30 -46
- data/spec/unit/ogr/geometries/geometry_collection_25d_spec.rb +23 -0
- data/spec/unit/ogr/geometries/geometry_collection_spec.rb +3 -3
- data/spec/unit/ogr/geometries/line_string_25d_spec.rb +23 -0
- data/spec/unit/ogr/geometries/line_string_spec.rb +2 -2
- data/spec/unit/ogr/geometries/linear_ring_spec.rb +2 -2
- data/spec/unit/ogr/geometries/multi_line_string_25d_spec.rb +23 -0
- data/spec/unit/ogr/geometries/multi_point_25d_spec.rb +23 -0
- data/spec/unit/ogr/geometries/multi_polygon_25d_spec.rb +23 -0
- data/spec/unit/ogr/geometries/point_25d_spec.rb +23 -0
- data/spec/unit/ogr/geometries/point_spec.rb +14 -24
- data/spec/unit/ogr/geometries/polygon_25d_spec.rb +23 -0
- data/spec/unit/ogr/geometries/polygon_spec.rb +1 -1
- data/spec/unit/ogr/geometry_field_definition_spec.rb +1 -1
- data/spec/unit/ogr/geometry_spec.rb +196 -30
- data/spec/unit/ogr/internal_helpers_spec.rb +20 -9
- data/spec/unit/ogr/layer_mixins/ogr_feature_methods_spec.rb +14 -6
- data/spec/unit/ogr/spatial_reference_mixins/exporters_spec.rb +9 -1
- data/spec/unit/ogr/spatial_reference_mixins/parameter_getter_setters_spec.rb +2 -1
- data/spec/unit/ogr/style_table_spec.rb +1 -1
- data/tmp/.keep +0 -0
- metadata +121 -19
- data/examples/points.txt +0 -127
- data/lib/gdal/grid_types.rb +0 -22
- data/lib/ogr/geometries/point_extensions.rb +0 -32
- data/lib/ogr/geometry_extensions.rb +0 -59
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'thor'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'gdal/dataset'
|
5
|
+
require 'gdal/raster_band'
|
6
|
+
|
7
|
+
GDAL::Logger.logging_enabled = true
|
8
|
+
|
9
|
+
module Examples
|
10
|
+
class RemoveSmallPolygons < ::Thor
|
11
|
+
desc 'filter SOURCE_PATH DEST_PATH SIZE',
|
12
|
+
'Removes polygons from SOURCE that are under SIZE'
|
13
|
+
option :band_number, type: :numeric, default: 1
|
14
|
+
def filter(source_path, dest_path, size)
|
15
|
+
puts "Copying source '#{source_path}' to '#{dest_path}'..."
|
16
|
+
FileUtils.cp(source_path, dest_path)
|
17
|
+
|
18
|
+
size = size.to_f
|
19
|
+
dataset = GDAL::Dataset.open(dest_path, 'w')
|
20
|
+
puts "Raster area: #{dataset.extent.area}"
|
21
|
+
raster_band = dataset.raster_band(options[:band_number])
|
22
|
+
|
23
|
+
puts "Filtering polygons under size #{size}"
|
24
|
+
raster_band.sieve_filter!(size, 4, progress_function: GDAL.simple_progress_formatter)
|
25
|
+
shapefile_dir = "#{File.basename(dest_path, '.tif')}-shapefile"
|
26
|
+
|
27
|
+
make_shapefile(shapefile_dir, dataset.spatial_reference.dup) do |layer|
|
28
|
+
raster_band.polygonize(layer, pixel_value_field: 0)
|
29
|
+
end
|
30
|
+
|
31
|
+
puts "\nDone!"
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def make_shapefile(dir_path, srs)
|
37
|
+
if File.exist?(dir_path)
|
38
|
+
puts "Removing old shapefile: #{dir_path}"
|
39
|
+
FileUtils.rm_rf(dir_path)
|
40
|
+
end
|
41
|
+
|
42
|
+
shp_driver = OGR::Driver.by_name 'ESRI Shapefile'
|
43
|
+
data_source = shp_driver.create_data_source(dir_path)
|
44
|
+
layer = data_source.create_layer('sieve-filtered', geometry_type: :wkbMultiPolygon,
|
45
|
+
spatial_reference: srs)
|
46
|
+
zone_num_field_def = OGR::FieldDefinition.new 'ZONE', :OFTInteger
|
47
|
+
layer.create_field(zone_num_field_def)
|
48
|
+
yield layer
|
49
|
+
|
50
|
+
puts "feature count: #{layer.feature_count}"
|
51
|
+
|
52
|
+
layer.each_feature.with_index do |feature, i|
|
53
|
+
area = feature.geometry.area
|
54
|
+
puts "Feature #{i} area: #{area}"
|
55
|
+
end
|
56
|
+
|
57
|
+
data_source.close
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
Examples::RemoveSmallPolygons.start(ARGV)
|
data/examples/testing_gdal.rb
CHANGED
@@ -24,8 +24,6 @@ usg = GDAL::Dataset.open(usg_path, 'r')
|
|
24
24
|
world_file_path = "#{__dir__}/spec/support/worldfiles/SR_50M/SR_50M.tif"
|
25
25
|
world_file = GDAL::GeoTransform.from_world_file(world_file_path, 'tfw')
|
26
26
|
|
27
|
-
binding.pry
|
28
|
-
|
29
27
|
# floyd.image_warp('meow.tif', 'GTiff', 1, cutline: floyd_geometry )
|
30
28
|
# extract_ndvi(floyd, 'ndvi.tif', floyd_wkt)
|
31
29
|
|
@@ -35,7 +33,6 @@ def warp_to_geometry(dataset, wkt_geometry)
|
|
35
33
|
geometry = OGR::Geometry.create_from_wkt(wkt_geometry, wkt_spatial_ref)
|
36
34
|
geometry.transform_to!(dataset.spatial_reference)
|
37
35
|
|
38
|
-
binding.pry
|
39
36
|
# Create a .shp from the geometry
|
40
37
|
shape = geometry.to_vector('geom.shp', 'ESRI Shapefile',
|
41
38
|
spatial_reference: dataset.spatial_reference)
|
data/examples/warping.rb
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'ffi-gdal'
|
3
|
+
require 'gdal/dataset'
|
4
|
+
require 'gdal/warp_operation'
|
5
|
+
require 'gdal/warp_options'
|
6
|
+
require 'gdal/transformers/general_image_projection_transformer'
|
7
|
+
require 'gdal/transformers/general_image_projection_transformer2'
|
8
|
+
require 'byebug'
|
9
|
+
|
10
|
+
GDAL::Logger.logging_enabled = true
|
11
|
+
|
12
|
+
module Examples
|
13
|
+
module Warping
|
14
|
+
class << self
|
15
|
+
def make_basic_options(source_dataset, dest_dataset)
|
16
|
+
options = GDAL::WarpOptions.new
|
17
|
+
options.source_dataset = source_dataset
|
18
|
+
options.destination_dataset = dest_dataset
|
19
|
+
options.source_bands = [1]
|
20
|
+
options.band_count = 1
|
21
|
+
options.destination_bands = [1]
|
22
|
+
options.progress_formatter = GDAL.simple_progress_formatter
|
23
|
+
|
24
|
+
options
|
25
|
+
end
|
26
|
+
|
27
|
+
def make_general_reprojection_options(source_dataset, dest_dataset)
|
28
|
+
options = make_basic_options(source_dataset, dest_dataset)
|
29
|
+
|
30
|
+
# Reprojection Transformer
|
31
|
+
transformer_arg = GDAL::Transformers::GeneralImageProjectionTransformer.new(
|
32
|
+
source_dataset, destination_dataset: dest_dataset, order: 0
|
33
|
+
)
|
34
|
+
options.transformer_arg = transformer_arg
|
35
|
+
|
36
|
+
options
|
37
|
+
end
|
38
|
+
|
39
|
+
def make_clipped_options(source_dataset, dest_dataset, clip_wkt)
|
40
|
+
options = make_basic_options(source_dataset, dest_dataset)
|
41
|
+
|
42
|
+
geom = OGR::Geometry.create_from_wkt(clip_wkt)
|
43
|
+
spatial_reference = OGR::SpatialReference.new_from_epsg(source_dataset.spatial_reference.authority_code.to_i)
|
44
|
+
geom.spatial_reference = spatial_reference
|
45
|
+
options.cutline_geometry = geom
|
46
|
+
# options.cutline_blend_distance = 100
|
47
|
+
options.resample_algorithm = :GRA_Average
|
48
|
+
|
49
|
+
options.warp_operation_options = {
|
50
|
+
init_dest: 'NO_DATA',
|
51
|
+
cutline: clip_wkt,
|
52
|
+
# cutline_all_touched: 'TRUE'
|
53
|
+
# cutline_all_touched: true
|
54
|
+
}
|
55
|
+
|
56
|
+
transformer_arg = GDAL::Transformers::GeneralImageProjectionTransformer2.new(
|
57
|
+
source_dataset, destination_dataset: dest_dataset,
|
58
|
+
insert_center_long: 'FALSE',
|
59
|
+
# DST_SRS: spatial_reference.to_wkt
|
60
|
+
)
|
61
|
+
# transformer_arg = GDAL::Transformers::GeneralImageProjectionTransformer.new(
|
62
|
+
# source_dataset, destination_dataset: dest_dataset,
|
63
|
+
# # source_wkt: source_dataset.projection, destination_wkt: dest_dataset.projection,
|
64
|
+
# gcp_use_ok: true, order: 0
|
65
|
+
# )
|
66
|
+
|
67
|
+
options.transformer_arg = transformer_arg
|
68
|
+
# options.transformer = cutline_transformer
|
69
|
+
# options.resample_algorithm = :GRA_CubicSpline
|
70
|
+
|
71
|
+
no_data_value = source_dataset.raster_band(1).no_data_value[:value]
|
72
|
+
puts "source no data value: #{no_data_value}"
|
73
|
+
# options.source_no_data_real = [no_data_value]
|
74
|
+
# options.source_no_data_imaginary = [no_data_value]
|
75
|
+
# options.destination_no_data_real = [no_data_value]
|
76
|
+
# options.destination_no_data_imaginary = [no_data_value]
|
77
|
+
|
78
|
+
options
|
79
|
+
end
|
80
|
+
|
81
|
+
def copy_dataset(source_dataset, dest_path)
|
82
|
+
driver = source_dataset.driver
|
83
|
+
|
84
|
+
driver.copy_dataset(source_dataset, dest_path)
|
85
|
+
end
|
86
|
+
|
87
|
+
def create_destination_reprojected_dataset(source_dataset, path, srid)
|
88
|
+
dest_wkt = OGR::SpatialReference.new_from_epsg(srid).to_wkt
|
89
|
+
|
90
|
+
transformer_arg = GDAL::Transformers::GeneralImageProjectionTransformer.new(
|
91
|
+
source_dataset, destination_wkt: dest_wkt, order: 1
|
92
|
+
)
|
93
|
+
|
94
|
+
suggested_options = source_dataset.suggested_warp_output(transformer_arg)
|
95
|
+
|
96
|
+
driver = GDAL::Driver.by_name 'GTiff'
|
97
|
+
ds = driver.create_dataset(path, suggested_options[:pixels], suggested_options[:lines], data_type: source_dataset.raster_band(1).data_type)
|
98
|
+
ds.geo_transform = suggested_options[:geo_transform]
|
99
|
+
ds.projection = dest_wkt
|
100
|
+
ds.raster_band(1).no_data_value = source_dataset.raster_band(1).no_data_value[:value]
|
101
|
+
|
102
|
+
ds
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
if $PROGRAM_NAME == __FILE__
|
109
|
+
args = ARGV.dup
|
110
|
+
raise 'Must only supply 2 args: [source destination]' unless args.length == 2
|
111
|
+
|
112
|
+
# 32616
|
113
|
+
# harper_wkt = <<-WKT
|
114
|
+
# POLYGON ((446272.16070421785116196 3450423.99460560129955411, 446267.51794699463061988 3450225.33339292788878083, 446169.27478282485390082 3450181.28046096721664071, 446167.92126038181595504 3449679.13779170718044043, 446257.50292950111906976 3449447.46736949309706688, 446177.33125468820799142 3449388.86781942518427968, 446181.49593684601131827 3449256.37749340012669563, 446201.94002113211899996 3449230.98345079040154815, 446963.20628352143103257 3449239.17042332561686635, 446960.24312665761681274 3449612.50297579308971763, 446866.33160242711892352 3449708.10946208890527487, 446750.25655526417540386 3449727.9624758935533464, 446691.84310374449705705 3449902.8676586695946753, 446610.46438609907636419 3450082.70331544848158956, 446642.15819176007062197 3450128.30150367366150022, 446528.87474136805394664 3450220.39211917016655207, 446272.16070421785116196 3450423.99460560129955411))
|
115
|
+
# WKT
|
116
|
+
# 4326
|
117
|
+
chualar_wkt = <<-WKT
|
118
|
+
Polygon ((-121.52653414366494644 36.58183382122394534, -121.52612663439269625 36.57798512254166923, -121.52503994300006696 36.57793984373364538, -121.52503994300006696 36.57952460201457967, -121.5239985304154402 36.57952460201457967, -121.52404380922347116 36.57789456492562152, -121.52245905094252976 36.57789456492562152, -121.52264016617463938 36.58151686956775706, -121.52413436683951886 36.58165270599183572, -121.52422492445558078 36.58002266890287757, -121.52513050061611466 36.58002266890287757, -121.52653414366494644 36.58183382122394534))
|
119
|
+
WKT
|
120
|
+
|
121
|
+
source_path = args.shift
|
122
|
+
dest_path = args.shift
|
123
|
+
|
124
|
+
source_dataset = GDAL::Dataset.open(source_path, 'r')
|
125
|
+
puts "source srid: #{source_dataset.spatial_reference.authority_code.to_i}"
|
126
|
+
|
127
|
+
dest_dataset = Examples::Warping.create_destination_reprojected_dataset(source_dataset, dest_path, source_dataset.spatial_reference.authority_code.to_i)
|
128
|
+
# Examples::Warping.copy_dataset(source_dataset, dest_path)
|
129
|
+
# dest_dataset = GDAL::Dataset.open(dest_path, 'w')
|
130
|
+
|
131
|
+
options = Examples::Warping.make_clipped_options(source_dataset, dest_dataset, chualar_wkt)
|
132
|
+
warp_operation = GDAL::WarpOperation.new(options)
|
133
|
+
puts "output raster size: #{dest_dataset.raster_x_size}, #{dest_dataset.raster_y_size}"
|
134
|
+
warp_operation.chunk_and_warp_image(0, 0, dest_dataset.raster_x_size, dest_dataset.raster_y_size)
|
135
|
+
# source_dataset.simple_image_warp(dest_dataset, options.transformer, options.transformer_arg,
|
136
|
+
# band_numbers = [1], options)
|
137
|
+
|
138
|
+
source_dataset.close
|
139
|
+
dest_dataset.close
|
140
|
+
end
|
data/ffi-gdal.gemspec
CHANGED
@@ -7,9 +7,9 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = 'ffi-gdal'
|
8
8
|
spec.version = FFI::GDAL::VERSION
|
9
9
|
spec.authors = ['Steve Loveless']
|
10
|
-
spec.email = %w[steve
|
10
|
+
spec.email = %w[steve@agrian.com]
|
11
11
|
spec.summary = 'FFI wrapper for GDAL/OGR.'
|
12
|
-
spec.homepage = '
|
12
|
+
spec.homepage = 'http://bitbucket.org/agrian/ffi-gdal'
|
13
13
|
spec.license = 'MIT'
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -21,9 +21,12 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency 'log_switch', '~> 1.0.0'
|
22
22
|
spec.add_dependency 'multi_xml'
|
23
23
|
spec.add_dependency 'narray', '~> 0.6.0'
|
24
|
+
|
24
25
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
26
|
+
spec.add_development_dependency 'byebug'
|
25
27
|
spec.add_development_dependency 'fakefs'
|
26
28
|
spec.add_development_dependency 'rake'
|
27
29
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
|
+
spec.add_development_dependency 'rubocop'
|
28
31
|
spec.add_development_dependency 'simplecov', '~> 0.9.0'
|
29
32
|
end
|
data/lib/ext/error_symbols.rb
CHANGED
@@ -5,7 +5,7 @@ module FFI
|
|
5
5
|
# Redefining #attach_function so we can avoid bombing out if a called method
|
6
6
|
# is not defined.
|
7
7
|
module Library
|
8
|
-
|
8
|
+
alias old_attach_function attach_function
|
9
9
|
|
10
10
|
def attach_function(*args)
|
11
11
|
old_attach_function(*args)
|
@@ -13,7 +13,8 @@ module FFI
|
|
13
13
|
@unsupported_gdal_functions ||= []
|
14
14
|
|
15
15
|
if $VERBOSE || ENV['VERBOSE']
|
16
|
-
warn "ffi-gdal warning: function '#{args.first}' is not available in this
|
16
|
+
warn "ffi-gdal warning: function '#{args.first}' is not available in this " \
|
17
|
+
"build of GDAL/OGR (v#{FFI::GDAL.GDALVersionInfo('RELEASE_NAME')})"
|
17
18
|
end
|
18
19
|
|
19
20
|
@unsupported_gdal_functions << args.first
|
data/lib/ext/float_ext.rb
CHANGED
@@ -3,13 +3,13 @@ class Float
|
|
3
3
|
#
|
4
4
|
# @return [Float]
|
5
5
|
def to_decimal_degrees
|
6
|
-
FFI::GDAL.GDALPackedDMSToDec(self)
|
6
|
+
FFI::GDAL::GDAL.GDALPackedDMSToDec(self)
|
7
7
|
end
|
8
8
|
|
9
9
|
# Converts decimal degrees int a packed DMS value (DDDMMMSSS.SS).
|
10
10
|
#
|
11
11
|
# @return [Float]
|
12
12
|
def to_dms
|
13
|
-
FFI::GDAL.GDALDecToPackedDMS(self)
|
13
|
+
FFI::GDAL::GDAL.GDALDecToPackedDMS(self)
|
14
14
|
end
|
15
15
|
end
|
data/lib/ext/narray_ext.rb
CHANGED
data/lib/ext/to_bool.rb
CHANGED
@@ -2,7 +2,7 @@ class Fixnum
|
|
2
2
|
def to_bool
|
3
3
|
return true if self == 1
|
4
4
|
return false if self == 0
|
5
|
-
|
5
|
+
raise "Fixnum '#{self}' can't be converted to Boolean."
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
@@ -10,6 +10,6 @@ class String
|
|
10
10
|
def to_bool
|
11
11
|
return true if to_i == 1
|
12
12
|
return false if to_i == 0
|
13
|
-
|
13
|
+
raise "String '#{self}' can't be converted to Boolean."
|
14
14
|
end
|
15
15
|
end
|
data/lib/ffi/cpl/conv.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'ffi'
|
2
|
-
require_relative 'error'
|
3
|
-
require_relative 'port'
|
4
2
|
require_relative '../../ext/ffi_library_function_checks'
|
5
3
|
|
6
4
|
module FFI
|
@@ -93,7 +91,7 @@ module FFI
|
|
93
91
|
attach_function :CPLPopFinderLocation, %i[], :void
|
94
92
|
attach_function :CPLFinderClean, %i[], :void
|
95
93
|
attach_function :CPLStat, %i[string pointer], :int
|
96
|
-
attach_function :CPLOpenShared, %i[string string
|
94
|
+
attach_function :CPLOpenShared, %i[string string bool], :pointer
|
97
95
|
attach_function :CPLCloseShared, %i[pointer], :void
|
98
96
|
attach_function :CPLGetSharedList, %i[pointer], :pointer
|
99
97
|
attach_function :CPLDumpSharedList, %i[pointer], :void
|
data/lib/ffi/cpl/error.rb
CHANGED
@@ -31,9 +31,6 @@ module FFI
|
|
31
31
|
attach_function :CPLGetLastErrorMsg, [], :string
|
32
32
|
|
33
33
|
attach_function :CPLGetErrorHandlerUserData, [], :pointer
|
34
|
-
attach_function :CPLErrorSetState,
|
35
|
-
[CPLErr, :int, :string],
|
36
|
-
:void
|
37
34
|
attach_function :CPLCleanupErrorMutex, [], :void
|
38
35
|
attach_function :CPLLoggingErrorHandler,
|
39
36
|
[CPLErr, :int, :string],
|
data/lib/ffi/cpl/minixml.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
require 'ffi'
|
2
|
-
# require_relative 'xml_node'
|
3
2
|
require_relative '../../ext/ffi_library_function_checks'
|
4
3
|
|
5
4
|
module FFI
|
6
5
|
module CPL
|
7
|
-
autoload :MiniXML, __FILE__
|
8
|
-
autoload :XMLNode, File.expand_path('xml_node', __dir__)
|
9
|
-
|
10
6
|
module MiniXML
|
11
7
|
extend ::FFI::Library
|
12
8
|
ffi_lib [::FFI::CURRENT_PROCESS, ::FFI::GDAL.gdal_library_path]
|
@@ -23,25 +19,25 @@ module FFI
|
|
23
19
|
#-------------------------------------------------------------------------
|
24
20
|
# Functions
|
25
21
|
#-------------------------------------------------------------------------
|
26
|
-
attach_function :CPLParseXMLString, %i[string], XMLNode.ptr
|
27
|
-
attach_function :CPLDestroyXMLNode, [XMLNode.ptr], :void
|
28
|
-
attach_function :CPLGetXMLNode, [XMLNode.ptr, :string], XMLNode.ptr
|
29
|
-
attach_function :CPLSearchXMLNode, [XMLNode.ptr, :string], XMLNode.ptr
|
30
|
-
attach_function :CPLGetXMLValue, [XMLNode.ptr, :string, :string], :string
|
31
|
-
attach_function :CPLCreateXMLNode, [XMLNode.ptr, XMLNode.ptr, :string], XMLNode.ptr
|
32
|
-
attach_function :CPLSerializeXMLTree, [XMLNode.ptr], :string
|
33
|
-
attach_function :CPLAddXMLChild, [XMLNode.ptr, XMLNode.ptr], :void
|
34
|
-
attach_function :CPLRemoveXMLChild, [XMLNode.ptr, XMLNode.ptr], :bool
|
35
|
-
attach_function :CPLAddXMLSibling, [XMLNode.ptr, XMLNode.ptr], :void
|
22
|
+
attach_function :CPLParseXMLString, %i[string], CPL::XMLNode.ptr
|
23
|
+
attach_function :CPLDestroyXMLNode, [CPL::XMLNode.ptr], :void
|
24
|
+
attach_function :CPLGetXMLNode, [CPL::XMLNode.ptr, :string], CPL::XMLNode.ptr
|
25
|
+
attach_function :CPLSearchXMLNode, [CPL::XMLNode.ptr, :string], CPL::XMLNode.ptr
|
26
|
+
attach_function :CPLGetXMLValue, [CPL::XMLNode.ptr, :string, :string], :string
|
27
|
+
attach_function :CPLCreateXMLNode, [CPL::XMLNode.ptr, CPL::XMLNode.ptr, :string], CPL::XMLNode.ptr
|
28
|
+
attach_function :CPLSerializeXMLTree, [CPL::XMLNode.ptr], :string
|
29
|
+
attach_function :CPLAddXMLChild, [CPL::XMLNode.ptr, CPL::XMLNode.ptr], :void
|
30
|
+
attach_function :CPLRemoveXMLChild, [CPL::XMLNode.ptr, CPL::XMLNode.ptr], :bool
|
31
|
+
attach_function :CPLAddXMLSibling, [CPL::XMLNode.ptr, CPL::XMLNode.ptr], :void
|
36
32
|
attach_function :CPLCreateXMLElementAndValue,
|
37
|
-
[XMLNode.ptr, :string, :string],
|
38
|
-
XMLNode.ptr
|
39
|
-
attach_function :CPLCloneXMLTree, [XMLNode.ptr], XMLNode.ptr
|
40
|
-
attach_function :CPLSetXMLValue, [XMLNode.ptr, :string, :string], :bool
|
41
|
-
attach_function :CPLStripXMLNamespace, [XMLNode.ptr, :string, :bool], :void
|
33
|
+
[CPL::XMLNode.ptr, :string, :string],
|
34
|
+
CPL::XMLNode.ptr
|
35
|
+
attach_function :CPLCloneXMLTree, [CPL::XMLNode.ptr], CPL::XMLNode.ptr
|
36
|
+
attach_function :CPLSetXMLValue, [CPL::XMLNode.ptr, :string, :string], :bool
|
37
|
+
attach_function :CPLStripXMLNamespace, [CPL::XMLNode.ptr, :string, :bool], :void
|
42
38
|
attach_function :CPLCleanXMLElementName, %i[string], :void
|
43
|
-
attach_function :CPLParseXMLFile, %i[string], XMLNode.ptr
|
44
|
-
attach_function :CPLSerializeXMLTreeToFile, [XMLNode.ptr, :string], :bool
|
39
|
+
attach_function :CPLParseXMLFile, %i[string], CPL::XMLNode.ptr
|
40
|
+
attach_function :CPLSerializeXMLTreeToFile, [CPL::XMLNode.ptr, :string], :bool
|
45
41
|
end
|
46
42
|
end
|
47
43
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
require_relative '../../ext/ffi_library_function_checks'
|
3
|
+
|
4
|
+
module FFI
|
5
|
+
module CPL
|
6
|
+
module Progress
|
7
|
+
extend ::FFI::Library
|
8
|
+
ffi_lib [FFI::CURRENT_PROCESS, FFI::GDAL.gdal_library_path]
|
9
|
+
|
10
|
+
#-------------------------------------------------------------------------
|
11
|
+
# Functions
|
12
|
+
#-------------------------------------------------------------------------
|
13
|
+
attach_function :GDALCreateScaledProgress,
|
14
|
+
[:double, :double, FFI::GDAL::GDAL.find_type(:GDALProgressFunc), :pointer],
|
15
|
+
:pointer
|
16
|
+
attach_function :GDALDestroyScaledProgress,
|
17
|
+
%i[pointer],
|
18
|
+
:void
|
19
|
+
ScaledProgress = attach_function :GDALScaledProgress,
|
20
|
+
%i[double string pointer],
|
21
|
+
:int
|
22
|
+
TermProgress = attach_function :GDALTermProgress,
|
23
|
+
%i[double string pointer],
|
24
|
+
:int
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/ffi/cpl/string.rb
CHANGED
@@ -40,7 +40,6 @@ module FFI
|
|
40
40
|
attach_function :CSLInsertString, %i[pointer int string], :pointer
|
41
41
|
attach_function :CSLRemoveStrings, %i[pointer int int pointer], :pointer
|
42
42
|
attach_function :CSLFindString, %i[pointer string], :int
|
43
|
-
attach_function :CSLFindStringCaseSensitive, %i[pointer string], :int
|
44
43
|
attach_function :CSLPartialFindString, %i[pointer string], :int
|
45
44
|
attach_function :CSLFindName, %i[pointer string], :int
|
46
45
|
|
@@ -66,11 +65,6 @@ module FFI
|
|
66
65
|
attach_function :CPLStrlcpy, %i[string string size_t], :size_t
|
67
66
|
attach_function :CPLStrlcat, %i[string string size_t], :size_t
|
68
67
|
attach_function :CPLStrnlen, %i[string size_t], :size_t
|
69
|
-
attach_function :CPLvsnprintf, %i[string size_t string varargs], :size_t
|
70
|
-
attach_function :CPLsnprintf, %i[string size_t varargs], :size_t
|
71
|
-
attach_function :CPLsprintf, %i[string varargs], :size_t
|
72
|
-
attach_function :CPLprintf, %i[varargs], :size_t
|
73
|
-
attach_function :CPLsscanf, %i[string varargs], :size_t
|
74
68
|
attach_function :CPLSPrintf, %i[string varargs], :string
|
75
69
|
attach_function :CSLAppendPrintf, %i[pointer string varargs], :pointer
|
76
70
|
attach_function :CPLVASPrintf, %i[pointer string varargs], :pointer
|
@@ -86,8 +80,6 @@ module FFI
|
|
86
80
|
attach_function :CPLForceToASCII, %i[string int char], :string
|
87
81
|
attach_function :CPLStrlenUTF8, %i[string], :int
|
88
82
|
|
89
|
-
attach_function :CPLOPrintf, %i[string varargs], :CPLString
|
90
|
-
attach_function :CPLOvPrintf, %i[string varargs], :CPLString
|
91
83
|
attach_function :CPLURLGetValue, %i[string string], :CPLString
|
92
84
|
attach_function :CPLURLAddKVP, %i[string string string], :CPLString
|
93
85
|
end
|
data/lib/ffi/cpl/vsi.rb
CHANGED
data/lib/ffi/cpl/xml_node.rb
CHANGED
data/lib/ffi/cpl.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module FFI
|
2
|
+
module CPL
|
3
|
+
autoload :Conv, File.expand_path('cpl/conv.rb', __dir__)
|
4
|
+
autoload :Error, File.expand_path('cpl/error.rb', __dir__)
|
5
|
+
autoload :HashSet, File.expand_path('cpl/hash_set.rb', __dir__)
|
6
|
+
autoload :HTTP, File.expand_path('cpl/http.rb', __dir__)
|
7
|
+
autoload :MiniXML, File.expand_path('cpl/minixml.rb', __dir__)
|
8
|
+
autoload :Port, File.expand_path('cpl/port.rb', __dir__)
|
9
|
+
autoload :Progress, File.expand_path('cpl/progress.rb', __dir__)
|
10
|
+
autoload :QuadTree, File.expand_path('cpl/quad_tree.rb', __dir__)
|
11
|
+
autoload :String, File.expand_path('cpl/string.rb', __dir__)
|
12
|
+
autoload :VSI, File.expand_path('cpl/vsi.rb', __dir__)
|
13
|
+
autoload :XMLNode, File.expand_path('cpl/xml_node.rb', __dir__)
|
14
|
+
end
|
15
|
+
end
|