ffi-ogr 0.0.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +72 -0
- data/bin/ogr_console +6 -0
- data/lib/ffi-ogr/data_source.rb +55 -0
- data/lib/ffi-ogr/feature.rb +79 -0
- data/lib/ffi-ogr/generic_reader.rb +9 -0
- data/lib/ffi-ogr/generic_writer.rb +9 -0
- data/lib/ffi-ogr/geo_json.rb +5 -0
- data/lib/ffi-ogr/geo_json_reader.rb +8 -0
- data/lib/ffi-ogr/geo_json_writer.rb +8 -0
- data/lib/ffi-ogr/geometry.rb +84 -0
- data/lib/ffi-ogr/geometry_collection.rb +15 -0
- data/lib/ffi-ogr/geometry_collection_25d.rb +15 -0
- data/lib/ffi-ogr/layer.rb +48 -0
- data/lib/ffi-ogr/line_string.rb +13 -0
- data/lib/ffi-ogr/line_string_25d.rb +13 -0
- data/lib/ffi-ogr/linear_ring.rb +15 -0
- data/lib/ffi-ogr/multi_line_string.rb +14 -0
- data/lib/ffi-ogr/multi_line_string_25d.rb +14 -0
- data/lib/ffi-ogr/multi_point.rb +14 -0
- data/lib/ffi-ogr/multi_point_25d.rb +14 -0
- data/lib/ffi-ogr/multi_polygon.rb +14 -0
- data/lib/ffi-ogr/multi_polygon_25d.rb +14 -0
- data/lib/ffi-ogr/point.rb +24 -0
- data/lib/ffi-ogr/point_25d.rb +9 -0
- data/lib/ffi-ogr/polygon.rb +14 -0
- data/lib/ffi-ogr/polygon_25d.rb +14 -0
- data/lib/ffi-ogr/reader.rb +33 -0
- data/lib/ffi-ogr/shapefile.rb +5 -0
- data/lib/ffi-ogr/shp_reader.rb +8 -0
- data/lib/ffi-ogr/shp_writer.rb +8 -0
- data/lib/ffi-ogr/tools.rb +65 -0
- data/lib/ffi-ogr/version.rb +3 -0
- data/lib/ffi-ogr/writer.rb +42 -0
- data/lib/ffi-ogr.rb +291 -0
- metadata +145 -0
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
ffi-ogr
|
2
|
+
... for convenient access to OGR functionality from Ruby
|
3
|
+
|
4
|
+
To run: `bin/ogr_console`
|
5
|
+
|
6
|
+
To read a shapefile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
|
10
|
+
shp = OGR::ShpReader.new.read './spec/data/ne_110m_coastline/ne_110m_coastline.shp'
|
11
|
+
# => #<OGR::DataSource:0x007fba4d19c328 @ds=#<FFI::AutoPointer address=0x007fba4c4cdc50>>
|
12
|
+
|
13
|
+
shp.to_geojson
|
14
|
+
# => geojson feature collection from Shapefile
|
15
|
+
|
16
|
+
shp.to_geojson true
|
17
|
+
# => "pretty print" geojson feature collection from Shapefile
|
18
|
+
```
|
19
|
+
|
20
|
+
A reader may also be inferred by file extension (currently works for shp and json/geojson):
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
|
24
|
+
shp = OGR::Reader.from_file_type './spec/data/ne_110m_coastline/ne_110m_coastline.shp'
|
25
|
+
|
26
|
+
```
|
27
|
+
|
28
|
+
To create a shapefile:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
|
32
|
+
writer = OGR::ShpWriter.new
|
33
|
+
writer.set_output '~/Documents/shapefiles/my_new.shp'
|
34
|
+
|
35
|
+
shp = writer.ds
|
36
|
+
|
37
|
+
# add layer to shp : add_layer(name, geometry_type, spatial_reference)
|
38
|
+
# currently does not handle spatial reference, will automatically be nil
|
39
|
+
layer = shp.add_layer 'first_layer', :point
|
40
|
+
|
41
|
+
# add field to layer : add_field(name, field_type, width) NOTE: width defaults to 32
|
42
|
+
layer.add_field 'name', :string
|
43
|
+
|
44
|
+
# create feature on layer
|
45
|
+
feature = layer.create_feature
|
46
|
+
|
47
|
+
# add field value to feature : set_field_value(field_name, field_value, field_type) NOTE: type can be inferred
|
48
|
+
feature.set_field_value 'name', 'my_feature'
|
49
|
+
|
50
|
+
# create point
|
51
|
+
point = OGR::Point.create [-104.789322, 38.992961]
|
52
|
+
|
53
|
+
# add point to first_feature
|
54
|
+
feature.add_geometry point
|
55
|
+
|
56
|
+
# add feature to first_layer
|
57
|
+
layer.add_feature feature
|
58
|
+
|
59
|
+
# sync to disk
|
60
|
+
layer.sync
|
61
|
+
|
62
|
+
```
|
63
|
+
|
64
|
+
A writer may also be inferred by file extension (currently works for shp and json/geojson):
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
|
68
|
+
writer = OGR::Writer.from_file_type '~/Documents/shapefiles/my_new.shp'
|
69
|
+
|
70
|
+
```
|
71
|
+
|
72
|
+
Tested on: MRI 1.9.3-p392 and JRuby 1.7.3
|
data/bin/ogr_console
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module OGR
|
2
|
+
class DataSource
|
3
|
+
include FFIOGR
|
4
|
+
|
5
|
+
attr_accessor :ds
|
6
|
+
|
7
|
+
def initialize(ptr=nil, auto_free=true)
|
8
|
+
@ds = FFI::AutoPointer.new(ptr, self.class.method(:release))
|
9
|
+
@ds.autorelease = auto_free
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.release(ptr)
|
13
|
+
FFIOGR.OGR_DS_Destroy(ptr)
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_layer(name, geometry_type, spatial_ref=nil, options={})
|
17
|
+
# need to add spatial reference mapping
|
18
|
+
# need to add options as StringList ...
|
19
|
+
layer = FFIOGR.OGR_DS_CreateLayer(@ds, name, spatial_ref, geometry_type.to_sym, nil)
|
20
|
+
OGR::Tools.cast_layer(layer)
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_layers
|
24
|
+
layers = []
|
25
|
+
|
26
|
+
num_layers = OGR_DS_GetLayerCount(@ds)
|
27
|
+
|
28
|
+
for i in (0...num_layers) do
|
29
|
+
layers << OGR::Tools.cast_layer(OGR_DS_GetLayer(@ds, i))
|
30
|
+
end
|
31
|
+
|
32
|
+
layers
|
33
|
+
end
|
34
|
+
alias_method :layers, :get_layers
|
35
|
+
|
36
|
+
def get_features
|
37
|
+
layers.map {|l| l.features}.first
|
38
|
+
end
|
39
|
+
alias_method :features, :get_features
|
40
|
+
|
41
|
+
def get_geometries
|
42
|
+
features.map {|f| OGR::Tools.cast_geometry(f.geometry)}
|
43
|
+
end
|
44
|
+
alias_method :geometries, :get_geometries
|
45
|
+
|
46
|
+
def get_fields
|
47
|
+
features.map {|f| f.fields}
|
48
|
+
end
|
49
|
+
alias_method :fields, :get_fields
|
50
|
+
|
51
|
+
def to_geojson(pretty=false)
|
52
|
+
MultiJson.dump({type: 'FeatureCollection', features: features.map {|f| f.to_geojson}}, pretty: pretty)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module OGR
|
2
|
+
class Feature
|
3
|
+
attr_accessor :ptr
|
4
|
+
|
5
|
+
def initialize(ptr, auto_free=true)
|
6
|
+
@ptr = FFI::AutoPointer.new(ptr, self.class.method(:release))
|
7
|
+
@ptr.autorelease = auto_free
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.release(ptr)
|
11
|
+
FFIOGR.OGR_F_Destroy(ptr)
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_field_value(name, value, field_type=nil)
|
15
|
+
field_index = FFIOGR.OGR_F_GetFieldIndex(@ptr, name)
|
16
|
+
|
17
|
+
unless field_type.nil?
|
18
|
+
field_type = field_type.to_sym
|
19
|
+
else
|
20
|
+
field_definition = FFIOGR.OGR_F_GetFieldDefnRef(@ptr, field_index)
|
21
|
+
field_type = FFIOGR.OGR_Fld_GetType(field_definition)
|
22
|
+
end
|
23
|
+
|
24
|
+
case field_type
|
25
|
+
when :integer
|
26
|
+
FFIOGR.OGR_F_SetFieldInteger(@ptr, field_index, Integer(value))
|
27
|
+
when :real
|
28
|
+
FFIOGR.OGR_F_SetFieldDouble(@ptr, field_index, Float(value))
|
29
|
+
when :string
|
30
|
+
FFIOGR.OGR_F_SetFieldString(@ptr, field_index, String(value))
|
31
|
+
when :binary
|
32
|
+
FFIOGR.OGR_F_SetFieldBinary(@ptr, field_index, to_binary(value))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_geometry(geometry)
|
37
|
+
FFIOGR.OGR_F_SetGeometry(@ptr, geometry.ptr)
|
38
|
+
#FFIOGR.OGR_F_SetGeometryDirectly(@ptr, geometry.ptr)
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_geometry
|
42
|
+
FFIOGR.OGR_F_GetGeometryRef(@ptr)
|
43
|
+
end
|
44
|
+
alias_method :geometry, :get_geometry
|
45
|
+
|
46
|
+
def get_field_count
|
47
|
+
FFIOGR.OGR_F_GetFieldCount(@ptr)
|
48
|
+
end
|
49
|
+
alias_method :field_count, :get_field_count
|
50
|
+
|
51
|
+
def get_fields
|
52
|
+
fields = {}
|
53
|
+
|
54
|
+
for i in (0...field_count)
|
55
|
+
fd = FFIOGR.OGR_F_GetFieldDefnRef(@ptr, i)
|
56
|
+
field_name = FFIOGR.OGR_Fld_GetNameRef(fd)
|
57
|
+
field_type = FFIOGR.OGR_Fld_GetType(fd)
|
58
|
+
|
59
|
+
case field_type
|
60
|
+
when :integer
|
61
|
+
field_value = FFIOGR.OGR_F_GetFieldAsInteger(@ptr, i)
|
62
|
+
when :real
|
63
|
+
field_value = FFIOGR.OGR_F_GetFieldAsDouble(@ptr, i)
|
64
|
+
else
|
65
|
+
field_value = FFIOGR.OGR_F_GetFieldAsString(@ptr, i)
|
66
|
+
end
|
67
|
+
|
68
|
+
fields[field_name] = field_value
|
69
|
+
end
|
70
|
+
|
71
|
+
fields
|
72
|
+
end
|
73
|
+
alias_method :fields, :get_fields
|
74
|
+
|
75
|
+
def to_geojson
|
76
|
+
{type: 'Feature', geometry: OGR::Tools.cast_geometry(geometry).to_geojson, properties: fields}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module OGR
|
2
|
+
class Geometry
|
3
|
+
attr_reader :ptr
|
4
|
+
|
5
|
+
def initialize(ptr, auto_free=true)
|
6
|
+
@ptr = FFI::AutoPointer.new(ptr, self.class.method(:release))
|
7
|
+
#@ptr.autorelease = auto_free
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.release(ptr);end
|
11
|
+
|
12
|
+
def self.create_empty(geometry_type)
|
13
|
+
OGR::Tools.cast_geometry(FFIOGR.OGR_G_CreateGeometry(geometry_type))
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_geometry(geometry)
|
17
|
+
FFIOGR.OGR_G_AddGeometry(@ptr, geometry.ptr)
|
18
|
+
#FFIOGR.OGR_G_AddGeometryDirectly(@ptr, geometry.ptr)
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_point(coords)
|
22
|
+
raise RuntimeError.new("Invalid coordinate(s) specified") unless coords.size >= 2
|
23
|
+
x = Float(coords[0])
|
24
|
+
y = Float(coords[1])
|
25
|
+
z = Float(coords[2]) if coords.size >= 3
|
26
|
+
|
27
|
+
unless z
|
28
|
+
FFIOGR.OGR_G_AddPoint_2D(@ptr, x, y)
|
29
|
+
else
|
30
|
+
FFIOGR.OGR_G_AddPoint(@ptr, x, y, z)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def set_point(coords, idx)
|
35
|
+
raise RuntimeError.new("Invalid coordinate(s) specified") unless coords.size >= 2
|
36
|
+
x = Float(coords[0])
|
37
|
+
y = Float(coords[1])
|
38
|
+
z = Float(coords[2]) if coords.size >= 3
|
39
|
+
|
40
|
+
unless z
|
41
|
+
FFIOGR.OGR_G_SetPoint_2D(@ptr, idx, x, y)
|
42
|
+
else
|
43
|
+
FFIOGR.OGR_G_SetPoint(@ptr, idx, x, y, z)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def flatten
|
48
|
+
FFIOGR.OGR_G_FlattenTo2D(@ptr)
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_geometry_type
|
52
|
+
FFIOGR.OGR_G_GetGeometryType(@ptr)
|
53
|
+
end
|
54
|
+
alias_method :geometry_type, :get_geometry_type
|
55
|
+
|
56
|
+
def get_length
|
57
|
+
FFIOGR.OGR_G_Length(@ptr)
|
58
|
+
end
|
59
|
+
alias_method :length, :get_length
|
60
|
+
|
61
|
+
def get_area
|
62
|
+
FFIOGR.OGR_G_Area(@ptr)
|
63
|
+
end
|
64
|
+
alias_method :area, :get_area
|
65
|
+
|
66
|
+
def get_boundary
|
67
|
+
FFIOGR.OGR_G_Boundary(@ptr)
|
68
|
+
end
|
69
|
+
alias_method :boundary, :get_boundary
|
70
|
+
|
71
|
+
def to_geojson
|
72
|
+
MultiJson.load(FFIOGR.OGR_G_ExportToJson(@ptr))
|
73
|
+
end
|
74
|
+
|
75
|
+
def to_kml(elevation=nil)
|
76
|
+
elevation = String(elevation) unless elevation.nil?
|
77
|
+
FFIOGR.OGR_G_ExportToKML(@ptr, elevation)
|
78
|
+
end
|
79
|
+
|
80
|
+
def to_gml
|
81
|
+
FFIOGR.OGR_G_ExportToGML(@ptr)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module OGR
|
2
|
+
class GeometryCollection < Geometry
|
3
|
+
def self.create(geometries)
|
4
|
+
geometry_collection = OGR::Tools.cast_geometry(FFIOGR.OGR_G_CreateGeometry(:geometry_collection))
|
5
|
+
|
6
|
+
if geometries.size > 0
|
7
|
+
geometries.each do |geometry|
|
8
|
+
geometry_collection.add_geometry(geometry)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
geometry_collection
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module OGR
|
2
|
+
class GeometryCollection25D < Geometry
|
3
|
+
def self.create(geometries)
|
4
|
+
geometry_collection = OGR::Tools.cast_geometry(FFIOGR.OGR_G_CreateGeometry(:geometry_collection_25d))
|
5
|
+
|
6
|
+
if geometries.size > 0
|
7
|
+
geometries.each do |geometry|
|
8
|
+
geometry_collection.add_geometry(geometry)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
geometry_collection
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module OGR
|
2
|
+
class Layer
|
3
|
+
attr_accessor :ptr, :name, :geometry_type
|
4
|
+
|
5
|
+
def initialize(ptr, auto_free=true)
|
6
|
+
@ptr = FFI::AutoPointer.new(ptr, self.class.method(:release))
|
7
|
+
@name = FFIOGR.OGR_L_GetName(@ptr)
|
8
|
+
@geometry_type = FFIOGR.OGR_L_GetGeomType(@ptr)
|
9
|
+
#@ptr.autorelease = auto_free
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.release(ptr);end
|
13
|
+
|
14
|
+
def sync
|
15
|
+
FFIOGR.OGR_L_SyncToDisk(@ptr)
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_field(name, field_type, field_width=32)
|
19
|
+
field = FFIOGR.OGR_Fld_Create(name, field_type.to_sym)
|
20
|
+
FFIOGR.OGR_Fld_SetWidth(field, field_width)
|
21
|
+
FFIOGR.OGR_L_CreateField(@ptr, field, 1)
|
22
|
+
FFIOGR.OGR_Fld_Destroy(field)
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_feature
|
26
|
+
feature = FFIOGR.OGR_F_Create(FFIOGR.OGR_L_GetLayerDefn(@ptr))
|
27
|
+
OGR::Tools.cast_feature(feature)
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_feature(feature)
|
31
|
+
FFIOGR.OGR_L_CreateFeature(@ptr, feature.ptr)
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_features
|
35
|
+
features = []
|
36
|
+
|
37
|
+
FFIOGR.OGR_L_ResetReading(@ptr)
|
38
|
+
num_features = FFIOGR.OGR_L_GetFeatureCount(@ptr, 0)
|
39
|
+
|
40
|
+
for i in (0...num_features) do
|
41
|
+
features << OGR::Tools.cast_feature(FFIOGR.OGR_L_GetNextFeature(@ptr))
|
42
|
+
end
|
43
|
+
|
44
|
+
features
|
45
|
+
end
|
46
|
+
alias_method :features, :get_features
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module OGR
|
2
|
+
class LinearRing < Geometry
|
3
|
+
def self.create(points)
|
4
|
+
points << points.first unless points.first == points.last
|
5
|
+
|
6
|
+
lr = OGR::Tools.cast_geometry(FFIOGR.OGR_G_CreateGeometry(:linear_ring))
|
7
|
+
|
8
|
+
points.each do |point|
|
9
|
+
lr.add_point(point)
|
10
|
+
end
|
11
|
+
|
12
|
+
lr
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module OGR
|
2
|
+
class MultiLineString < Geometry
|
3
|
+
def self.create(line_strings)
|
4
|
+
multi_line_string = OGR::Tools.cast_geometry(FFIOGR.OGR_G_CreateGeometry(:multi_line_string))
|
5
|
+
|
6
|
+
line_strings.each do |line_string|
|
7
|
+
ls = OGR::LineString.create(line_string)
|
8
|
+
multi_line_string.add_geometry(ls)
|
9
|
+
end
|
10
|
+
|
11
|
+
multi_line_string
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module OGR
|
2
|
+
class MultiLineString25D < Geometry
|
3
|
+
def self.create(line_strings)
|
4
|
+
multi_line_string = OGR::Tools.cast_geometry(FFIOGR.OGR_G_CreateGeometry(:multi_line_string_25d))
|
5
|
+
|
6
|
+
line_strings.each do |line_string|
|
7
|
+
ls = OGR::LineString.create(line_string)
|
8
|
+
multi_line_string.add_geometry(ls)
|
9
|
+
end
|
10
|
+
|
11
|
+
multi_line_string
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module OGR
|
2
|
+
class MultiPoint < Geometry
|
3
|
+
def self.create(points)
|
4
|
+
multi_point = OGR::Tools.cast_geometry(FFIOGR.OGR_G_CreateGeometry(:multi_point))
|
5
|
+
|
6
|
+
points.each do |point|
|
7
|
+
pt = OGR::Point.create(point)
|
8
|
+
multi_point.add_geometry(pt)
|
9
|
+
end
|
10
|
+
|
11
|
+
multi_point
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module OGR
|
2
|
+
class MultiPoint25D < Geometry
|
3
|
+
def self.create(points)
|
4
|
+
multi_point = OGR::Tools.cast_geometry(FFIOGR.OGR_G_CreateGeometry(:multi_point_25d))
|
5
|
+
|
6
|
+
points.each do |point|
|
7
|
+
pt = OGR::Point.create(point)
|
8
|
+
multi_point.add_geometry(pt)
|
9
|
+
end
|
10
|
+
|
11
|
+
multi_point
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module OGR
|
2
|
+
class MultiPolygon < Geometry
|
3
|
+
def self.create(polygons)
|
4
|
+
multi_polygon = OGR::Tools.cast_geometry(FFIOGR.OGR_G_CreateGeometry(:multi_polygon))
|
5
|
+
|
6
|
+
polygons.each do |polygon|
|
7
|
+
poly = OGR::Polygon.create(polygon)
|
8
|
+
multi_polygon.add_geometry(poly)
|
9
|
+
end
|
10
|
+
|
11
|
+
multi_polygon
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module OGR
|
2
|
+
class MultiPolygon25D < Geometry
|
3
|
+
def self.create(polygons)
|
4
|
+
multi_polygon = OGR::Tools.cast_geometry(FFIOGR.OGR_G_CreateGeometry(:multi_polygon_25d))
|
5
|
+
|
6
|
+
polygons.each do |polygon|
|
7
|
+
poly = OGR::Polygon.create(polygon)
|
8
|
+
multi_polygon.add_geometry(poly)
|
9
|
+
end
|
10
|
+
|
11
|
+
multi_polygon
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module OGR
|
2
|
+
class Point < Geometry
|
3
|
+
def self.create(coords)
|
4
|
+
point = OGR::Tools.cast_geometry(FFIOGR.OGR_G_CreateGeometry(:point))
|
5
|
+
point.add_point(coords)
|
6
|
+
point
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_x
|
10
|
+
FFIOGR.OGR_G_GetX(@ptr, 0)
|
11
|
+
end
|
12
|
+
alias_method :x, :get_x
|
13
|
+
|
14
|
+
def get_y
|
15
|
+
FFIOGR.OGR_G_GetY(@ptr, 0)
|
16
|
+
end
|
17
|
+
alias_method :y, :get_y
|
18
|
+
|
19
|
+
def get_z
|
20
|
+
FFIOGR.OGR_G_GetZ(@ptr, 0)
|
21
|
+
end
|
22
|
+
alias_method :z, :get_z
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module OGR
|
2
|
+
class Polygon < Geometry
|
3
|
+
def self.create(rings)
|
4
|
+
polygon = OGR::Tools.cast_geometry(FFIOGR.OGR_G_CreateGeometry(:polygon))
|
5
|
+
|
6
|
+
rings.each do |ring|
|
7
|
+
lr = LinearRing.create(ring)
|
8
|
+
polygon.add_geometry(lr)
|
9
|
+
end
|
10
|
+
|
11
|
+
polygon
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module OGR
|
2
|
+
class Polygon25D < Geometry
|
3
|
+
def self.create(rings)
|
4
|
+
polygon = OGR::Tools.cast_geometry(FFIOGR.OGR_G_CreateGeometry(:polygon_25d))
|
5
|
+
|
6
|
+
rings.each do |ring|
|
7
|
+
lr = LinearRing.create(ring)
|
8
|
+
polygon.add_geometry(lr)
|
9
|
+
end
|
10
|
+
|
11
|
+
polygon
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module OGR
|
2
|
+
class Reader
|
3
|
+
include OGR::FFIOGR
|
4
|
+
|
5
|
+
TF_MAP = {
|
6
|
+
true => 1,
|
7
|
+
false => 0,
|
8
|
+
1 => true,
|
9
|
+
0 => false
|
10
|
+
}
|
11
|
+
|
12
|
+
# Reader Class NOT to be used directly
|
13
|
+
# Use subclasses e.g. ShpReader
|
14
|
+
def initialize;end
|
15
|
+
|
16
|
+
def self.from_file_type(path)
|
17
|
+
path = File.expand_path(path)
|
18
|
+
|
19
|
+
if path =~ /.shp/
|
20
|
+
ShpReader.new
|
21
|
+
elsif path =~ /.geojson|.json/
|
22
|
+
GeoJSONReader.new
|
23
|
+
else
|
24
|
+
raise RuntimeError.new("Could not determine appropriate reader for this file type")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def read(file_path, writeable=false)
|
29
|
+
ds = OGR_Dr_Open(@driver, File.expand_path(file_path), TF_MAP[writeable])
|
30
|
+
OGR::Tools.cast_data_source(ds)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module OGR
|
2
|
+
module Tools
|
3
|
+
class << self
|
4
|
+
def cast_data_source(ds_ptr, options={})
|
5
|
+
options = {auto_free: true}.merge(options)
|
6
|
+
raise RuntimeError.new("Data Source pointer is NULL") if ds_ptr.null?
|
7
|
+
DataSource.new ds_ptr, options[:auto_free]
|
8
|
+
end
|
9
|
+
|
10
|
+
def cast_layer(l_ptr, options={})
|
11
|
+
options = {auto_free: true}.merge(options)
|
12
|
+
raise RuntimeError.new("Layer pointer is NULL") if l_ptr.null?
|
13
|
+
Layer.new l_ptr, options[:aut_free]
|
14
|
+
end
|
15
|
+
|
16
|
+
def cast_feature(f_ptr, options={})
|
17
|
+
options = {auto_free: true}.merge(options)
|
18
|
+
raise RuntimeError.new("Feature pointer is NULL") if f_ptr.null?
|
19
|
+
Feature.new f_ptr, options[:auto_free]
|
20
|
+
end
|
21
|
+
|
22
|
+
def cast_geometry(geom_ptr, options={})
|
23
|
+
options = {auto_free: true}.merge(options)
|
24
|
+
raise RuntimeError.new("Geometry pointer is NULL") if geom_ptr.null?
|
25
|
+
|
26
|
+
geom_type = FFIOGR.OGR_G_GetGeometryType(geom_ptr)
|
27
|
+
|
28
|
+
klass = case geom_type
|
29
|
+
when :point
|
30
|
+
OGR::Point
|
31
|
+
when :line_string
|
32
|
+
OGR::LineString
|
33
|
+
when :polygon
|
34
|
+
OGR::Polygon
|
35
|
+
when :multi_point
|
36
|
+
OGR::MultiPoint
|
37
|
+
when :multi_line_string
|
38
|
+
OGR::MultiLineString
|
39
|
+
when :multi_polygon
|
40
|
+
OGR::MultiPolygon
|
41
|
+
when :geometry_collection
|
42
|
+
OGR::GeometryCollection
|
43
|
+
when :linear_ring
|
44
|
+
OGR::LinearRing
|
45
|
+
when :point_25d
|
46
|
+
OGR::Point25D
|
47
|
+
when :line_string_25d
|
48
|
+
OGR::LineString25D
|
49
|
+
when :polygon_25d
|
50
|
+
OGR::Polygon25D
|
51
|
+
when :multi_point_25d
|
52
|
+
OGR::MultiPoint25D
|
53
|
+
when :multi_line_string_25d
|
54
|
+
OGR::MultiLineString25D
|
55
|
+
when :multi_polygon_25d
|
56
|
+
OGR::MultiPolygon25D
|
57
|
+
when :geometry_collection_25d
|
58
|
+
OGR::GeometryCollection25D
|
59
|
+
end
|
60
|
+
|
61
|
+
klass.new(geom_ptr, options[:auto_free])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module OGR
|
2
|
+
class Writer
|
3
|
+
include OGR::FFIOGR
|
4
|
+
|
5
|
+
attr_accessor :ds
|
6
|
+
|
7
|
+
def initialize;end
|
8
|
+
|
9
|
+
def set_output(path, options={})
|
10
|
+
path = File.expand_path(path)
|
11
|
+
ds = OGR_Dr_CreateDataSource(@driver, path, nil)
|
12
|
+
@ds = OGR::Tools.cast_data_source(ds)
|
13
|
+
@ds
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.from_file_type(path)
|
17
|
+
path = File.expand_path(path)
|
18
|
+
|
19
|
+
unless File.exists? path
|
20
|
+
if path =~ /.shp/
|
21
|
+
writer = ShpWriter.new
|
22
|
+
elsif path =~ /.geojson|.json/
|
23
|
+
writer = GeoJSONWriter.new
|
24
|
+
else
|
25
|
+
raise RuntimeError.new("Could not determine appropriate writer for this file type")
|
26
|
+
end
|
27
|
+
|
28
|
+
writer.set_output(path)
|
29
|
+
writer
|
30
|
+
else
|
31
|
+
raise RuntimeError.new("Path already exists: #{path}")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def export(output_path)
|
36
|
+
writer = Writer.from_file_type output_path
|
37
|
+
data_source = writer.ds
|
38
|
+
|
39
|
+
# @ds -> data_source
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/ffi-ogr.rb
ADDED
@@ -0,0 +1,291 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OGR
|
5
|
+
OGR_BASE = File.join(File.dirname(__FILE__), 'ffi-ogr')
|
6
|
+
|
7
|
+
autoload :Reader, File.join(OGR_BASE, 'reader')
|
8
|
+
autoload :GenericReader, File.join(OGR_BASE, 'generic_reader')
|
9
|
+
autoload :ShpReader, File.join(OGR_BASE, 'shp_reader')
|
10
|
+
autoload :GeoJSONReader, File.join(OGR_BASE, 'geo_json_reader')
|
11
|
+
autoload :Writer, File.join(OGR_BASE, 'writer')
|
12
|
+
autoload :GenericWriter, File.join(OGR_BASE, 'generic_writer')
|
13
|
+
autoload :ShpWriter, File.join(OGR_BASE, 'shp_writer')
|
14
|
+
autoload :GeoJSONWriter, File.join(OGR_BASE, 'geo_json_writer')
|
15
|
+
autoload :DataSource, File.join(OGR_BASE, 'data_source')
|
16
|
+
autoload :Shapefile, File.join(OGR_BASE, 'shapefile')
|
17
|
+
autoload :GeoJSON, File.join(OGR_BASE, 'geo_json')
|
18
|
+
autoload :Tools, File.join(OGR_BASE, 'tools')
|
19
|
+
autoload :Layer, File.join(OGR_BASE, 'layer')
|
20
|
+
autoload :Feature, File.join(OGR_BASE, 'feature')
|
21
|
+
autoload :Geometry, File.join(OGR_BASE, 'geometry')
|
22
|
+
autoload :Point, File.join(OGR_BASE, 'point')
|
23
|
+
autoload :LineString, File.join(OGR_BASE, 'line_string')
|
24
|
+
autoload :Polygon, File.join(OGR_BASE, 'polygon')
|
25
|
+
autoload :MultiPoint, File.join(OGR_BASE, 'multi_point')
|
26
|
+
autoload :MultiLineString, File.join(OGR_BASE, 'multi_line_string')
|
27
|
+
autoload :MultiPolygon, File.join(OGR_BASE, 'multi_polygon')
|
28
|
+
autoload :GeometryCollection, File.join(OGR_BASE, 'geometry_collection')
|
29
|
+
autoload :LinearRing, File.join(OGR_BASE, 'linear_ring')
|
30
|
+
autoload :Point25D, File.join(OGR_BASE, 'point_25d')
|
31
|
+
autoload :LineString25D, File.join(OGR_BASE, 'line_string_25d')
|
32
|
+
autoload :Polygon25D, File.join(OGR_BASE, 'polygon_25d')
|
33
|
+
autoload :MultiPoint25D, File.join(OGR_BASE, 'multi_point_25d')
|
34
|
+
autoload :MultiLineString25D, File.join(OGR_BASE, 'multi_line_string_25d')
|
35
|
+
autoload :MultiPolygon25D, File.join(OGR_BASE, 'multi_polygon_25d')
|
36
|
+
autoload :GeometryCollection25D, File.join(OGR_BASE, 'geometry_collection_25d')
|
37
|
+
|
38
|
+
module FFIOGR
|
39
|
+
def self.search_paths
|
40
|
+
@search_paths ||= begin
|
41
|
+
if ENV['GDAL_LIBRARY_PATH']
|
42
|
+
elsif FFI::Platform.windows?
|
43
|
+
ENV['PATH'].split(File::PATH_SEPARATOR)
|
44
|
+
else
|
45
|
+
['/usr/local/{lib64,lib}', '/opt/local/{lib64,lib}', '/usr/{lib64,lib}']
|
46
|
+
['/usr/local/{lib64,lib}', '/opt/local/{lib64,lib}', '/usr/{lib64,lib}', '/usr/lib/{x86_64,i386}-linux-gnu']
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.find_lib(lib)
|
52
|
+
if ENV['GDAL_LIBRARY_PATH'] && File.file?(ENV['GDAL_LIBRARY_PATH'])
|
53
|
+
ENV['GDAL_LIBRARY_PATH']
|
54
|
+
else
|
55
|
+
Dir.glob(search_paths.map {|path|
|
56
|
+
File.expand_path(File.join(path, "#{lib}.#{FFI::Platform::LIBSUFFIX}"))
|
57
|
+
}).first
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.gdal_library_path
|
62
|
+
@gdal_library_path ||= begin
|
63
|
+
find_lib('{lib,}gdal{,-?}')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
extend ::FFI::Library
|
68
|
+
|
69
|
+
ffi_lib(gdal_library_path)
|
70
|
+
|
71
|
+
enum :ogr_field_type, [
|
72
|
+
:integer, 0,
|
73
|
+
:integer_list, 1,
|
74
|
+
:real, 2,
|
75
|
+
:real_list, 3,
|
76
|
+
:string, 4,
|
77
|
+
:string_list, 5,
|
78
|
+
:wide_string, 6,
|
79
|
+
:wide_string_list, 7,
|
80
|
+
:binary, 8,
|
81
|
+
:date, 9,
|
82
|
+
:time, 10,
|
83
|
+
:date_time, 11
|
84
|
+
]
|
85
|
+
|
86
|
+
enum :ogr_geometry_type, [
|
87
|
+
:unknown, 0,
|
88
|
+
:point, 1,
|
89
|
+
:line_string, 2,
|
90
|
+
:polygon, 3,
|
91
|
+
:multi_point, 4,
|
92
|
+
:multi_line_string, 5,
|
93
|
+
:multi_polygon, 6,
|
94
|
+
:geometry_collection, 7,
|
95
|
+
:none, 100,
|
96
|
+
:linear_ring, 101,
|
97
|
+
:point_25d, 0x80000001,
|
98
|
+
:line_string_25d, 0x80000002,
|
99
|
+
:polygon_25d, 0x80000003,
|
100
|
+
:multi_point_25d, 0x80000004,
|
101
|
+
:multi_line_string_25d, 0x80000005,
|
102
|
+
:multi_polygon_25d, 0x80000006,
|
103
|
+
:geometry_collection_25d, 0x80000007
|
104
|
+
]
|
105
|
+
|
106
|
+
enum :ogr_justification, [
|
107
|
+
:undefined, 0,
|
108
|
+
:left, 1,
|
109
|
+
:right, 2
|
110
|
+
]
|
111
|
+
|
112
|
+
attach_function :OGRRegisterAll, [], :void
|
113
|
+
attach_function :OGR_Dr_GetName, [:pointer], :string
|
114
|
+
attach_function :OGR_Dr_Open, [:pointer, :string, :int], :pointer
|
115
|
+
attach_function :OGR_Dr_TestCapability, [:pointer, :string], :int
|
116
|
+
attach_function :OGR_Dr_CreateDataSource, [:pointer, :string, :string], :pointer
|
117
|
+
attach_function :OGR_Dr_CopyDataSource, [:pointer, :pointer, :string, :string], :pointer
|
118
|
+
attach_function :OGR_Dr_DeleteDataSource, [:pointer, :string], :pointer
|
119
|
+
attach_function :OGRGetDriverCount, [], :int
|
120
|
+
attach_function :OGRGetDriver, [:int], :pointer
|
121
|
+
attach_function :OGRGetDriverByName, [:string], :pointer
|
122
|
+
attach_function :OGROpen, [:string, :int, :pointer], :pointer
|
123
|
+
attach_function :OGR_DS_Destroy, [:pointer], :void
|
124
|
+
attach_function :OGR_DS_GetName, [:pointer], :string
|
125
|
+
attach_function :OGR_DS_GetLayerCount, [:pointer], :int
|
126
|
+
attach_function :OGR_DS_GetLayer, [:pointer, :int], :pointer
|
127
|
+
attach_function :OGR_DS_GetLayerByName, [:pointer, :string], :pointer
|
128
|
+
attach_function :OGR_DS_DeleteLayer, [:pointer, :int], :pointer
|
129
|
+
attach_function :OGR_DS_GetDriver, [:pointer], :pointer
|
130
|
+
attach_function :OGR_DS_CreateLayer, [:pointer, :string, :pointer, :ogr_geometry_type, :string], :pointer
|
131
|
+
attach_function :OGR_DS_CopyLayer, [:pointer, :pointer, :string, :string], :pointer
|
132
|
+
attach_function :OGR_DS_TestCapability, [:pointer, :string], :int
|
133
|
+
attach_function :OGR_DS_ExecuteSQL, [:pointer, :string, :pointer, :string], :pointer
|
134
|
+
attach_function :OGR_DS_ReleaseResultSet, [:pointer, :pointer], :void
|
135
|
+
attach_function :OGR_DS_SyncToDisk, [:pointer], :pointer
|
136
|
+
attach_function :OGR_L_GetGeomType, [:pointer], :ogr_geometry_type
|
137
|
+
attach_function :OGR_L_GetName, [:pointer], :string
|
138
|
+
attach_function :OGR_L_GetSpatialFilter, [:pointer], :pointer
|
139
|
+
attach_function :OGR_L_SetSpatialFilter, [:pointer, :pointer], :void
|
140
|
+
attach_function :OGR_L_SetSpatialFilterRect, [:pointer, :double, :double, :double, :double], :void
|
141
|
+
attach_function :OGR_L_SetAttributeFilter, [:pointer, :string], :pointer
|
142
|
+
attach_function :OGR_L_ResetReading, [:pointer], :void
|
143
|
+
attach_function :OGR_L_GetNextFeature, [:pointer], :pointer
|
144
|
+
attach_function :OGR_L_SetNextByIndex, [:pointer, :long], :pointer
|
145
|
+
attach_function :OGR_L_GetFeature, [:pointer, :long], :pointer
|
146
|
+
attach_function :OGR_L_SetFeature, [:pointer, :pointer], :pointer
|
147
|
+
attach_function :OGR_L_CreateFeature, [:pointer, :pointer], :pointer
|
148
|
+
attach_function :OGR_L_DeleteFeature, [:pointer, :long], :pointer
|
149
|
+
attach_function :OGR_L_GetLayerDefn, [:pointer], :pointer
|
150
|
+
attach_function :OGR_L_GetSpatialRef, [:pointer], :pointer
|
151
|
+
attach_function :OGR_L_GetFeatureCount, [:pointer, :int], :int
|
152
|
+
attach_function :OGR_L_GetExtent, [:pointer, :pointer, :int], :pointer
|
153
|
+
attach_function :OGR_L_CreateField, [:pointer, :pointer, :int], :pointer
|
154
|
+
attach_function :OGR_L_SyncToDisk, [:pointer], :pointer
|
155
|
+
attach_function :OGR_FD_GetFieldCount, [:pointer], :int
|
156
|
+
attach_function :OGR_FD_GetFieldDefn, [:pointer, :int], :pointer
|
157
|
+
attach_function :OGR_Fld_Create, [:string, :ogr_field_type], :pointer
|
158
|
+
attach_function :OGR_Fld_Destroy, [:pointer], :void
|
159
|
+
attach_function :OGR_Fld_SetName, [:pointer, :string], :void
|
160
|
+
attach_function :OGR_Fld_GetNameRef, [:pointer], :string
|
161
|
+
attach_function :OGR_Fld_GetType, [:pointer], :ogr_field_type
|
162
|
+
attach_function :OGR_Fld_SetType, [:pointer, :ogr_field_type], :void
|
163
|
+
attach_function :OGR_Fld_GetJustify, [:pointer], :ogr_justification
|
164
|
+
attach_function :OGR_Fld_SetJustify, [:pointer, :ogr_justification], :void
|
165
|
+
attach_function :OGR_Fld_GetWidth, [:pointer], :int
|
166
|
+
attach_function :OGR_Fld_SetWidth, [:pointer, :int], :void
|
167
|
+
attach_function :OGR_Fld_GetPrecision, [:pointer], :int
|
168
|
+
attach_function :OGR_Fld_SetPrecision, [:pointer, :int], :void
|
169
|
+
attach_function :OGR_Fld_Set, [:pointer, :string, :ogr_field_type, :int, :int, :ogr_justification], :void
|
170
|
+
attach_function :OGR_Fld_IsIgnored, [:pointer], :int
|
171
|
+
attach_function :OGR_Fld_SetIgnored, [:pointer, :int], :void
|
172
|
+
attach_function :OGR_F_Create, [:pointer], :pointer
|
173
|
+
attach_function :OGR_F_GetFieldAsInteger, [:pointer, :int], :int
|
174
|
+
attach_function :OGR_F_GetFieldAsDouble, [:pointer, :int], :double
|
175
|
+
attach_function :OGR_F_GetFieldAsString, [:pointer, :int], :string
|
176
|
+
attach_function :OGR_F_GetFieldAsIntegerList, [:pointer, :int, :pointer], :pointer
|
177
|
+
attach_function :OGR_F_GetFieldAsDoubleList, [:pointer, :int, :pointer], :pointer
|
178
|
+
attach_function :OGR_F_GetFieldAsStringList, [:pointer, :int], :pointer
|
179
|
+
attach_function :OGR_F_GetFieldAsBinary, [:pointer, :int, :pointer], :pointer
|
180
|
+
attach_function :OGR_F_GetFieldAsDateTime, [:pointer, :int, :pointer, :pointer, :pointer, :pointer, :pointer, :pointer, :pointer], :pointer
|
181
|
+
attach_function :OGR_F_SetFieldInteger, [:pointer, :int, :int], :void
|
182
|
+
attach_function :OGR_F_SetFieldDouble, [:pointer, :int, :double], :void
|
183
|
+
attach_function :OGR_F_SetFieldString, [:pointer, :int, :string], :void
|
184
|
+
attach_function :OGR_F_SetFieldIntegerList, [:pointer, :int, :int, :pointer], :void
|
185
|
+
attach_function :OGR_F_SetFieldDoubleList, [:pointer, :int, :int, :pointer], :void
|
186
|
+
attach_function :OGR_F_SetFieldStringList, [:pointer, :int, :int, :pointer], :void
|
187
|
+
attach_function :OGR_F_SetFieldRaw, [:pointer, :int, :pointer], :void
|
188
|
+
attach_function :OGR_F_SetFieldBinary, [:pointer, :int, :int, :pointer], :void
|
189
|
+
attach_function :OGR_F_SetFieldDateTime, [:pointer, :int, :int, :int, :int, :int, :int, :int, :int], :void
|
190
|
+
attach_function :OGR_F_GetDefnRef, [:pointer], :pointer
|
191
|
+
attach_function :OGR_F_GetFieldCount, [:pointer], :int
|
192
|
+
attach_function :OGR_F_GetFieldDefnRef, [:pointer, :int], :pointer
|
193
|
+
attach_function :OGR_F_GetFieldIndex, [:pointer, :string], :int
|
194
|
+
attach_function :OGR_F_IsFieldSet, [:pointer, :int], :int
|
195
|
+
attach_function :OGR_F_GetGeometryRef, [:pointer], :pointer
|
196
|
+
attach_function :OGR_F_GetFID, [:pointer], :long
|
197
|
+
attach_function :OGR_F_SetFID, [:pointer, :long], :pointer
|
198
|
+
attach_function :OGR_F_SetGeometry, [:pointer, :pointer], :pointer
|
199
|
+
attach_function :OGR_F_SetGeometryDirectly, [:pointer, :pointer], :pointer
|
200
|
+
attach_function :OGR_G_CreateFromWkb, [:pointer, :pointer, :pointer, :int], :pointer
|
201
|
+
attach_function :OGR_G_CreateFromWkt, [:pointer, :pointer, :pointer], :pointer
|
202
|
+
attach_function :OGR_G_DestroyGeometry, [:pointer], :void
|
203
|
+
attach_function :OGR_G_CreateGeometry, [:ogr_geometry_type], :pointer
|
204
|
+
attach_function :OGR_G_ApproximateArcAngles, [:double, :double, :double, :double, :double, :double, :double, :double, :double], :pointer
|
205
|
+
attach_function :OGR_G_ForceToPolygon, [:pointer], :pointer
|
206
|
+
#attach_function :OGR_G_ForceToLineString, [:pointer], :pointer
|
207
|
+
attach_function :OGR_G_ForceToMultiPolygon, [:pointer], :pointer
|
208
|
+
attach_function :OGR_G_ForceToMultiPoint, [:pointer], :pointer
|
209
|
+
attach_function :OGR_G_ForceToMultiLineString, [:pointer], :pointer
|
210
|
+
attach_function :OGR_G_GetDimension, [:pointer], :int
|
211
|
+
attach_function :OGR_G_GetCoordinateDimension, [:pointer], :int
|
212
|
+
attach_function :OGR_G_SetCoordinateDimension, [:pointer, :int], :void
|
213
|
+
attach_function :OGR_G_Clone, [:pointer], :pointer
|
214
|
+
attach_function :OGR_G_GetEnvelope, [:pointer, :pointer], :void
|
215
|
+
attach_function :OGR_G_GetEnvelope3D, [:pointer, :pointer], :void
|
216
|
+
attach_function :OGR_G_ImportFromWkb, [:pointer, :pointer, :int], :pointer
|
217
|
+
attach_function :OGR_G_ExportToWkb, [:pointer, :pointer, :pointer], :pointer
|
218
|
+
attach_function :OGR_G_WkbSize, [:pointer], :int
|
219
|
+
attach_function :OGR_G_ImportFromWkt, [:pointer, :string], :pointer
|
220
|
+
attach_function :OGR_G_ExportToWkt, [:pointer, :pointer], :pointer
|
221
|
+
attach_function :OGR_G_GetGeometryType, [:pointer], :ogr_geometry_type
|
222
|
+
attach_function :OGR_G_GetGeometryName, [:pointer], :string
|
223
|
+
attach_function :OGR_G_DumpReadable, [:pointer, :pointer, :string], :void
|
224
|
+
attach_function :OGR_G_FlattenTo2D, [:pointer], :void
|
225
|
+
attach_function :OGR_G_CloseRings, [:pointer], :void
|
226
|
+
attach_function :OGR_G_CreateFromGML, [:string], :pointer
|
227
|
+
attach_function :OGR_G_ExportToGML, [:pointer], :string
|
228
|
+
#attach_function :OGR_G_ExportToGMLEx, [:pointer, :pointer], :string
|
229
|
+
attach_function :OGR_G_ExportToKML, [:pointer, :string], :string
|
230
|
+
attach_function :OGR_G_ExportToJson, [:pointer], :string
|
231
|
+
attach_function :OGR_G_ExportToJsonEx, [:pointer, :string], :string
|
232
|
+
attach_function :OGR_G_AssignSpatialReference, [:pointer, :pointer], :void
|
233
|
+
attach_function :OGR_G_GetSpatialReference, [:pointer], :pointer
|
234
|
+
attach_function :OGR_G_Transform, [:pointer, :pointer], :pointer
|
235
|
+
attach_function :OGR_G_TransformTo, [:pointer, :pointer], :pointer
|
236
|
+
attach_function :OGR_G_Simplify, [:pointer, :double], :pointer
|
237
|
+
attach_function :OGR_G_SimplifyPreserveTopology, [:pointer, :double], :pointer
|
238
|
+
attach_function :OGR_G_Segmentize, [:pointer, :double], :pointer
|
239
|
+
attach_function :OGR_G_Intersects, [:pointer, :pointer], :int
|
240
|
+
attach_function :OGR_G_Equals, [:pointer, :pointer], :int
|
241
|
+
attach_function :OGR_G_Disjoint, [:pointer, :pointer], :int
|
242
|
+
attach_function :OGR_G_Touches, [:pointer, :pointer], :int
|
243
|
+
attach_function :OGR_G_Crosses, [:pointer, :pointer], :int
|
244
|
+
attach_function :OGR_G_Within, [:pointer, :pointer], :int
|
245
|
+
attach_function :OGR_G_Contains, [:pointer, :pointer], :int
|
246
|
+
attach_function :OGR_G_Overlaps, [:pointer, :pointer], :int
|
247
|
+
attach_function :OGR_G_Boundary, [:pointer], :pointer
|
248
|
+
attach_function :OGR_G_ConvexHull, [:pointer], :pointer
|
249
|
+
attach_function :OGR_G_Buffer, [:pointer, :double, :int], :pointer
|
250
|
+
attach_function :OGR_G_Intersection, [:pointer, :pointer], :pointer
|
251
|
+
attach_function :OGR_G_Union, [:pointer, :pointer], :pointer
|
252
|
+
attach_function :OGR_G_UnionCascaded, [:pointer], :pointer
|
253
|
+
#attach_function :OGR_G_PointOnSurface, [:pointer], :pointer
|
254
|
+
attach_function :OGR_G_Difference, [:pointer, :pointer], :pointer
|
255
|
+
attach_function :OGR_G_SymDifference, [:pointer, :pointer], :pointer
|
256
|
+
attach_function :OGR_G_Distance, [:pointer, :pointer], :double
|
257
|
+
attach_function :OGR_G_Length, [:pointer], :double
|
258
|
+
attach_function :OGR_G_Area, [:pointer], :double
|
259
|
+
attach_function :OGR_G_Centroid, [:pointer, :pointer], :int
|
260
|
+
attach_function :OGR_G_Empty, [:pointer], :void
|
261
|
+
attach_function :OGR_G_IsEmpty, [:pointer], :int
|
262
|
+
attach_function :OGR_G_IsValid, [:pointer], :int
|
263
|
+
attach_function :OGR_G_IsSimple, [:pointer], :int
|
264
|
+
attach_function :OGR_G_IsRing, [:pointer], :int
|
265
|
+
attach_function :OGR_G_Polygonize, [:pointer], :pointer
|
266
|
+
attach_function :OGR_G_GetPointCount, [:pointer], :int
|
267
|
+
attach_function :OGR_G_GetPoints, [:pointer, :pointer, :int, :pointer, :int, :pointer, :int], :int
|
268
|
+
attach_function :OGR_G_GetX, [:pointer, :int], :double
|
269
|
+
attach_function :OGR_G_GetY, [:pointer, :int], :double
|
270
|
+
attach_function :OGR_G_GetZ, [:pointer, :int], :double
|
271
|
+
attach_function :OGR_G_GetPoint, [:pointer, :int, :pointer, :pointer, :pointer], :void
|
272
|
+
attach_function :OGR_G_SetPoint, [:pointer, :int, :double, :double, :double], :void
|
273
|
+
attach_function :OGR_G_SetPoint_2D, [:pointer, :int, :double, :double], :void
|
274
|
+
attach_function :OGR_G_AddPoint, [:pointer, :double, :double, :double], :void
|
275
|
+
attach_function :OGR_G_AddPoint_2D, [:pointer, :double, :double], :void
|
276
|
+
attach_function :OGR_G_GetGeometryCount, [:pointer], :int
|
277
|
+
attach_function :OGR_G_GetGeometryRef, [:pointer, :int], :pointer
|
278
|
+
attach_function :OGR_G_AddGeometry, [:pointer, :pointer], :pointer
|
279
|
+
attach_function :OGR_G_AddGeometryDirectly, [:pointer, :pointer], :pointer
|
280
|
+
attach_function :OGR_G_RemoveGeometry, [:pointer, :int, :int], :pointer
|
281
|
+
attach_function :OGR_F_Destroy, [:pointer], :void
|
282
|
+
end
|
283
|
+
|
284
|
+
class << self
|
285
|
+
def to_binary(data)
|
286
|
+
buf = FFI::MemoryPointer.new(:char, value.size)
|
287
|
+
buf.put_bytes(0, data)
|
288
|
+
buf
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ffi-ogr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.pre
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Scooter Wadsworth
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ffi
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.5.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.5.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: multi_json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: FFI wrapper for OGR
|
79
|
+
email:
|
80
|
+
- scooterwadsworth@gmail.com
|
81
|
+
executables:
|
82
|
+
- ogr_console
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- README.md
|
87
|
+
- bin/ogr_console
|
88
|
+
- lib/ffi-ogr/data_source.rb
|
89
|
+
- lib/ffi-ogr/feature.rb
|
90
|
+
- lib/ffi-ogr/generic_reader.rb
|
91
|
+
- lib/ffi-ogr/generic_writer.rb
|
92
|
+
- lib/ffi-ogr/geo_json.rb
|
93
|
+
- lib/ffi-ogr/geo_json_reader.rb
|
94
|
+
- lib/ffi-ogr/geo_json_writer.rb
|
95
|
+
- lib/ffi-ogr/geometry.rb
|
96
|
+
- lib/ffi-ogr/geometry_collection.rb
|
97
|
+
- lib/ffi-ogr/geometry_collection_25d.rb
|
98
|
+
- lib/ffi-ogr/layer.rb
|
99
|
+
- lib/ffi-ogr/line_string.rb
|
100
|
+
- lib/ffi-ogr/line_string_25d.rb
|
101
|
+
- lib/ffi-ogr/linear_ring.rb
|
102
|
+
- lib/ffi-ogr/multi_line_string.rb
|
103
|
+
- lib/ffi-ogr/multi_line_string_25d.rb
|
104
|
+
- lib/ffi-ogr/multi_point.rb
|
105
|
+
- lib/ffi-ogr/multi_point_25d.rb
|
106
|
+
- lib/ffi-ogr/multi_polygon.rb
|
107
|
+
- lib/ffi-ogr/multi_polygon_25d.rb
|
108
|
+
- lib/ffi-ogr/point.rb
|
109
|
+
- lib/ffi-ogr/point_25d.rb
|
110
|
+
- lib/ffi-ogr/polygon.rb
|
111
|
+
- lib/ffi-ogr/polygon_25d.rb
|
112
|
+
- lib/ffi-ogr/reader.rb
|
113
|
+
- lib/ffi-ogr/shapefile.rb
|
114
|
+
- lib/ffi-ogr/shp_reader.rb
|
115
|
+
- lib/ffi-ogr/shp_writer.rb
|
116
|
+
- lib/ffi-ogr/tools.rb
|
117
|
+
- lib/ffi-ogr/version.rb
|
118
|
+
- lib/ffi-ogr/writer.rb
|
119
|
+
- lib/ffi-ogr.rb
|
120
|
+
homepage: https://github.com/scooterw/ffi-ogr
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ! '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 1.9.2
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.3.6
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 1.8.23
|
142
|
+
signing_key:
|
143
|
+
specification_version: 3
|
144
|
+
summary: Convenient access to OGR functionality from Ruby
|
145
|
+
test_files: []
|