postgis_adapter 0.7.7 → 0.7.8

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.7
1
+ 0.7.8
@@ -249,17 +249,17 @@ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
249
249
  end
250
250
 
251
251
  # # For version of Rails where exists disable_referential_integrity
252
- # if self.instance_methods.include? "disable_referential_integrity"
253
- # #Pete Deffendol's patch
254
- # alias :original_disable_referential_integrity :disable_referential_integrity
255
- # def disable_referential_integrity(&block) #:nodoc:
256
- # ignore_tables = %w{ geometry_columns spatial_ref_sys }
257
- # execute(tables.select { |name| !ignore_tables.include?(name) }.collect { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(";"))
258
- # yield
259
- # ensure
260
- # execute(tables.select { |name| !ignore_tables.include?(name)}.collect { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER ALL" }.join(";"))
261
- # end
262
- # end
252
+ if self.instance_methods.include? "disable_referential_integrity"
253
+ #Pete Deffendol's patch
254
+ alias :original_disable_referential_integrity :disable_referential_integrity
255
+ def disable_referential_integrity(&block) #:nodoc:
256
+ ignore_tables = %w{ geometry_columns spatial_ref_sys geography_columns }
257
+ execute(tables.select { |name| !ignore_tables.include?(name) }.collect { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(";"))
258
+ yield
259
+ ensure
260
+ execute(tables.select { |name| !ignore_tables.include?(name)}.collect { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER ALL" }.join(";"))
261
+ end
262
+ end
263
263
 
264
264
  private
265
265
 
@@ -399,7 +399,7 @@ module ActiveRecord
399
399
  end
400
400
  end
401
401
 
402
- #Would prefer creation of a PostgreSQLColumn type instead but I would
402
+ # Would prefer creation of a PostgreSQLColumn type instead but I would
403
403
  # need to reimplement methods where Column objects are instantiated so
404
404
  # I leave it like this
405
405
  module ActiveRecord
@@ -408,7 +408,7 @@ module ActiveRecord
408
408
 
409
409
  include SpatialColumn
410
410
 
411
- #Transforms a string to a geometry. PostGIS returns a HewEWKB string.
411
+ #Transforms a string to a geometry. PostGIS returns a HexEWKB string.
412
412
  def self.string_to_geometry(string)
413
413
  return string unless string.is_a?(String)
414
414
  GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb(string) rescue nil
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # Some links:
13
13
  #
14
- # PostGis Manual - http://postgis.refractions.net/documentation/manual-svn/ch07.html
14
+ # PostGis Manual - http://postgis.refractions.net/documentation/manual-svn
15
15
  # Earth Spheroid - http://en.wikipedia.org/wiki/Figure_of_the_Earth
16
16
  #
17
17
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{postgis_adapter}
8
- s.version = "0.7.7"
8
+ s.version = "0.7.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marcos Piccinini"]
12
- s.date = %q{2010-01-29}
12
+ s.date = %q{2010-02-26}
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 = [
@@ -55,12 +55,12 @@ Gem::Specification.new do |s|
55
55
  "spec/db/schema_postgis.rb",
56
56
  "spec/postgis_adapter/acts_as_geom_spec.rb",
57
57
  "spec/postgis_adapter/common_spatial_adapter_spec.rb",
58
+ "spec/postgis_functions_spec.rb",
59
+ "spec/spec_helper.rb",
58
60
  "spec/postgis_adapter_spec.rb",
59
- "spec/postgis_functions/bbox_spec.rb",
60
61
  "spec/postgis_functions/class_spec.rb",
61
62
  "spec/postgis_functions/common_spec.rb",
62
- "spec/postgis_functions_spec.rb",
63
- "spec/spec_helper.rb"
63
+ "spec/postgis_functions/bbox_spec.rb"
64
64
  ]
65
65
 
66
66
  if s.respond_to? :specification_version then
@@ -22,7 +22,8 @@ describe "PostgisAdapter" do
22
22
  end
23
23
 
24
24
  it "should est_3dz_points" do
25
- pt = Table3dzPoint.create!(:data => "Hello!",:geom => Point.from_x_y_z(-1.6,2.8,-3.4))
25
+ pt = Table3dzPoint.create!(:data => "Hello!",
26
+ :geom => Point.from_x_y_z(-1.6,2.8,-3.4))
26
27
  pt = Table3dzPoint.find(:first)
27
28
  pt.geom.should be_instance_of(Point)
28
29
  pt.geom.z.should eql(-3.4)
@@ -36,7 +37,7 @@ describe "PostgisAdapter" do
36
37
  end
37
38
 
38
39
  it "should est_4d_points" do
39
- pt = Table4dPoint.create!(:geom => Point.from_x_y_z_m(-1.6,2.8,-3.4,15))
40
+ pt = Table4dPoint.create!(:geom => Point.from_x_y_z_m(-1,2.8,-3.4,15))
40
41
  pt = Table4dPoint.find(:first)
41
42
  pt.geom.should be_instance_of(Point)
42
43
  pt.geom.z.should eql(-3.4)
@@ -59,7 +60,8 @@ describe "PostgisAdapter" do
59
60
 
60
61
  describe "LineString" do
61
62
  it "should record a linestring nicely" do
62
- @ls = TableLineString.new(:value => 3, :geom => LineString.from_coordinates([[1.4,2.5],[1.5,6.7]]))
63
+ @ls = TableLineString.new(:value => 3,
64
+ :geom => LineString.from_coordinates([[1.4,2.5],[1.5,6.7]]))
63
65
  @ls.save.should be_true
64
66
  end
65
67
 
@@ -70,7 +72,8 @@ describe "PostgisAdapter" do
70
72
  end
71
73
 
72
74
  it "should test_srid_line_string" do
73
- ls = TableSridLineString.create!(:geom => LineString.from_coordinates([[1.4,2.5],[1.5,6.7]],4326))
75
+ ls = TableSridLineString.create!(
76
+ :geom => LineString.from_coordinates([[1.4,2.5],[1.5,6.7]],4326))
74
77
  ls = TableSridLineString.find(:first)
75
78
  ls_e = LineString.from_coordinates([[1.4,2.5],[1.5,6.7]],4326)
76
79
  ls.geom.should be_instance_of(LineString)
@@ -143,12 +146,13 @@ describe "PostgisAdapter" do
143
146
 
144
147
  it "should create some points" do
145
148
  Area.create!(:data => "Point1", :geom => Point.from_x_y(1.2,0.75,4326))
146
- Area.create!(:data => "Point2",:geom => Point.from_x_y(0.6,1.3,4326))
149
+ Area.create!(:data => "Point2", :geom => Point.from_x_y(0.6,1.3,4326))
147
150
  Area.create!(:data => "Point3", :geom => Point.from_x_y(2.5,2,4326))
148
151
  end
149
152
 
150
153
  it "should find by geom" do
151
- pts = Area.find_all_by_geom(LineString.from_coordinates([[0,0],[2,2]],4326))
154
+ pts = Area.find_all_by_geom(LineString.
155
+ from_coordinates([[0,0],[2,2]],4326))
152
156
  pts.should be_instance_of(Array)
153
157
  pts.length.should eql(2)
154
158
  pts[0].data.should match(/Point/)
@@ -156,7 +160,8 @@ describe "PostgisAdapter" do
156
160
  end
157
161
 
158
162
  it "should find by geom again" do
159
- pts = Area.find_all_by_geom(LineString.from_coordinates([[2.49,1.99],[2.51,2.01]],4326))
163
+ pts = Area.find_all_by_geom(LineString.
164
+ from_coordinates([[2.49,1.99],[2.51,2.01]],4326))
160
165
  pts[0].data.should eql("Point3")
161
166
  end
162
167
 
@@ -175,14 +180,12 @@ describe "PostgisAdapter" do
175
180
 
176
181
  end
177
182
 
183
+ # Verify that a non-NULL column with a default value is handled correctly. # Additionally, if the database uses UTF8, set the binary (bytea)
184
+ # column value to an illegal UTF8 string; it should be stored as the
185
+ # specified binary string and not as a text string. (The binary data test
186
+ # cannot fail if the database uses SQL_ASCII or LATIN1 encoding.)
178
187
  describe "PostgreSQL-specific types and default values" do
179
188
 
180
- # Verify that a non-NULL column with a default value is handled correctly.
181
- # Additionally, if the database uses UTF8 encoding, set the binary (bytea)
182
- # column value to an illegal UTF8 string; it should be stored as the
183
- # specified binary string and not as a text string. (The binary data test
184
- # cannot fail if the database uses SQL_ASCII or LATIN1 encoding.)
185
-
186
189
  ActiveRecord::Schema.define() do
187
190
  create_table :binary_defaults, :force => true do |t|
188
191
  t.string :name, :null => false
@@ -196,10 +199,13 @@ describe "PostgisAdapter" do
196
199
 
197
200
  it "should create some records" do
198
201
  if BinaryDefault.connection.encoding == "UTF8"
202
+ # fôo as ISO-8859-1 (i.e., not valid UTF-8 data)
199
203
  BinaryDefault.create!(:name => "foo", :data => "baz",
200
- :value => "f\xf4o") # fôo as ISO-8859-1 (i.e., not valid UTF-8 data)
201
- BinaryDefault.create!(:name => "bar", # data value not specified, should use default
202
- :value => "b\xe5r") # bår as ISO-8859-1 (i.e., not valid UTF-8 data)
204
+ :value => "f\xf4o")
205
+ # data value not specified, should use default
206
+ # bår as ISO-8859-1 (i.e., not valid UTF-8 data)
207
+ BinaryDefault.create!(:name => "bar",
208
+ :value => "b\xe5r")
203
209
  else
204
210
  BinaryDefault.create!(:name => "foo", :data => "baz")
205
211
  BinaryDefault.create!(:name => "bar")
@@ -221,4 +227,14 @@ describe "PostgisAdapter" do
221
227
 
222
228
  end
223
229
 
230
+ describe "Extras" do
231
+ it "should disable referencial integrity" do
232
+ lambda do
233
+ Area.connection.disable_referential_integrity do
234
+ Area.delete_all
235
+ end
236
+ end.should_not raise_error
237
+ end
238
+ end
239
+
224
240
  end
@@ -39,11 +39,11 @@ describe "Common Functions" do
39
39
  it { @p1.distance_to(@c1).should be_close(3.0, 0.0001) }
40
40
  it { @p1.distance_to(@c2).should be_close(21.0237960416286, 0.000001) }
41
41
  it { @p1.distance_to(@s2).should be_close(4.24264068711928, 0.000001) }
42
- it { @p1.distance_sphere_to(@p2).should be_close(628516.874554178, 0.0001) }
43
- it { @p1.distance_sphere_to(@p3).should be_close(1098726.61466584, 0.00001) }
42
+ it { @p1.distance_sphere_to(@p2).should be_close(628519.033787529, 0.0001) }
43
+ it { @p1.distance_sphere_to(@p3).should be_close(1098730.38927754, 0.00001) }
44
44
  it { @p1.distance_spheroid_to(@p2).should be_close(627129.50,0.01) }
45
- it { @p1.distance_spheroid_to(@p2).should be_close(627129.502639041, 0.000001) }
46
- it { @p1.distance_spheroid_to(@p3).should be_close(1096324.48117672, 0.000001) }
45
+ it { @p1.distance_spheroid_to(@p2).should be_close(627129.502561203, 0.000001) }
46
+ it { @p1.distance_spheroid_to(@p3).should be_close(1096324.48105195, 0.000001) }
47
47
 
48
48
  it "should find the distance from a unsaved point" do
49
49
  @p1.distance_to(@p2).should be_close(5.65685424949238,0.001)
@@ -184,7 +184,7 @@ describe "Common Functions" do
184
184
  end
185
185
 
186
186
  it "distance to a linestring" do
187
- @c1.distance_to(@s1).should be_close(1.8,0.001)
187
+ @c1.distance_to(@s1).should be_close(2.146,0.001)
188
188
  end
189
189
 
190
190
  it "should simplify me" do
@@ -312,18 +312,12 @@ describe "Common Functions" do
312
312
  end
313
313
  end
314
314
 
315
- describe "Distance" do
315
+ describe "More Distance" do
316
316
 
317
317
  it { @s1.distance_to(@p3).should be_close(8.48528137423857,0.0001) }
318
318
  it { @s1.distance_to(@p3).should be_close(8.48,0.01) }
319
-
320
- it do
321
- lambda { @p1.distance_spheroid_to(@c3) }.should raise_error
322
- end
323
-
324
- it do
325
- lambda { @p3.distance_spheroid_to(@s1) }.should raise_error
326
- end
319
+ it { @p1.distance_spheroid_to(@c3).should be_close(384735.205204477, 1) }
320
+ it { @p3.distance_spheroid_to(@s1).should be_close(939450.671670147,1) }
327
321
 
328
322
  end
329
323
 
@@ -356,8 +350,15 @@ describe "Common Functions" do
356
350
  it { @s1.disjoint?(@s2).should be_true }
357
351
  it { @s1.polygonize.should be_instance_of(GeometryCollection) }
358
352
  it { @s3.polygonize.geometries.should be_empty }
359
- it { @s2.locate_along_measure(1.6).should be_nil }
360
- it { @s2.locate_between_measures(0.1,0.3).should be_nil }
353
+
354
+ # TODO: Starting with Pgis 1.5 this fail.. need to check
355
+ it do
356
+ lambda { @s2.locate_along_measure(1.6) }.should raise_error
357
+ end
358
+
359
+ it do
360
+ lambda { @s2.locate_between_measures(0.1,0.3).should be_nil }.should raise_error
361
+ end
361
362
 
362
363
  it "should build area" do
363
364
  @s2.build_area.should be_nil
data/spec/spec_helper.rb CHANGED
@@ -6,17 +6,19 @@ $:.unshift((File.join(File.dirname(__FILE__), '..', 'lib')))
6
6
  gem 'activerecord', "=2.3.5"
7
7
  gem 'nofxx-georuby'
8
8
  require 'postgis_adapter'
9
+ # GeoRuby::SimpleFeatures::DEFAULT_SRID = -1
9
10
 
10
11
  # Monkey patch Schema.define logger
11
12
  $logger = Logger.new(StringIO.new)
12
13
  def $logger.write(d); self.info(d); end
13
14
  # $stdout = $logger
14
15
 
15
- # GeoRuby::SimpleFeatures.srid = -1
16
16
 
17
17
  ActiveRecord::Base.logger = $logger
18
- ActiveRecord::Base.establish_connection({ :adapter => "postgresql", :database => "postgis_adapter",
19
- :username => "nofxx", :password => "" })
18
+ ActiveRecord::Base.establish_connection({ :adapter => "postgresql",
19
+ :database => "postgis_adapter",
20
+ :username => "postgres",
21
+ :password => "" })
20
22
 
21
23
  PG_VERSION = ActiveRecord::Base.connection.select_value("SELECT version()").scan(/PostgreSQL ([\d\.]*)/)[0][0]
22
24
 
@@ -24,3 +26,4 @@ puts "Running against PostgreSQL #{PG_VERSION}"
24
26
 
25
27
  require File.dirname(__FILE__) + '/db/schema_postgis.rb'
26
28
  require File.dirname(__FILE__) + '/db/models_postgis.rb'
29
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postgis_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.7
4
+ version: 0.7.8
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: 2010-01-29 00:00:00 -02:00
12
+ date: 2010-02-26 00:00:00 -03:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -82,9 +82,9 @@ test_files:
82
82
  - spec/db/schema_postgis.rb
83
83
  - spec/postgis_adapter/acts_as_geom_spec.rb
84
84
  - spec/postgis_adapter/common_spatial_adapter_spec.rb
85
+ - spec/postgis_functions_spec.rb
86
+ - spec/spec_helper.rb
85
87
  - spec/postgis_adapter_spec.rb
86
- - spec/postgis_functions/bbox_spec.rb
87
88
  - spec/postgis_functions/class_spec.rb
88
89
  - spec/postgis_functions/common_spec.rb
89
- - spec/postgis_functions_spec.rb
90
- - spec/spec_helper.rb
90
+ - spec/postgis_functions/bbox_spec.rb