geos-extensions 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ .*.swp
2
+ .*.swo
3
+ *.tmp
4
+ *.kpf
5
+ *.komodoproject
6
+ *~
7
+ .DS_Store
8
+ *tmp*
9
+ pkg/
10
+ doc/
11
+ *.orig
12
+ *.patch
13
+ .vimrc_local
14
+ debug.log
15
+ test/local_database.yml
16
+ *.gem
17
+ *.rbc
18
+ .bundle
19
+ .config
20
+ .yardoc
21
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 2167961 Ontario Inc., Zoocasa <code@zoocasa.com>
1
+ Copyright (c) 2012 2167961 Ontario Inc., Zoocasa <code@zoocasa.com>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation
data/README.rdoc CHANGED
@@ -10,10 +10,16 @@ extend the GEOS Ruby bindings module. From http://geos.refractions.net/ ...
10
10
  predicate functions and spatial operators, as well as specific JTS
11
11
  enhanced topology functions.
12
12
 
13
- The GEOS bindings for Ruby can be installed by installing the GEOS library
14
- itself using the --enable-ruby switch during configure or can often be
15
- installed via package managers. There is also an FFI-based Ruby gem being
16
- written available at https://github.com/dark-panda/ffi-geos .
13
+ The GEOS bindings for Ruby come in two flavours these days: the native
14
+ version bundled with the GEOS source itself and an FFI version. The
15
+ native bindings seem to be rather abandoned these days while the FFI
16
+ bindings are actively maintained by... well, the author of this gem,
17
+ actually. We're going to effectively deprecate the use of the native
18
+ bindings for the purposes of this gem and recommend that the FFI bindings
19
+ be used instead and as such the ffi-geos gem will now become a dependency
20
+ in the geos-extensions gemspec.
21
+
22
+ The ffi-geos gem is available at https://github.com/dark-panda/ffi-geos .
17
23
 
18
24
  ZGEL contains a number of enhancements to the GEOS Ruby library:
19
25
 
data/Rakefile CHANGED
@@ -8,6 +8,7 @@ gem 'rdoc', '~> 3.12'
8
8
  require 'rubygems/package_task'
9
9
  require 'rake/testtask'
10
10
  require 'rdoc/task'
11
+ require 'bundler/gem_tasks'
11
12
 
12
13
  if RUBY_VERSION >= '1.9'
13
14
  begin
@@ -19,27 +20,13 @@ end
19
20
 
20
21
  $:.push 'lib'
21
22
 
22
- version = File.read('VERSION') rescue ''
23
-
24
- begin
25
- require 'jeweler'
26
- Jeweler::Tasks.new do |gem|
27
- gem.name = "geos-extensions"
28
- gem.summary = "Extensions for the GEOS library."
29
- gem.description = gem.summary
30
- gem.email = "code@zoocasa.com"
31
- gem.homepage = "http://github.com/zoocasa/geos-extensions"
32
- gem.authors = [ "J Smith" ]
33
- end
34
- Jeweler::GemcutterTasks.new
35
- rescue LoadError
36
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
37
- end
23
+ version = Geos::Extensions::VERSION
38
24
 
39
25
  desc 'Test GEOS interface'
40
26
  Rake::TestTask.new(:test) do |t|
41
27
  t.test_files = FileList['test/**/*_tests.rb']
42
- t.verbose = false
28
+ t.verbose = !!ENV['VERBOSE_TESTS']
29
+ t.warning = !!ENV['WARNINGS']
43
30
  end
44
31
 
45
32
  desc 'Build docs'
@@ -1,70 +1,30 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
5
2
 
3
+ require File.expand_path('../lib/geos/extensions/version', __FILE__)
4
+
6
5
  Gem::Specification.new do |s|
7
6
  s.name = "geos-extensions"
8
- s.version = "0.2.0"
7
+ s.version = Geos::Extensions::VERSION
9
8
 
10
9
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
10
  s.authors = ["J Smith"]
12
- s.date = "2012-05-23"
13
11
  s.description = "Extensions for the GEOS library."
12
+ s.summary = s.description
14
13
  s.email = "code@zoocasa.com"
15
14
  s.extra_rdoc_files = [
16
15
  "README.rdoc"
17
16
  ]
18
- s.files = [
19
- "MIT-LICENSE",
20
- "README.rdoc",
21
- "Rakefile",
22
- "VERSION",
23
- "app/models/geos/geometry_column.rb",
24
- "app/models/geos/spatial_ref_sys.rb",
25
- "geos-extensions.gemspec",
26
- "lib/geos-extensions.rb",
27
- "lib/geos/active_record_extensions.rb",
28
- "lib/geos/active_record_extensions/connection_adapters/postgresql_adapter.rb",
29
- "lib/geos/active_record_extensions/spatial_columns.rb",
30
- "lib/geos/active_record_extensions/spatial_scopes.rb",
31
- "lib/geos/geos_helper.rb",
32
- "lib/geos/google_maps.rb",
33
- "lib/geos/google_maps/api_2.rb",
34
- "lib/geos/google_maps/api_3.rb",
35
- "lib/geos/google_maps/polyline_encoder.rb",
36
- "lib/geos/rails/engine.rb",
37
- "lib/geos_extensions.rb",
38
- "lib/tasks/test.rake",
39
- "test/adapter_tests.rb",
40
- "test/database.yml",
41
- "test/fixtures/foo3ds.yml",
42
- "test/fixtures/foo_geographies.yml",
43
- "test/fixtures/foos.yml",
44
- "test/geography_columns_tests.rb",
45
- "test/geometry_columns_tests.rb",
46
- "test/google_maps_api_2_tests.rb",
47
- "test/google_maps_api_3_tests.rb",
48
- "test/google_maps_polyline_encoder_tests.rb",
49
- "test/misc_tests.rb",
50
- "test/reader_tests.rb",
51
- "test/spatial_scopes_geographies_tests.rb",
52
- "test/spatial_scopes_tests.rb",
53
- "test/test_helper.rb",
54
- "test/writer_tests.rb"
55
- ]
17
+ s.files = `git ls-files`.split($\)
18
+ s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) }
19
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
56
20
  s.homepage = "http://github.com/zoocasa/geos-extensions"
57
21
  s.require_paths = ["lib"]
58
- s.rubygems_version = "1.8.24"
59
- s.summary = "Extensions for the GEOS library."
60
-
61
- if s.respond_to? :specification_version then
62
- s.specification_version = 3
63
22
 
64
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
65
- else
66
- end
67
- else
68
- end
23
+ s.add_dependency("activerecord", [">= 2.3"])
24
+ s.add_dependency("ffi", ["~> 1.0.0"])
25
+ s.add_dependency("ffi-geos", ["~> 0.0.4"])
26
+ s.add_dependency("pg")
27
+ s.add_dependency("rdoc")
28
+ s.add_dependency("rake", ["~> 0.9"])
69
29
  end
70
30
 
@@ -104,19 +104,22 @@ module Geos
104
104
 
105
105
  %w{ geometry geography }.each do |m|
106
106
  src, line = <<-EOF, __LINE__ + 1
107
+ undef :#{m}_columns
107
108
  def #{m}_columns
108
- if @#{m}_columns.nil?
109
+ if !defined?(@#{m}_columns) || @#{m}_columns.nil?
109
110
  @#{m}_columns = connection.#{m}_columns(self.table_name)
110
111
  @#{m}_columns.freeze
111
112
  end
112
113
  @#{m}_columns
113
114
  end
114
115
 
116
+ undef :#{m}_columns!
115
117
  def #{m}_columns!
116
118
  @#{m}_columns = nil
117
119
  #{m}_columns
118
120
  end
119
121
 
122
+ undef :#{m}_column_by_name
120
123
  def #{m}_column_by_name(name)
121
124
  @#{m}_column_by_name ||= self.#{m}_columns.inject(HashWithIndifferentAccess.new) do |memo, obj|
122
125
  memo[obj.name] = obj
@@ -339,12 +339,14 @@ module Geos
339
339
  #{SCOPE_METHOD} :st_#{relationship}, lambda { |*args|
340
340
  assert_arguments_length(args, 1, 2)
341
341
 
342
- {
343
- :conditions => build_function_call(
344
- '#{relationship}',
345
- *args
346
- )
347
- }
342
+ unless args.first.nil?
343
+ {
344
+ :conditions => build_function_call(
345
+ '#{relationship}',
346
+ *args
347
+ )
348
+ }
349
+ end
348
350
  }
349
351
  EOF
350
352
  base.class_eval(src, __FILE__, line)
@@ -0,0 +1,7 @@
1
+
2
+ module Geos
3
+ module Extensions
4
+ VERSION = "0.2.1"
5
+ end
6
+ end
7
+
@@ -46,9 +46,6 @@ module Geos
46
46
  lng = 0
47
47
 
48
48
  while (index < encoded.length)
49
- shift = 0
50
- result = 0
51
-
52
49
  index, lat = decode_number(encoded, lat, index)
53
50
  index, lng = decode_number(encoded, lng, index)
54
51
 
@@ -99,4 +96,3 @@ module Geos
99
96
  end
100
97
  end
101
98
  end
102
-
@@ -8,10 +8,12 @@ end
8
8
 
9
9
  require 'geos' unless defined?(Geos)
10
10
 
11
+ require File.join(File.dirname(__FILE__), *%w{ geos extensions version })
12
+
11
13
  # Some custom extensions to the SWIG-based Geos Ruby extension.
12
14
  module Geos
13
15
  GEOS_EXTENSIONS_BASE = File.join(File.dirname(__FILE__))
14
- GEOS_EXTENSIONS_VERSION = File.read(File.join(GEOS_EXTENSIONS_BASE, %w{ .. VERSION })).strip rescue nil
16
+ GEOS_EXTENSIONS_VERSION = Geos::Extensions::VERSION
15
17
 
16
18
  autoload :Helper, File.join(GEOS_EXTENSIONS_BASE, *%w{ geos geos_helper })
17
19
  autoload :ActiveRecord, File.join(GEOS_EXTENSIONS_BASE, *%w{ geos active_record_extensions })
@@ -43,6 +45,14 @@ module Geos
43
45
  \)?
44
46
  $/x
45
47
 
48
+ REGEXP_BOX2D = /^
49
+ BOX\s*\(\s*
50
+ #{REGEXP_FLOAT}\s+#{REGEXP_FLOAT}
51
+ \s*,\s*
52
+ #{REGEXP_FLOAT}\s+#{REGEXP_FLOAT}
53
+ \s*\)
54
+ $/mix
55
+
46
56
  def self.wkb_reader_singleton
47
57
  Thread.current[:geos_extensions_wkb_reader] ||= WkbReader.new
48
58
  end
@@ -73,6 +83,8 @@ module Geos
73
83
  Geos.from_wkb(geom)
74
84
  when REGEXP_G_LAT_LNG_BOUNDS, REGEXP_G_LAT_LNG
75
85
  Geos.from_g_lat_lng(geom, options)
86
+ when REGEXP_BOX2D
87
+ Geos.from_box2d(geom)
76
88
  when String
77
89
  Geos.from_wkb(geom.unpack('H*').first.upcase)
78
90
  when nil
@@ -146,6 +158,23 @@ module Geos
146
158
  self.from_g_lat_lng(geometry, options.merge(:points => true))
147
159
  end
148
160
 
161
+ # Creates a Geometry from a PostGIS-style BOX string.
162
+ def self.from_box2d(geometry)
163
+ if geometry =~ REGEXP_BOX2D
164
+ coords = []
165
+ $~.captures.compact.each_slice(2) { |f|
166
+ coords << f.collect(&:to_f)
167
+ }
168
+
169
+ Geos.from_wkt("LINESTRING(%s, %s)" % [
170
+ coords[0].join(' '),
171
+ coords[1].join(' ')
172
+ ]).envelope
173
+ else
174
+ raise "Invalid BOX2D"
175
+ end
176
+ end
177
+
149
178
  # This is our base module that we use for some generic methods used all
150
179
  # over the place.
151
180
  class Geometry
@@ -371,7 +400,7 @@ module Geos
371
400
  # Build some XmlMarkup for GeoRSS GML. You should include the
372
401
  # appropriate georss and gml XML namespaces in your document.
373
402
  def to_georss *args
374
- xml, options = Geos::Helper.xml_options(*args)
403
+ xml = Geos::Helper.xml_options(*args)[0]
375
404
 
376
405
  xml.georss(:where) do
377
406
  xml.gml(:LineString) do
@@ -507,7 +536,7 @@ module Geos
507
536
  # Build some XmlMarkup for GeoRSS. You should include the
508
537
  # appropriate georss and gml XML namespaces in your document.
509
538
  def to_georss *args
510
- xml, options = Geos::Helper.xml_options(*args)
539
+ xml = Geos::Helper.xml_options(*args)[0]
511
540
  xml.georss(:where) do
512
541
  xml.gml(:Point) do
513
542
  xml.gml(:pos, "#{self.lat} #{self.lng}")
@@ -583,7 +612,7 @@ module Geos
583
612
  # Build some XmlMarkup for GeoRSS. You should include the
584
613
  # appropriate georss and gml XML namespaces in your document.
585
614
  def to_georss *args
586
- xml, options = Geos::Helper.xml_options(*args)
615
+ xml = Geos::Helper.xml_options(*args)[0]
587
616
 
588
617
  xml.georss(:where) do
589
618
  xml.gml(:Polygon) do
@@ -147,7 +147,7 @@ if ENV['TEST_ACTIVERECORD']
147
147
  end
148
148
 
149
149
  def test_create_with_converting_from_900913_to_4326
150
- foo = FooGeography.create!(
150
+ FooGeography.create!(
151
151
  :name => 'test_create_with_converting_from_900913_to_4326',
152
152
  :the_other_geom => "SRID=900913; #{POINT_WKT}"
153
153
  )
@@ -148,7 +148,7 @@ if ENV['TEST_ACTIVERECORD']
148
148
 
149
149
  def test_create_with_converting_from_900913_to_4326
150
150
  assert_raise(Geos::ActiveRecord::GeometryColumns::CantConvertSRID) do
151
- foo = Foo.create!(
151
+ Foo.create!(
152
152
  :name => 'test_create_with_converting_from_900913_to_4326',
153
153
  :the_other_geom => "SRID=900913; #{POINT_WKT}"
154
154
  )
@@ -192,7 +192,7 @@ class GoogleMapsApi3Tests < Test::Unit::TestCase
192
192
  def test_to_g_marker
193
193
  marker = @point.to_g_marker
194
194
 
195
- lat, lng, json = if marker =~ /^new\s+
195
+ lat, lng = if marker =~ /^new\s+
196
196
  google\.maps\.Marker\(\{
197
197
  "position":\s*
198
198
  new\s+google\.maps\.LatLng\(
@@ -201,7 +201,7 @@ class GoogleMapsApi3Tests < Test::Unit::TestCase
201
201
  \)
202
202
  \}\)
203
203
  /x
204
- [ $1, $2, $3 ]
204
+ [ $1, $2 ]
205
205
  end
206
206
 
207
207
  assert_in_delta(10.00, lng.to_f, 0.000001)
data/test/reader_tests.rb CHANGED
@@ -141,4 +141,11 @@ class GeosReaderTests < Test::Unit::TestCase
141
141
  def test_no_leading_digits
142
142
  assert_equal('POINT (0.01 0.02)', Geos.read('.02, .01').to_wkt(:trim => true))
143
143
  end
144
+
145
+ def test_from_box2d
146
+ assert_equal('POLYGON ((10 54, 123 54, 123 79, 10 79, 10 54))',
147
+ Geos.read('BOX(123.456 78.9, 9.876 54.321)').to_wkt(:rounding_precision => 0))
148
+
149
+ assert_equal('POINT (0 0)', Geos.read('BOX(0 0, 0 0)').to_wkt(:trim => true))
150
+ end
144
151
  end
@@ -86,6 +86,10 @@ if ENV['TEST_ACTIVERECORD']
86
86
  end
87
87
  end
88
88
 
89
+ def test_nil_relationship
90
+ assert_equal([ 1, 2, 3 ], Foo.st_within(nil).all.collect(&:id).sort)
91
+ end
92
+
89
93
  def test_with_column
90
94
  assert_equal([1, 2, 3], Foo.st_disjoint('POINT(100 100)', :column => :the_other_geom).all.collect(&:id).sort)
91
95
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geos-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,104 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-23 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-07-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '2.3'
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: '2.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: ffi
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.0.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: 1.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: ffi-geos
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.0.4
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.4
62
+ - !ruby/object:Gem::Dependency
63
+ name: pg
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
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
+ - !ruby/object:Gem::Dependency
79
+ name: rdoc
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rake
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '0.9'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '0.9'
14
110
  description: Extensions for the GEOS library.
15
111
  email: code@zoocasa.com
16
112
  executables: []
@@ -18,10 +114,11 @@ extensions: []
18
114
  extra_rdoc_files:
19
115
  - README.rdoc
20
116
  files:
117
+ - .gitignore
118
+ - Gemfile
21
119
  - MIT-LICENSE
22
120
  - README.rdoc
23
121
  - Rakefile
24
- - VERSION
25
122
  - app/models/geos/geometry_column.rb
26
123
  - app/models/geos/spatial_ref_sys.rb
27
124
  - geos-extensions.gemspec
@@ -30,6 +127,7 @@ files:
30
127
  - lib/geos/active_record_extensions/connection_adapters/postgresql_adapter.rb
31
128
  - lib/geos/active_record_extensions/spatial_columns.rb
32
129
  - lib/geos/active_record_extensions/spatial_scopes.rb
130
+ - lib/geos/extensions/version.rb
33
131
  - lib/geos/geos_helper.rb
34
132
  - lib/geos/google_maps.rb
35
133
  - lib/geos/google_maps/api_2.rb
@@ -74,8 +172,24 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
172
  version: '0'
75
173
  requirements: []
76
174
  rubyforge_project:
77
- rubygems_version: 1.8.24
175
+ rubygems_version: 1.8.23
78
176
  signing_key:
79
177
  specification_version: 3
80
178
  summary: Extensions for the GEOS library.
81
- test_files: []
179
+ test_files:
180
+ - test/adapter_tests.rb
181
+ - test/database.yml
182
+ - test/fixtures/foo3ds.yml
183
+ - test/fixtures/foo_geographies.yml
184
+ - test/fixtures/foos.yml
185
+ - test/geography_columns_tests.rb
186
+ - test/geometry_columns_tests.rb
187
+ - test/google_maps_api_2_tests.rb
188
+ - test/google_maps_api_3_tests.rb
189
+ - test/google_maps_polyline_encoder_tests.rb
190
+ - test/misc_tests.rb
191
+ - test/reader_tests.rb
192
+ - test/spatial_scopes_geographies_tests.rb
193
+ - test/spatial_scopes_tests.rb
194
+ - test/test_helper.rb
195
+ - test/writer_tests.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.0