nofxx-postgis_adapter 0.5.7 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/VERSION +1 -1
- data/lib/postgis_adapter/acts_as_geom.rb +18 -13
- data/lib/postgis_functions/common.rb +4 -4
- data/lib/postgis_functions.rb +3 -3
- data/postgis_adapter.gemspec +2 -2
- data/spec/db/models_postgis.rb +5 -5
- data/spec/postgis_adapter/acts_as_geom_spec.rb +1 -1
- data/spec/postgis_functions/common_spec.rb +10 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -79,7 +79,7 @@ Here are this fork additions. To use it:
|
|
79
79
|
|
80
80
|
|
81
81
|
class Street < ActiveRecord::Base
|
82
|
-
acts_as_geom :line
|
82
|
+
acts_as_geom :line => :line_string
|
83
83
|
end
|
84
84
|
|
85
85
|
...
|
@@ -324,7 +324,7 @@ Postgis Adapter is released under the MIT license.
|
|
324
324
|
|
325
325
|
== Support
|
326
326
|
|
327
|
-
Tested using rails 2.2.2/2.3.
|
327
|
+
Tested using rails 2.2.2/2.3.3 / postgresql 8.3.7 / postgis 1.3.3 / linux / osx
|
328
328
|
|
329
329
|
Any questions, enhancement proposals, bug notifications or corrections:
|
330
330
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
@@ -10,23 +10,28 @@ module PostgisFunctions
|
|
10
10
|
|
11
11
|
module ClassMethods
|
12
12
|
|
13
|
-
# acts_as_geom :
|
14
|
-
|
13
|
+
# acts_as_geom :db_field => :geom_type
|
14
|
+
# Examples:
|
15
|
+
#
|
16
|
+
# acts_as_geom :data => :point
|
17
|
+
# acts_as_geom :geom => :line_string
|
18
|
+
# acts_as_geom :geom => :polygon
|
19
|
+
#
|
20
|
+
def acts_as_geom(*geom)
|
15
21
|
cattr_accessor :postgis_geoms
|
16
|
-
self.postgis_geoms = {:columns =>
|
17
|
-
|
18
|
-
|
19
|
-
when :
|
20
|
-
when :
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
22
|
+
self.postgis_geoms = geom[0] # {:columns => column
|
23
|
+
send :include, case geom[0].values[0]
|
24
|
+
when :point then PointFunctions
|
25
|
+
when :polygon then PolygonFunctions
|
26
|
+
when :line_string then LineStringFunctions
|
27
|
+
end unless geom[0].kind_of? Symbol
|
24
28
|
end
|
25
29
|
|
26
30
|
def get_geom_type(column)
|
27
|
-
self.
|
28
|
-
|
29
|
-
|
31
|
+
self.postgis_geoms.values[0] rescue nil
|
32
|
+
# self.columns.select { |c| c.name == column.to_s }[0].geometry_type
|
33
|
+
# rescue ActiveRecord::StatementInvalid => e
|
34
|
+
# nil
|
30
35
|
end
|
31
36
|
end
|
32
37
|
end
|
@@ -438,7 +438,7 @@ module PostgisFunctions
|
|
438
438
|
# Return Geometry ST_Transform(geometry g1, integer srid);
|
439
439
|
#
|
440
440
|
def transform!(new_srid)
|
441
|
-
self[
|
441
|
+
self[postgis_geoms.keys[0]] = postgis_calculate("Transform", self.new_record? ? self.geom : self, new_srid)
|
442
442
|
end
|
443
443
|
|
444
444
|
def transform(new_srid)
|
@@ -461,7 +461,7 @@ module PostgisFunctions
|
|
461
461
|
# Returns the instance`s geom srid
|
462
462
|
#
|
463
463
|
def srid
|
464
|
-
self[
|
464
|
+
self[postgis_geoms.keys.first].srid
|
465
465
|
end
|
466
466
|
|
467
467
|
#
|
@@ -494,7 +494,7 @@ module PostgisFunctions
|
|
494
494
|
# Return Geometry
|
495
495
|
def to_utm!(utm=nil)
|
496
496
|
utm ||= utm_zone
|
497
|
-
self[
|
497
|
+
self[postgis_geoms.keys.first] = transform(utm)
|
498
498
|
end
|
499
499
|
|
500
500
|
def to_utm
|
@@ -792,7 +792,7 @@ module PostgisFunctions
|
|
792
792
|
# use 'length'. Measurements are in the units of the spatial reference system of
|
793
793
|
# the geometry.
|
794
794
|
#
|
795
|
-
# Accepts optional parameter, the
|
795
|
+
# Accepts optional parameter, the sridto transform to.
|
796
796
|
#
|
797
797
|
# Returns Float ST_Perimeter(geometry g1);
|
798
798
|
#
|
data/lib/postgis_functions.rb
CHANGED
@@ -22,8 +22,8 @@ module PostgisFunctions
|
|
22
22
|
def postgis_calculate(operation, subjects, options = {})
|
23
23
|
subjects = [subjects] unless subjects.respond_to?(:map)
|
24
24
|
return execute_geometrical_calculation(operation, subjects, options)
|
25
|
-
rescue Exception => e
|
26
|
-
raise StandardError, "#{e}"
|
25
|
+
#rescue Exception => e
|
26
|
+
#raise StandardError, "#{e}"
|
27
27
|
end
|
28
28
|
|
29
29
|
def geo_columns
|
@@ -44,7 +44,7 @@ module PostgisFunctions
|
|
44
44
|
|
45
45
|
tables = on_db.map do |t| {
|
46
46
|
:name => t.class.table_name,
|
47
|
-
:column => t.
|
47
|
+
:column => t.postgis_geoms.keys[0],
|
48
48
|
:uid => unique_identifier,
|
49
49
|
:id => t[:id] }
|
50
50
|
end
|
data/postgis_adapter.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{postgis_adapter}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.7.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Marcos Augusto"]
|
12
|
-
s.date = %q{2009-08-
|
12
|
+
s.date = %q{2009-08-16}
|
13
13
|
s.description = %q{Execute PostGIS functions on Active Record}
|
14
14
|
s.email = %q{x@nofxx.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/db/models_postgis.rb
CHANGED
@@ -41,21 +41,21 @@ class TableSrid4dPolygon < ActiveRecord::Base
|
|
41
41
|
end
|
42
42
|
|
43
43
|
class City < ActiveRecord::Base
|
44
|
-
acts_as_geom :geom
|
44
|
+
acts_as_geom :geom => :polygon
|
45
45
|
end
|
46
46
|
|
47
47
|
class Position < ActiveRecord::Base
|
48
|
-
acts_as_geom :geom
|
48
|
+
acts_as_geom :geom => :point
|
49
49
|
end
|
50
50
|
|
51
51
|
class Street < ActiveRecord::Base
|
52
|
-
acts_as_geom :geom
|
52
|
+
acts_as_geom :geom => :line_string
|
53
53
|
end
|
54
54
|
|
55
55
|
class CommonGeo < ActiveRecord::Base
|
56
|
-
acts_as_geom :geom
|
56
|
+
acts_as_geom :geom => :point
|
57
57
|
end
|
58
58
|
|
59
59
|
class DiffName < ActiveRecord::Base
|
60
|
-
acts_as_geom :the_geom
|
60
|
+
acts_as_geom :the_geom => :point
|
61
61
|
end
|
@@ -3,7 +3,8 @@ require File.dirname(__FILE__) + '/../spec_helper.rb'
|
|
3
3
|
describe "Common Functions" do
|
4
4
|
|
5
5
|
before(:all) do
|
6
|
-
@
|
6
|
+
@poly = Polygon.from_coordinates([[[12,45],[45,41],[4,1],[12,45]],[[2,5],[5,1],[14,1],[2,5]]], 4326)
|
7
|
+
@c1 ||= City.create!(:data => "City1", :geom => @poly)
|
7
8
|
@c2 ||= City.create!(:data => "City1", :geom => Polygon.from_coordinates([[[22,66],[65,65],[20,10],[22,66]],[[10,15],[15,11],[34,14],[10,15]]],4326))
|
8
9
|
@c3 ||= City.create!(:data => "City3", :geom => Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],4326))
|
9
10
|
@s1 ||= Street.create!(:data => "Street1", :geom => LineString.from_coordinates([[1,1],[2,2]],4326))
|
@@ -190,6 +191,14 @@ describe "Common Functions" do
|
|
190
191
|
# @c1.disjoint?(@p2).should be_true
|
191
192
|
# end
|
192
193
|
|
194
|
+
it "should check overlaps" do
|
195
|
+
@c2.contains?(@c1).should be_false
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should check overlaps non saved" do
|
199
|
+
@c2.contains?(@poly).should be_false
|
200
|
+
end
|
201
|
+
|
193
202
|
it "should find the UTM zone" do
|
194
203
|
@c2.utm_zone.should eql(32737)
|
195
204
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nofxx-postgis_adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcos Augusto
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-16 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|