postgis_adapter 0.5.1 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +37 -24
- data/Rakefile +29 -3
- data/VERSION +1 -0
- data/lib/postgis_adapter/acts_as_geom.rb +18 -13
- data/lib/postgis_adapter/common_spatial_adapter.rb +4 -2
- data/lib/postgis_adapter.rb +70 -30
- data/lib/postgis_functions/common.rb +26 -9
- data/lib/postgis_functions.rb +19 -15
- data/postgis_adapter.gemspec +16 -20
- data/spec/db/models_postgis.rb +11 -7
- data/spec/db/schema_postgis.rb +17 -13
- data/spec/postgis_adapter/acts_as_geom_spec.rb +2 -2
- data/spec/postgis_adapter/common_spatial_adapter_spec.rb +3 -3
- data/spec/postgis_adapter_spec.rb +13 -13
- data/spec/postgis_functions/common_spec.rb +53 -1
- data/spec/postgis_functions_spec.rb +9 -1
- data/spec/spec.opts +2 -3
- data/spec/spec_helper.rb +17 -8
- metadata +10 -17
- data/Manifest.txt +0 -32
- data/VERSION.yml +0 -4
- data/install.rb +0 -0
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/spec/db/database_postgis.yml +0 -4
- data/uninstall.rb +0 -0
data/README.rdoc
CHANGED
@@ -7,6 +7,7 @@ It also provides a way to manage these columns in migrations.
|
|
7
7
|
This fork adds handy methods to make geometrical calculations on postgis.
|
8
8
|
Based on http://georuby.rubyforge.org Spatial Adapter
|
9
9
|
|
10
|
+
RDocs - http://docs.github.com/nofxx/postgis_adapter
|
10
11
|
Postgis Manual - http://postgis.refractions.net/documentation/manual-svn
|
11
12
|
|
12
13
|
*PostGIS and Rails 2+ only*.
|
@@ -32,6 +33,7 @@ Rails:
|
|
32
33
|
|
33
34
|
config.gem "postgis_adapter"
|
34
35
|
|
36
|
+
|
35
37
|
Github version:
|
36
38
|
|
37
39
|
|
@@ -77,20 +79,29 @@ model and the table defined above :
|
|
77
79
|
|
78
80
|
Here are this fork additions. To use it:
|
79
81
|
|
82
|
+
acts_as_geom [column_name] => [geom_type]
|
83
|
+
|
84
|
+
|
85
|
+
Examples:
|
86
|
+
|
87
|
+
class POI < ActiveRecord::Base
|
88
|
+
acts_as_geom :geom => :point
|
89
|
+
end
|
80
90
|
|
81
91
|
class Street < ActiveRecord::Base
|
82
|
-
acts_as_geom :line
|
92
|
+
acts_as_geom :line => :line_string
|
83
93
|
end
|
84
94
|
|
85
95
|
...
|
86
96
|
|
87
|
-
@place = Poi.new( :data => **Point** )
|
88
|
-
@park = Park.new( :area => **Polygon** )
|
89
|
-
@street = Street.new( :line => **LineString** )
|
90
97
|
|
91
98
|
|
92
99
|
== Play!
|
93
100
|
|
101
|
+
@place = Poi.new( :geom => Point.from_x_y(10,20) )
|
102
|
+
@park = Park.new( :area => **Polygon** )
|
103
|
+
@street = Street.new( :line => **LineString** )
|
104
|
+
|
94
105
|
@place.inside?(@park)
|
95
106
|
=> true
|
96
107
|
|
@@ -98,10 +109,9 @@ Here are this fork additions. To use it:
|
|
98
109
|
=> false
|
99
110
|
|
100
111
|
@place.outside?(@park)
|
101
|
-
|
102
112
|
@street.crosses?(@park)
|
103
|
-
|
104
113
|
@area.contains?(@place)
|
114
|
+
...
|
105
115
|
|
106
116
|
|
107
117
|
=== Polygons:
|
@@ -121,7 +131,7 @@ Supports transform (useful to transform SRID to UTM for area in Km^2)
|
|
121
131
|
=> Area with new SRID
|
122
132
|
|
123
133
|
|
124
|
-
===
|
134
|
+
=== LineStrings:
|
125
135
|
|
126
136
|
@street_east.intersects?(@street_west)
|
127
137
|
=> false
|
@@ -129,9 +139,6 @@ Supports transform (useful to transform SRID to UTM for area in Km^2)
|
|
129
139
|
@street_central.length
|
130
140
|
=> 4508.53636
|
131
141
|
|
132
|
-
@street_central.length(:miles)
|
133
|
-
=> 2.81798593
|
134
|
-
|
135
142
|
@street.length_spheroid
|
136
143
|
=> 4.40853636
|
137
144
|
|
@@ -147,7 +154,7 @@ Supports transform (useful to transform SRID to UTM for area in Km^2)
|
|
147
154
|
Country.contain(@point)
|
148
155
|
=> The Conutry that contains the point
|
149
156
|
|
150
|
-
|
157
|
+
Area.contains(@point)
|
151
158
|
=> [Array of areas contains the point...
|
152
159
|
|
153
160
|
|
@@ -183,7 +190,6 @@ Or use a (almost) PostGIS like notation:
|
|
183
190
|
@area.bbox "@", @park
|
184
191
|
|
185
192
|
|
186
|
-
|
187
193
|
=== Warning
|
188
194
|
|
189
195
|
*To be fixed:*
|
@@ -194,12 +200,6 @@ implement a multi geom.
|
|
194
200
|
http://nofxx.lighthouseapp.com/projects/20712/tickets/3-multiple-geoms-in-model
|
195
201
|
|
196
202
|
|
197
|
-
=== Wiki
|
198
|
-
|
199
|
-
Check out the wiki pages (http://github.com/nofxx/postgis_adapter/wikis).
|
200
|
-
For all functions.
|
201
|
-
|
202
|
-
|
203
203
|
=== Find_by
|
204
204
|
|
205
205
|
find_by_*column* has been redefined when column is of a geometric type.
|
@@ -237,16 +237,29 @@ geometric column in PostGIS, along with the addition of a spatial
|
|
237
237
|
index on the column :
|
238
238
|
|
239
239
|
ActiveRecord::Schema.define do
|
240
|
-
|
241
|
-
t.string
|
242
|
-
t.point
|
240
|
+
create_table :places do |t|
|
241
|
+
t.string :name
|
242
|
+
t.point :geom, :srid => 4326, :with_z => true, :null => false
|
243
243
|
|
244
244
|
t.timestamps
|
245
245
|
end
|
246
|
-
|
246
|
+
|
247
|
+
add_index :places, :geom, :spatial => true
|
247
248
|
end
|
248
249
|
|
249
250
|
|
251
|
+
Types:
|
252
|
+
|
253
|
+
point
|
254
|
+
polygon
|
255
|
+
line_string
|
256
|
+
multi_point
|
257
|
+
multi_polygon
|
258
|
+
multi_line_string
|
259
|
+
geometry
|
260
|
+
geometry_collection
|
261
|
+
|
262
|
+
|
250
263
|
=== Fixtures
|
251
264
|
|
252
265
|
If you use fixtures for your unit tests, at some point,
|
@@ -311,14 +324,14 @@ Postgis Adapter is released under the MIT license.
|
|
311
324
|
|
312
325
|
== Support
|
313
326
|
|
314
|
-
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
|
315
328
|
|
316
329
|
Any questions, enhancement proposals, bug notifications or corrections:
|
317
330
|
|
318
331
|
|
319
332
|
=== PostgisAdapter
|
320
333
|
|
321
|
-
|
334
|
+
http://github.com/nofxx/postgis_adapter/issues
|
322
335
|
|
323
336
|
|
324
337
|
=== SpatialAdapter
|
data/Rakefile
CHANGED
@@ -34,11 +34,37 @@ task :default => :spec
|
|
34
34
|
|
35
35
|
require 'rake/rdoctask'
|
36
36
|
Rake::RDocTask.new do |rdoc|
|
37
|
-
|
38
|
-
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
39
|
-
|
37
|
+
version = File.exist?('VERSION') ? File.read('VERSION').chomp : ""
|
40
38
|
rdoc.rdoc_dir = 'rdoc'
|
41
39
|
rdoc.title = "postgis_adapter #{version}"
|
42
40
|
rdoc.rdoc_files.include('README*')
|
43
41
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
44
42
|
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# Reek & Roodi
|
46
|
+
#
|
47
|
+
begin
|
48
|
+
require 'reek/rake_task'
|
49
|
+
Reek::RakeTask.new do |t|
|
50
|
+
t.fail_on_error = true
|
51
|
+
t.verbose = false
|
52
|
+
t.source_files = 'lib/**/*.rb'
|
53
|
+
end
|
54
|
+
rescue LoadError
|
55
|
+
task :reek do
|
56
|
+
abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
begin
|
61
|
+
require 'roodi'
|
62
|
+
require 'roodi_task'
|
63
|
+
RoodiTask.new do |t|
|
64
|
+
t.verbose = false
|
65
|
+
end
|
66
|
+
rescue LoadError
|
67
|
+
task :roodi do
|
68
|
+
abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
|
69
|
+
end
|
70
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.7.1
|
@@ -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
|
@@ -60,8 +60,10 @@ ActiveRecord::SchemaDumper.class_eval do
|
|
60
60
|
else
|
61
61
|
tbl.print " t.column #{column.name.inspect}, #{column.type.inspect}"
|
62
62
|
end
|
63
|
-
tbl.print ", :limit => #{column.limit.inspect}" if column.limit != @types[column.type][:limit]
|
64
|
-
tbl.print ", :
|
63
|
+
tbl.print ", :limit => #{column.limit.inspect}" if column.limit != @types[column.type][:limit] && column.precision.blank? && column.scale.blank?
|
64
|
+
tbl.print ", :precision => #{column.precision.inspect}" if column.precision != @types[column.type][:precision]
|
65
|
+
tbl.print ", :scale => #{column.scale.inspect}" if column.scale != @types[column.type][:scale]
|
66
|
+
tbl.print ", :default => #{default_string(column.default)}" if !column.default.nil?
|
65
67
|
tbl.print ", :null => false" if !column.null
|
66
68
|
tbl.puts
|
67
69
|
end
|
data/lib/postgis_adapter.rb
CHANGED
@@ -29,35 +29,73 @@ GeoRuby::SimpleFeatures::Geometry.class_eval do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
ActiveRecord::Base.class_eval do
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
if
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
"#{table_name}.#{column_name} && SetSRID(?::box3d, #{value.srid} ) "
|
46
|
-
else
|
47
|
-
"#{table_name}.#{column_name} && ? "
|
48
|
-
end
|
32
|
+
|
33
|
+
#Vit Ondruch & Tilmann Singer 's patch
|
34
|
+
def self.get_conditions(attrs)
|
35
|
+
attrs.map do |attr, value|
|
36
|
+
attr = attr.to_s
|
37
|
+
column_name = connection.quote_column_name(attr)
|
38
|
+
if columns_hash[attr].is_a?(SpatialColumn)
|
39
|
+
if value.is_a?(Array)
|
40
|
+
attrs[attr.to_sym]= "BOX3D(" + value[0].join(" ") + "," + value[1].join(" ") + ")"
|
41
|
+
"#{table_name}.#{column_name} && SetSRID(?::box3d, #{value[2] || @@default_srid || DEFAULT_SRID} ) "
|
42
|
+
elsif value.is_a?(Envelope)
|
43
|
+
attrs[attr.to_sym]= "BOX3D(" + value.lower_corner.text_representation + "," + value.upper_corner.text_representation + ")"
|
44
|
+
"#{table_name}.#{column_name} && SetSRID(?::box3d, #{value.srid} ) "
|
49
45
|
else
|
50
|
-
"#{table_name}.#{
|
46
|
+
"#{table_name}.#{column_name} && ? "
|
51
47
|
end
|
52
|
-
|
53
|
-
|
48
|
+
else
|
49
|
+
attribute_condition("#{table_name}.#{column_name}", value)
|
50
|
+
end
|
51
|
+
end.join(' AND ')
|
52
|
+
end
|
54
53
|
|
55
|
-
|
54
|
+
#For Rails >= 2
|
55
|
+
if method(:sanitize_sql_hash_for_conditions).arity == 1
|
56
|
+
# Before Rails 2.3.3, the method had only one argument
|
56
57
|
def self.sanitize_sql_hash_for_conditions(attrs)
|
57
58
|
conditions = get_conditions(attrs)
|
58
59
|
replace_bind_variables(conditions, expand_range_bind_variables(attrs.values))
|
59
60
|
end
|
61
|
+
elsif method(:sanitize_sql_hash_for_conditions).arity == -2
|
62
|
+
# After Rails 2.3.3, the method had only two args, the last one optional
|
63
|
+
def self.sanitize_sql_hash_for_conditions(attrs, table_name = quoted_table_name)
|
64
|
+
attrs = expand_hash_conditions_for_aggregates(attrs)
|
65
|
+
|
66
|
+
conditions = attrs.map do |attr, value|
|
67
|
+
unless value.is_a?(Hash)
|
68
|
+
attr = attr.to_s
|
69
|
+
|
70
|
+
# Extract table name from qualified attribute names.
|
71
|
+
if attr.include?('.')
|
72
|
+
table_name, attr = attr.split('.', 2)
|
73
|
+
table_name = connection.quote_table_name(table_name)
|
74
|
+
end
|
75
|
+
|
76
|
+
if columns_hash[attr].is_a?(SpatialColumn)
|
77
|
+
if value.is_a?(Array)
|
78
|
+
attrs[attr.to_sym]= "BOX3D(" + value[0].join(" ") + "," + value[1].join(" ") + ")"
|
79
|
+
"#{table_name}.#{connection.quote_column_name(attr)} && SetSRID(?::box3d, #{value[2] || DEFAULT_SRID} ) "
|
80
|
+
elsif value.is_a?(Envelope)
|
81
|
+
attrs[attr.to_sym]= "BOX3D(" + value.lower_corner.text_representation + "," + value.upper_corner.text_representation + ")"
|
82
|
+
"#{table_name}.#{connection.quote_column_name(attr)} && SetSRID(?::box3d, #{value.srid} ) "
|
83
|
+
else
|
84
|
+
"#{table_name}.#{connection.quote_column_name(attr)} && ? "
|
85
|
+
end
|
86
|
+
else
|
87
|
+
attribute_condition("#{table_name}.#{connection.quote_column_name(attr)}", value)
|
88
|
+
end
|
89
|
+
else
|
90
|
+
sanitize_sql_hash_for_conditions(value, connection.quote_table_name(attr.to_s))
|
91
|
+
end
|
92
|
+
end.join(' AND ')
|
60
93
|
|
94
|
+
replace_bind_variables(conditions, expand_range_bind_variables(attrs.values))
|
95
|
+
end
|
96
|
+
else
|
97
|
+
raise "Spatial Adapter will not work with this version of Rails"
|
98
|
+
end
|
61
99
|
end
|
62
100
|
|
63
101
|
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
|
@@ -81,11 +119,15 @@ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
|
|
81
119
|
|
82
120
|
alias :original_tables :tables
|
83
121
|
def tables(name = nil) #:nodoc:
|
122
|
+
original_tables(name) + views(name)
|
123
|
+
end
|
124
|
+
|
125
|
+
def views(name = nil) #:nodoc:
|
84
126
|
schemas = schema_search_path.split(/,/).map { |p| quote(p.strip) }.join(',')
|
85
|
-
|
127
|
+
query(<<-SQL, name).map { |row| row[0] }
|
86
128
|
SELECT viewname
|
87
|
-
|
88
|
-
|
129
|
+
FROM pg_views
|
130
|
+
WHERE schemaname IN (#{schemas})
|
89
131
|
SQL
|
90
132
|
end
|
91
133
|
|
@@ -145,14 +187,12 @@ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
|
|
145
187
|
# <table_name>_<column_name>_spatial_index unless
|
146
188
|
# the key :name is present in the options hash, in which case its
|
147
189
|
# value is taken as the name of the index.
|
148
|
-
def add_index(table_name,column_name,options = {})
|
190
|
+
def add_index(table_name, column_name, options = {})
|
149
191
|
index_name = options[:name] || index_name(table_name,:column => Array(column_name))
|
150
192
|
if options[:spatial]
|
151
193
|
execute "CREATE INDEX #{index_name} ON #{table_name} USING GIST (#{Array(column_name).join(", ")} GIST_GEOMETRY_OPS)"
|
152
194
|
else
|
153
|
-
|
154
|
-
#all together
|
155
|
-
execute "CREATE #{index_type} INDEX #{index_name} ON #{table_name} (#{Array(column_name).join(", ")})"
|
195
|
+
super
|
156
196
|
end
|
157
197
|
end
|
158
198
|
|
@@ -198,12 +238,12 @@ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
|
|
198
238
|
if type =~ /geometry/i
|
199
239
|
raw_geom_info = raw_geom_infos[name]
|
200
240
|
if raw_geom_info.nil?
|
201
|
-
ActiveRecord::ConnectionAdapters::SpatialPostgreSQLColumn.create_simplified(name,default,notnull == "f")
|
241
|
+
ActiveRecord::ConnectionAdapters::SpatialPostgreSQLColumn.create_simplified(name, default, notnull == "f")
|
202
242
|
else
|
203
243
|
ActiveRecord::ConnectionAdapters::SpatialPostgreSQLColumn.new(name, default,raw_geom_info.type, notnull == "f", raw_geom_info.srid, raw_geom_info.with_z, raw_geom_info.with_m)
|
204
244
|
end
|
205
245
|
else
|
206
|
-
ActiveRecord::ConnectionAdapters::
|
246
|
+
ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new(name, ActiveRecord::ConnectionAdapters::PostgreSQLColumn.extract_value_from_default( default), type, notnull == "f")
|
207
247
|
end
|
208
248
|
end
|
209
249
|
end
|
@@ -235,7 +235,7 @@ module PostgisFunctions
|
|
235
235
|
|
236
236
|
def simplify!(tolerance=0.1)
|
237
237
|
#FIXME: not good..
|
238
|
-
self.update_attribute(
|
238
|
+
self.update_attribute(geo_columns.first, simplify)
|
239
239
|
end
|
240
240
|
|
241
241
|
#
|
@@ -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
|
@@ -502,6 +502,15 @@ module PostgisFunctions
|
|
502
502
|
end
|
503
503
|
|
504
504
|
#
|
505
|
+
# Returns Geometry as GeoJSON
|
506
|
+
#
|
507
|
+
# http://geojson.org/
|
508
|
+
#
|
509
|
+
def as_geo_json
|
510
|
+
postgis_calculate(:AsGeoJSON, self)
|
511
|
+
end
|
512
|
+
|
513
|
+
|
505
514
|
#
|
506
515
|
#
|
507
516
|
# LINESTRING
|
@@ -519,7 +528,7 @@ module PostgisFunctions
|
|
519
528
|
# Returns Float
|
520
529
|
#
|
521
530
|
def length
|
522
|
-
|
531
|
+
postgis_calculate(:length, self).to_f
|
523
532
|
end
|
524
533
|
|
525
534
|
#
|
@@ -530,7 +539,7 @@ module PostgisFunctions
|
|
530
539
|
# Returns Float
|
531
540
|
#
|
532
541
|
def length_3d
|
533
|
-
|
542
|
+
postgis_calculate(:length3d, self).to_f
|
534
543
|
end
|
535
544
|
|
536
545
|
#
|
@@ -551,7 +560,7 @@ module PostgisFunctions
|
|
551
560
|
# Returns Float length_spheroid(geometry linestring, spheroid);
|
552
561
|
#
|
553
562
|
def length_spheroid(spheroid = EARTH_SPHEROID)
|
554
|
-
|
563
|
+
postgis_calculate(:length_spheroid, self, spheroid).to_f
|
555
564
|
end
|
556
565
|
|
557
566
|
#
|
@@ -594,6 +603,14 @@ module PostgisFunctions
|
|
594
603
|
postgis_calculate(:crosses, [self, other])
|
595
604
|
end
|
596
605
|
|
606
|
+
#
|
607
|
+
# Warning: PostGIS 1.4+
|
608
|
+
#
|
609
|
+
# Return crossing direction
|
610
|
+
def line_crossing_direction(other)
|
611
|
+
postgis_calculate(:lineCrossingDirection, [self, other])
|
612
|
+
end
|
613
|
+
|
597
614
|
#
|
598
615
|
# Returns a float between 0 and 1 representing the location of the closest point
|
599
616
|
# on LineString to the given Point, as a fraction of total 2d line length.
|
@@ -709,7 +726,7 @@ module PostgisFunctions
|
|
709
726
|
# Returns Float ST_Distance_Sphere(geometry pointlonlatA, geometry pointlonlatB);
|
710
727
|
#
|
711
728
|
def distance_sphere_to(other)
|
712
|
-
|
729
|
+
postgis_calculate(:distance_sphere, [self, other]).to_f
|
713
730
|
end
|
714
731
|
|
715
732
|
#
|
@@ -792,7 +809,7 @@ module PostgisFunctions
|
|
792
809
|
# use 'length'. Measurements are in the units of the spatial reference system of
|
793
810
|
# the geometry.
|
794
811
|
#
|
795
|
-
# Accepts optional parameter, the
|
812
|
+
# Accepts optional parameter, the sridto transform to.
|
796
813
|
#
|
797
814
|
# Returns Float ST_Perimeter(geometry g1);
|
798
815
|
#
|
data/lib/postgis_functions.rb
CHANGED
@@ -5,8 +5,8 @@
|
|
5
5
|
# Hope you enjoy this plugin.
|
6
6
|
#
|
7
7
|
#
|
8
|
-
# Post any bugs/suggestions to
|
9
|
-
# http://
|
8
|
+
# Post any bugs/suggestions to GitHub issues tracker:
|
9
|
+
# http://github.com/nofxx/postgis_adapter/issues
|
10
10
|
#
|
11
11
|
#
|
12
12
|
# Some links:
|
@@ -21,17 +21,15 @@ module PostgisFunctions
|
|
21
21
|
|
22
22
|
def postgis_calculate(operation, subjects, options = {})
|
23
23
|
subjects = [subjects] unless subjects.respond_to?(:map)
|
24
|
-
|
25
|
-
rescue Exception => e
|
26
|
-
raise StandardError, "#{e}"
|
24
|
+
execute_geometrical_calculation(operation, subjects, options)
|
27
25
|
end
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
def get_column_name
|
32
|
-
@geo_column ||= postgis_geoms[:columns][0]
|
27
|
+
def geo_columns
|
28
|
+
@geo_columns ||= postgis_geoms[:columns]
|
33
29
|
end
|
34
30
|
|
31
|
+
private
|
32
|
+
|
35
33
|
#
|
36
34
|
# Construct the PostGIS SQL query
|
37
35
|
#
|
@@ -44,6 +42,7 @@ module PostgisFunctions
|
|
44
42
|
|
45
43
|
tables = on_db.map do |t| {
|
46
44
|
:name => t.class.table_name,
|
45
|
+
:column => t.postgis_geoms.keys[0],
|
47
46
|
:uid => unique_identifier,
|
48
47
|
:id => t[:id] }
|
49
48
|
end
|
@@ -54,7 +53,7 @@ module PostgisFunctions
|
|
54
53
|
options = nil
|
55
54
|
end
|
56
55
|
|
57
|
-
fields = tables.map { |f| "#{f[:uid]}.#{
|
56
|
+
fields = tables.map { |f| "#{f[:uid]}.#{f[:column]}" } # W1.geom
|
58
57
|
fields << not_db.map { |g| "'#{g.as_hex_ewkb}'::geometry"} unless not_db.empty?
|
59
58
|
fields.map! { |f| "ST_Transform(#{f}, #{transform})" } if transform # ST_Transform(W1.geom,x)
|
60
59
|
conditions = tables.map { |f| "#{f[:uid]}.id = #{f[:id]}" } # W1.id = 5
|
@@ -74,10 +73,10 @@ module PostgisFunctions
|
|
74
73
|
fields = fields.join(" #{options} ")
|
75
74
|
end
|
76
75
|
|
77
|
-
sql =
|
78
|
-
sql <<
|
79
|
-
sql <<
|
80
|
-
|
76
|
+
sql = "SELECT #{opcode}(#{fields}) "
|
77
|
+
sql << "FROM #{tables.join(",")} " unless tables.empty?
|
78
|
+
sql << "WHERE #{conditions.join(" AND ")}" unless conditions.empty?
|
79
|
+
sql
|
81
80
|
end
|
82
81
|
|
83
82
|
#
|
@@ -92,11 +91,16 @@ module PostgisFunctions
|
|
92
91
|
def execute_geometrical_calculation(operation, subject, options) #:nodoc:
|
93
92
|
value = connection.select_value(construct_geometric_sql(operation, subject, options))
|
94
93
|
return nil unless value
|
95
|
-
|
94
|
+
# TODO: bench case vs if here
|
95
|
+
if value =~ /^[tf]$/
|
96
96
|
{"f" => false, "t" => true}[value]
|
97
|
+
elsif value =~ /^\{/
|
98
|
+
value
|
97
99
|
else
|
98
100
|
GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb(value) rescue value
|
99
101
|
end
|
102
|
+
rescue Exception => e
|
103
|
+
raise StandardError, "#{e}"
|
100
104
|
end
|
101
105
|
|
102
106
|
# Get a unique ID for tables
|
data/postgis_adapter.gemspec
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
1
4
|
# -*- encoding: utf-8 -*-
|
2
5
|
|
3
6
|
Gem::Specification.new do |s|
|
4
7
|
s.name = %q{postgis_adapter}
|
5
|
-
s.version = "0.
|
8
|
+
s.version = "0.7.1"
|
6
9
|
|
7
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
11
|
s.authors = ["Marcos Augusto"]
|
9
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-10-10}
|
10
13
|
s.description = %q{Execute PostGIS functions on Active Record}
|
11
14
|
s.email = %q{x@nofxx.com}
|
12
15
|
s.extra_rdoc_files = [
|
@@ -16,12 +19,10 @@ Gem::Specification.new do |s|
|
|
16
19
|
".gitignore",
|
17
20
|
"History.txt",
|
18
21
|
"MIT-LICENSE",
|
19
|
-
"Manifest.txt",
|
20
22
|
"README.rdoc",
|
21
23
|
"Rakefile",
|
22
|
-
"VERSION
|
24
|
+
"VERSION",
|
23
25
|
"init.rb",
|
24
|
-
"install.rb",
|
25
26
|
"lib/postgis_adapter.rb",
|
26
27
|
"lib/postgis_adapter/acts_as_geom.rb",
|
27
28
|
"lib/postgis_adapter/common_spatial_adapter.rb",
|
@@ -31,10 +32,6 @@ Gem::Specification.new do |s|
|
|
31
32
|
"lib/postgis_functions/common.rb",
|
32
33
|
"postgis_adapter.gemspec",
|
33
34
|
"rails/init.rb",
|
34
|
-
"script/console",
|
35
|
-
"script/destroy",
|
36
|
-
"script/generate",
|
37
|
-
"spec/db/database_postgis.yml",
|
38
35
|
"spec/db/models_postgis.rb",
|
39
36
|
"spec/db/schema_postgis.rb",
|
40
37
|
"spec/postgis_adapter/acts_as_geom_spec.rb",
|
@@ -45,26 +42,25 @@ Gem::Specification.new do |s|
|
|
45
42
|
"spec/postgis_functions/common_spec.rb",
|
46
43
|
"spec/postgis_functions_spec.rb",
|
47
44
|
"spec/spec.opts",
|
48
|
-
"spec/spec_helper.rb"
|
49
|
-
"uninstall.rb"
|
45
|
+
"spec/spec_helper.rb"
|
50
46
|
]
|
51
47
|
s.homepage = %q{http://github.com/nofxx/postgis_adapter}
|
52
48
|
s.rdoc_options = ["--charset=UTF-8"]
|
53
49
|
s.require_paths = ["lib"]
|
54
50
|
s.rubyforge_project = %q{postgis_adapter}
|
55
|
-
s.rubygems_version = %q{1.3.
|
51
|
+
s.rubygems_version = %q{1.3.5}
|
56
52
|
s.summary = %q{PostGIS Adapter for Active Record}
|
57
53
|
s.test_files = [
|
58
|
-
"spec/
|
59
|
-
"spec/postgis_functions/class_spec.rb",
|
60
|
-
"spec/postgis_functions/bbox_spec.rb",
|
61
|
-
"spec/postgis_functions/common_spec.rb",
|
62
|
-
"spec/db/models_postgis.rb",
|
54
|
+
"spec/db/models_postgis.rb",
|
63
55
|
"spec/db/schema_postgis.rb",
|
64
|
-
"spec/postgis_adapter_spec.rb",
|
65
|
-
"spec/postgis_adapter/common_spatial_adapter_spec.rb",
|
66
56
|
"spec/postgis_adapter/acts_as_geom_spec.rb",
|
67
|
-
"spec/
|
57
|
+
"spec/postgis_adapter/common_spatial_adapter_spec.rb",
|
58
|
+
"spec/postgis_functions_spec.rb",
|
59
|
+
"spec/spec_helper.rb",
|
60
|
+
"spec/postgis_adapter_spec.rb",
|
61
|
+
"spec/postgis_functions/class_spec.rb",
|
62
|
+
"spec/postgis_functions/common_spec.rb",
|
63
|
+
"spec/postgis_functions/bbox_spec.rb"
|
68
64
|
]
|
69
65
|
|
70
66
|
if s.respond_to? :specification_version then
|
data/spec/db/models_postgis.rb
CHANGED
@@ -31,27 +31,31 @@ end
|
|
31
31
|
class Table3dmPoint < ActiveRecord::Base
|
32
32
|
end
|
33
33
|
|
34
|
-
class
|
34
|
+
class Table4dPoint < ActiveRecord::Base
|
35
35
|
end
|
36
36
|
|
37
|
-
class
|
37
|
+
class TableSridLineString < ActiveRecord::Base
|
38
38
|
end
|
39
39
|
|
40
|
-
class
|
40
|
+
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
|
+
end
|
58
|
+
|
59
|
+
class DiffName < ActiveRecord::Base
|
60
|
+
acts_as_geom :the_geom => :point
|
57
61
|
end
|
data/spec/db/schema_postgis.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
#add some postgis specific tables
|
3
2
|
ActiveRecord::Schema.define() do
|
4
3
|
|
@@ -62,27 +61,32 @@ ActiveRecord::Schema.define() do
|
|
62
61
|
end
|
63
62
|
|
64
63
|
create_table :cities, :force => true do |t|
|
65
|
-
t.string
|
66
|
-
t.integer
|
67
|
-
t.polygon
|
64
|
+
t.string :data, :limit => 100
|
65
|
+
t.integer :value
|
66
|
+
t.polygon :geom, :null => false, :srid => 4326
|
68
67
|
end
|
69
68
|
|
70
69
|
create_table :positions, :force => true do |t|
|
71
|
-
t.string
|
72
|
-
t.integer
|
73
|
-
t.point
|
70
|
+
t.string :data, :limit => 100
|
71
|
+
t.integer :value
|
72
|
+
t.point :geom, :null => false, :srid => 4326
|
74
73
|
end
|
75
74
|
|
76
75
|
create_table :streets, :force => true do |t|
|
77
|
-
t.string
|
78
|
-
t.integer
|
79
|
-
t.line_string
|
76
|
+
t.string :data, :limit => 100
|
77
|
+
t.integer :value
|
78
|
+
t.line_string :geom, :null => false, :srid => 4326
|
80
79
|
end
|
81
80
|
|
82
81
|
create_table :common_geos, :force => true do |t|
|
83
|
-
t.string
|
84
|
-
t.integer
|
85
|
-
t.point
|
82
|
+
t.string :data, :limit => 100
|
83
|
+
t.integer :value
|
84
|
+
t.point :geom, :null => false, :srid => 4326
|
85
|
+
end
|
86
|
+
|
87
|
+
create_table :diff_names, :force => true do |t|
|
88
|
+
t.string :data
|
89
|
+
t.point :the_geom, :null => false, :srid => 4326
|
86
90
|
end
|
87
91
|
|
88
92
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
2
|
|
3
3
|
class DiffColumn < ActiveRecord::Base
|
4
|
-
acts_as_geom :ponto
|
4
|
+
acts_as_geom :ponto => :point
|
5
5
|
end
|
6
6
|
|
7
7
|
class NotInDb < ActiveRecord::Base
|
@@ -11,7 +11,7 @@ end
|
|
11
11
|
describe "ActsAsGeom" do
|
12
12
|
|
13
13
|
it "should get the geom type" do
|
14
|
-
|
14
|
+
City.connection.columns("cities").select { |c| c.name == "geom" }[0]
|
15
15
|
City.get_geom_type(:geom).should eql(:polygon)
|
16
16
|
end
|
17
17
|
|
@@ -13,7 +13,7 @@ describe "CommonSpatialAdapter" do
|
|
13
13
|
create_table "parks", :force => true do |t|
|
14
14
|
t.string "data", :limit => 100
|
15
15
|
t.integer "value"
|
16
|
-
t.polygon "geom", :null=>false, :srid => 4326 , :with_z => true
|
16
|
+
t.polygon "geom", :null => false, :srid => 4326 , :with_z => true, :with_m => true
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -180,8 +180,8 @@ describe "CommonSpatialAdapter" do
|
|
180
180
|
|
181
181
|
after(:all) do
|
182
182
|
ActiveRecord::Base.connection.execute('DROP VIEW viewparks')
|
183
|
-
end
|
184
|
-
|
183
|
+
end
|
184
|
+
end
|
185
185
|
|
186
186
|
describe "Dump" do
|
187
187
|
before(:all) do
|
@@ -129,25 +129,25 @@ describe "PostgisAdapter" do
|
|
129
129
|
describe "Find" do
|
130
130
|
|
131
131
|
ActiveRecord::Schema.define() do
|
132
|
-
create_table
|
133
|
-
t.
|
134
|
-
t.
|
135
|
-
t.
|
132
|
+
create_table :areas, :force => true do |t|
|
133
|
+
t.string :data, :limit => 100
|
134
|
+
t.integer :value
|
135
|
+
t.point :geom, :null => false, :srid => 4326
|
136
136
|
end
|
137
|
-
add_index
|
137
|
+
add_index :areas, :geom, :spatial => true, :name => "areas_spatial_index"
|
138
138
|
end
|
139
139
|
|
140
|
-
class
|
140
|
+
class Area < ActiveRecord::Base
|
141
141
|
end
|
142
142
|
|
143
143
|
it "should create some points" do
|
144
|
-
|
145
|
-
|
146
|
-
|
144
|
+
Area.create!(:data => "Point1", :geom => Point.from_x_y(1.2,0.75,4326))
|
145
|
+
Area.create!(:data => "Point2",:geom => Point.from_x_y(0.6,1.3,4326))
|
146
|
+
Area.create!(:data => "Point3", :geom => Point.from_x_y(2.5,2,4326))
|
147
147
|
end
|
148
148
|
|
149
149
|
it "should find by geom" do
|
150
|
-
pts =
|
150
|
+
pts = Area.find_all_by_geom(LineString.from_coordinates([[0,0],[2,2]],4326))
|
151
151
|
pts.should be_instance_of(Array)
|
152
152
|
pts.length.should eql(2)
|
153
153
|
pts[0].data.should match /Point/
|
@@ -155,12 +155,12 @@ describe "PostgisAdapter" do
|
|
155
155
|
end
|
156
156
|
|
157
157
|
it "should find by geom again" do
|
158
|
-
pts =
|
158
|
+
pts = Area.find_all_by_geom(LineString.from_coordinates([[2.49,1.99],[2.51,2.01]],4326))
|
159
159
|
pts[0].data.should eql("Point3")
|
160
160
|
end
|
161
161
|
|
162
162
|
it "should find by geom column bbox condition" do
|
163
|
-
pts =
|
163
|
+
pts = Area.find_all_by_geom([[0,0],[2,2],4326])
|
164
164
|
pts.should be_instance_of(Array)
|
165
165
|
pts.length.should eql(2)
|
166
166
|
pts[0].data.should match /Point/
|
@@ -168,7 +168,7 @@ describe "PostgisAdapter" do
|
|
168
168
|
end
|
169
169
|
|
170
170
|
it "should not mess with rails finder" do
|
171
|
-
pts =
|
171
|
+
pts = Area.find_all_by_data "Point1"
|
172
172
|
pts.should have(1).park
|
173
173
|
end
|
174
174
|
|
@@ -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))
|
@@ -69,6 +70,14 @@ describe "Common Functions" do
|
|
69
70
|
@p1.geom.srid.should eql(29101)
|
70
71
|
end
|
71
72
|
|
73
|
+
it "should transform non saved srid geoms" do
|
74
|
+
pt = Point.from_x_y(11121381.4586196,10161852.0494475, 29101)
|
75
|
+
pos = Position.new(:geom => pt)
|
76
|
+
pos.transform(4326)
|
77
|
+
pos.geom.x.should be_close(1.00000000000005, 0.00001)
|
78
|
+
pos.geom.y.should be_close(1.00000000000005, 0.00001)
|
79
|
+
end
|
80
|
+
|
72
81
|
it "should see in what fraction of the ls it is" do
|
73
82
|
@p1.where_on_line(@s1).should eql(0.0)
|
74
83
|
end
|
@@ -89,6 +98,13 @@ describe "Common Functions" do
|
|
89
98
|
lambda { @p2.to_utm! }.should change(@p2, :srid)
|
90
99
|
end
|
91
100
|
|
101
|
+
if PG_VERSION >= "8.4.0"
|
102
|
+
it "should export as GeoJSON" do
|
103
|
+
@p1.as_geo_json.should eql("{\"type\":\"Point\",\"coordinates\":[1,1]}")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
|
92
108
|
# it { @p3.x.should be_close(8.0, 0.1) }
|
93
109
|
# it { @p3.y.should be_close(8.0, 0.1) }
|
94
110
|
# it { @p3.z.should be_close(0.0, 0.1) }
|
@@ -182,10 +198,24 @@ describe "Common Functions" do
|
|
182
198
|
# @c1.disjoint?(@p2).should be_true
|
183
199
|
# end
|
184
200
|
|
201
|
+
it "should check overlaps" do
|
202
|
+
@c2.contains?(@c1).should be_false
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should check overlaps non saved" do
|
206
|
+
@c2.contains?(@poly).should be_false
|
207
|
+
end
|
208
|
+
|
185
209
|
it "should find the UTM zone" do
|
186
210
|
@c2.utm_zone.should eql(32737)
|
187
211
|
end
|
188
212
|
|
213
|
+
if PG_VERSION >= "8.4.0"
|
214
|
+
it "should export as GeoJSON" do
|
215
|
+
@c1.as_geo_json.should eql("{\"type\":\"Polygon\",\"coordinates\":[[[12,45],[45,41],[4,1],[12,45]],[[2,5],[5,1],[14,1],[2,5]]]}")
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
189
219
|
end
|
190
220
|
|
191
221
|
describe "LineString" do
|
@@ -203,6 +233,12 @@ describe "Common Functions" do
|
|
203
233
|
it { @s1.touches?(@s2).should be_false }
|
204
234
|
it { @s4.touches?(@s3).should be_false }
|
205
235
|
|
236
|
+
if PG_VERSION >= "8.4.0"
|
237
|
+
it "should calculate crossing direction" do
|
238
|
+
@s4.line_crossing_direction(@s3).should eql("1")
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
206
242
|
it "should intersect with linestring" do
|
207
243
|
@s4.intersects?(@s3).should be_true
|
208
244
|
end
|
@@ -251,6 +287,13 @@ describe "Common Functions" do
|
|
251
287
|
it { @s1.should_not be_envelopes_intersect(@s2) }
|
252
288
|
it { @s1.boundary.should be_instance_of(MultiPoint) }
|
253
289
|
|
290
|
+
|
291
|
+
if PG_VERSION >= "8.4.0"
|
292
|
+
it "should export as GeoJSON" do
|
293
|
+
@s1.as_geo_json.should eql("{\"type\":\"LineString\",\"coordinates\":[[1,1],[2,2]]}")
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
254
297
|
end
|
255
298
|
|
256
299
|
describe "Distance" do
|
@@ -317,6 +360,15 @@ describe "Common Functions" do
|
|
317
360
|
@s2.utm_zone.should eql(32732)
|
318
361
|
end
|
319
362
|
|
363
|
+
it "should transform non saved" do
|
364
|
+
ls = LineString.from_coordinates([[11435579.3992231,10669620.8116516],[11721337.4281638,11210714.9524106]],29101)
|
365
|
+
str = Street.new(:geom => ls)
|
366
|
+
str.transform(4326)
|
367
|
+
str.geom[0].x.should be_close(4,0.0000001)
|
368
|
+
str.geom[0].y.should be_close(4,0.0000001)
|
369
|
+
str.geom[1].x.should be_close(7,0.0000001)
|
370
|
+
str.geom[1].y.should be_close(7,0.0000001)
|
371
|
+
end
|
320
372
|
end
|
321
373
|
|
322
374
|
end
|
@@ -6,6 +6,7 @@ describe "PostgisFunctions" do
|
|
6
6
|
@s1 ||= Street.create!(:data => "Street1", :geom => LineString.from_coordinates([[-43,-20],[-42,-28]],4326))
|
7
7
|
@p1 ||= Position.create!(:data => "Point1", :geom => Point.from_x_y(-43,-22,4326))
|
8
8
|
@cg ||= CommonGeo.create!(:data => "Point1", :geom => Point.from_x_y(-43,-22,4326))
|
9
|
+
@px = DiffName.create!(:data => "Hey", :the_geom => Point.from_x_y(10,20, 4326))
|
9
10
|
end
|
10
11
|
|
11
12
|
describe "Common Mix" do
|
@@ -40,6 +41,13 @@ describe "PostgisFunctions" do
|
|
40
41
|
|
41
42
|
it { @s1.length_spheroid.should be_close(891883.597963462,0.0001) }
|
42
43
|
|
43
|
-
|
44
|
+
it "should work with a diff column name" do
|
45
|
+
px2 = DiffName.create!(:data => "Hey 2", :the_geom => Point.from_x_y(20,20, 4326))
|
46
|
+
@px.distance_to(px2).should be_close(10.0, 0.1)
|
47
|
+
end
|
44
48
|
|
49
|
+
it "should work with mixed column names" do
|
50
|
+
@px.distance_to(@s1).should be_close(66.4,1)
|
51
|
+
end
|
52
|
+
end
|
45
53
|
end
|
data/spec/spec.opts
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -2,15 +2,24 @@ require 'rubygems'
|
|
2
2
|
require 'spec'
|
3
3
|
require 'pg'
|
4
4
|
require 'activerecord'
|
5
|
-
require 'rspec_spinner'
|
6
|
-
|
7
|
-
gem 'activerecord', "=2.3.2"
|
8
|
-
|
9
5
|
$:.unshift((File.join(File.dirname(__FILE__), '..', 'lib')))
|
6
|
+
gem 'activerecord', "=2.3.4"
|
10
7
|
require 'postgis_adapter'
|
8
|
+
|
9
|
+
# Monkey patch Schema.define logger
|
10
|
+
$logger = Logger.new(StringIO.new)
|
11
|
+
def $logger.write(d); self.info(d); end
|
12
|
+
# $stdout = $logger
|
13
|
+
|
11
14
|
GeoRuby::SimpleFeatures.srid = -1
|
12
|
-
|
13
|
-
|
14
|
-
ActiveRecord::Base.establish_connection(
|
15
|
-
|
15
|
+
|
16
|
+
ActiveRecord::Base.logger = $logger
|
17
|
+
ActiveRecord::Base.establish_connection({ :adapter => "postgresql", :database => "postgis_adapter",
|
18
|
+
:username => "postgres", :password => "" })
|
19
|
+
|
20
|
+
PG_VERSION = ActiveRecord::Base.connection.select_value("SELECT version()").scan(/PostgreSQL ([\d\.]*)/)[0][0]
|
21
|
+
|
22
|
+
puts "Running against PostgreSQL #{PG_VERSION}"
|
23
|
+
|
24
|
+
require File.dirname(__FILE__) + '/db/schema_postgis.rb'
|
16
25
|
require File.dirname(__FILE__) + '/db/models_postgis.rb'
|
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.
|
4
|
+
version: 0.7.1
|
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-
|
12
|
+
date: 2009-10-10 00:00:00 -03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -25,12 +25,10 @@ files:
|
|
25
25
|
- .gitignore
|
26
26
|
- History.txt
|
27
27
|
- MIT-LICENSE
|
28
|
-
- Manifest.txt
|
29
28
|
- README.rdoc
|
30
29
|
- Rakefile
|
31
|
-
- VERSION
|
30
|
+
- VERSION
|
32
31
|
- init.rb
|
33
|
-
- install.rb
|
34
32
|
- lib/postgis_adapter.rb
|
35
33
|
- lib/postgis_adapter/acts_as_geom.rb
|
36
34
|
- lib/postgis_adapter/common_spatial_adapter.rb
|
@@ -40,10 +38,6 @@ files:
|
|
40
38
|
- lib/postgis_functions/common.rb
|
41
39
|
- postgis_adapter.gemspec
|
42
40
|
- rails/init.rb
|
43
|
-
- script/console
|
44
|
-
- script/destroy
|
45
|
-
- script/generate
|
46
|
-
- spec/db/database_postgis.yml
|
47
41
|
- spec/db/models_postgis.rb
|
48
42
|
- spec/db/schema_postgis.rb
|
49
43
|
- spec/postgis_adapter/acts_as_geom_spec.rb
|
@@ -55,7 +49,6 @@ files:
|
|
55
49
|
- spec/postgis_functions_spec.rb
|
56
50
|
- spec/spec.opts
|
57
51
|
- spec/spec_helper.rb
|
58
|
-
- uninstall.rb
|
59
52
|
has_rdoc: true
|
60
53
|
homepage: http://github.com/nofxx/postgis_adapter
|
61
54
|
licenses: []
|
@@ -80,18 +73,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
73
|
requirements: []
|
81
74
|
|
82
75
|
rubyforge_project: postgis_adapter
|
83
|
-
rubygems_version: 1.3.
|
76
|
+
rubygems_version: 1.3.5
|
84
77
|
signing_key:
|
85
78
|
specification_version: 3
|
86
79
|
summary: PostGIS Adapter for Active Record
|
87
80
|
test_files:
|
88
|
-
- spec/postgis_functions_spec.rb
|
89
|
-
- spec/postgis_functions/class_spec.rb
|
90
|
-
- spec/postgis_functions/bbox_spec.rb
|
91
|
-
- spec/postgis_functions/common_spec.rb
|
92
81
|
- spec/db/models_postgis.rb
|
93
82
|
- spec/db/schema_postgis.rb
|
94
|
-
- spec/postgis_adapter_spec.rb
|
95
|
-
- spec/postgis_adapter/common_spatial_adapter_spec.rb
|
96
83
|
- spec/postgis_adapter/acts_as_geom_spec.rb
|
84
|
+
- spec/postgis_adapter/common_spatial_adapter_spec.rb
|
85
|
+
- spec/postgis_functions_spec.rb
|
97
86
|
- spec/spec_helper.rb
|
87
|
+
- spec/postgis_adapter_spec.rb
|
88
|
+
- spec/postgis_functions/class_spec.rb
|
89
|
+
- spec/postgis_functions/common_spec.rb
|
90
|
+
- spec/postgis_functions/bbox_spec.rb
|
data/Manifest.txt
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
History.txt
|
2
|
-
MIT-LICENSE
|
3
|
-
Manifest.txt
|
4
|
-
README.rdoc
|
5
|
-
Rakefile
|
6
|
-
init.rb
|
7
|
-
install.rb
|
8
|
-
lib/postgis_adapter.rb
|
9
|
-
lib/postgis_adapter/acts_as_geom.rb
|
10
|
-
lib/postgis_adapter/common_spatial_adapter.rb
|
11
|
-
lib/postgis_functions.rb
|
12
|
-
lib/postgis_functions/bbox.rb
|
13
|
-
lib/postgis_functions/class.rb
|
14
|
-
lib/postgis_functions/common.rb
|
15
|
-
postgis_adapter.gemspec
|
16
|
-
rails/init.rb
|
17
|
-
script/console
|
18
|
-
script/destroy
|
19
|
-
script/generate
|
20
|
-
spec/db/database_postgis.yml
|
21
|
-
spec/db/models_postgis.rb
|
22
|
-
spec/db/schema_postgis.rb
|
23
|
-
spec/postgis_adapter/acts_as_geom_spec.rb
|
24
|
-
spec/postgis_adapter/common_spatial_adapter_spec.rb
|
25
|
-
spec/postgis_adapter_spec.rb
|
26
|
-
spec/postgis_functions/bbox_spec.rb
|
27
|
-
spec/postgis_functions/class_spec.rb
|
28
|
-
spec/postgis_functions/common_spec.rb
|
29
|
-
spec/postgis_functions_spec.rb
|
30
|
-
spec/spec.opts
|
31
|
-
spec/spec_helper.rb
|
32
|
-
uninstall.rb
|
data/VERSION.yml
DELETED
data/install.rb
DELETED
File without changes
|
data/script/console
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# File: script/console
|
3
|
-
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
-
|
5
|
-
libs = " -r irb/completion"
|
6
|
-
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
-
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
-
libs << " -r #{File.dirname(__FILE__) + '/../lib/postgis_adapter.rb'}"
|
9
|
-
puts "Loading postgis_adapter gem"
|
10
|
-
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/destroy'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/generate'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/uninstall.rb
DELETED
File without changes
|