ffi-gdal-extensions 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.rubocop.yml +49 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/History.md +8 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ffi-gdal-extensions.gemspec +32 -0
- data/lib/ffi/gdal/extensions/version.rb +7 -0
- data/lib/ffi/gdal/extensions.rb +8 -0
- data/lib/ffi/lwgeom/gbox.rb +17 -0
- data/lib/ffi/lwgeom/geom.rb +14 -0
- data/lib/ffi/lwgeom.rb +44 -0
- data/lib/ogr/geometry_extensions/ewkb_io.rb +47 -0
- data/lib/ogr/geometry_extensions/ewkb_record.rb +90 -0
- data/lib/ogr/geometry_extensions/lwgeom_wrappers.rb +32 -0
- data/lib/ogr/geometry_extensions/wkb_record.rb +61 -0
- metadata +165 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5887b1ab4134d7b9e2cc0165da509b19293285dd
|
4
|
+
data.tar.gz: 472fd89fe70ba2308ebb84ad35c67654b50edade
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c37e14d287542c9a20631606a9cc71cf53b3a9a90c0558410226582277121b5083a099e245fb3361ac242d79f4f322b790f9043a9427f831bc740707440c7c2c
|
7
|
+
data.tar.gz: 12bb2ab95ac73c98a4ab9938430af100a2be68388831ee06b8dc25335f225b609b41f75ee3dd622e0f8faa69d35446c2eb7f933ab5bceacb564cefc8eb61059d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
Metrics/ClassLength:
|
2
|
+
Max: 300
|
3
|
+
|
4
|
+
Metrics/LineLength:
|
5
|
+
Max: 120
|
6
|
+
|
7
|
+
Metrics/MethodLength:
|
8
|
+
Max: 20
|
9
|
+
|
10
|
+
Style/AlignParameters:
|
11
|
+
EnforcedStyle: with_fixed_indentation
|
12
|
+
|
13
|
+
Style/Documentation:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/DotPosition:
|
17
|
+
EnforcedStyle: trailing
|
18
|
+
|
19
|
+
Style/DoubleNegation:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/FormatString:
|
23
|
+
EnforcedStyle: percent
|
24
|
+
|
25
|
+
Style/PercentLiteralDelimiters:
|
26
|
+
PreferredDelimiters:
|
27
|
+
'%i': '[]'
|
28
|
+
'%w': '[]'
|
29
|
+
'%W': '[]'
|
30
|
+
|
31
|
+
Style/PredicateName:
|
32
|
+
Exclude:
|
33
|
+
# Bindata has problems with srid? since srid is a parsed attribute. #z? and
|
34
|
+
# m? could get around this but it seemed more important to keep the API
|
35
|
+
# consistent.
|
36
|
+
- lib/ogr/geometry_extensions/ewkb_record.rb
|
37
|
+
- lib/ogr/geometry_extensions/wkb_record.rb
|
38
|
+
|
39
|
+
Style/SymbolArray:
|
40
|
+
Enabled: true
|
41
|
+
|
42
|
+
AllCops:
|
43
|
+
DisplayCopNames: true
|
44
|
+
DisplayStyleGuide: true
|
45
|
+
Include:
|
46
|
+
- Gemfile
|
47
|
+
Exclude:
|
48
|
+
- vendor/bundle/**/*
|
49
|
+
TargetRubyVersion: 2.2
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at steve.loveless@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/History.md
ADDED
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# FFI::GDAL::Extensions
|
2
|
+
|
3
|
+
[ffi-gdal](https://bitbucket.org/agrian/ffi-gdal) is a wrapper around the GDAL
|
4
|
+
(and OGR) library, but since that is written in C/C++, much of its API feels
|
5
|
+
like those languages. Methods found in this gem extend that gem by a) making
|
6
|
+
it feel more Rubyesque, and b) adding some new functionality.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'ffi-gdal-extensions'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install ffi-gdal-extensions
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
TODO: Write usage instructions here
|
27
|
+
|
28
|
+
## Development
|
29
|
+
|
30
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
31
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
32
|
+
prompt that will allow you to experiment.
|
33
|
+
|
34
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
35
|
+
release a new version, update the version number in `version.rb`, and then run
|
36
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
37
|
+
git commits and tags, and push the `.gem` file to
|
38
|
+
[rubygems.org](https://rubygems.org).
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
Bug reports and pull requests are welcome on BitBucket at
|
43
|
+
https://bitbucket.org/agrian/ffi-gdal-extensions. This project is intended to be
|
44
|
+
a safe, welcoming space for collaboration, and contributors are expected to
|
45
|
+
adhere to the [Contributor Covenant](http://contributor-covenant.org) code of
|
46
|
+
conduct.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'ffi/gdal/extensions'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ffi/gdal/extensions/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'ffi-gdal-extensions'
|
8
|
+
spec.version = FFI::GDAL::Extensions::VERSION
|
9
|
+
spec.authors = ['Steve Loveless']
|
10
|
+
spec.email = ['steve.loveless@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Additional functionality to the ffi-gdal gem'
|
13
|
+
spec.description = %(Make ffi-gdal feel more like Ruby, plus adds some new
|
14
|
+
functionality)
|
15
|
+
spec.homepage = 'https://bitbucket.org/agrian/ffi-gdal-extensions'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_dependency 'bindata', '~> 2.0'
|
25
|
+
spec.add_dependency 'ffi-gdal', '>= 1.0.0.beta6'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
28
|
+
spec.add_development_dependency 'byebug'
|
29
|
+
spec.add_development_dependency 'rake'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
31
|
+
spec.add_development_dependency 'rubocop'
|
32
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module FFI
|
4
|
+
module LWGeom
|
5
|
+
class GBOX < FFI::Struct
|
6
|
+
layout :flags, :uint8,
|
7
|
+
:xmin, :double,
|
8
|
+
:xmax, :double,
|
9
|
+
:ymin, :double,
|
10
|
+
:ymax, :double,
|
11
|
+
:zmin, :double,
|
12
|
+
:zmax, :double,
|
13
|
+
:mmin, :double,
|
14
|
+
:mmax, :double
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/ffi/lwgeom.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'ffi-gdal'
|
2
|
+
require_relative 'lwgeom/geom'
|
3
|
+
|
4
|
+
module FFI
|
5
|
+
module LWGeom
|
6
|
+
extend ::FFI::Library
|
7
|
+
|
8
|
+
# @param [String] lib Name of the library file to find.
|
9
|
+
# @return [String] Path to the library file.
|
10
|
+
def self.find_lib(lib)
|
11
|
+
lib_file_name = "#{lib}.#{FFI::Platform::LIBSUFFIX}*"
|
12
|
+
|
13
|
+
if ENV['LWGEOM_LIBRARY_PATH']
|
14
|
+
return File.join(ENV['LWGEOM_LIBRARY_PATH'], lib_file_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
FFI::GDAL.search_paths.flat_map do |search_path|
|
18
|
+
Dir.glob(search_path).flat_map do |path|
|
19
|
+
Dir.glob(File.join(path, lib_file_name))
|
20
|
+
end
|
21
|
+
end.uniq.first
|
22
|
+
end
|
23
|
+
|
24
|
+
ffi_lib [::FFI::CURRENT_PROCESS, find_lib('liblwgeom')]
|
25
|
+
|
26
|
+
VARIANT_WKB_ISO = 0x01
|
27
|
+
VARIANT_WKB_SFSQL = 0x02
|
28
|
+
VARIANT_WKB_EXTENDED = 0x04
|
29
|
+
VARIANT_WKB_NDR = 0x08
|
30
|
+
VARIANT_WKB_XDR = 0x10
|
31
|
+
VARIANT_WKB_HEX = 0x20
|
32
|
+
|
33
|
+
VARIANT_WKT_ISO = 0x01
|
34
|
+
VARIANT_WKT_SFSQL = 0x02
|
35
|
+
VARIANT_WKT_EXTENDED = 0x04
|
36
|
+
|
37
|
+
attach_function :lwgeom_from_wkt, [:string, :bool], Geom.ptr
|
38
|
+
attach_function :lwgeom_from_wkb, [:pointer, :size_t, :bool], Geom.ptr
|
39
|
+
attach_function :lwgeom_to_wkt, [Geom.ptr, :uint8, :int, :pointer], :string
|
40
|
+
attach_function :lwgeom_to_wkb, [Geom.ptr, :uint8, :pointer], :pointer
|
41
|
+
|
42
|
+
attach_function :lwgeom_make_valid, [Geom.ptr], Geom.ptr
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'ffi-gdal'
|
2
|
+
require 'ogr'
|
3
|
+
require_relative 'ewkb_record'
|
4
|
+
require_relative 'wkb_record'
|
5
|
+
|
6
|
+
module OGR
|
7
|
+
module GeometryExtensions
|
8
|
+
# Extends OGR::Geometry with methods that allow creating a Geometry from
|
9
|
+
# EKWB or outputting a Geometry as EWKB (EWKB is the WKB format that PostGIS
|
10
|
+
# uses).
|
11
|
+
module EWKBIO
|
12
|
+
# Methods to extend OGR::Geometry with.
|
13
|
+
module ClassMethods
|
14
|
+
# @param ewkb_data [String] Binary EWKB string.
|
15
|
+
# @param [OGR::Geometry]
|
16
|
+
def create_from_ewkb(ewkb_data)
|
17
|
+
e = EWKBRecord.read(ewkb_data)
|
18
|
+
|
19
|
+
if e.srid?
|
20
|
+
spatial_ref = OGR::SpatialReference.new_from_epsg(e.srid)
|
21
|
+
create_from_wkb(e.to_wkb, spatial_ref)
|
22
|
+
else
|
23
|
+
create_from_wkb(e.to_wkb)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.included(base)
|
29
|
+
base.extend(ClassMethods)
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [String] Binary string representative of EWKB.
|
33
|
+
def to_ewkb
|
34
|
+
wkb_record = WKBRecord.read(to_wkb)
|
35
|
+
srid = spatial_reference ? spatial_reference.authority_code.to_i : 0
|
36
|
+
|
37
|
+
EWKBRecord.from_wkb_record(wkb_record, srid).to_binary_s
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module OGR
|
44
|
+
module Geometry
|
45
|
+
include OGR::GeometryExtensions::EWKBIO
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'bindata'
|
2
|
+
require 'ffi-gdal'
|
3
|
+
require 'ogr'
|
4
|
+
require_relative 'wkb_record'
|
5
|
+
|
6
|
+
module OGR
|
7
|
+
module GeometryExtensions
|
8
|
+
# Parses raw EWKB and turns into a data structure. Only really exists for
|
9
|
+
# converting to and from EWKB.
|
10
|
+
#
|
11
|
+
# @see http://trac.osgeo.org/postgis/browser/trunk/doc/ZMSgeoms.txt
|
12
|
+
# @see {{OGR::GeometryExtensions::EWKBRecord}}
|
13
|
+
class EWKBRecord < BinData::Record
|
14
|
+
uint8 :endianness, assert: -> { value == 0 || value == 1 }
|
15
|
+
|
16
|
+
# Choose the type based on the endianness.
|
17
|
+
choice :wkb_type, selection: :endianness do
|
18
|
+
uint32be 0
|
19
|
+
uint32le 1
|
20
|
+
end
|
21
|
+
|
22
|
+
# Make sure the geometry_type is one OGR knows about.
|
23
|
+
virtual assert: -> { FFI::OGR::Core::WKBGeometryType.symbol_map.values.include? geometry_type }
|
24
|
+
|
25
|
+
# If the wkb_type has the SRID flag set, there's an SRID.
|
26
|
+
choice :srid, onlyif: :has_srid?, selection: :endianness do
|
27
|
+
uint32be 0
|
28
|
+
uint32le 1
|
29
|
+
end
|
30
|
+
|
31
|
+
# The #geometry attribute is just the rest of the data. We don't care what
|
32
|
+
# kind of geom it actually is; that doesn't matter for building EWKB.
|
33
|
+
rest :geometry
|
34
|
+
|
35
|
+
WKB_Z = 0x8000_0000
|
36
|
+
WKB_M = 0x4000_0000
|
37
|
+
WKB_SRID = 0x2000_0000
|
38
|
+
|
39
|
+
# @param wkb_record [OGR::GeometryExtensions::WKBRecord]
|
40
|
+
# @param srid [Fixnum]
|
41
|
+
# @return [OGR::GeometryExtensions::EWKBRecord]
|
42
|
+
def self.from_wkb_record(wkb_record, srid = 0)
|
43
|
+
ewkb_type_flag = if srid.zero?
|
44
|
+
wkb_record.wkb_type
|
45
|
+
else
|
46
|
+
(wkb_record.wkb_type | WKB_SRID)
|
47
|
+
end
|
48
|
+
|
49
|
+
ewkb_type_flag |= WKB_Z if wkb_record.has_z?
|
50
|
+
|
51
|
+
new(endianness: wkb_record.endianness,
|
52
|
+
wkb_type: ewkb_type_flag,
|
53
|
+
srid: srid,
|
54
|
+
geometry: wkb_record.geometry)
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [Boolean] Is the Z flag set?
|
58
|
+
def has_z?
|
59
|
+
wkb_type & WKB_Z != 0
|
60
|
+
end
|
61
|
+
|
62
|
+
# @return [Boolean] Is the M flag set?
|
63
|
+
def has_m?
|
64
|
+
wkb_type & WKB_M != 0
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [Boolean] Is the SRID flag set?
|
68
|
+
def has_srid?
|
69
|
+
wkb_type & WKB_SRID != 0
|
70
|
+
end
|
71
|
+
|
72
|
+
# @return [Fixnum] Enum number that matches the FFI::OGR::Core::WKBGeometryType.
|
73
|
+
def geometry_type
|
74
|
+
type = wkb_type & 0x0fff_ffff
|
75
|
+
|
76
|
+
has_z? ? (type | WKB_Z) : type
|
77
|
+
end
|
78
|
+
|
79
|
+
# @return [OGR::GeometryExtensions::WKBRecord]
|
80
|
+
def to_wkb_record
|
81
|
+
WKBRecord.from_ewkb_record(self)
|
82
|
+
end
|
83
|
+
|
84
|
+
# @return [String] WKB binary string.
|
85
|
+
def to_wkb
|
86
|
+
to_wkb_record.to_binary_s
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'ogr'
|
2
|
+
require_relative '../../ffi/lwgeom'
|
3
|
+
|
4
|
+
module OGR
|
5
|
+
module GeometryExtensions
|
6
|
+
# Methods for {{OGR::Geometry}}s that use lwgeom to operate on
|
7
|
+
# themselves.
|
8
|
+
#
|
9
|
+
# @see http://postgis.net/docs/doxygen/2.1/da/de7/liblwgeom_8h_af8d208cf4c0bb7c9f96c75bddc6c498a.html#af8d208cf4c0bb7c9f96c75bddc6c498a
|
10
|
+
module LWGeomWrappers
|
11
|
+
# Uses lwgeom's MakeValid to make the current geometry valid.
|
12
|
+
#
|
13
|
+
# @return [OGR::Geometry] Returns a new geometry, based on the
|
14
|
+
# lwgeom_make_valid call.
|
15
|
+
def make_valid
|
16
|
+
geom = FFI::LWGeom.lwgeom_from_wkb(to_wkb, wkb_size, false)
|
17
|
+
valid_geom = FFI::LWGeom.lwgeom_make_valid(geom)
|
18
|
+
valid_wkb_size = FFI::MemoryPointer.new(:size_t)
|
19
|
+
valid_wkb_ptr = FFI::LWGeom.lwgeom_to_wkb(valid_geom, FFI::LWGeom::VARIANT_WKB_EXTENDED, valid_wkb_size)
|
20
|
+
valid_wkb = valid_wkb_ptr.read_bytes(valid_wkb_size.read_int)
|
21
|
+
|
22
|
+
OGR::Geometry.create_from_wkb(valid_wkb)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module OGR
|
29
|
+
module Geometry
|
30
|
+
include OGR::GeometryExtensions::LWGeomWrappers
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'bindata'
|
2
|
+
require 'ffi-gdal'
|
3
|
+
require 'ogr'
|
4
|
+
|
5
|
+
module OGR
|
6
|
+
module GeometryExtensions
|
7
|
+
# Parses raw WKB and turns into a data structure. Only really exists for
|
8
|
+
# converting to and from EWKB.
|
9
|
+
#
|
10
|
+
# @see {{OGR::GeometryExtensions::EWKBRecord}}
|
11
|
+
class WKBRecord < BinData::Record
|
12
|
+
uint8 :endianness, assert: -> { value == 0 || value == 1 }
|
13
|
+
|
14
|
+
# Choose the type based on the endianness
|
15
|
+
choice :wkb_type, selection: :endianness do
|
16
|
+
uint32be 0
|
17
|
+
uint32le 1
|
18
|
+
end
|
19
|
+
|
20
|
+
# Make sure the geometry_type is one OGR knows about.
|
21
|
+
virtual assert: -> { FFI::OGR::Core::WKBGeometryType.symbol_map.values.include? geometry_type }
|
22
|
+
|
23
|
+
# The #geometry attribute is just the rest of the data. We don't care what
|
24
|
+
# kind of geom it actually is; that doesn't matter for building EWKB.
|
25
|
+
rest :geometry
|
26
|
+
|
27
|
+
WKB_Z = 0x8000_0000
|
28
|
+
|
29
|
+
# @param ewkb_record [OGR::GeometryExtensions::EWKBRecord]
|
30
|
+
# @return [OGR::GeometryExtensions::WKBRecord]
|
31
|
+
def self.from_ewkb_record(ewkb_record)
|
32
|
+
new(endianness: ewkb_record.endianness,
|
33
|
+
wkb_type: ewkb_record.geometry_type,
|
34
|
+
geometry: ewkb_record.geometry)
|
35
|
+
end
|
36
|
+
|
37
|
+
# @param ewkb_data [String] Binary string with the EWKB data.
|
38
|
+
# @return [OGR::GeometryExtensions::WKBRecord]
|
39
|
+
def self.from_ewkb(ewkb_data)
|
40
|
+
from_ewkb_record(EWKBRecord.read(ewkb_data))
|
41
|
+
end
|
42
|
+
|
43
|
+
# @return [Boolean] Is the Z flag set?
|
44
|
+
def has_z?
|
45
|
+
geometry_type & WKB_Z != 0
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return [Fixnum] Enum number that matches the FFI::OGR::Core::WKBGeometryType.
|
49
|
+
# Defined to keep the API consistent with EWKBRecord.
|
50
|
+
def geometry_type
|
51
|
+
# ISO SQL/MM style Z types are between 1001 and 1007
|
52
|
+
if wkb_type.value >= 1001 && wkb_type.value <= 1007
|
53
|
+
raw_type_int = wkb_type.value - 1000
|
54
|
+
raw_type_int | WKB_Z
|
55
|
+
else
|
56
|
+
wkb_type.value
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ffi-gdal-extensions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steve Loveless
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bindata
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ffi-gdal
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0.beta6
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.0.beta6
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.11'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.11'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: |-
|
112
|
+
Make ffi-gdal feel more like Ruby, plus adds some new
|
113
|
+
functionality
|
114
|
+
email:
|
115
|
+
- steve.loveless@gmail.com
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- ".gitignore"
|
121
|
+
- ".rspec"
|
122
|
+
- ".rubocop.yml"
|
123
|
+
- ".travis.yml"
|
124
|
+
- CODE_OF_CONDUCT.md
|
125
|
+
- Gemfile
|
126
|
+
- History.md
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- bin/console
|
130
|
+
- bin/setup
|
131
|
+
- ffi-gdal-extensions.gemspec
|
132
|
+
- lib/ffi/gdal/extensions.rb
|
133
|
+
- lib/ffi/gdal/extensions/version.rb
|
134
|
+
- lib/ffi/lwgeom.rb
|
135
|
+
- lib/ffi/lwgeom/gbox.rb
|
136
|
+
- lib/ffi/lwgeom/geom.rb
|
137
|
+
- lib/ogr/geometry_extensions/ewkb_io.rb
|
138
|
+
- lib/ogr/geometry_extensions/ewkb_record.rb
|
139
|
+
- lib/ogr/geometry_extensions/lwgeom_wrappers.rb
|
140
|
+
- lib/ogr/geometry_extensions/wkb_record.rb
|
141
|
+
homepage: https://bitbucket.org/agrian/ffi-gdal-extensions
|
142
|
+
licenses: []
|
143
|
+
metadata: {}
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.5.1
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: Additional functionality to the ffi-gdal gem
|
164
|
+
test_files: []
|
165
|
+
has_rdoc:
|