ppe-postgis-adapter 0.7.3 → 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.2
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
@@ -10,22 +10,23 @@ module PostgisFunctions
10
10
 
11
11
  module ClassMethods
12
12
 
13
- # acts_as_geom :db_field => :geom_type
13
+ # has_geom :db_field => :geom_type
14
14
  # Examples:
15
15
  #
16
- # acts_as_geom :data => :point
17
- # acts_as_geom :geom => :line_string
18
- # acts_as_geom :geom => :polygon
16
+ # has_geom :data => :point
17
+ # has_geom :geom => :line_string
18
+ # has_geom :geom => :polygon
19
19
  #
20
- def acts_as_geom(*geom)
20
+ def has_geom(*geom)
21
21
  cattr_accessor :postgis_geoms
22
22
  self.postgis_geoms = geom[0] # {:columns => column
23
23
  send :include, case geom[0].values[0]
24
24
  when :point then PointFunctions
25
25
  when :polygon then PolygonFunctions
26
- when :line_string then LineStringFunctions
26
+ when :line_string, :multi_line_string then LineStringFunctions
27
27
  end unless geom[0].kind_of? Symbol
28
28
  end
29
+ alias :acts_as_geom :has_geom
29
30
 
30
31
  def get_geom_type(column)
31
32
  self.postgis_geoms.values[0] 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
 
@@ -38,7 +38,8 @@ module PostgisFunctions
38
38
  # DistanceSphere/Spheroid => meters
39
39
  #
40
40
  def construct_geometric_sql(type,geoms,options)
41
- not_db, on_db = geoms.partition { |g| g.is_a? Geometry }
41
+ not_db, on_db = geoms.partition { |g| g.is_a?(Geometry) || g.new_record? }
42
+ not_db.map! {|o| o.respond_to?(:new_record?) ? o.geom : o }
42
43
 
43
44
  tables = on_db.map do |t| {
44
45
  :name => t.class.table_name,
@@ -50,13 +51,15 @@ module PostgisFunctions
50
51
  # Implement a better way for options?
51
52
  if options.instance_of? Hash
52
53
  transform = options.delete(:transform)
54
+ stcollect = options.delete(:stcollect)
53
55
  options = nil
54
56
  end
55
57
 
56
58
  fields = tables.map { |f| "#{f[:uid]}.#{f[:column]}" } # W1.geom
57
59
  fields << not_db.map { |g| "'#{g.as_hex_ewkb}'::geometry"} unless not_db.empty?
58
60
  fields.map! { |f| "ST_Transform(#{f}, #{transform})" } if transform # ST_Transform(W1.geom,x)
59
- conditions = tables.map { |f| "#{f[:uid]}.id = #{f[:id]}" } # W1.id = 5
61
+ fields.map! { |f| "ST_Union(#{f})" } if stcollect # ST_Transform(W1.geom,x)
62
+ conditions = tables.map {|f| "#{f[:uid]}.id = #{f[:id]}" } # W1.id = 5
60
63
  tables.map! { |f| "#{f[:name]} #{f[:uid]}" } # streets W1
61
64
 
62
65
  #
@@ -73,6 +76,7 @@ module PostgisFunctions
73
76
  fields = fields.join(" #{options} ")
74
77
  end
75
78
 
79
+
76
80
  sql = "SELECT #{opcode}(#{fields}) "
77
81
  sql << "FROM #{tables.join(",")} " unless tables.empty?
78
82
  sql << "WHERE #{conditions.join(" AND ")}" unless conditions.empty?
@@ -100,7 +104,7 @@ module PostgisFunctions
100
104
  GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb(value) rescue value
101
105
  end
102
106
  rescue Exception => e
103
- raise StandardError, "#{e}"
107
+ raise StandardError, e.to_s #+ e.backtrace.inspect
104
108
  end
105
109
 
106
110
  # Get a unique ID for tables
@@ -341,6 +341,9 @@ module PostgisFunctions
341
341
  postgis_calculate(:touches, [self, other])
342
342
  end
343
343
 
344
+ def st_collect(other=nil)
345
+ postgis_calculate(:collect, [self, other])
346
+ end
344
347
  #
345
348
  # The convex hull of a geometry represents the minimum closed geometry that
346
349
  # encloses all geometries within the set.
@@ -517,8 +520,8 @@ module PostgisFunctions
517
520
  # Returns Geometry as GeoJSON
518
521
  #
519
522
  # http://geojson.org/
520
- #
521
- def as_geo_json(precision=15, bbox = 0)
523
+ #
524
+ def as_geo_json(precision=15, bbox=0)
522
525
  postgis_calculate(:AsGeoJSON, self, [precision, bbox])
523
526
  end
524
527
 
@@ -705,9 +708,19 @@ module PostgisFunctions
705
708
  # #float ST_Max_Distance(geometry g1, geometry g2);
706
709
  # postgis_calculate(:max_distance, [self, other])
707
710
  #end
708
- end
709
711
 
712
+ #
713
+ # Returns a (set of) LineString(s) formed by sewing together a MULTILINESTRING.
714
+ #
715
+ # Only use with MULTILINESTRING/LINESTRINGs. If you feed a polygon or geometry collection into this function, it will return an empty GEOMETRYCOLLECTION
716
+ #
717
+ # Returns geometry ST_LineMerge(geometry amultilinestring);
718
+ #
719
+ def line_merge
720
+ postgis_calculate(:LineMerge, self, { :stcollect => self})
721
+ end
710
722
 
723
+ end
711
724
  #
712
725
  #
713
726
  #
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ppe-postgis-adapter}
8
- s.version = "0.7.3"
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
- s.authors = ["Marcos Piccinini"]
12
- s.date = %q{2009-10-18}
11
+ s.authors = ["Marcos Piccinini", "Simon Tokumine"]
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 = [
@@ -73,3 +73,4 @@ Gem::Specification.new do |s|
73
73
  else
74
74
  end
75
75
  end
76
+
@@ -52,6 +52,10 @@ class Street < ActiveRecord::Base
52
52
  acts_as_geom :geom => :line_string
53
53
  end
54
54
 
55
+ class Road < ActiveRecord::Base
56
+ acts_as_geom :geom => :multi_line_string
57
+ end
58
+
55
59
  class CommonGeo < ActiveRecord::Base
56
60
  acts_as_geom :geom => :point
57
61
  end
@@ -3,53 +3,53 @@ ActiveRecord::Schema.define() do
3
3
 
4
4
  create_table "table_points", :force => true do |t|
5
5
  t.string "data"
6
- t.point "geom", :null=>false
6
+ t.point "geom", :null=>false, :srid => 4326
7
7
  end
8
8
 
9
9
  create_table "table_keyword_column_points", :force => true do |t|
10
- t.point "location", :null => false
10
+ t.point "location", :null => false, :srid => 4326
11
11
  end
12
12
 
13
13
  create_table "table_line_strings", :force => true do |t|
14
14
  t.integer "value"
15
- t.line_string "geom", :null=>false
15
+ t.line_string "geom", :null=>false, :srid => 4326
16
16
  end
17
17
 
18
18
  create_table "table_polygons", :force => true do |t|
19
- t.polygon "geom", :null=>false
19
+ t.polygon "geom", :null=>false, :srid => 4326
20
20
  end
21
21
 
22
22
  create_table "table_multi_points", :force => true do |t|
23
- t.multi_point "geom", :null=>false
23
+ t.multi_point "geom", :null=>false, :srid => 4326
24
24
  end
25
25
 
26
26
  create_table "table_multi_line_strings", :force => true do |t|
27
- t.multi_line_string "geom", :null=>false
27
+ t.multi_line_string "geom", :null=>false, :srid => 4326
28
28
  end
29
29
 
30
30
  create_table "table_multi_polygons", :force => true do |t|
31
- t.multi_polygon "geom", :null=>false
31
+ t.multi_polygon "geom", :null=>false, :srid => 4326
32
32
  end
33
33
 
34
34
  create_table "table_geometries", :force => true do |t|
35
- t.geometry "geom", :null=>false
35
+ t.geometry "geom", :null=>false, :srid => 4326
36
36
  end
37
37
 
38
38
  create_table "table_geometry_collections", :force => true do |t|
39
- t.geometry_collection "geom", :null=>false
39
+ t.geometry_collection "geom", :null=>false, :srid => 4326
40
40
  end
41
41
 
42
42
  create_table "table3dz_points", :force => true do |t|
43
43
  t.column "data", :string
44
- t.point "geom", :null => false , :with_z => true
44
+ t.point "geom", :null => false , :with_z => true, :srid => 4326
45
45
  end
46
46
 
47
47
  create_table "table3dm_points", :force => true do |t|
48
- t.point "geom", :null => false , :with_m => true
48
+ t.point "geom", :null => false , :with_m => true, :srid => 4326
49
49
  end
50
50
 
51
51
  create_table "table4d_points", :force => true do |t|
52
- t.point "geom", :null => false, :with_m => true, :with_z => true
52
+ t.point "geom", :null => false, :with_m => true, :with_z => true, :srid => 4326
53
53
  end
54
54
 
55
55
  create_table "table_srid_line_strings", :force => true do |t|
@@ -78,6 +78,12 @@ ActiveRecord::Schema.define() do
78
78
  t.line_string :geom, :null => false, :srid => 4326
79
79
  end
80
80
 
81
+ create_table :roads, :force => true do |t|
82
+ t.string :data, :limit => 100
83
+ t.integer :value
84
+ t.multi_line_string :geom, :null => false, :srid => 4326
85
+ end
86
+
81
87
  create_table :common_geos, :force => true do |t|
82
88
  t.string :data, :limit => 100
83
89
  t.integer :value
@@ -40,7 +40,7 @@ describe "CommonSpatialAdapter" do
40
40
 
41
41
  before(:all)do
42
42
  ActiveRecord::Schema.define do
43
- add_column "parks","geom2", :multi_point
43
+ add_column "parks","geom2", :multi_point, :srid => 4326
44
44
  end
45
45
  end
46
46
 
@@ -55,7 +55,7 @@ describe "CommonSpatialAdapter" do
55
55
  col.geometry_type.should eql(:multi_point)
56
56
  col.type.should eql(:geometry)
57
57
  col.null.should be_true
58
- col.srid.should eql(-1)
58
+ col.srid.should eql(4326)
59
59
  col.with_z.should be_false
60
60
  col.with_m.should be_false
61
61
  end
@@ -159,7 +159,7 @@ describe "CommonSpatialAdapter" do
159
159
  create_table "parks", :force => true do |t|
160
160
  t.column "data" , :string, :limit => 100
161
161
  t.column "value", :integer
162
- t.column "geom", :point,:null=>false
162
+ t.column "geom", :point,:null=>false, :srid => 4326
163
163
  end
164
164
  end
165
165
 
@@ -246,7 +246,7 @@ describe "CommonSpatialAdapter" do
246
246
  [144.819402,13.568565],[144.822373,13.572223],[144.8242032,13.57381149],
247
247
  [144.82634,13.575666],[144.83416,13.590365],[144.83514,13.595657],
248
248
  [144.834284,13.59652],[144.834024,13.598031],[144.83719,13.598061],
249
- [144.857742,13.598263]]]).to_fixture_format.split(/\s+/).should eql(["0103000020FFFFFFFF0100000020000000FBCC599F721B62404ED026874F322B40056A3178981B6240BF61A2410A2E2B406B10E676AF1B6240E486DF4DB72C2B40BC7A15199D1B6240F701486DE22C2B40CE893DB48F1B62400E828E56B52C2B40BA84436F711B624054C37E4FAC2B2B407862D68B211B62408F183DB7D0252B40D8817346141B6240C51D6FF25B242B40BFB7E9CFFE1A624071FF91E9D0212B401EA33CF3F21A624024F1F274AE202B408EEA7420EB1A6240ED4ACB48BD1F2B4058E20165D31A6240BEBC00FBE81C2B40A3586E69B51A6240E6E5B0FB8E192B40452BF702B31A6240FE2B2B4D4A192B40CA32C4B1AE1A624084B872F6CE182B403291D26C9E1A62408B8C0E48C2162B4072E14048961A624014B35E0CE5142B403FA88B144A1A6240732EC55565172B405CBA38E0E9196240344179C48D1A2B402C2AE274121A624005C58F31771D2B40892650C4221A62406D62793EA01F2B40FDBD141E341A62405D328E91EC212B40DD088B8A381A6240EC4CA1F31A232B40A1832EE1501A6240BB09BE69FA242B4046A863DF5F1A6240F23C9F9ECA252B400D6C9560711A624099D6A6B1BD262B4034F44F70B11A6240F5673F52442E2B409B728577B91A624056444DF4F9302B406FF25B74B21A6240E1D1C6116B312B4088821953B01A624005FD851E31322B4039D1AE42CA1A6240AF06280D35322B40FBCC599F721B62404ED026874F322B40"])
249
+ [144.857742,13.598263]]]).to_fixture_format.split(/\s+/).should eql(["0103000020E61000000100000020000000FBCC599F721B62404ED026874F322B40056A3178981B6240BF61A2410A2E2B406B10E676AF1B6240E486DF4DB72C2B40BC7A15199D1B6240F701486DE22C2B40CE893DB48F1B62400E828E56B52C2B40BA84436F711B624054C37E4FAC2B2B407862D68B211B62408F183DB7D0252B40D8817346141B6240C51D6FF25B242B40BFB7E9CFFE1A624071FF91E9D0212B401EA33CF3F21A624024F1F274AE202B408EEA7420EB1A6240ED4ACB48BD1F2B4058E20165D31A6240BEBC00FBE81C2B40A3586E69B51A6240E6E5B0FB8E192B40452BF702B31A6240FE2B2B4D4A192B40CA32C4B1AE1A624084B872F6CE182B403291D26C9E1A62408B8C0E48C2162B4072E14048961A624014B35E0CE5142B403FA88B144A1A6240732EC55565172B405CBA38E0E9196240344179C48D1A2B402C2AE274121A624005C58F31771D2B40892650C4221A62406D62793EA01F2B40FDBD141E341A62405D328E91EC212B40DD088B8A381A6240EC4CA1F31A232B40A1832EE1501A6240BB09BE69FA242B4046A863DF5F1A6240F23C9F9ECA252B400D6C9560711A624099D6A6B1BD262B4034F44F70B11A6240F5673F52442E2B409B728577B91A624056444DF4F9302B406FF25B74B21A6240E1D1C6116B312B4088821953B01A624005FD851E31322B4039D1AE42CA1A6240AF06280D35322B40FBCC599F721B62404ED026874F322B40"])
250
250
  end
251
251
 
252
252
  end
@@ -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
@@ -8,6 +8,7 @@ describe "Common Functions" do
8
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
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
10
  @s1 ||= Street.create!(:data => "Street1", :geom => LineString.from_coordinates([[1,1],[2,2]],4326))
11
+ @sx ||= Street.create!(:data => "Street1", :geom => LineString.from_coordinates([[2,2],[4,4]],4326))
11
12
  @s2 ||= Street.create!(:data => "Street2", :geom => LineString.from_coordinates([[4,4],[7,7]],4326))
12
13
  @s3 ||= Street.create!(:data => "Street3", :geom => LineString.from_coordinates([[8,8],[18,18],[20,20],[25,25],[30,30],[38,38]],4326))
13
14
  @s4 ||= Street.create!(:data => "Street4", :geom => LineString.from_coordinates([[10,8],[15,18]],4326))
@@ -16,6 +17,9 @@ describe "Common Functions" do
16
17
  @p3 ||= Position.create!(:data => "Point3", :geom => Point.from_x_y(8,8,4326))
17
18
  @p4 ||= Position.create!(:data => "Point4", :geom => Point.from_x_y(18.1,18,4326))
18
19
  @p5 ||= Position.create!(:data => "Point5", :geom => Point.from_x_y(30,30,4326))
20
+ @m1 ||= Road.create(:data => "MG-050", :geom => MultiLineString.from_line_strings([@s1.geom, @sx.geom]))
21
+ @m2 ||= Road.create(:data => "MG-050", :geom => MultiLineString.from_line_strings([@s3.geom, @s4.geom]))
22
+ @p6 ||= Position.create!(:data => "Point6", :geom => Point.from_x_y(30.9999,30.9999,4326))
19
23
  end
20
24
 
21
25
  describe "Point" do
@@ -35,11 +39,11 @@ describe "Common Functions" do
35
39
  it { @p1.distance_to(@c1).should be_close(3.0, 0.0001) }
36
40
  it { @p1.distance_to(@c2).should be_close(21.0237960416286, 0.000001) }
37
41
  it { @p1.distance_to(@s2).should be_close(4.24264068711928, 0.000001) }
38
- it { @p1.distance_sphere_to(@p2).should be_close(628516.874554178, 0.0001) }
39
- 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) }
40
44
  it { @p1.distance_spheroid_to(@p2).should be_close(627129.50,0.01) }
41
- it { @p1.distance_spheroid_to(@p2).should be_close(627129.502639041, 0.000001) }
42
- 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) }
43
47
 
44
48
  it "should find the distance from a unsaved point" do
45
49
  @p1.distance_to(@p2).should be_close(5.65685424949238,0.001)
@@ -102,9 +106,18 @@ describe "Common Functions" do
102
106
  it "should export as GeoJSON" do
103
107
  @p1.as_geo_json.should eql("{\"type\":\"Point\",\"coordinates\":[1,1]}")
104
108
  end
109
+
110
+ it "should export as GeoJSON with variable precision" do
111
+ @p6.as_geo_json(1).should eql("{\"type\":\"Point\",\"coordinates\":[31,31]}")
112
+ end
113
+
114
+ it "should export as GeoJSON with variable precision and bounding box" do
115
+ @p6.as_geo_json(1,1).should eql("{\"type\":\"Point\",\"bbox\":[31.0,31.0,31.0,31.0],\"coordinates\":[31,31]}")
116
+ end
105
117
  end
106
118
 
107
119
 
120
+
108
121
  # it { @p3.x.should be_close(8.0, 0.1) }
109
122
  # it { @p3.y.should be_close(8.0, 0.1) }
110
123
  # it { @p3.z.should be_close(0.0, 0.1) }
@@ -171,7 +184,7 @@ describe "Common Functions" do
171
184
  end
172
185
 
173
186
  it "distance to a linestring" do
174
- @c1.distance_to(@s1).should be_close(1.8,0.001)
187
+ @c1.distance_to(@s1).should be_close(2.146,0.001)
175
188
  end
176
189
 
177
190
  it "should simplify me" do
@@ -239,6 +252,10 @@ describe "Common Functions" do
239
252
  end
240
253
  end
241
254
 
255
+ it "should have 1 geometry" do
256
+ @s1.should_not respond_to(:geometries)
257
+ end
258
+
242
259
  it "should intersect with linestring" do
243
260
  @s4.intersects?(@s3).should be_true
244
261
  end
@@ -293,21 +310,14 @@ describe "Common Functions" do
293
310
  @s1.as_geo_json.should eql("{\"type\":\"LineString\",\"coordinates\":[[1,1],[2,2]]}")
294
311
  end
295
312
  end
296
-
297
313
  end
298
314
 
299
- describe "Distance" do
315
+ describe "More Distance" do
300
316
 
301
317
  it { @s1.distance_to(@p3).should be_close(8.48528137423857,0.0001) }
302
318
  it { @s1.distance_to(@p3).should be_close(8.48,0.01) }
303
-
304
- it do
305
- lambda { @p1.distance_spheroid_to(@c3) }.should raise_error
306
- end
307
-
308
- it do
309
- lambda { @p3.distance_spheroid_to(@s1) }.should raise_error
310
- 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) }
311
321
 
312
322
  end
313
323
 
@@ -340,8 +350,15 @@ describe "Common Functions" do
340
350
  it { @s1.disjoint?(@s2).should be_true }
341
351
  it { @s1.polygonize.should be_instance_of(GeometryCollection) }
342
352
  it { @s3.polygonize.geometries.should be_empty }
343
- it { @s2.locate_along_measure(1.6).should be_nil }
344
- 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
345
362
 
346
363
  it "should build area" do
347
364
  @s2.build_area.should be_nil
@@ -369,6 +386,37 @@ describe "Common Functions" do
369
386
  str.geom[1].x.should be_close(7,0.0000001)
370
387
  str.geom[1].y.should be_close(7,0.0000001)
371
388
  end
389
+
390
+ describe "MultiLineString" do
391
+
392
+ it "should write nicely" do
393
+ @m1.geom.should be_instance_of(MultiLineString)
394
+ end
395
+
396
+ it "should have 2 geometries" do
397
+ @m1.geom.should have(2).geometries
398
+ end
399
+
400
+ it "should have 2 points on the geometry" do
401
+ @m1.geom.geometries[0].length.should eql(2)
402
+ end
403
+
404
+ it "should calculate multi line string length" do
405
+ @m1.length_spheroid.should be_close(470464.54, 0.01)
406
+ end
407
+
408
+ it "should line merge!" do
409
+ merged = @m1.line_merge
410
+ merged.should be_instance_of(LineString)
411
+ merged.length.should eql(3)
412
+ end
413
+
414
+ it "should line merge collect" do
415
+ pending
416
+ co = @m2.line_merge
417
+ co.should be_instance_of(LineString)
418
+ end
419
+ end
372
420
  end
373
421
 
374
422
  end
@@ -31,11 +31,18 @@ describe "PostgisFunctions" do
31
31
  @p1.distance_to(Point.from_x_y(5,5,4326)).should be_close(55.0726792520575, 0.001)
32
32
  end
33
33
 
34
+ it "should work with unsaved objects" do
35
+ ss = Street.new(:data => "Street1", :geom => LineString.from_coordinates([[-44,-21],[-43,-29]],4326))
36
+ ss.length_spheroid.should be_close(891908.39, 0.01)
37
+ end
38
+
34
39
  it { @c1.area(32640).should be_close(9165235788987.37, 0.01) }
35
40
 
36
41
  it { @c1.area.should be_close(720.0, 0.1) }
37
42
 
38
- it { @p1.should be_strictly_left_of(@c1) }
43
+ it "should be strictly left of city" do
44
+ @p1.should be_strictly_left_of(@c1)
45
+ end
39
46
 
40
47
  it { @s1.length.should be_close(8.06225774829855, 0.001) }
41
48
 
@@ -3,20 +3,22 @@ require 'spec'
3
3
  require 'pg'
4
4
  require 'activerecord'
5
5
  $:.unshift((File.join(File.dirname(__FILE__), '..', 'lib')))
6
- gem 'activerecord', "=2.3.4"
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 => "postgres", :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,15 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ppe-postgis-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 7
8
+ - 8
9
+ version: 0.7.8
5
10
  platform: ruby
6
11
  authors:
7
12
  - Marcos Piccinini
13
+ - Simon Tokumine
8
14
  autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-10-18 00:00:00 +01:00
18
+ date: 2010-02-26 00:00:00 +01:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -62,18 +68,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
68
  requirements:
63
69
  - - ">="
64
70
  - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
65
73
  version: "0"
66
- version:
67
74
  required_rubygems_version: !ruby/object:Gem::Requirement
68
75
  requirements:
69
76
  - - ">="
70
77
  - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
71
80
  version: "0"
72
- version:
73
81
  requirements: []
74
82
 
75
83
  rubyforge_project: postgis_adapter
76
- rubygems_version: 1.3.5
84
+ rubygems_version: 1.3.6
77
85
  signing_key:
78
86
  specification_version: 3
79
87
  summary: PostGIS Adapter for Active Record