ffi-geos 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -146,3 +146,6 @@ Ruby bindings along with the following enhancements and additions:
146
146
  * Christopher Meiklejohn for the bug reporting and PreparedGeometry fix.
147
147
 
148
148
  * Wayne Meissner for some help with some ffi issues.
149
+
150
+ * Charlie Savage for the original SWIG-based GEOS bindings implementation and
151
+ some fixes for MinGW.
data/Rakefile CHANGED
@@ -4,7 +4,7 @@
4
4
  require 'rubygems'
5
5
  require 'rubygems/package_task'
6
6
  require 'rake/testtask'
7
- require 'rdoc/task'
7
+ require 'rake/rdoctask'
8
8
 
9
9
  $:.push 'lib'
10
10
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/ffi-geos.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ffi-geos}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["J Smith"]
12
- s.date = %q{2011-07-22}
11
+ s.authors = [%q{J Smith}]
12
+ s.date = %q{2011-08-22}
13
13
  s.description = %q{An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).}
14
14
  s.email = %q{dark.panda@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -55,8 +55,8 @@ Gem::Specification.new do |s|
55
55
  "test/wkt_writer_tests.rb"
56
56
  ]
57
57
  s.homepage = %q{http://github.com/dark-panda/ffi-geos}
58
- s.require_paths = ["lib"]
59
- s.rubygems_version = %q{1.6.2}
58
+ s.require_paths = [%q{lib}]
59
+ s.rubygems_version = %q{1.8.8}
60
60
  s.summary = %q{An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).}
61
61
 
62
62
  if s.respond_to? :specification_version then
data/lib/ffi-geos.rb CHANGED
@@ -45,29 +45,32 @@ module Geos
45
45
  File.join(GEOS_BASE, 'utils')
46
46
 
47
47
  module FFIGeos
48
- def self.geos_library_paths
49
- return @geos_library_paths if @geos_library_paths
50
-
51
- paths = if ENV['GEOS_LIBRARY_PATH']
52
- [ ENV['GEOS_LIBRARY_PATH'] ]
53
- else
54
- [ '/usr/local/{lib64,lib}', '/opt/local/{lib64,lib}', '/usr/{lib64,lib}' ]
48
+ def self.search_paths
49
+ @search_paths ||= begin
50
+ if ENV['GEOS_LIBRARY_PATH']
51
+ [ ENV['GEOS_LIBRARY_PATH'] ]
52
+ elsif FFI::Platform::IS_WINDOWS
53
+ ENV['PATH'].split(File::PATH_SEPARATOR)
54
+ else
55
+ [ '/usr/local/{lib64,lib}', '/opt/local/{lib64,lib}', '/usr/{lib64,lib}' ]
56
+ end
55
57
  end
58
+ end
56
59
 
57
- libs = if [
58
- Config::CONFIG['arch'],
59
- Config::CONFIG['host_os']
60
- ].detect { |c| c =~ /darwin/ }
61
- %w{ libgeos_c.dylib libgeos.dylib }
62
- else
63
- %w{ libgeos.so libgeos_c.so }
64
- end
60
+ def self.find_lib(lib)
61
+ search_paths.inject(Array.new) { |array, path|
62
+ file_name = File.expand_path(File.join(path, "#{lib}.#{FFI::Platform::LIBSUFFIX}"))
63
+ array << Dir.glob(file_name)
64
+ }.flatten.sort.compact.first
65
+ end
65
66
 
66
- @geos_library_paths = libs.collect { |lib|
67
- Dir.glob(paths.collect { |path|
68
- "#{path}/#{lib}"
69
- }).first
70
- }
67
+ def self.geos_library_paths
68
+ @geos_library_paths ||= begin
69
+ # On MingW the libraries have version numbers
70
+ [ 'libgeos_c{,-?}', 'libgeos{,-?-?-?}' ].map { |lib|
71
+ find_lib(lib)
72
+ }.compact
73
+ end
71
74
  end
72
75
 
73
76
  extend ::FFI::Library
@@ -154,12 +154,20 @@ module Geos
154
154
  end
155
155
  alias :size :length
156
156
 
157
+ def empty?
158
+ self.length == 0
159
+ end
160
+
157
161
  def dimensions
158
162
  @dimensions ||= FFI::MemoryPointer.new(:int).tap { |ret|
159
163
  FFIGeos.GEOSCoordSeq_getDimensions_r(Geos.current_handle, self.ptr, ret)
160
164
  }.read_int
161
165
  end
162
166
 
167
+ def to_point
168
+ Geos.create_point(self)
169
+ end
170
+
163
171
  def to_linear_ring
164
172
  Geos.create_linear_ring(self)
165
173
  end
@@ -172,6 +180,12 @@ module Geos
172
180
  Geos.create_polygon(self)
173
181
  end
174
182
 
183
+ def to_s
184
+ self.entries.collect { |entry|
185
+ entry.join(' ')
186
+ }.join(', ')
187
+ end
188
+
175
189
  protected
176
190
 
177
191
  def check_bounds(idx) #:nodoc:
@@ -23,6 +23,9 @@ module Geos
23
23
  FFIGeos.GEOSGeom_clone_r(Geos.current_handle, source.ptr),
24
24
  self.class.method(:release)
25
25
  )
26
+
27
+ # Copy over SRID since GEOS does not
28
+ self.srid = source.srid
26
29
  end
27
30
 
28
31
  def self.no_release(ptr) #:nodoc:
@@ -123,6 +123,11 @@ class CoordinateSequenceTests < Test::Unit::TestCase
123
123
  end
124
124
  end
125
125
 
126
+ def test_to_point
127
+ cs = Geos::CoordinateSequence.new([5,7])
128
+ assert_equal('POINT (5 7)', write(cs.to_point, :trim => true))
129
+ end
130
+
126
131
  def test_to_to_linear_ring
127
132
  cs = Geos::CoordinateSequence.new([
128
133
  [ 0, 0 ],
@@ -135,6 +140,14 @@ class CoordinateSequenceTests < Test::Unit::TestCase
135
140
  assert_equal('LINEARRING (0 0, 0 5, 5 5, 5 0, 0 0)', write(cs.to_linear_ring, :trim => true))
136
141
  end
137
142
 
143
+ def test_empty
144
+ cs = Geos::CoordinateSequence.new
145
+ assert(cs.empty?)
146
+
147
+ cs = Geos::CoordinateSequence.new([4,1])
148
+ assert(!cs.empty?)
149
+ end
150
+
138
151
  def test_to_empty_linear_ring
139
152
  cs = Geos::CoordinateSequence.new
140
153
 
@@ -175,4 +188,12 @@ class CoordinateSequenceTests < Test::Unit::TestCase
175
188
 
176
189
  assert_equal('POLYGON EMPTY', write(cs.to_polygon, :trim => true))
177
190
  end
191
+
192
+ def test_to_s
193
+ cs = Geos::CoordinateSequence.new([[1, 2], [10, 11]])
194
+ assert_equal("1.0 2.0, 10.0 11.0", cs.to_s)
195
+
196
+ cs = Geos::CoordinateSequence.new([[1, 2, 3], [10, 11, 12]])
197
+ assert_equal("1.0 2.0 3.0, 10.0 11.0 12.0", cs.to_s)
198
+ end
178
199
  end
@@ -1524,6 +1524,16 @@ class GeometryTests < Test::Unit::TestCase
1524
1524
  assert(geom_a.eql?(geom_b))
1525
1525
  end
1526
1526
 
1527
+ def test_clone_srid
1528
+ srid = 4326
1529
+ geom_a = read('POINT(0 0)')
1530
+ geom_a.srid = srid
1531
+ geom_b = geom_a.clone
1532
+
1533
+ assert(geom_a.eql?(geom_b))
1534
+ assert_equal(srid, geom_b.srid)
1535
+ end
1536
+
1527
1537
  def test_dup
1528
1538
  geom_a = read('POINT(0 0)')
1529
1539
  geom_b = geom_a.dup
@@ -1531,6 +1541,15 @@ class GeometryTests < Test::Unit::TestCase
1531
1541
  assert(geom_a.eql?(geom_b))
1532
1542
  end
1533
1543
 
1544
+ def test_dup_srid
1545
+ srid = 4326
1546
+ geom_a = read('POINT(0 0)')
1547
+ geom_a.srid = srid
1548
+ geom_b = geom_a.dup
1549
+ assert(geom_a.eql?(geom_b))
1550
+ assert_equal(srid, geom_b.srid)
1551
+ end
1552
+
1534
1553
  def test_geometry_collection_enumerator
1535
1554
  geom = read('GEOMETRYCOLLECTION(POINT(0 0))')
1536
1555
  assert_kind_of(Enumerable, geom.each)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-geos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-22 00:00:00.000000000 -04:00
13
- default_executable:
12
+ date: 2011-08-22 00:00:00.000000000Z
14
13
  dependencies: []
15
14
  description: An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).
16
15
  email: dark.panda@gmail.com
@@ -56,7 +55,6 @@ files:
56
55
  - test/wkb_writer_tests.rb
57
56
  - test/wkt_reader_tests.rb
58
57
  - test/wkt_writer_tests.rb
59
- has_rdoc: true
60
58
  homepage: http://github.com/dark-panda/ffi-geos
61
59
  licenses: []
62
60
  post_install_message:
@@ -77,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
75
  version: '0'
78
76
  requirements: []
79
77
  rubyforge_project:
80
- rubygems_version: 1.6.2
78
+ rubygems_version: 1.8.8
81
79
  signing_key:
82
80
  specification_version: 3
83
81
  summary: An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).