ffi-gdal 1.0.0.beta3 → 1.0.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +62 -0
- data/Gemfile +1 -1
- data/History.md +53 -28
- data/README.md +6 -0
- data/Rakefile +23 -1
- data/examples/extract_and_colorize.rb +21 -22
- data/examples/geometries.rb +2 -2
- data/examples/gridding.rb +106 -0
- data/examples/ogr_layer_to_layer.rb +1 -1
- data/examples/points.txt +127 -0
- data/examples/testing_gdal.rb +3 -4
- data/ffi-gdal.gemspec +3 -2
- data/lib/ext/error_symbols.rb +2 -57
- data/lib/ext/ffi_library_function_checks.rb +26 -0
- data/lib/ext/float_ext.rb +2 -2
- data/lib/ext/narray_ext.rb +2 -0
- data/lib/ext/numeric_as_data_type.rb +19 -0
- data/lib/ext/to_bool.rb +4 -4
- data/lib/ffi/cpl/conv.rb +132 -0
- data/lib/ffi/cpl/error.rb +67 -0
- data/lib/ffi/cpl/hash_set.rb +39 -0
- data/lib/ffi/cpl/http.rb +25 -0
- data/lib/ffi/cpl/http_result.rb +18 -0
- data/lib/ffi/cpl/list.rb +38 -0
- data/lib/ffi/cpl/mime_part.rb +11 -0
- data/lib/ffi/cpl/minixml.rb +47 -0
- data/lib/ffi/cpl/port.rb +23 -0
- data/lib/ffi/cpl/quad_tree.rb +51 -0
- data/lib/ffi/{ogr/ogr_envelope.rb → cpl/rect_obj.rb} +3 -3
- data/lib/ffi/cpl/string.rb +95 -0
- data/lib/ffi/cpl/vsi.rb +115 -0
- data/lib/ffi/cpl/xml_node.rb +6 -6
- data/lib/ffi/gdal/alg.rb +385 -0
- data/lib/ffi/gdal/{gdal_color_entry.rb → color_entry.rb} +1 -2
- data/lib/ffi/gdal/exceptions.rb +6 -0
- data/lib/ffi/gdal/{gdal_gcp.rb → gcp.rb} +1 -3
- data/lib/ffi/gdal/{gdal_h.rb → gdal.rb} +253 -252
- data/lib/ffi/gdal/grid.rb +58 -0
- data/lib/ffi/gdal/{gdal_grid_data_metrics_options.rb → grid_data_metrics_options.rb} +1 -2
- data/lib/ffi/gdal/{gdal_grid_inverse_distance_to_a_power_options.rb → grid_inverse_distance_to_a_power_options.rb} +1 -2
- data/lib/ffi/gdal/{gdal_grid_moving_average_options.rb → grid_moving_average_options.rb} +1 -2
- data/lib/ffi/gdal/{gdal_grid_nearest_neighbor_options.rb → grid_nearest_neighbor_options.rb} +1 -2
- data/lib/ffi/gdal/matching.rb +20 -0
- data/lib/ffi/gdal/{gdal_rpc_info.rb → rpc_info.rb} +1 -2
- data/lib/ffi/gdal/{gdal_transformer_info.rb → transformer_info.rb} +1 -2
- data/lib/ffi/gdal/version.rb +1 -1
- data/lib/ffi/gdal/vrt.rb +92 -0
- data/lib/ffi/gdal/{gdal_warp_options.rb → warp_options.rb} +8 -4
- data/lib/ffi/gdal/warper.rb +70 -0
- data/lib/ffi/gdal.rb +56 -69
- data/lib/ffi/ogr/api.rb +567 -0
- data/lib/ffi/ogr/{ogr_contour_writer_info.rb → contour_writer_info.rb} +2 -3
- data/lib/ffi/ogr/core.rb +181 -0
- data/lib/ffi/ogr/envelope.rb +12 -0
- data/lib/ffi/ogr/{ogr_envelope_3d.rb → envelope_3d.rb} +2 -2
- data/lib/ffi/ogr/featurestyle.rb +29 -0
- data/lib/ffi/ogr/field.rb +63 -0
- data/lib/ffi/ogr/geocoding.rb +30 -0
- data/lib/ffi/ogr/srs_api.rb +407 -0
- data/lib/ffi/ogr/style_param.rb +13 -0
- data/lib/ffi/ogr/{ogr_style_value.rb → style_value.rb} +4 -3
- data/lib/ffi/ogr.rb +7 -7
- data/lib/ffi-gdal.rb +7 -145
- data/lib/gdal/color_entry.rb +18 -14
- data/lib/gdal/color_entry_mixins/extensions.rb +32 -0
- data/lib/gdal/color_interpretation.rb +2 -2
- data/lib/gdal/color_table.rb +37 -32
- data/lib/gdal/color_table_mixins/extensions.rb +48 -0
- data/lib/gdal/cpl_error_handler.rb +119 -0
- data/lib/gdal/data_type.rb +7 -7
- data/lib/gdal/dataset.rb +131 -238
- data/lib/gdal/dataset_mixins/algorithm_methods.rb +182 -0
- data/lib/gdal/dataset_mixins/extensions.rb +542 -0
- data/lib/gdal/dataset_mixins/matching.rb +26 -0
- data/lib/gdal/driver.rb +68 -92
- data/lib/gdal/driver_mixins/extensions.rb +93 -0
- data/lib/gdal/exceptions.rb +32 -4
- data/lib/gdal/geo_transform.rb +63 -43
- data/lib/gdal/geo_transform_mixins/extensions.rb +57 -0
- data/lib/gdal/grid.rb +144 -0
- data/lib/gdal/grid_types/data_metrics_base.rb +14 -0
- data/lib/gdal/grid_types/inverse_distance_to_a_power.rb +19 -0
- data/lib/gdal/grid_types/metric_average_distance.rb +12 -0
- data/lib/gdal/grid_types/metric_average_distance_pts.rb +12 -0
- data/lib/gdal/grid_types/metric_count.rb +12 -0
- data/lib/gdal/grid_types/metric_maximum.rb +12 -0
- data/lib/gdal/grid_types/metric_minimum.rb +12 -0
- data/lib/gdal/grid_types/metric_range.rb +12 -0
- data/lib/gdal/grid_types/moving_average.rb +19 -0
- data/lib/gdal/grid_types/nearest_neighbor.rb +19 -0
- data/lib/gdal/grid_types.rb +22 -0
- data/lib/gdal/internal_helpers.rb +94 -0
- data/lib/gdal/major_object.rb +4 -7
- data/lib/gdal/options.rb +14 -7
- data/lib/gdal/raster_attribute_table.rb +38 -47
- data/lib/gdal/raster_attribute_table_mixins/extensions.rb +41 -0
- data/lib/gdal/raster_band.rb +193 -227
- data/lib/gdal/raster_band_classifier.rb +107 -0
- data/lib/gdal/raster_band_mixins/algorithm_methods.rb +292 -0
- data/lib/gdal/raster_band_mixins/extensions.rb +238 -0
- data/lib/gdal/rpc_info.rb +35 -0
- data/lib/gdal/transformer.rb +15 -0
- data/lib/gdal/transformers/approximate_transformer.rb +48 -0
- data/lib/gdal/transformers/base_general_image_projection_transformer.rb +45 -0
- data/lib/gdal/transformers/gcp_transformer.rb +55 -0
- data/lib/gdal/transformers/general_image_projection_transformer.rb +31 -0
- data/lib/gdal/transformers/general_image_projection_transformer2.rb +52 -0
- data/lib/gdal/transformers/general_image_projection_transformer3.rb +25 -0
- data/lib/gdal/transformers/geolocation_transformer.rb +42 -0
- data/lib/gdal/transformers/reprojection_transformer.rb +39 -0
- data/lib/gdal/transformers/rpc_transformer.rb +56 -0
- data/lib/gdal/transformers/tps_transformer.rb +40 -0
- data/lib/gdal/virtual_dataset.rb +96 -0
- data/lib/gdal/warp_operation.rb +20 -23
- data/lib/gdal.rb +17 -0
- data/lib/ogr/coordinate_transformation.rb +16 -41
- data/lib/ogr/data_source.rb +103 -58
- data/lib/ogr/data_source_extensions.rb +5 -6
- data/lib/ogr/data_source_mixins/capability_methods.rb +27 -0
- data/lib/ogr/driver.rb +61 -33
- data/lib/ogr/driver_mixins/capability_methods.rb +16 -0
- data/lib/ogr/envelope.rb +29 -18
- data/lib/ogr/envelope_extensions.rb +70 -49
- data/lib/ogr/error_handling.rb +46 -0
- data/lib/ogr/exceptions.rb +58 -12
- data/lib/ogr/feature.rb +334 -86
- data/lib/ogr/feature_definition.rb +94 -51
- data/lib/ogr/feature_definition_extensions.rb +36 -13
- data/lib/ogr/feature_extensions.rb +62 -11
- data/lib/ogr/field.rb +175 -54
- data/lib/ogr/field_definition.rb +110 -0
- data/lib/ogr/{field_extensions.rb → field_definition_extensions.rb} +4 -5
- data/lib/ogr/{geocoding_session.rb → geocoder.rb} +14 -13
- data/lib/ogr/geometries/geometry_collection.rb +13 -0
- data/lib/ogr/geometries/line_string.rb +35 -0
- data/lib/ogr/geometries/linear_ring.rb +11 -0
- data/lib/ogr/geometries/multi_line_string.rb +16 -0
- data/lib/ogr/geometries/multi_point.rb +14 -0
- data/lib/ogr/geometries/multi_polygon.rb +21 -0
- data/lib/ogr/geometries/none_geometry.rb +13 -0
- data/lib/ogr/geometries/point.rb +65 -0
- data/lib/ogr/geometries/point_extensions.rb +32 -0
- data/lib/ogr/geometries/polygon.rb +14 -0
- data/lib/ogr/geometries/unknown_geometry.rb +10 -0
- data/lib/ogr/geometry.rb +270 -242
- data/lib/ogr/geometry_extensions.rb +8 -9
- data/lib/ogr/geometry_field_definition.rb +99 -0
- data/lib/ogr/geometry_field_definition_extensions.rb +19 -0
- data/lib/ogr/geometry_types/container.rb +75 -0
- data/lib/ogr/geometry_types/curve.rb +25 -28
- data/lib/ogr/geometry_types/surface.rb +13 -4
- data/lib/ogr/internal_helpers.rb +57 -0
- data/lib/ogr/layer.rb +60 -181
- data/lib/ogr/layer_mixins/capability_methods.rb +102 -0
- data/lib/ogr/layer_mixins/extensions.rb +59 -0
- data/lib/ogr/layer_mixins/ogr_feature_methods.rb +127 -0
- data/lib/ogr/layer_mixins/ogr_field_methods.rb +143 -0
- data/lib/ogr/layer_mixins/ogr_layer_method_methods.rb +163 -0
- data/lib/ogr/layer_mixins/ogr_query_filter_methods.rb +89 -0
- data/lib/ogr/layer_mixins/ogr_sql_methods.rb +48 -0
- data/lib/ogr/spatial_reference.rb +108 -589
- data/lib/ogr/spatial_reference_extensions.rb +29 -3
- data/lib/ogr/spatial_reference_mixins/coordinate_system_getter_setters.rb +494 -0
- data/lib/ogr/spatial_reference_mixins/exporters.rb +134 -0
- data/lib/ogr/spatial_reference_mixins/importers.rb +243 -0
- data/lib/ogr/spatial_reference_mixins/morphers.rb +25 -0
- data/lib/ogr/spatial_reference_mixins/parameter_getter_setters.rb +122 -0
- data/lib/ogr/spatial_reference_mixins/type_checks.rb +62 -0
- data/lib/ogr/style_table.rb +53 -5
- data/lib/ogr/style_table_extensions.rb +21 -5
- data/lib/ogr/style_tool.rb +118 -0
- data/lib/ogr.rb +8 -0
- data/spec/ffi-gdal_spec.rb +1 -2
- data/spec/integration/{color_table_info_spec.rb → gdal/color_table_info_spec.rb} +12 -12
- data/spec/integration/{dataset_info_spec.rb → gdal/dataset_info_spec.rb} +2 -6
- data/spec/integration/{driver_info_spec.rb → gdal/driver_info_spec.rb} +5 -5
- data/spec/integration/{geo_transform_info_spec.rb → gdal/geo_transform_info_spec.rb} +1 -14
- data/spec/integration/{raster_attribute_table_info_spec.rb → gdal/raster_attribute_table_info_spec.rb} +1 -2
- data/spec/integration/{raster_band_info_spec.rb → gdal/raster_band_info_spec.rb} +30 -42
- data/spec/integration/ogr/layer_spec.rb +97 -0
- data/spec/spec_helper.rb +94 -5
- data/spec/support/integration_help.rb +1 -0
- data/spec/support/shared_contexts.rb +26 -0
- data/spec/support/shared_examples/{major_object_examples.rb → gdal/major_object_examples.rb} +5 -5
- data/spec/support/shared_examples/ogr/a_25D_geometry.rb +7 -0
- data/spec/support/shared_examples/ogr/a_container_geometry.rb +47 -0
- data/spec/support/shared_examples/ogr/a_geometry.rb +404 -0
- data/spec/support/shared_examples/ogr/a_line_string.rb +16 -0
- data/spec/support/test_style_table.txt +3 -0
- data/spec/unit/ext/error_symbols_spec.rb +41 -53
- data/spec/unit/ext/numeric_as_data_type_spec.rb +113 -0
- data/spec/unit/ffi/gdal_spec.rb +70 -0
- data/spec/unit/gdal/color_entry_spec.rb +5 -0
- data/spec/unit/gdal/color_interpretation_spec.rb +5 -0
- data/spec/unit/gdal/{color_table_extensions_spec.rb → color_table_mixins/extensions_spec.rb} +3 -3
- data/spec/unit/gdal/color_table_spec.rb +14 -16
- data/spec/unit/gdal/data_type_spec.rb +10 -17
- data/spec/unit/gdal/dataset_spec.rb +4 -7
- data/spec/unit/gdal/driver_mixins/extensions_spec.rb +22 -0
- data/spec/unit/gdal/driver_spec.rb +49 -0
- data/spec/unit/gdal/environment_methods_spec.rb +6 -0
- data/spec/unit/gdal/geo_transform_spec.rb +276 -0
- data/spec/unit/gdal/grid_spec.rb +5 -0
- data/spec/unit/gdal/internal_helpers_spec.rb +112 -0
- data/spec/unit/gdal/major_object_spec.rb +6 -0
- data/spec/unit/gdal/options_spec.rb +5 -0
- data/spec/unit/gdal/raster_attribute_table_spec.rb +5 -0
- data/spec/unit/gdal/raster_band_classifier_spec.rb +134 -0
- data/spec/unit/gdal/raster_band_spec.rb +5 -0
- data/spec/unit/gdal/rpc_info_spec.rb +5 -0
- data/spec/unit/gdal/version_info_spec.rb +6 -0
- data/spec/unit/gdal/virtual_dataset_spec.rb +32 -0
- data/spec/unit/gdal/warp_operation_spec.rb +5 -0
- data/spec/unit/ogr/data_source_mixins/capability_methods_spec.rb +30 -0
- data/spec/unit/ogr/data_source_spec.rb +209 -0
- data/spec/unit/ogr/driver_mixins/capability_methods_spec.rb +18 -0
- data/spec/unit/ogr/driver_spec.rb +150 -0
- data/spec/unit/ogr/envelope_spec.rb +322 -0
- data/spec/unit/ogr/feature_definition_spec.rb +313 -0
- data/spec/unit/ogr/feature_spec.rb +379 -0
- data/spec/unit/ogr/field_definition_spec.rb +135 -0
- data/spec/unit/ogr/field_spec.rb +193 -0
- data/spec/unit/ogr/geometries/geometry_collection_spec.rb +186 -0
- data/spec/unit/ogr/geometries/line_string_spec.rb +105 -0
- data/spec/unit/ogr/{linear_ring_spec.rb → geometries/linear_ring_spec.rb} +10 -31
- data/spec/unit/ogr/geometries/multi_line_string_spec.rb +14 -0
- data/spec/unit/ogr/geometries/multi_point_spec.rb +14 -0
- data/spec/unit/ogr/geometries/multi_polygon_spec.rb +41 -0
- data/spec/unit/ogr/geometries/none_geometry_spec.rb +12 -0
- data/spec/unit/ogr/{point_spec.rb → geometries/point_spec.rb} +19 -25
- data/spec/unit/ogr/geometries/polygon_spec.rb +17 -0
- data/spec/unit/ogr/geometries/unknown_geometry_spec.rb +10 -0
- data/spec/unit/ogr/geometry_field_definition_spec.rb +87 -0
- data/spec/unit/ogr/geometry_spec.rb +542 -0
- data/spec/unit/ogr/internal_helpers_spec.rb +57 -0
- data/spec/unit/ogr/layer_mixins/capability_methods_spec.rb +88 -0
- data/spec/unit/ogr/layer_mixins/ogr_feature_methods_spec.rb +145 -0
- data/spec/unit/ogr/layer_mixins/ogr_field_methods_spec.rb +432 -0
- data/spec/unit/ogr/layer_mixins/ogr_layer_method_methods_spec.rb +20 -0
- data/spec/unit/ogr/layer_mixins/ogr_query_filter_methods_spec.rb +42 -0
- data/spec/unit/ogr/layer_mixins/ogr_sql_methods_spec.rb +12 -0
- data/spec/unit/ogr/layer_spec.rb +66 -67
- data/spec/unit/ogr/spatial_reference_mixins/coordinate_system_getter_setters_spec.rb +46 -0
- data/spec/unit/ogr/spatial_reference_mixins/exporters_spec.rb +139 -0
- data/spec/unit/ogr/spatial_reference_mixins/importers_spec.rb +38 -0
- data/spec/unit/ogr/spatial_reference_mixins/morphers_spec.rb +36 -0
- data/spec/unit/ogr/spatial_reference_mixins/parameter_getter_setters_spec.rb +102 -0
- data/spec/unit/ogr/spatial_reference_mixins/type_checks_spec.rb +157 -0
- data/spec/unit/ogr/spatial_reference_spec.rb +42 -0
- data/spec/unit/ogr/style_table_spec.rb +132 -0
- data/spec/unit/ogr/style_tool_spec.rb +157 -0
- data/spec/unit/version_info_spec.rb +1 -1
- metadata +285 -75
- data/lib/ffi/cpl/conv_h.rb +0 -143
- data/lib/ffi/cpl/error_h.rb +0 -63
- data/lib/ffi/cpl/minixml_h.rb +0 -14
- data/lib/ffi/cpl/string_h.rb +0 -81
- data/lib/ffi/cpl/vsi_h.rb +0 -112
- data/lib/ffi/gdal/alg_h.rb +0 -127
- data/lib/ffi/gdal/grid_h.rb +0 -51
- data/lib/ffi/gdal/warper_h.rb +0 -48
- data/lib/ffi/ogr/api_h.rb +0 -553
- data/lib/ffi/ogr/core_h.rb +0 -148
- data/lib/ffi/ogr/featurestyle_h.rb +0 -22
- data/lib/ffi/ogr/geocoding_h.rb +0 -21
- data/lib/ffi/ogr/ogr_field.rb +0 -50
- data/lib/ffi/ogr/ogr_style_param.rb +0 -12
- data/lib/ffi/ogr/srs_api_h.rb +0 -325
- data/lib/gdal/color_entry_extensions.rb +0 -30
- data/lib/gdal/color_table_extensions.rb +0 -47
- data/lib/gdal/dataset_extensions.rb +0 -496
- data/lib/gdal/driver_extensions.rb +0 -56
- data/lib/gdal/geo_transform_extensions.rb +0 -90
- data/lib/gdal/raster_attribute_table_extensions.rb +0 -40
- data/lib/gdal/raster_band_extensions.rb +0 -198
- data/lib/ogr/geometry_types/collection.rb +0 -45
- data/lib/ogr/layer_extensions.rb +0 -55
- data/lib/ogr/line_string.rb +0 -7
- data/lib/ogr/linear_ring.rb +0 -6
- data/lib/ogr/multi_line_string.rb +0 -9
- data/lib/ogr/multi_point.rb +0 -7
- data/lib/ogr/multi_polygon.rb +0 -14
- data/lib/ogr/point.rb +0 -89
- data/lib/ogr/polygon.rb +0 -9
@@ -2,12 +2,11 @@ require 'json'
|
|
2
2
|
|
3
3
|
module OGR
|
4
4
|
module GeometryExtensions
|
5
|
-
|
6
5
|
# @return [Hash]
|
7
|
-
def as_json
|
6
|
+
def as_json(options = nil)
|
8
7
|
json = {
|
9
8
|
coordinate_dimension: coordinate_dimension,
|
10
|
-
|
9
|
+
geometry_count: geometry_count,
|
11
10
|
dimension: dimension,
|
12
11
|
is_empty: empty?,
|
13
12
|
is_ring: ring?,
|
@@ -15,7 +14,7 @@ module OGR
|
|
15
14
|
is_valid: valid?,
|
16
15
|
name: name,
|
17
16
|
point_count: point_count,
|
18
|
-
spatial_reference: spatial_reference.as_json,
|
17
|
+
spatial_reference: spatial_reference.nil? ? nil : spatial_reference.as_json(options),
|
19
18
|
type: type_to_name,
|
20
19
|
wkb_size: wkb_size
|
21
20
|
}
|
@@ -28,8 +27,8 @@ module OGR
|
|
28
27
|
end
|
29
28
|
|
30
29
|
# @return [String]
|
31
|
-
def to_json
|
32
|
-
as_json.to_json
|
30
|
+
def to_json(options = nil)
|
31
|
+
as_json(options).to_json
|
33
32
|
end
|
34
33
|
|
35
34
|
def collection?
|
@@ -42,13 +41,13 @@ module OGR
|
|
42
41
|
data_source = driver.create_data_source(file_name)
|
43
42
|
log "Creating layer #{layer_name}, type: #{type}"
|
44
43
|
layer = data_source.create_layer(layer_name, geometry_type: type,
|
45
|
-
|
44
|
+
spatial_reference: spatial_reference)
|
46
45
|
|
47
|
-
# field =
|
46
|
+
# field = FieldDefinition.new('Name', :OFTString)
|
48
47
|
# field.width = 32
|
49
48
|
|
50
49
|
unless layer
|
51
|
-
|
50
|
+
fail OGR::InvalidLayer, "Unable to create layer '#{layer_name}'."
|
52
51
|
end
|
53
52
|
|
54
53
|
feature = layer.create_feature(layer_name)
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require_relative 'geometry_field_definition_extensions'
|
2
|
+
|
3
|
+
module OGR
|
4
|
+
class GeometryFieldDefinition
|
5
|
+
include GeometryFieldDefinitionExtensions
|
6
|
+
|
7
|
+
# @return [FFI::Pointer]
|
8
|
+
attr_reader :c_pointer
|
9
|
+
|
10
|
+
# @param value [Boolean]
|
11
|
+
attr_writer :read_only
|
12
|
+
|
13
|
+
# @param name_or_pointer [String, FFI::Pointer]
|
14
|
+
# @param type [FFI::OGR::API::WKBGeometryType]
|
15
|
+
def initialize(name_or_pointer, type = :wkbUnknown)
|
16
|
+
@c_pointer =
|
17
|
+
if name_or_pointer.is_a? String
|
18
|
+
FFI::OGR::API.OGR_GFld_Create(name_or_pointer, type)
|
19
|
+
else
|
20
|
+
name_or_pointer
|
21
|
+
end
|
22
|
+
|
23
|
+
unless @c_pointer.is_a?(FFI::Pointer) && !@c_pointer.null?
|
24
|
+
fail OGR::InvalidGeometryFieldDefinition,
|
25
|
+
"Unable to create #{self.class.name} from #{name_or_pointer}"
|
26
|
+
end
|
27
|
+
|
28
|
+
@read_only = false
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Boolean]
|
32
|
+
def read_only?
|
33
|
+
@read_only || false
|
34
|
+
end
|
35
|
+
|
36
|
+
def destroy!
|
37
|
+
FFI::OGR::API.OGR_GFld_Destroy(@c_pointer)
|
38
|
+
@c_pointer = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [String]
|
42
|
+
def name
|
43
|
+
FFI::OGR::API.OGR_GFld_GetNameRef(@c_pointer)
|
44
|
+
end
|
45
|
+
|
46
|
+
# @param new_name [String]
|
47
|
+
def name=(new_name)
|
48
|
+
fail OGR::ReadOnlyObject if @read_only
|
49
|
+
|
50
|
+
FFI::OGR::API.OGR_GFld_SetName(@c_pointer, new_name)
|
51
|
+
end
|
52
|
+
|
53
|
+
# @return [FFI::OGR::API::WKBGeometryType]
|
54
|
+
def type
|
55
|
+
FFI::OGR::API.OGR_GFld_GetType(@c_pointer)
|
56
|
+
end
|
57
|
+
|
58
|
+
# @param new_type [FFI::OGR::API::WKBGeometryType]
|
59
|
+
def type=(new_type)
|
60
|
+
fail OGR::ReadOnlyObject if @read_only
|
61
|
+
|
62
|
+
FFI::OGR::API.OGR_GFld_SetType(@c_pointer, new_type)
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return [OGR::SpatialReference]
|
66
|
+
def spatial_reference
|
67
|
+
spatial_ref_ptr = FFI::OGR::API.OGR_GFld_GetSpatialRef(@c_pointer)
|
68
|
+
|
69
|
+
if spatial_ref_ptr.nil? || spatial_ref_ptr.null?
|
70
|
+
nil
|
71
|
+
else
|
72
|
+
OGR::SpatialReference.new(spatial_ref_ptr)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# @param new_spatial_reference [OGR::SpatialReference, FFI::Pointer]
|
77
|
+
def spatial_reference=(new_spatial_reference)
|
78
|
+
fail OGR::ReadOnlyObject if @read_only
|
79
|
+
|
80
|
+
spatial_ref_ptr = GDAL._pointer(OGR::SpatialReference, new_spatial_reference)
|
81
|
+
|
82
|
+
FFI::OGR::API.OGR_GFld_SetSpatialRef(
|
83
|
+
@c_pointer,
|
84
|
+
spatial_ref_ptr)
|
85
|
+
end
|
86
|
+
|
87
|
+
# @return [Boolean]
|
88
|
+
def ignored?
|
89
|
+
FFI::OGR::API.OGR_GFld_IsIgnored(@c_pointer)
|
90
|
+
end
|
91
|
+
|
92
|
+
# @param value [Boolean]
|
93
|
+
def ignore=(value)
|
94
|
+
fail OGR::ReadOnlyObject if @read_only
|
95
|
+
|
96
|
+
FFI::OGR::API.OGR_GFld_SetIgnored(@c_pointer, value)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module OGR
|
4
|
+
module GeometryFieldDefinitionExtensions
|
5
|
+
# @return [Hash]
|
6
|
+
def as_json(options = nil)
|
7
|
+
{
|
8
|
+
is_ignored: ignored?,
|
9
|
+
name: name,
|
10
|
+
spatial_reference: spatial_reference ? spatial_reference.as_json(options) : nil,
|
11
|
+
type: type
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_json(options = nil)
|
16
|
+
as_json(options).to_json
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module OGR
|
2
|
+
module GeometryTypes
|
3
|
+
module Container
|
4
|
+
def collection?
|
5
|
+
true
|
6
|
+
end
|
7
|
+
|
8
|
+
# If this geometry is a container, this adds +geometry+ to the container.
|
9
|
+
# If this is a Polygon, +geometry+ must be a LinearRing. If the Polygon is
|
10
|
+
# empty, the first added +geometry+ will be the exterior ring. Subsequent
|
11
|
+
# geometries added will be interior rings.
|
12
|
+
#
|
13
|
+
# @param sub_geometry [OGR::Geometry, FFI::Pointer]
|
14
|
+
# @return +true+ if successful, otherwise raises an OGR exception.
|
15
|
+
def add_geometry(sub_geometry)
|
16
|
+
sub_geometry_ptr = GDAL._pointer(OGR::Geometry, sub_geometry)
|
17
|
+
ogr_err = FFI::OGR::API.OGR_G_AddGeometry(@c_pointer, sub_geometry_ptr)
|
18
|
+
|
19
|
+
ogr_err.handle_result "Unable to add geometry: #{sub_geometry}"
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param sub_geometry [OGR::Geometry, FFI::Pointer]
|
23
|
+
# @return +true+ if successful, otherwise raises an OGR exception.
|
24
|
+
def add_directly(sub_geometry)
|
25
|
+
sub_geometry_ptr = GDAL._pointer(OGR::Geometry, sub_geometry)
|
26
|
+
ogr_err = FFI::OGR::API.OGR_G_AddGeometryDirectly(@c_pointer, sub_geometry_ptr)
|
27
|
+
|
28
|
+
ogr_err.handle_result
|
29
|
+
end
|
30
|
+
|
31
|
+
# @param geometry_index [Fixnum]
|
32
|
+
# @param delete [Boolean]
|
33
|
+
# @return +true+ if successful, otherwise raises an OGR exception.
|
34
|
+
def remove_geometry(geometry_index, delete = true)
|
35
|
+
ogr_err = FFI::OGR::API.OGR_G_RemoveGeometry(@c_pointer, geometry_index, delete)
|
36
|
+
|
37
|
+
ogr_err.handle_result
|
38
|
+
end
|
39
|
+
|
40
|
+
# If this geometry is a container, this fetches the geometry at the
|
41
|
+
# sub_geometry_index.
|
42
|
+
#
|
43
|
+
# @param sub_geometry_index [Fixnum]
|
44
|
+
# @return [OGR::Geometry]
|
45
|
+
def geometry_at(sub_geometry_index)
|
46
|
+
build_geometry do |ptr|
|
47
|
+
FFI::OGR::API.OGR_G_GetGeometryRef(ptr, sub_geometry_index)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Build a ring from a bunch of arcs. The collection must be
|
52
|
+
# a MultiLineString or GeometryCollection.
|
53
|
+
#
|
54
|
+
# @param tolerance [Float]
|
55
|
+
# @param auto_close [Boolean]
|
56
|
+
# @return [OGR::Geometry]
|
57
|
+
def polygon_from_edges(tolerance, auto_close: false)
|
58
|
+
best_effort = false
|
59
|
+
ogrerr_ptr = FFI::MemoryPointer.new(:pointer)
|
60
|
+
|
61
|
+
new_geometry_ptr = FFI::OGR::API.OGRBuildPolygonFromEdges(@c_pointer,
|
62
|
+
best_effort,
|
63
|
+
auto_close,
|
64
|
+
tolerance,
|
65
|
+
ogrerr_ptr)
|
66
|
+
|
67
|
+
ogrerr_int = ogrerr_ptr.read_int
|
68
|
+
ogrerr = FFI::OGR::Core::Err[ogrerr_int]
|
69
|
+
ogrerr.handle_result "Couldn't create polygon"
|
70
|
+
|
71
|
+
OGR::Geometry.factory(new_geometry_ptr)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -1,20 +1,19 @@
|
|
1
1
|
module OGR
|
2
2
|
module GeometryTypes
|
3
3
|
module Curve
|
4
|
-
|
5
4
|
# @return [Float]
|
6
5
|
def x(point_number)
|
7
|
-
FFI::
|
6
|
+
FFI::OGR::API.OGR_G_GetX(@c_pointer, point_number)
|
8
7
|
end
|
9
8
|
|
10
9
|
# @return [Float]
|
11
10
|
def y(point_number)
|
12
|
-
FFI::
|
11
|
+
FFI::OGR::API.OGR_G_GetY(@c_pointer, point_number)
|
13
12
|
end
|
14
13
|
|
15
14
|
# @return [Float]
|
16
15
|
def z(point_number)
|
17
|
-
FFI::
|
16
|
+
FFI::OGR::API.OGR_G_GetZ(@c_pointer, point_number)
|
18
17
|
end
|
19
18
|
|
20
19
|
# @return [Array<Float, Float, Float>] [x, y] if 2d or [x, y, z] if 3d.
|
@@ -23,7 +22,7 @@ module OGR
|
|
23
22
|
y_ptr = FFI::MemoryPointer.new(:double)
|
24
23
|
z_ptr = FFI::MemoryPointer.new(:double)
|
25
24
|
|
26
|
-
FFI::
|
25
|
+
FFI::OGR::API.OGR_G_GetPoint(@c_pointer, number, x_ptr, y_ptr, z_ptr)
|
27
26
|
|
28
27
|
if coordinate_dimension == 2
|
29
28
|
[x_ptr.read_double, y_ptr.read_double]
|
@@ -37,16 +36,16 @@ module OGR
|
|
37
36
|
# @param x [Float]
|
38
37
|
# @param y [Float]
|
39
38
|
# @param z [Float]
|
40
|
-
def add_point(x, y, z=0)
|
39
|
+
def add_point(x, y, z = 0)
|
41
40
|
if coordinate_dimension == 3
|
42
|
-
FFI::
|
41
|
+
FFI::OGR::API.OGR_G_AddPoint(@c_pointer, x, y, z)
|
43
42
|
else
|
44
|
-
FFI::
|
43
|
+
FFI::OGR::API.OGR_G_AddPoint_2D(@c_pointer, x, y)
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
48
|
-
def set_point(index, x, y, z=0)
|
49
|
-
FFI::
|
47
|
+
def set_point(index, x, y, z = 0)
|
48
|
+
FFI::OGR::API.OGR_G_SetPoint(@c_pointer, index, x, y, z)
|
50
49
|
end
|
51
50
|
|
52
51
|
# @return [Array<Array>] An array of (x, y) or (x, y, z) points.
|
@@ -61,21 +60,19 @@ module OGR
|
|
61
60
|
y_buffer = FFI::MemoryPointer.new(:buffer_out, buffer_size)
|
62
61
|
|
63
62
|
z_buffer = if coordinate_dimension == 3
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
0.upto(num_points - 1).map do |i|
|
63
|
+
z_size = FFI::Type::DOUBLE.size * point_count
|
64
|
+
FFI::MemoryPointer.new(:buffer_out, z_size)
|
65
|
+
end
|
66
|
+
|
67
|
+
num_points = FFI::OGR::API.OGR_G_GetPoints(@c_pointer,
|
68
|
+
x_buffer,
|
69
|
+
x_stride,
|
70
|
+
y_buffer,
|
71
|
+
y_stride,
|
72
|
+
z_buffer,
|
73
|
+
z_stride)
|
74
|
+
|
75
|
+
num_points.times.map do |i|
|
79
76
|
point(i)
|
80
77
|
end
|
81
78
|
end
|
@@ -87,13 +84,13 @@ module OGR
|
|
87
84
|
points.map do |x_and_y|
|
88
85
|
result = geo_transform.world_to_pixel(*x_and_y)
|
89
86
|
|
90
|
-
[result[:
|
87
|
+
[result[:pixel].to_i.abs, result[:line].to_i.abs]
|
91
88
|
end
|
92
89
|
end
|
93
90
|
|
94
91
|
# @param new_count [Fixnum]
|
95
92
|
def point_count=(new_count)
|
96
|
-
FFI::
|
93
|
+
FFI::OGR::API.OGR_G_SetPointCount(@c_pointer, new_count)
|
97
94
|
end
|
98
95
|
|
99
96
|
# Computes the length for this geometry. Computes area for Curve or
|
@@ -101,7 +98,7 @@ module OGR
|
|
101
98
|
#
|
102
99
|
# @return [Float] 0.0 for unsupported geometry types.
|
103
100
|
def length
|
104
|
-
FFI::
|
101
|
+
FFI::OGR::API.OGR_G_Length(@c_pointer)
|
105
102
|
end
|
106
103
|
|
107
104
|
def start_point
|
@@ -1,19 +1,28 @@
|
|
1
|
+
require_relative '../../ffi/ogr/api'
|
2
|
+
|
1
3
|
module OGR
|
2
4
|
module GeometryTypes
|
3
5
|
module Surface
|
4
|
-
|
5
|
-
#
|
6
|
+
# Computes area for a LinearRing, Polygon, or MultiPolygon. The area of
|
7
|
+
# the feature is in square units of the spatial reference system in use.
|
6
8
|
#
|
7
9
|
# @return [Float] 0.0 for unsupported geometry types.
|
8
10
|
def area
|
9
|
-
FFI::
|
11
|
+
FFI::OGR::API.OGR_G_Area(@c_pointer)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns the units used by the associated OGR::SpatialReference.
|
15
|
+
#
|
16
|
+
# @return [Hash]
|
17
|
+
def area_units
|
18
|
+
spatial_reference ? spatial_reference.linear_units : nil
|
10
19
|
end
|
11
20
|
|
12
21
|
# Returns a point that's guaranteed to lie on the surface.
|
13
22
|
#
|
14
23
|
# @return [OGR::Point]
|
15
24
|
def point_on_surface
|
16
|
-
build_geometry { |ptr| FFI::
|
25
|
+
build_geometry { |ptr| FFI::OGR::API.OGR_G_PointOnSurface(ptr) }
|
17
26
|
end
|
18
27
|
end
|
19
28
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module OGR
|
4
|
+
module InternalHelpers
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
# Makes the interface consistent with the access flags for GDAL.
|
11
|
+
#
|
12
|
+
# @param flag [String] 'w' for writing, 'r' for reading.
|
13
|
+
def _boolean_access_flag(flag)
|
14
|
+
case flag
|
15
|
+
when 'w' then true
|
16
|
+
when 'r' then false
|
17
|
+
else fail "Invalid access_flag '#{flag}'. Use 'r' or 'w'."
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# OGR's time zone rules:
|
22
|
+
# * 0 = unknown
|
23
|
+
# * 1 = local time
|
24
|
+
# * 100 = GMT
|
25
|
+
#
|
26
|
+
# This converts the OGR integer into something usable by Ruby's DateTime.
|
27
|
+
#
|
28
|
+
# @param time_zone [Fixnum]
|
29
|
+
def _format_time_zone_for_ruby(time_zone)
|
30
|
+
case time_zone
|
31
|
+
when 0 then nil
|
32
|
+
when 1 then (Time.now.getlocal.utc_offset / 3600).to_s
|
33
|
+
when 100 then '+0'
|
34
|
+
else fail "Unable to process time zone: #{time_zone}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# OGR's time zone rules:
|
39
|
+
# * 0 = unknown
|
40
|
+
# * 1 = local time
|
41
|
+
# * 100 = GMT
|
42
|
+
#
|
43
|
+
# This converts Ruby's DateTime time zone info into OGR's integer.
|
44
|
+
#
|
45
|
+
# @param time_zone [String]
|
46
|
+
def _format_time_zone_for_ogr(time_zone)
|
47
|
+
if time_zone =~ /GMT/
|
48
|
+
100
|
49
|
+
elsif time_zone
|
50
|
+
1
|
51
|
+
else
|
52
|
+
0
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|