geos-extensions 0.0.4 → 0.0.5
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/Rakefile +1 -1
- data/geos-extensions.gemspec +5 -3
- data/lib/active_record_extensions/geometry_columns.rb +10 -4
- data/lib/geos-extensions.rb +5 -0
- data/lib/geos_extensions.rb +1 -1
- data/rails/railtie.rb +11 -0
- data/rails/tasks/test.rake +42 -0
- data/test/geospatial_scopes_test.rb +14 -14
- metadata +7 -5
data/Rakefile
CHANGED
data/geos-extensions.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{geos-extensions}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["J Smith"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-03-15}
|
13
13
|
s.description = %q{Extensions for the GEOS library.}
|
14
14
|
s.email = %q{code@zoocasa.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -29,6 +29,8 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/geos_helper.rb",
|
30
30
|
"lib/google_maps.rb",
|
31
31
|
"lib/google_maps/polyline_encoder.rb",
|
32
|
+
"rails/railtie.rb",
|
33
|
+
"rails/tasks/test.rake",
|
32
34
|
"test/fixtures/foos.yml",
|
33
35
|
"test/geometry_columns_test.rb",
|
34
36
|
"test/geospatial_scopes_test.rb",
|
@@ -38,7 +40,7 @@ Gem::Specification.new do |s|
|
|
38
40
|
]
|
39
41
|
s.homepage = %q{http://github.com/zoocasa/geos-extensions}
|
40
42
|
s.require_paths = ["lib"]
|
41
|
-
s.rubygems_version = %q{1.
|
43
|
+
s.rubygems_version = %q{1.6.2}
|
42
44
|
s.summary = %q{Extensions for the GEOS library.}
|
43
45
|
s.test_files = [
|
44
46
|
"test/geometry_columns_test.rb",
|
@@ -62,6 +62,12 @@ module Geos
|
|
62
62
|
@geometry_columns
|
63
63
|
end
|
64
64
|
|
65
|
+
# Force a reload of available geometry columns.
|
66
|
+
def geometry_columns!
|
67
|
+
@geometry_columns = nil
|
68
|
+
geometry_columns
|
69
|
+
end
|
70
|
+
|
65
71
|
# Grabs a geometry column based on name.
|
66
72
|
def geometry_column_by_name(name)
|
67
73
|
@geometry_column_by_name ||= self.geometry_columns.inject(HashWithIndifferentAccess.new) do |memo, obj|
|
@@ -117,12 +123,12 @@ module Geos
|
|
117
123
|
src, line = <<-EOF, __LINE__ + 1
|
118
124
|
def #{k.name}=(geom)
|
119
125
|
geos = case geom
|
120
|
-
when /^SRID=default;/
|
121
|
-
if #{k.
|
122
|
-
geom = geom.sub(/default
|
126
|
+
when /^SRID=default;/i
|
127
|
+
if srid = self.class.srid_for(#{k.name.inspect})
|
128
|
+
geom = geom.sub(/default/i, srid.to_s)
|
123
129
|
Geos.from_wkt(geom)
|
124
130
|
else
|
125
|
-
raise SRIDNotFound.new(self.table_name, #{k.name})
|
131
|
+
raise SRIDNotFound.new(self.class.table_name, #{k.name.inspect})
|
126
132
|
end
|
127
133
|
else
|
128
134
|
Geos.read(geom)
|
data/lib/geos-extensions.rb
CHANGED
@@ -6,3 +6,8 @@ if defined?(ActiveRecord)
|
|
6
6
|
require File.join(GEOS_EXTENSIONS_BASE, *%w{ active_record_extensions geometry_columns })
|
7
7
|
require File.join(GEOS_EXTENSIONS_BASE, *%w{ active_record_extensions geospatial_scopes })
|
8
8
|
end
|
9
|
+
|
10
|
+
if defined?(Rails)
|
11
|
+
require File.join(File.dirname(__FILE__), %w{ .. rails railtie })
|
12
|
+
end
|
13
|
+
|
data/lib/geos_extensions.rb
CHANGED
data/rails/railtie.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
namespace :test do
|
3
|
+
desc "Dumps data from the geometry_columns and spatial_ref_sys tables."
|
4
|
+
task :postgis_dump do
|
5
|
+
abcs = ActiveRecord::Base.configurations
|
6
|
+
ENV['PGHOST'] = abcs[Rails.env]["host"] if abcs[Rails.env]["host"]
|
7
|
+
ENV['PGPORT'] = abcs[Rails.env]["port"].to_s if abcs[Rails.env]["port"]
|
8
|
+
ENV['PGPASSWORD'] = abcs[Rails.env]["password"].to_s if abcs[Rails.env]["password"]
|
9
|
+
search_path = abcs[Rails.env]["schema_search_path"]
|
10
|
+
unless search_path.blank?
|
11
|
+
search_path = search_path.split(",").map{|search_path| "--schema=#{search_path.strip}" }.join(" ")
|
12
|
+
end
|
13
|
+
|
14
|
+
tables = %w{ geometry_columns spatial_ref_sys }.select do |table|
|
15
|
+
ActiveRecord::Base.connection.table_exists?(table)
|
16
|
+
end
|
17
|
+
|
18
|
+
unless tables.empty?
|
19
|
+
`pg_dump -i -U "#{abcs[Rails.env]["username"]}" --data-only -t #{tables.join(' -t ')} -x -O -f db/#{Rails.env}_postgis_tables.sql #{search_path} #{abcs[Rails.env]["database"]}`
|
20
|
+
else
|
21
|
+
File.open("db/#{Rails.env}_postgis_tables.sql", 'w') do |fp|
|
22
|
+
fp.puts "-- empty, do geometry_columns and spatial_ref_sys tables exist?"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "Loads the geometry_columns and spatial_ref_sys tables."
|
28
|
+
task :postgis_load do
|
29
|
+
abcs = ActiveRecord::Base.configurations
|
30
|
+
ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
|
31
|
+
ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
|
32
|
+
ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
|
33
|
+
|
34
|
+
`psql -U "#{abcs["test"]["username"]}" -f #{Rails.root}/db/#{Rails.env}_postgis_tables.sql #{abcs["test"]["database"]}`
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Dumps and loads the geometry_columns and spatial_ref_sys_tables."
|
38
|
+
task :postgis_clone => [ :postgis_dump, :postgis_load ]
|
39
|
+
end
|
40
|
+
|
41
|
+
Rake::Task['test:prepare'].enhance(['test:postgis_clone'])
|
42
|
+
|
@@ -10,61 +10,61 @@ if ENV['TEST_ACTIVERECORD']
|
|
10
10
|
self.fixture_path = File.join(File.dirname(__FILE__), 'fixtures')
|
11
11
|
fixtures :foos
|
12
12
|
|
13
|
-
def
|
13
|
+
def ids_tester(method, args, ids = [])
|
14
14
|
geoms = Foo.send(method, *Array(args)).all
|
15
15
|
assert_equal(ids.sort, geoms.collect(&:id).sort)
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_contains
|
19
|
-
|
19
|
+
ids_tester(:st_contains, 'POINT(3 3)', [ 3 ])
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_containsproperly
|
23
|
-
|
23
|
+
ids_tester(:st_containsproperly, 'LINESTRING(-4 -4, 4 4)', [ 3 ])
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_covers
|
27
|
-
|
27
|
+
ids_tester(:st_covers, 'LINESTRING(-4 -4, 4 4)', [ 3 ])
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_coveredby
|
31
|
-
|
31
|
+
ids_tester(:st_coveredby, 'POLYGON((-6 -6, -6 6, 6 6, 6 -6, -6 -6))', [ 1, 3 ])
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_crosses
|
35
|
-
|
35
|
+
ids_tester(:st_crosses, 'LINESTRING(-6 -6, 4 4)', [ 3 ])
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_disjoint
|
39
|
-
|
39
|
+
ids_tester(:st_disjoint, 'POINT(100 100)', [ 1, 2, 3 ])
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_equal
|
43
|
-
|
43
|
+
ids_tester(:st_equals, 'POLYGON((-5 -5, -5 5, 5 5, 5 -5, -5 -5))', [ 3 ])
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_intersects
|
47
|
-
|
47
|
+
ids_tester(:st_intersects, 'LINESTRING(-5 -5, 10 10)', [ 1, 2, 3 ])
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_orderingequals
|
51
|
-
|
51
|
+
ids_tester(:st_orderingequals, 'POLYGON((-5 -5, -5 5, 5 5, 5 -5, -5 -5))', [ 3 ])
|
52
52
|
end
|
53
53
|
|
54
54
|
def test_overlaps
|
55
|
-
|
55
|
+
ids_tester(:st_overlaps, 'POLYGON((-6 -6, -5 0, 0 0, 0 -5, -6 -6))', [ 3 ])
|
56
56
|
end
|
57
57
|
|
58
58
|
def test_touches
|
59
|
-
|
59
|
+
ids_tester(:st_touches, 'POLYGON((-5 -5, -5 -10, -10 -10, -10 -5, -5 -5))', [ 3 ])
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_within
|
63
|
-
|
63
|
+
ids_tester(:st_within, 'POLYGON((-5 -5, 5 10, 20 20, 10 5, -5 -5))', [ 1, 2 ])
|
64
64
|
end
|
65
65
|
|
66
66
|
def test_dwithin
|
67
|
-
|
67
|
+
ids_tester(:st_dwithin, [ 'POINT(5 5)', 10 ], [ 1, 2, 3 ])
|
68
68
|
end
|
69
69
|
|
70
70
|
def test_with_column
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geos-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- J Smith
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-15 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -41,6 +41,8 @@ files:
|
|
41
41
|
- lib/geos_helper.rb
|
42
42
|
- lib/google_maps.rb
|
43
43
|
- lib/google_maps/polyline_encoder.rb
|
44
|
+
- rails/railtie.rb
|
45
|
+
- rails/tasks/test.rake
|
44
46
|
- test/fixtures/foos.yml
|
45
47
|
- test/geometry_columns_test.rb
|
46
48
|
- test/geospatial_scopes_test.rb
|
@@ -77,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
79
|
requirements: []
|
78
80
|
|
79
81
|
rubyforge_project:
|
80
|
-
rubygems_version: 1.
|
82
|
+
rubygems_version: 1.6.2
|
81
83
|
signing_key:
|
82
84
|
specification_version: 3
|
83
85
|
summary: Extensions for the GEOS library.
|