ffi-geos 0.1.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ffi-geos.rb CHANGED
@@ -975,14 +975,17 @@ module Geos
975
975
  attr_reader :ptr
976
976
 
977
977
  def initialize
978
- @ptr = FFIGeos.initGEOS_r(
979
- @notice_handler = self.method(:notice_handler),
980
- @error_handler = self.method(:error_handler)
978
+ @ptr = FFI::AutoPointer.new(
979
+ FFIGeos.initGEOS_r(
980
+ @notice_handler = self.method(:notice_handler),
981
+ @error_handler = self.method(:error_handler)
982
+ ),
983
+ self.class.method(:release)
981
984
  )
985
+ end
982
986
 
983
- Kernel.at_exit {
984
- FFIGeos.finishGEOS_r(@ptr)
985
- }
987
+ def self.release(ptr)
988
+ FFIGeos.finishGEOS_r(ptr)
986
989
  end
987
990
 
988
991
  def notice_handler(*args)
@@ -8,13 +8,18 @@ module Geos
8
8
 
9
9
  # For internal use. Geometry objects should be created via WkbReader,
10
10
  # WktReader and the various Geos.create_* methods.
11
- def initialize(ptr, auto_free = true)
11
+ def initialize(ptr, options = {})
12
+ options = {
13
+ :auto_free => true
14
+ }.merge(options)
15
+
12
16
  @ptr = FFI::AutoPointer.new(
13
17
  ptr,
14
18
  self.class.method(:release)
15
19
  )
16
20
 
17
- @ptr.autorelease = auto_free
21
+ @ptr.autorelease = !!options[:auto_free]
22
+ @parent = options[:parent] if options[:parent]
18
23
  end
19
24
 
20
25
  def initialize_copy(source)
@@ -5,5 +5,9 @@ module Geos
5
5
  def to_polygon
6
6
  Geos.create_polygon(self, :srid => pick_srid_according_to_policy(self.srid))
7
7
  end
8
+
9
+ def to_line_string
10
+ Geos.create_line_string(self.coord_seq, :srid => pick_srid_according_to_policy(self.srid))
11
+ end
8
12
  end
9
13
  end
@@ -13,7 +13,8 @@ module Geos
13
13
  cast_geometry_ptr(
14
14
  FFIGeos.GEOSGetInteriorRingN_r(Geos.current_handle, self.ptr, n), {
15
15
  :auto_free => false,
16
- :srid_copy => self.srid
16
+ :srid_copy => self.srid,
17
+ :parent => self
17
18
  }
18
19
  )
19
20
  end
@@ -24,7 +25,8 @@ module Geos
24
25
  cast_geometry_ptr(
25
26
  FFIGeos.GEOSGetExteriorRing_r(Geos.current_handle, self.ptr), {
26
27
  :auto_free => false,
27
- :srid_copy => self.srid
28
+ :srid_copy => self.srid,
29
+ :parent => self
28
30
  }
29
31
  )
30
32
  end
@@ -8,21 +8,20 @@ module Geos
8
8
 
9
9
  undef :clone, :dup
10
10
 
11
- def initialize(geom, auto_free = true)
11
+ def initialize(geom, options = {})
12
12
  check_geometry(geom)
13
13
 
14
+ options = {
15
+ :auto_free => true
16
+ }.merge(options)
17
+
14
18
  @ptr = FFI::AutoPointer.new(
15
19
  FFIGeos.GEOSPrepare_r(Geos.current_handle, geom.ptr),
16
- auto_free ? self.class.method(:release) : self.class.method(:no_release)
20
+ self.class.method(:release)
17
21
  )
18
22
  @geometry = geom
19
23
 
20
- if !auto_free
21
- @ptr.autorelease = false
22
- end
23
- end
24
-
25
- def self.no_release(ptr) #:nodoc:
24
+ @ptr.autorelease = !!options[:auto_free]
26
25
  end
27
26
 
28
27
  def self.release(ptr) #:nodoc:
@@ -34,7 +34,7 @@ module Geos
34
34
  raise RuntimeError.new("Invalid geometry type")
35
35
  end
36
36
 
37
- klass.new(geom_ptr, options[:auto_free]).tap { |ret|
37
+ klass.new(geom_ptr, options).tap { |ret|
38
38
  if options[:srid]
39
39
  ret.srid = options[:srid] || 0
40
40
  elsif options[:srid_copy]
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Geos
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.1"
5
5
  end
6
6
 
@@ -6,11 +6,23 @@ require 'test_helper'
6
6
  class LinearRingTests < MiniTest::Unit::TestCase
7
7
  include TestHelper
8
8
 
9
+ def setup
10
+ super
11
+ writer.trim = true
12
+ end
13
+
9
14
  def test_to_polygon
10
15
  geom = read('POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))')
11
16
  ring = geom.exterior_ring
12
17
 
13
- assert_equal(write(geom), write(ring.to_polygon))
18
+ assert_equal('POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))', write(ring.to_polygon))
19
+ end
20
+
21
+ def test_to_line_string
22
+ geom = read('POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))')
23
+ ring = geom.exterior_ring
24
+
25
+ assert_equal('LINESTRING (0 0, 5 0, 5 5, 0 5, 0 0)', write(ring.to_line_string))
14
26
  end
15
27
 
16
28
  def test_to_polygon_with_srid
metadata CHANGED
@@ -1,29 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-geos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ prerelease:
5
+ version: 0.2.1
5
6
  platform: ruby
6
7
  authors:
7
8
  - J Smith
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-05-21 00:00:00.000000000 Z
12
+ date: 2013-08-02 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
15
+ name: ffi
16
+ type: :runtime
14
17
  requirement: !ruby/object:Gem::Requirement
18
+ none: false
15
19
  requirements:
16
20
  - - ! '>='
17
21
  - !ruby/object:Gem::Version
18
22
  version: 1.0.0
23
+ prerelease: false
19
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ! '>='
22
28
  - !ruby/object:Gem::Version
23
29
  version: 1.0.0
24
- type: :runtime
25
- prerelease: false
26
- name: ffi
27
30
  description: An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).
28
31
  email: dark.panda@gmail.com
29
32
  executables: []
@@ -78,26 +81,27 @@ files:
78
81
  - test/wkt_writer_tests.rb
79
82
  homepage: http://github.com/dark-panda/ffi-geos
80
83
  licenses: []
81
- metadata: {}
82
84
  post_install_message:
83
85
  rdoc_options: []
84
86
  require_paths:
85
87
  - lib
86
88
  required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
87
90
  requirements:
88
91
  - - ! '>='
89
92
  - !ruby/object:Gem::Version
90
93
  version: '0'
91
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
92
96
  requirements:
93
97
  - - ! '>='
94
98
  - !ruby/object:Gem::Version
95
99
  version: '0'
96
100
  requirements: []
97
101
  rubyforge_project:
98
- rubygems_version: 2.0.3
102
+ rubygems_version: 1.8.23
99
103
  signing_key:
100
- specification_version: 4
104
+ specification_version: 3
101
105
  summary: An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).
102
106
  test_files:
103
107
  - test/coordinate_sequence_tests.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OTIxMDI2MjAzYTBlNmI2MTJlNDU2NzVkN2I2ZGJhY2U5MmVmMWNmYQ==
5
- data.tar.gz: !binary |-
6
- MjY3YWI1MzAzMTNkZDhlNDEyMzRkNTlmOGE1NzA5MWQ3NzliNWU1Yw==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZjRhYjc0ZDdjMWE3YzllYmRlYmQ4MmZjMDM1MWFhNTZjNTFjOTUzNWY0YmFm
10
- ODcxNzY0MTBkOWVhNmUxNzdjZjE2ZTZiOTA4YTM2OGI5YTRiNDgzMWM4Mzdk
11
- YWQ3NWNjOThmM2VlOThmMTI4YmQwNDQyMjcxOTMzOWZkMjcwNGE=
12
- data.tar.gz: !binary |-
13
- YjU2NTI1NjZjM2VhNDE0ZmI4Y2NlMzhmYmEwNzY3OWQzNjk3NWY4ZmE1MDhl
14
- NzAxOGJlYmJmZWIxMTcyZTlmZGI1YzBmODMwNmFmM2Y2MDBhZTZjZGFiMzUz
15
- MTljMGQ3NThjYTYxMTdlODYyMWQzMjhjMjIwMGRmNWFmMzNlOTM=