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.
- data/Manifest.txt +4 -8
- data/README.rdoc +7 -5
- data/lib/postgis_adapter/acts_as_geom.rb +4 -3
- data/lib/postgis_adapter.rb +1 -6
- data/lib/postgis_functions/common.rb +353 -2
- data/lib/postgis_functions.rb +13 -14
- data/postgis_adapter.gemspec +13 -11
- data/spec/db/database_postgis.yml +1 -1
- data/spec/db/models_postgis.rb +1 -0
- data/spec/db/schema_postgis.rb +18 -21
- data/spec/postgis_adapter/acts_as_geom_spec.rb +27 -0
- data/spec/{common_spatial_adapter_spec.rb → postgis_adapter/common_spatial_adapter_spec.rb} +1 -1
- data/spec/postgis_adapter_spec.rb +17 -17
- data/spec/postgis_functions/bbox_spec.rb +23 -56
- data/spec/postgis_functions/class_spec.rb +0 -0
- data/spec/postgis_functions/common_spec.rb +281 -0
- data/spec/postgis_functions_spec.rb +3 -6
- data/spec/spec.opts +1 -2
- data/spec/spec_helper.rb +1 -0
- metadata +17 -20
- data/lib/postgis_functions/linestring.rb +0 -172
- data/lib/postgis_functions/point.rb +0 -89
- data/lib/postgis_functions/polygon.rb +0 -78
- data/spec/acts_as_geom_spec.rb +0 -15
- data/spec/postgis_functions/linestring_spec.rb +0 -219
- data/spec/postgis_functions/point_spec.rb +0 -136
- data/spec/postgis_functions/polygon_spec.rb +0 -146
@@ -1,146 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
-
|
3
|
-
|
4
|
-
describe "Point" do
|
5
|
-
|
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))
|
17
|
-
@p4 ||= Position.create!(:data => "Point4", :geom => Point.from_x_y(30,30,123))
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
describe "Polygon" do
|
25
|
-
|
26
|
-
it "sort by area size" do
|
27
|
-
City.by_area.first.data.should == "City1" #[@c1, @c2, @c3]
|
28
|
-
end
|
29
|
-
|
30
|
-
it do
|
31
|
-
@c2.should be_closed
|
32
|
-
end
|
33
|
-
|
34
|
-
it do
|
35
|
-
@c3.area.should be_close(1093.270089, 0.1)
|
36
|
-
end
|
37
|
-
|
38
|
-
it do
|
39
|
-
@c2.area.should be_close(1159.5, 0.1)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "dimension x" do
|
43
|
-
@c2.dimension.should eql(2)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "perimter 2d" do
|
47
|
-
@c2.perimeter.should be_close(219.770013855493, 0.1)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "perimter 3d" do
|
51
|
-
@c2.perimeter3d.should be_close(219.770013855493, 0.1)
|
52
|
-
end
|
53
|
-
|
54
|
-
it "contains points?" do
|
55
|
-
@c1.contains?(@p1).should be_false
|
56
|
-
end
|
57
|
-
|
58
|
-
it "contains created point?" do
|
59
|
-
@c1.contains?(@p4).should be_true
|
60
|
-
end
|
61
|
-
|
62
|
-
it do
|
63
|
-
@c1.should_not be_spatially_equal(@c2)
|
64
|
-
end
|
65
|
-
|
66
|
-
it "find all cities that contains a point" do
|
67
|
-
City.contains(@p1.geom, 123).should eql([])
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should find one city (first) that contains a point" do
|
71
|
-
City.contain(@p4.geom, 123).data.should eql("City1")
|
72
|
-
end
|
73
|
-
|
74
|
-
it do
|
75
|
-
@c1.covers?(@p1).should be_false
|
76
|
-
end
|
77
|
-
|
78
|
-
it do
|
79
|
-
@c1.covers?(@p4).should be_true
|
80
|
-
end
|
81
|
-
|
82
|
-
it do
|
83
|
-
@c1.should_not be_within(@c2)
|
84
|
-
end
|
85
|
-
|
86
|
-
it "city overlaps point?" do
|
87
|
-
lambda { @c3.overlaps?(@c2) }.should raise_error # WHY??
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should get a polygon for envelope" do
|
91
|
-
@c2.envelope.should be_instance_of(Polygon)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should get a polygon for envelope" do
|
95
|
-
@c2.envelope.rings[0].points[0].should be_instance_of(Point)
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should get the center" do
|
99
|
-
@c2.centroid.x.should be_close(36.2945235015093,0.00001)
|
100
|
-
@c2.centroid.y.should be_close(48.3211154233146,0.00001)
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should get the center with the correct srid" do
|
104
|
-
@c1.centroid.srid.should eql(123)
|
105
|
-
end
|
106
|
-
|
107
|
-
it "distance from another" do
|
108
|
-
@c1.distance_to(@c3).should eql(0.0)
|
109
|
-
end
|
110
|
-
|
111
|
-
it "distance to a linestring" do
|
112
|
-
@c1.distance_to(@s1).should be_close(1.8,0.001)
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should simplify me" do
|
116
|
-
@c3.simplify.should be_instance_of(Polygon)
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should simplify me number of points" do
|
120
|
-
@c3.simplify[0].length.should eql(4)
|
121
|
-
end
|
122
|
-
|
123
|
-
#Strange again.... s2 s3 ... error
|
124
|
-
it do
|
125
|
-
@c3.touches?(@s1).should be_false
|
126
|
-
end
|
127
|
-
|
128
|
-
it do
|
129
|
-
@c2.should be_simple
|
130
|
-
end
|
131
|
-
|
132
|
-
it do
|
133
|
-
@c2.disjoint?(@p2).should be_true
|
134
|
-
end
|
135
|
-
|
136
|
-
it do
|
137
|
-
@c3.polygonize.should have(2).geometries
|
138
|
-
end
|
139
|
-
|
140
|
-
# weird...
|
141
|
-
# it do
|
142
|
-
# @c1.disjoint?(@s2).should be_true
|
143
|
-
# end
|
144
|
-
|
145
|
-
end
|
146
|
-
end
|