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
@@ -21,7 +21,7 @@ module OGR
|
|
21
21
|
end
|
22
22
|
|
23
23
|
unless @c_pointer.is_a?(FFI::Pointer) && !@c_pointer.null?
|
24
|
-
|
24
|
+
raise OGR::InvalidGeometryFieldDefinition,
|
25
25
|
"Unable to create #{self.class.name} from #{name_or_pointer}"
|
26
26
|
end
|
27
27
|
|
@@ -34,6 +34,8 @@ module OGR
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def destroy!
|
37
|
+
return unless @c_pointer
|
38
|
+
|
37
39
|
FFI::OGR::API.OGR_GFld_Destroy(@c_pointer)
|
38
40
|
@c_pointer = nil
|
39
41
|
end
|
@@ -45,7 +47,7 @@ module OGR
|
|
45
47
|
|
46
48
|
# @param new_name [String]
|
47
49
|
def name=(new_name)
|
48
|
-
|
50
|
+
raise OGR::ReadOnlyObject if @read_only
|
49
51
|
|
50
52
|
FFI::OGR::API.OGR_GFld_SetName(@c_pointer, new_name)
|
51
53
|
end
|
@@ -57,7 +59,7 @@ module OGR
|
|
57
59
|
|
58
60
|
# @param new_type [FFI::OGR::API::WKBGeometryType]
|
59
61
|
def type=(new_type)
|
60
|
-
|
62
|
+
raise OGR::ReadOnlyObject if @read_only
|
61
63
|
|
62
64
|
FFI::OGR::API.OGR_GFld_SetType(@c_pointer, new_type)
|
63
65
|
end
|
@@ -75,7 +77,7 @@ module OGR
|
|
75
77
|
|
76
78
|
# @param new_spatial_reference [OGR::SpatialReference, FFI::Pointer]
|
77
79
|
def spatial_reference=(new_spatial_reference)
|
78
|
-
|
80
|
+
raise OGR::ReadOnlyObject if @read_only
|
79
81
|
|
80
82
|
spatial_ref_ptr = GDAL._pointer(OGR::SpatialReference, new_spatial_reference)
|
81
83
|
|
@@ -91,7 +93,7 @@ module OGR
|
|
91
93
|
|
92
94
|
# @param value [Boolean]
|
93
95
|
def ignore=(value)
|
94
|
-
|
96
|
+
raise OGR::ReadOnlyObject if @read_only
|
95
97
|
|
96
98
|
FFI::OGR::API.OGR_GFld_SetIgnored(@c_pointer, value)
|
97
99
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module OGR
|
2
|
+
module GeometryMixins
|
3
|
+
module ContainerMixins
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
# Iterates over each geometry in the container geometry. Per OGR docs, the
|
7
|
+
# yielded geometry should not be modified; if you need to do something to
|
8
|
+
# that geometry, you should {{#clone}} it. Additionally, the yielded
|
9
|
+
# geometry is only valid until the containing changes.
|
10
|
+
#
|
11
|
+
# @yieldparam [OGR::Geometry]
|
12
|
+
# @return [Enumerator]
|
13
|
+
# @see http://gdal.org/1.11/ogr/ogr__api_8h.html#a6bac93150529a5c98811db29e289dd66
|
14
|
+
def each
|
15
|
+
return enum_for(:each) unless block_given?
|
16
|
+
|
17
|
+
geometry_count.times do |i|
|
18
|
+
yield geometry_at(i)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module OGR
|
4
|
+
module GeometryMixins
|
5
|
+
module Extensions
|
6
|
+
# @return [Fixnum] The number of the UTM zone this geometry belongs to.
|
7
|
+
def utm_zone
|
8
|
+
return unless spatial_reference
|
9
|
+
|
10
|
+
if spatial_reference.authority_code == '4326'.freeze
|
11
|
+
self_as_4326 = self
|
12
|
+
else
|
13
|
+
self_as_4326 = dup
|
14
|
+
self_as_4326.transform_to!(OGR::SpatialReference.new_from_epsg(4326))
|
15
|
+
end
|
16
|
+
|
17
|
+
self_as_4326 = self_as_4326.buffer(0) unless self_as_4326.valid?
|
18
|
+
|
19
|
+
return unless self_as_4326.point_on_surface.x
|
20
|
+
|
21
|
+
((self_as_4326.point_on_surface.x + 180) / 6.to_f).floor + 1
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Boolean]
|
25
|
+
def container?
|
26
|
+
self.class.ancestors.include? OGR::GeometryTypes::Container
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Boolean]
|
30
|
+
def curve?
|
31
|
+
self.class.ancestors.include? OGR::GeometryTypes::Curve
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Boolean]
|
35
|
+
def surface?
|
36
|
+
self.class.ancestors.include? OGR::GeometryTypes::Surface
|
37
|
+
end
|
38
|
+
|
39
|
+
def !=(other)
|
40
|
+
!equals?(other)
|
41
|
+
end
|
42
|
+
|
43
|
+
def is_2d?
|
44
|
+
coordinate_dimension == 2
|
45
|
+
end
|
46
|
+
|
47
|
+
def is_3d?
|
48
|
+
coordinate_dimension == 3
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [Boolean]
|
52
|
+
def invalid?
|
53
|
+
!valid?
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [Hash]
|
57
|
+
def as_json(options = nil)
|
58
|
+
json = {
|
59
|
+
coordinate_dimension: coordinate_dimension,
|
60
|
+
geometry_count: geometry_count,
|
61
|
+
dimension: dimension,
|
62
|
+
is_empty: empty?,
|
63
|
+
is_ring: ring?,
|
64
|
+
is_simple: simple?,
|
65
|
+
is_valid: valid?,
|
66
|
+
name: name,
|
67
|
+
point_count: point_count,
|
68
|
+
spatial_reference: spatial_reference.nil? ? nil : spatial_reference.as_json(options),
|
69
|
+
type: type_to_name,
|
70
|
+
wkb_size: wkb_size
|
71
|
+
}
|
72
|
+
|
73
|
+
json[:area] = area if respond_to? :area
|
74
|
+
json[:length] = length if respond_to? :length
|
75
|
+
json[:points] = points if respond_to? :points
|
76
|
+
|
77
|
+
json
|
78
|
+
end
|
79
|
+
|
80
|
+
# @return [String]
|
81
|
+
def to_json(options = nil)
|
82
|
+
as_json(options).to_json
|
83
|
+
end
|
84
|
+
|
85
|
+
def collection?
|
86
|
+
false
|
87
|
+
end
|
88
|
+
|
89
|
+
def to_vector(file_name, driver, layer_name: 'vectorized_geometry', spatial_reference: nil)
|
90
|
+
driver = OGR::Driver.by_name(driver)
|
91
|
+
|
92
|
+
data_source = driver.create_data_source(file_name)
|
93
|
+
log "Creating layer #{layer_name}, type: #{type}"
|
94
|
+
layer = data_source.create_layer(layer_name, geometry_type: type,
|
95
|
+
spatial_reference: spatial_reference)
|
96
|
+
|
97
|
+
# field = FieldDefinition.new('Name', :OFTString)
|
98
|
+
# field.width = 32
|
99
|
+
|
100
|
+
unless layer
|
101
|
+
raise OGR::InvalidLayer, "Unable to create layer '#{layer_name}'."
|
102
|
+
end
|
103
|
+
|
104
|
+
feature = layer.create_feature(layer_name)
|
105
|
+
feature.geometry = self
|
106
|
+
|
107
|
+
data_source
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -1,6 +1,10 @@
|
|
1
|
+
require_relative '../geometry_mixins/container_mixins'
|
2
|
+
|
1
3
|
module OGR
|
2
4
|
module GeometryTypes
|
3
5
|
module Container
|
6
|
+
include OGR::GeometryMixins::ContainerMixins
|
7
|
+
|
4
8
|
def collection?
|
5
9
|
true
|
6
10
|
end
|
@@ -21,7 +25,7 @@ module OGR
|
|
21
25
|
|
22
26
|
# @param sub_geometry [OGR::Geometry, FFI::Pointer]
|
23
27
|
# @return +true+ if successful, otherwise raises an OGR exception.
|
24
|
-
def
|
28
|
+
def add_geometry_directly(sub_geometry)
|
25
29
|
sub_geometry_ptr = GDAL._pointer(OGR::Geometry, sub_geometry)
|
26
30
|
ogr_err = FFI::OGR::API.OGR_G_AddGeometryDirectly(@c_pointer, sub_geometry_ptr)
|
27
31
|
|
@@ -43,10 +47,13 @@ module OGR
|
|
43
47
|
# @param sub_geometry_index [Fixnum]
|
44
48
|
# @return [OGR::Geometry]
|
45
49
|
def geometry_at(sub_geometry_index)
|
46
|
-
build_geometry do
|
47
|
-
FFI::OGR::API.OGR_G_GetGeometryRef(
|
50
|
+
build_geometry do
|
51
|
+
tmp_ptr = FFI::OGR::API.OGR_G_GetGeometryRef(@c_pointer, sub_geometry_index)
|
52
|
+
tmp_ptr.autorelease = false
|
53
|
+
tmp_ptr.null? ? nil : FFI::OGR::API.OGR_G_Clone(tmp_ptr)
|
48
54
|
end
|
49
55
|
end
|
56
|
+
alias geometry_ref geometry_at
|
50
57
|
|
51
58
|
# Build a ring from a bunch of arcs. The collection must be
|
52
59
|
# a MultiLineString or GeometryCollection.
|
@@ -16,6 +16,7 @@ module OGR
|
|
16
16
|
FFI::OGR::API.OGR_G_GetZ(@c_pointer, point_number)
|
17
17
|
end
|
18
18
|
|
19
|
+
# @param [Fixnum] Index of the point to get.
|
19
20
|
# @return [Array<Float, Float, Float>] [x, y] if 2d or [x, y, z] if 3d.
|
20
21
|
def point(number)
|
21
22
|
x_ptr = FFI::MemoryPointer.new(:double)
|
@@ -30,6 +31,22 @@ module OGR
|
|
30
31
|
[x_ptr.read_double, y_ptr.read_double, z_ptr.read_double]
|
31
32
|
end
|
32
33
|
end
|
34
|
+
alias get_point point
|
35
|
+
|
36
|
+
# It seems as if {{#point}} should return an OGR::Point, but since OGR's
|
37
|
+
# OGR_G_GetPoint only returns coordinates, this allows getting the point
|
38
|
+
# as an OGR::Point.
|
39
|
+
#
|
40
|
+
# @param [Fixnum] Index of the point to get.
|
41
|
+
# @return [OGR::Point]
|
42
|
+
# TODO: Move to an extension.
|
43
|
+
def point_geometry(number)
|
44
|
+
coords = point(number)
|
45
|
+
point = OGR::Point.new
|
46
|
+
point.set_point(0, *coords)
|
47
|
+
|
48
|
+
point
|
49
|
+
end
|
33
50
|
|
34
51
|
# Adds a point to a LineString or Point geometry.
|
35
52
|
#
|
@@ -44,38 +61,66 @@ module OGR
|
|
44
61
|
end
|
45
62
|
end
|
46
63
|
|
47
|
-
|
48
|
-
|
64
|
+
# @param index [Fixnum] The index of the vertex to assign.
|
65
|
+
# @param x [Number]
|
66
|
+
# @param y [Number]
|
67
|
+
# @param z [Number]
|
68
|
+
def set_point(index, x, y, z = nil)
|
69
|
+
if is_3d?
|
70
|
+
FFI::OGR::API.OGR_G_SetPoint(@c_pointer, index, x, y, z)
|
71
|
+
else
|
72
|
+
FFI::OGR::API.OGR_G_SetPoint_2D(@c_pointer, index, x, y)
|
73
|
+
end
|
49
74
|
end
|
50
75
|
|
51
|
-
# @return [
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
76
|
+
# @return [Enumerator]
|
77
|
+
# @yieldparam [OGR::Point]
|
78
|
+
# TODO: Move to an extension.
|
79
|
+
def each_point_geometry
|
80
|
+
return enum_for(:each_point_as_geometry) unless block_given?
|
56
81
|
|
57
|
-
|
82
|
+
point_count.times do |point_num|
|
83
|
+
yield point_as_geometry(point_num)
|
84
|
+
end
|
85
|
+
end
|
58
86
|
|
87
|
+
# @return [Array<OGR::Point>]
|
88
|
+
# @see {{#each_point_geometry}}, {{#point_geometry}}
|
89
|
+
# TODO: Move to an extension.
|
90
|
+
def point_geometries
|
91
|
+
each_point_geometry.to_a
|
92
|
+
end
|
93
|
+
|
94
|
+
# @return [Array<Array<Float>>] An array of (x, y) or (x, y, z) points.
|
95
|
+
def points
|
96
|
+
x_stride = FFI::Type::DOUBLE.size
|
97
|
+
y_stride = FFI::Type::DOUBLE.size
|
98
|
+
z_stride = coordinate_dimension == 3 ? FFI::Type::DOUBLE.size : 0
|
99
|
+
|
100
|
+
buffer_size = point_count
|
59
101
|
x_buffer = FFI::MemoryPointer.new(:buffer_out, buffer_size)
|
60
102
|
y_buffer = FFI::MemoryPointer.new(:buffer_out, buffer_size)
|
103
|
+
z_buffer = FFI::MemoryPointer.new(:buffer_out, buffer_size) if coordinate_dimension == 3
|
104
|
+
|
105
|
+
FFI::OGR::API.OGR_G_GetPoints(@c_pointer,
|
106
|
+
x_buffer, x_stride, y_buffer,
|
107
|
+
y_stride, z_buffer, z_stride)
|
61
108
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
z_stride)
|
74
|
-
|
75
|
-
num_points.times.map do |i|
|
76
|
-
point(i)
|
109
|
+
log 'Got different number of points than point_count in #point_values' unless num_points == point_count
|
110
|
+
|
111
|
+
x_array = x_buffer.read_array_of_double(buffer_size)
|
112
|
+
y_array = y_buffer.read_array_of_double(buffer_size)
|
113
|
+
|
114
|
+
if z_buffer
|
115
|
+
z_array = z_buffer.read_array_of_double(buffer_size)
|
116
|
+
|
117
|
+
[x_array, y_array, z_array].transpose
|
118
|
+
else
|
119
|
+
[x_array, y_array].transpose
|
77
120
|
end
|
78
121
|
end
|
122
|
+
alias get_points points
|
123
|
+
alias point_values points
|
79
124
|
|
80
125
|
# @param geo_transform [GDAL::GeoTransform]
|
81
126
|
# @return [Array<Array>]
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require_relative '../../ffi/ogr/api'
|
2
|
-
|
3
1
|
module OGR
|
4
2
|
module GeometryTypes
|
5
3
|
module Surface
|
@@ -17,13 +15,6 @@ module OGR
|
|
17
15
|
def area_units
|
18
16
|
spatial_reference ? spatial_reference.linear_units : nil
|
19
17
|
end
|
20
|
-
|
21
|
-
# Returns a point that's guaranteed to lie on the surface.
|
22
|
-
#
|
23
|
-
# @return [OGR::Point]
|
24
|
-
def point_on_surface
|
25
|
-
build_geometry { |ptr| FFI::OGR::API.OGR_G_PointOnSurface(ptr) }
|
26
|
-
end
|
27
18
|
end
|
28
19
|
end
|
29
20
|
end
|
data/lib/ogr/internal_helpers.rb
CHANGED
@@ -15,7 +15,7 @@ module OGR
|
|
15
15
|
case flag
|
16
16
|
when 'w' then true
|
17
17
|
when 'r' then false
|
18
|
-
else
|
18
|
+
else raise "Invalid access_flag '#{flag}'. Use 'r' or 'w'."
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -32,7 +32,7 @@ module OGR
|
|
32
32
|
when 0 then nil
|
33
33
|
when 1 then (Time.now.getlocal.utc_offset / 3600).to_s
|
34
34
|
when 100 then '+0'
|
35
|
-
else
|
35
|
+
else raise "Unable to process time zone: #{time_zone}"
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -45,7 +45,7 @@ module OGR
|
|
45
45
|
#
|
46
46
|
# @param time_zone [String]
|
47
47
|
def _format_time_zone_for_ogr(time_zone)
|
48
|
-
if time_zone =~ /GMT/
|
48
|
+
if time_zone =~ /(00:00|GMT)\z/
|
49
49
|
100
|
50
50
|
elsif time_zone
|
51
51
|
1
|
data/lib/ogr/layer.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
require_relative '../
|
2
|
-
require_relative '../gdal
|
3
|
-
require_relative 'envelope'
|
1
|
+
require_relative '../ogr'
|
2
|
+
require_relative '../gdal'
|
4
3
|
require_relative 'layer_mixins/extensions'
|
5
4
|
require_relative 'layer_mixins/capability_methods'
|
6
5
|
require_relative 'layer_mixins/ogr_feature_methods'
|
@@ -12,6 +11,7 @@ require_relative 'layer_mixins/ogr_sql_methods'
|
|
12
11
|
module OGR
|
13
12
|
class Layer
|
14
13
|
include GDAL::MajorObject
|
14
|
+
include GDAL::Logger
|
15
15
|
include LayerMixins::Extensions
|
16
16
|
include LayerMixins::CapabilityMethods
|
17
17
|
include LayerMixins::OGRFeatureMethods
|
@@ -28,7 +28,6 @@ module OGR
|
|
28
28
|
# @param layer_ptr [FFI::Pointer]
|
29
29
|
def initialize(layer_ptr)
|
30
30
|
@c_pointer = layer_ptr
|
31
|
-
@features = []
|
32
31
|
end
|
33
32
|
|
34
33
|
# @return [String]
|
@@ -97,7 +96,7 @@ module OGR
|
|
97
96
|
# @param new_style_table [OGR::StyleTable, FFI::pointer]
|
98
97
|
def style_table=(new_style_table)
|
99
98
|
style_table_ptr = GDAL._pointer(OGR::StyleTable, new_style_table)
|
100
|
-
|
99
|
+
raise OGR::Failure if style_table_ptr.nil? || style_table_ptr.null?
|
101
100
|
|
102
101
|
FFI::OGR::API.OGR_L_SetStyleTable(@c_pointer, style_table_ptr)
|
103
102
|
end
|