nofxx-postgis_adapter 0.1.8 → 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.
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe "ActsAsGeom" do
4
+
5
+ before(:each) do
6
+ class DiffColumn < ActiveRecord::Base
7
+ acts_as_geom :ponto
8
+ end
9
+
10
+ class NotInDb < ActiveRecord::Base
11
+ acts_as_geom :geom
12
+ end
13
+ end
14
+
15
+ it "should get the geom type" do
16
+ City.get_geom_type(:geom).should eql(:polygon)
17
+ end
18
+
19
+ it "should not interfere with migrations" do
20
+ NotInDb.get_geom_type(:geom).should be_nil
21
+ end
22
+
23
+ it "should query a diff column name" do
24
+ # DiffColumn
25
+ end
26
+
27
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
2
 
3
3
  describe "CommonSpatialAdapter" do
4
4
 
@@ -48,9 +48,9 @@ describe "PostgisAdapter" do
48
48
  end
49
49
 
50
50
  it "should test multipoint" do
51
- mp = TableMultiPoint.create!(:geom => MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]]))
51
+ mp = TableMultiPoint.create!(:geom => MultiPoint.from_coordinates([[12.4,-4326.3],[-65.1,4326.4],[4326.55555555,4326]]))
52
52
  find = TableMultiPoint.find(:first)
53
- find.geom.should == MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]])
53
+ find.geom.should == MultiPoint.from_coordinates([[12.4,-4326.3],[-65.1,4326.4],[4326.55555555,4326]])
54
54
  end
55
55
 
56
56
  end
@@ -68,18 +68,18 @@ describe "PostgisAdapter" do
68
68
  end
69
69
 
70
70
  it "should test_srid_line_string" do
71
- ls = TableSridLineString.create!(:geom => LineString.from_coordinates([[1.4,2.5],[1.5,6.7]],123))
71
+ ls = TableSridLineString.create!(:geom => LineString.from_coordinates([[1.4,2.5],[1.5,6.7]],4326))
72
72
  ls = TableSridLineString.find(:first)
73
- ls_e = LineString.from_coordinates([[1.4,2.5],[1.5,6.7]],123)
73
+ ls_e = LineString.from_coordinates([[1.4,2.5],[1.5,6.7]],4326)
74
74
  ls.geom.should be_instance_of(LineString)
75
- ls.geom.srid.should eql(123)
75
+ ls.geom.srid.should eql(4326)
76
76
  end
77
77
 
78
78
 
79
79
  it "hsould test_multi_line_string" do
80
- ml = TableMultiLineString.create!(:geom => MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]]),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]])]))
80
+ ml = TableMultiLineString.create!(:geom => MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.432612,-0.012]]),LineString.from_coordinates([[1.5,45.2],[-54.432612,-0.012],[45.4326,4326.3]])]))
81
81
  find = TableMultiLineString.find(:first)
82
- find.geom.should == MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]]),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]])])
82
+ find.geom.should == MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.432612,-0.012]]),LineString.from_coordinates([[1.5,45.2],[-54.432612,-0.012],[45.4326,4326.3]])])
83
83
  end
84
84
  end
85
85
 
@@ -103,11 +103,11 @@ describe "PostgisAdapter" do
103
103
  end
104
104
 
105
105
  it "should test_srid_4d_polygon" do
106
- pg = TableSrid4dPolygon.create(:geom => Polygon.from_coordinates([[[0,0,2,-45.1],[4,0,2,5],[4,4,2,4.67],[0,4,2,1.34],[0,0,2,-45.1]],[[1,1,2,12.3],[3,1,2,123],[3,3,2,12.2],[1,3,2,12],[1,1,2,12.3]]],123,true,true))
106
+ pg = TableSrid4dPolygon.create(:geom => Polygon.from_coordinates([[[0,0,2,-45.1],[4,0,2,5],[4,4,2,4.67],[0,4,2,1.34],[0,0,2,-45.1]],[[1,1,2,12.3],[3,1,2,4326],[3,3,2,12.2],[1,3,2,12],[1,1,2,12.3]]],4326,true,true))
107
107
  find = TableSrid4dPolygon.find(:first)
108
- pg_e = Polygon.from_coordinates([[[0,0,2,-45.1],[4,0,2,5],[4,4,2,4.67],[0,4,2,1.34],[0,0,2,-45.1]],[[1,1,2,12.3],[3,1,2,123],[3,3,2,12.2],[1,3,2,12],[1,1,2,12.3]]],123,true,true)
108
+ pg_e = Polygon.from_coordinates([[[0,0,2,-45.1],[4,0,2,5],[4,4,2,4.67],[0,4,2,1.34],[0,0,2,-45.1]],[[1,1,2,12.3],[3,1,2,4326],[3,3,2,12.2],[1,3,2,12],[1,1,2,12.3]]],4326,true,true)
109
109
  pg.geom.should == pg_e
110
- pg.geom.srid.should eql(123)
110
+ pg.geom.srid.should eql(4326)
111
111
  end
112
112
  end
113
113
 
@@ -134,7 +134,7 @@ describe "PostgisAdapter" do
134
134
  create_table "parks", :force => true do |t|
135
135
  t.column "data" , :string, :limit => 100
136
136
  t.column "value", :integer
137
- t.column "geom", :point,:null=>false,:srid=>123
137
+ t.column "geom", :point,:null=>false,:srid=>4326
138
138
  end
139
139
  add_index "parks","geom",:spatial=>true,:name => "example_spatial_index"
140
140
  end
@@ -143,13 +143,13 @@ describe "PostgisAdapter" do
143
143
  end
144
144
 
145
145
  it "should create some points" do
146
- Park.create!(:data => "Point1", :geom => Point.from_x_y(1.2,0.75,123))
147
- Park.create!(:data => "Point2",:geom => Point.from_x_y(0.6,1.3,123))
148
- Park.create!(:data => "Point3", :geom => Point.from_x_y(2.5,2,123))
146
+ Park.create!(:data => "Point1", :geom => Point.from_x_y(1.2,0.75,4326))
147
+ Park.create!(:data => "Point2",:geom => Point.from_x_y(0.6,1.3,4326))
148
+ Park.create!(:data => "Point3", :geom => Point.from_x_y(2.5,2,4326))
149
149
  end
150
150
 
151
151
  it "should find by geom" do
152
- pts = Park.find_all_by_geom(LineString.from_coordinates([[0,0],[2,2]],123))
152
+ pts = Park.find_all_by_geom(LineString.from_coordinates([[0,0],[2,2]],4326))
153
153
  pts.should be_instance_of(Array)
154
154
  pts.length.should eql(2)
155
155
  pts[0].data.should match /Point/
@@ -157,12 +157,12 @@ describe "PostgisAdapter" do
157
157
  end
158
158
 
159
159
  it "should find by geom again" do
160
- pts = Park.find_all_by_geom(LineString.from_coordinates([[2.49,1.99],[2.51,2.01]],123))
160
+ pts = Park.find_all_by_geom(LineString.from_coordinates([[2.49,1.99],[2.51,2.01]],4326))
161
161
  pts[0].data.should eql("Point3")
162
162
  end
163
163
 
164
164
  it "should find by geom column bbox condition" do
165
- pts = Park.find_all_by_geom([[0,0],[2,2],123])
165
+ pts = Park.find_all_by_geom([[0,0],[2,2],4326])
166
166
  pts.should be_instance_of(Array)
167
167
  pts.length.should eql(2)
168
168
  pts[0].data.should match /Point/
@@ -4,18 +4,17 @@ require File.dirname(__FILE__) + '/../spec_helper.rb'
4
4
  describe "Point" do
5
5
 
6
6
  before(:all) do
7
- @c1 ||= City.create!(:data => "City1", :geom => Polygon.from_coordinates([[[12,45],[45,41],[4,1],[12,45]],[[2,5],[5,1],[14,1],[2,5]]],123))
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]]],123))
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]]],123))
10
- @s1 ||= Street.create!(:data => "Street1", :geom => LineString.from_coordinates([[1,1],[2,2]],123))
11
- @s2 ||= Street.create!(:data => "Street2", :geom => LineString.from_coordinates([[4,4],[7,7]],123))
12
- @s3 ||= Street.create!(:data => "Street3", :geom => LineString.from_coordinates([[8,8],[18,18],[20,20],[25,25],[30,30],[38,38]],123))
13
- @s4 ||= Street.create!(:data => "Street3", :geom => LineString.from_coordinates([[10,8],[15,18]],123))
14
- @p1 ||= Position.create!(:data => "Point1", :geom => Point.from_x_y(1,1,123))
15
- @p2 ||= Position.create!(:data => "Point2", :geom => Point.from_x_y(5,5,123))
16
- @p3 ||= Position.create!(:data => "Point3", :geom => Point.from_x_y(8,8,123))
7
+ @c1 ||= City.create!(:data => "City1", :geom => Polygon.from_coordinates([[[12,45],[45,41],[4,1],[12,45]],[[2,5],[5,1],[14,1],[2,5]]],4326))
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))
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))
10
+ @s1 ||= Street.create!(:data => "Street1", :geom => LineString.from_coordinates([[1,1],[2,2]],4326))
11
+ @s2 ||= Street.create!(:data => "Street2", :geom => LineString.from_coordinates([[4,4],[7,7]],4326))
12
+ @s3 ||= Street.create!(:data => "Street3", :geom => LineString.from_coordinates([[8,8],[18,18],[20,20],[25,25],[30,30],[38,38]],4326))
13
+ @s4 ||= Street.create!(:data => "Street3", :geom => LineString.from_coordinates([[10,8],[15,18]],4326))
14
+ @p1 ||= Position.create!(:data => "Point1", :geom => Point.from_x_y(1,1,4326))
15
+ @p2 ||= Position.create!(:data => "Point2", :geom => Point.from_x_y(5,5,4326))
16
+ @p3 ||= Position.create!(:data => "Point3", :geom => Point.from_x_y(8,8,4326))
17
17
  end
18
-
19
18
 
20
19
  describe "BBox operations" do
21
20
 
@@ -27,49 +26,17 @@ describe "Point" do
27
26
  @p1.bbox(">>", @c1).should be_false
28
27
  end
29
28
 
30
- it do
31
- @p1.should be_strictly_left_of(@c1)
32
- end
33
-
34
- it do
35
- @p1.should_not be_strictly_right_of(@c1)
36
- end
37
-
38
- it do
39
- @p1.should_not be_overlaps_or_right_of(@c1)
40
- end
41
-
42
- it do
43
- @p1.should be_overlaps_or_left_of(@c1)
44
- end
45
-
46
- it do
47
- @p1.should_not be_completely_contained_by(@c1)
48
- end
49
-
50
- it do
51
- @c2.completely_contains?(@p1).should be_false
52
- end
53
-
54
- it do
55
- @p1.should be_overlaps_or_above(@c1)
56
- end
57
-
58
- it do
59
- @p1.should be_overlaps_or_below(@c1)
60
- end
61
-
62
- it do
63
- @p1.should_not be_strictly_above(@c1)
64
- end
65
-
66
- it do
67
- @p1.should_not be_strictly_below(@c1)
68
- end
69
-
70
- it do
71
- @p1.interacts_with?(@c1).should be_false
72
- end
29
+ it do @p1.should be_strictly_left_of(@c1) end
30
+ it do @p1.should_not be_strictly_right_of(@c1) end
31
+ it do @p1.should_not be_overlaps_or_right_of(@c1) end
32
+ it do @p1.should be_overlaps_or_left_of(@c1) end
33
+ it do @p1.should_not be_completely_contained_by(@c1) end
34
+ it do @c2.completely_contains?(@p1).should be_false end
35
+ it do @p1.should be_overlaps_or_above(@c1) end
36
+ it do @p1.should be_overlaps_or_below(@c1) end
37
+ it do @p1.should_not be_strictly_above(@c1) end
38
+ it do @p1.should_not be_strictly_below(@c1) end
39
+ it do @p1.interacts_with?(@c1).should be_false end
73
40
 
74
41
  it do
75
42
  @p1.binary_equal?(@c1).should be_false
@@ -79,6 +46,6 @@ describe "Point" do
79
46
  @p1.same_as?(@c1).should be_false
80
47
  end
81
48
 
82
-
83
49
  end
84
- end
50
+
51
+ end
File without changes
@@ -0,0 +1,281 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe "Common Functions" do
4
+
5
+ before(:all) do
6
+ @c1 ||= City.create!(:data => "City1", :geom => Polygon.from_coordinates([[[12,45],[45,41],[4,1],[12,45]],[[2,5],[5,1],[14,1],[2,5]]],4326))
7
+ @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
+ @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
+ @s1 ||= Street.create!(:data => "Street1", :geom => LineString.from_coordinates([[1,1],[2,2]],4326))
10
+ @s2 ||= Street.create!(:data => "Street2", :geom => LineString.from_coordinates([[4,4],[7,7]],4326))
11
+ @s3 ||= Street.create!(:data => "Street3", :geom => LineString.from_coordinates([[8,8],[18,18],[20,20],[25,25],[30,30],[38,38]],4326))
12
+ @s4 ||= Street.create!(:data => "Street4", :geom => LineString.from_coordinates([[10,8],[15,18]],4326))
13
+ @p1 ||= Position.create!(:data => "Point1", :geom => Point.from_x_y(1,1,4326))
14
+ @p2 ||= Position.create!(:data => "Point2", :geom => Point.from_x_y(5,5,4326))
15
+ @p3 ||= Position.create!(:data => "Point3", :geom => Point.from_x_y(8,8,4326))
16
+ @p4 ||= Position.create!(:data => "Point4", :geom => Point.from_x_y(18.1,18,4326))
17
+ @p5 ||= Position.create!(:data => "Point5", :geom => Point.from_x_y(30,30,4326))
18
+ end
19
+
20
+ describe "Point" do
21
+
22
+ it "should find the closest other point" do
23
+ Position.close_to(@p1.geom,4326)[0].data.should == @p1.data
24
+ end
25
+
26
+ it "should find the closest other point" do
27
+ Position.closest_to(@p1.geom,4326).data.should == @p1.data
28
+ end
29
+
30
+ it { @p1.distance_to(@s2).should be_close(4.24264068711928, 0.0001) }
31
+ it { @p1.distance_to(@s3).should be_close(9.89949493661167, 0.0001) }
32
+ it { @p2.distance_to(@s3).should be_close(4.24264068711928, 0.0001) }
33
+ it { @p1.distance_to(@p2).should be_close(5.65685424949238, 0.0001) }
34
+ it { @p1.distance_to(@c1).should be_close(3.0, 0.0001) }
35
+ it { @p1.distance_to(@c2).should be_close(21.0237960416286, 0.000001) }
36
+ it { @p1.distance_to(@s2).should be_close(4.24264068711928, 0.000001) }
37
+ it { @p1.distance_sphere_to(@p2).should be_close(628516.874554178, 0.0001) }
38
+ it { @p1.distance_sphere_to(@p3).should be_close(1098726.61466584, 0.00001) }
39
+ it { @p1.distance_spheroid_to(@p2).should be_close(627129.50,0.01) }
40
+ it { @p1.distance_spheroid_to(@p2).should be_close(627129.502639041, 0.000001) }
41
+ it { @p1.distance_spheroid_to(@p3).should be_close(1096324.48117672, 0.000001) }
42
+
43
+ it { @p1.should_not be_inside(@c1) }
44
+ it { @p1.should be_outside(@c1) }
45
+ it { @p1.should be_inside_circle(2.0,2.0,20.0) }
46
+ it { @p1.should_not be_inside_circle(50,50,2) }
47
+ it { @p1.should be_in_bounds(@s1) }
48
+ it { @p3.should_not be_in_bounds(@s1, 1) }
49
+ it { @p4.in_bounds?(@s3, 0.01).should be_false }
50
+
51
+ it { @p1.azimuth(@p2).should be_close(0.785398163397448,0.000001) }
52
+ it { @p1.azimuth(@s2).should raise_error }
53
+ it { @p1.disjoint?(@s2).should be_true }
54
+ it { @p3.polygonize.geometries.should be_empty }
55
+ it { @p4.where_on_line(@s3).should be_close(0.335, 0.0001) }
56
+ it { @s3.locate_point(@p4).should be_close(0.335, 0.1)}
57
+ it { @s3.interpolate_point(0.335).x.should be_close(18.05, 0.01) }
58
+
59
+ it { @p1.relate?(@s3, "T*T***FF*").should be_false }
60
+ it { @p1.relate?(@s3).should eql("FF0FFF102") }
61
+
62
+ it "should transform srid" do
63
+ @p1.geom = @p1.transform(29101)
64
+ @p1.geom.srid.should eql(29101)
65
+ end
66
+
67
+ it "should see in what fraction of the ls it is" do
68
+ @p1.where_on_line(@s1).should eql(0.0)
69
+ end
70
+
71
+ end
72
+
73
+ describe "Polygon" do
74
+
75
+ it "sort by area size" do
76
+ City.by_area.first.data.should == "City1" #[@c1, @c2, @c3]
77
+ end
78
+
79
+ it "find all cities that contains a point" do
80
+ City.contains(@p1.geom, 4326).should eql([])
81
+ end
82
+
83
+ it "should find one city (first) that contains a point" do
84
+ City.contain(@p4.geom, 4326).data.should eql("City1")
85
+ end
86
+
87
+ it { @c2.should be_closed }
88
+ it { @c3.area.should be_close(1093.270089, 0.1) }
89
+ it { @c2.area.should be_close(1159.5, 0.1) }
90
+
91
+ it { @c2.dimension.should eql(2) }
92
+ it { @c2.perimeter.should be_close(219.770013855493, 0.1) }
93
+ it { @c2.perimeter3d.should be_close(219.770013855493, 0.1) }
94
+ it { @c1.contains?(@p1).should be_false }
95
+ it { @c1.contains?(@p4).should be_true }
96
+
97
+ it { @c1.should_not be_spatially_equal(@c2) }
98
+
99
+ it { @c1.covers?(@p1).should be_false }
100
+ it { @c1.covers?(@p4).should be_true }
101
+ it { @c1.should_not be_within(@c2) }
102
+
103
+ it "city overlaps point?" do
104
+ lambda { @c3.overlaps?(@c2) }.should raise_error # WHY??
105
+ end
106
+
107
+ it "should get a polygon for envelope" do
108
+ @c2.envelope.should be_instance_of(Polygon)
109
+ end
110
+
111
+ it "should get a polygon for envelope" do
112
+ @c2.envelope.rings[0].points[0].should be_instance_of(Point)
113
+ end
114
+
115
+ it "should get the center" do
116
+ @c2.centroid.x.should be_close(36.2945235015093,0.00001)
117
+ @c2.centroid.y.should be_close(48.3211154233146,0.00001)
118
+ end
119
+
120
+ it "should get the center with the correct srid" do
121
+ @c1.centroid.srid.should eql(4326)
122
+ end
123
+
124
+ it "distance from another" do
125
+ @c1.distance_to(@c3).should eql(0.0)
126
+ end
127
+
128
+ it "distance to a linestring" do
129
+ @c1.distance_to(@s1).should be_close(1.8,0.001)
130
+ end
131
+
132
+ it "should simplify me" do
133
+ @c3.simplify.should be_instance_of(Polygon)
134
+ end
135
+
136
+ it "should simplify me number of points" do
137
+ @c3.simplify[0].length.should eql(4)
138
+ end
139
+
140
+ #Strange again.... s2 s3 ... error
141
+ it { @c3.touches?(@s1).should be_false }
142
+ it { @c2.should be_simple }
143
+ it { @c2.disjoint?(@p2).should be_true }
144
+ it { @c3.polygonize.should have(2).geometries }
145
+
146
+ # weird...
147
+ # it do
148
+ # @c1.disjoint?(@s2).should be_true
149
+ # end
150
+
151
+ end
152
+
153
+ describe "LineString" do
154
+
155
+ it "should sort by size" do
156
+ Street.by_length.first.data.should == "Street1"
157
+ Street.by_length.last.data.should == "Street3"
158
+ end
159
+
160
+ it "largest" do
161
+ Street.longest.data.should == "Street3"
162
+ end
163
+
164
+ describe "Length" do
165
+ it { @s1.length.should be_close(1.4142135623731, 0.000001) }
166
+ it { @s2.length.should be_close(4.2, 0.1) }
167
+ it { @s3.length.should be_close(42.4264068, 0.001) }
168
+ it { @s1.length_spheroid.should be_close(156876.1494,0.0001) }
169
+ it { @s1.length_3d.should be_close(1.4142135623731,0.0001) }
170
+ end
171
+
172
+ it { @s1.crosses?(@s2).should be_false }
173
+ it { @s4.crosses?(@s3).should be_true }
174
+ it { @s1.touches?(@s2).should be_false }
175
+ it { @s4.touches?(@s3).should be_false }
176
+
177
+ it "should intersect with linestring" do
178
+ @s4.intersects?(@s3).should be_true
179
+ end
180
+
181
+ it "should not intersect with this linestring" do
182
+ @s4.intersects?(@s1).should be_false
183
+ end
184
+
185
+ it "intersection with a point" do
186
+ @s1.intersection(@p2).should be_instance_of(GeometryCollection)
187
+ end
188
+
189
+ describe "Self" do
190
+
191
+ it do
192
+ @s1.envelope.should be_instance_of(Polygon)
193
+ end
194
+
195
+ it "should get a polygon for envelope" do
196
+ @s1.envelope.rings[0].points[0].should be_instance_of(Point)
197
+ end
198
+
199
+ it "should get the center" do
200
+ @s1.centroid.x.should be_close(1.5,0.01)
201
+ @s1.centroid.y.should be_close(1.5,0.01)
202
+ end
203
+
204
+ it "should get the center with the correct srid" do
205
+ @s1.centroid.srid.should eql(4326)
206
+ end
207
+
208
+ it "number of points" do
209
+ @s3.num_points.should eql(6)
210
+ end
211
+
212
+ it "startpoint" do
213
+ @s3.start_point.should be_instance_of(Point)
214
+ @s3.start_point.x.should be_close(8.0, 0.1)
215
+ end
216
+
217
+ it "endpoint" do
218
+ @s2.end_point.should be_instance_of(Point)
219
+ @s2.end_point.x.should be_close(7.0, 0.1)
220
+ end
221
+
222
+ it { @s1.should_not be_envelopes_intersect(@s2) }
223
+ it { @s1.boundary.should be_instance_of(MultiPoint) }
224
+
225
+ end
226
+
227
+ describe "Distance" do
228
+
229
+ it { @s1.distance_to(@p3).should be_close(8.48528137423857,0.0001) }
230
+ it { @s1.distance_to(@p3).should be_close(8.48,0.01) }
231
+
232
+ it do
233
+ lambda { @p1.distance_spheroid_to(@c3) }.should raise_error
234
+ end
235
+
236
+ it do
237
+ lambda { @p3.distance_spheroid_to(@s1) }.should raise_error
238
+ end
239
+
240
+ end
241
+
242
+ it do @s1.locate_point(@p1).should eql(0.0) end
243
+ it do @s1.locate_point(@p2).should eql(1.0) end
244
+
245
+ it "should simplify a line" do
246
+ @s3.simplify.points.length.should eql(2)
247
+ end
248
+
249
+ it "should simplify the first correcty" do
250
+ @s3.simplify.points[0].y.should be_close(8.0, 0.1)
251
+ end
252
+
253
+ it "should simplify the last correcty" do
254
+ @s3.simplify.points[1].y.should be_close(38.0, 0.1)
255
+ end
256
+
257
+ it { @s1.overlaps?(@c2).should be_false }
258
+ it { @s1.overlaps?(@s2).should be_false }
259
+ it { @s1.convex_hull.should be_instance_of(LineString) }
260
+ it { @s1.line_substring(0.2,0.5).should be_instance_of(LineString) }
261
+
262
+ it do
263
+ @s1.interpolate_point(0.7).should be_instance_of(Point)
264
+ @s1.interpolate_point(0.7).x.should be_close(1.7,0.1)
265
+ end
266
+
267
+ it { @s1.should be_simple }
268
+ it { @s1.disjoint?(@s2).should be_true }
269
+ it { @s1.polygonize.should be_instance_of(GeometryCollection) }
270
+ it { @s3.polygonize.geometries.should be_empty }
271
+ it { @s2.locate_along_measure(1.6).should be_nil }
272
+ it { @s2.locate_between_measures(0.1,0.3).should be_nil }
273
+
274
+ it "should build area" do
275
+ @s2.build_area.should be_nil
276
+ end
277
+
278
+ end
279
+
280
+ end
281
+
@@ -3,14 +3,13 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
3
3
  describe "PostgisFunctions" do
4
4
  before(:all) do
5
5
  #load_schema
6
- @c1 ||= City.create!(:data => "City1", :geom => Polygon.from_coordinates([[[12,45],[45,41],[4,1],[12,45]],[[2,5],[5,1],[14,1],[2,5]]],123))
7
- @s1 ||= Street.create!(:data => "Street1", :geom => LineString.from_coordinates([[-43,-20],[-42,-28]],123))
8
- @p1 ||= Position.create!(:data => "Point1", :geom => Point.from_x_y(-43,-22,123))
6
+ @c1 ||= City.create!(:data => "City1", :geom => Polygon.from_coordinates([[[12,45],[45,41],[4,1],[12,45]],[[2,5],[5,1],[14,1],[2,5]]],4326))
7
+ @s1 ||= Street.create!(:data => "Street1", :geom => LineString.from_coordinates([[-43,-20],[-42,-28]],4326))
8
+ @p1 ||= Position.create!(:data => "Point1", :geom => Point.from_x_y(-43,-22,4326))
9
9
  end
10
10
 
11
11
  describe "Common Mix" do
12
12
 
13
-
14
13
  it "should calculate distance point to line" do
15
14
  @p1.distance_to(@s1).should be_close(0.248069469178417, 0.00000001)
16
15
  end
@@ -19,10 +18,8 @@ describe "PostgisFunctions" do
19
18
  @p1.should_not be_inside(@c1)
20
19
  end
21
20
 
22
-
23
21
  end
24
22
 
25
-
26
23
  #TODO is sorted rspec helper
27
24
  describe "Class methods" do
28
25
 
data/spec/spec.opts CHANGED
@@ -1,6 +1,5 @@
1
1
  --colour
2
- --format
3
- spinner
2
+ --format RspecSpinner::Spinner
4
3
  --timeout
5
4
  20
6
5
  --diff
data/spec/spec_helper.rb CHANGED
@@ -9,6 +9,7 @@ rescue LoadError
9
9
  require 'postgres'
10
10
  require 'activerecord'
11
11
  end
12
+ require 'rspec_spinner'
12
13
 
13
14
  $:.unshift(File.dirname(__FILE__) + '/../lib')
14
15
  config = YAML.load_file(File.dirname(__FILE__) + '/db/database_postgis.yml')
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.1.8
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcos Piccinini
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-16 00:00:00 -08:00
12
+ date: 2009-01-10 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -28,7 +28,7 @@ dependencies:
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: 1.1.0
31
+ version: 1.2.3
32
32
  version:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: hoe
@@ -65,14 +65,23 @@ files:
65
65
  - lib/postgis_functions/bbox.rb
66
66
  - lib/postgis_functions/class.rb
67
67
  - lib/postgis_functions/common.rb
68
- - lib/postgis_functions/linestring.rb
69
- - lib/postgis_functions/point.rb
70
- - lib/postgis_functions/polygon.rb
71
68
  - postgis_adapter.gemspec
72
69
  - rails/init.rb
73
70
  - script/console
74
71
  - script/destroy
75
72
  - script/generate
73
+ - spec/db/database_postgis.yml
74
+ - spec/db/models_postgis.rb
75
+ - spec/db/schema_postgis.rb
76
+ - spec/postgis_adapter/acts_as_geom_spec.rb
77
+ - spec/postgis_adapter/common_spatial_adapter_spec.rb
78
+ - spec/postgis_adapter_spec.rb
79
+ - spec/postgis_functions/bbox_spec.rb
80
+ - spec/postgis_functions/class_spec.rb
81
+ - spec/postgis_functions/common_spec.rb
82
+ - spec/postgis_functions_spec.rb
83
+ - spec/spec.opts
84
+ - spec/spec_helper.rb
76
85
  - uninstall.rb
77
86
  has_rdoc: true
78
87
  homepage: http://github.com/nofxx/postgis_adapter
@@ -101,17 +110,5 @@ rubygems_version: 1.2.0
101
110
  signing_key:
102
111
  specification_version: 2
103
112
  summary: Postgis Adapter for Activer Record
104
- test_files:
105
- - spec/acts_as_geom_spec.rb
106
- - spec/common_spatial_adapter_spec.rb
107
- - spec/db/database_postgis.yml
108
- - spec/db/models_postgis.rb
109
- - spec/db/schema_postgis.rb
110
- - spec/postgis_adapter_spec.rb
111
- - spec/postgis_functions/bbox_spec.rb
112
- - spec/postgis_functions/linestring_spec.rb
113
- - spec/postgis_functions/point_spec.rb
114
- - spec/postgis_functions/polygon_spec.rb
115
- - spec/postgis_functions_spec.rb
116
- - spec/spec.opts
117
- - spec/spec_helper.rb
113
+ test_files: []
114
+