postgis_adapter 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +1 -0
- data/lib/postgis_adapter.rb +10 -5
- data/lib/postgis_adapter/acts_as_geom_flymake.rb +69 -0
- data/postgis_adapter.gemspec +3 -3
- metadata +3 -2
data/Manifest.txt
CHANGED
data/lib/postgis_adapter.rb
CHANGED
@@ -18,7 +18,7 @@ include GeoRuby::SimpleFeatures
|
|
18
18
|
include SpatialAdapter
|
19
19
|
|
20
20
|
module PostgisAdapter
|
21
|
-
VERSION = '0.
|
21
|
+
VERSION = '0.3.0'
|
22
22
|
end
|
23
23
|
|
24
24
|
#tables to ignore in migration : relative to PostGIS management of geometric columns
|
@@ -38,18 +38,23 @@ ActiveRecord::Base.class_eval do
|
|
38
38
|
def self.get_conditions(attrs)
|
39
39
|
attrs.map do |attr, value|
|
40
40
|
attr = attr.to_s
|
41
|
+
column_name = connection.quote_column_name(attr)
|
41
42
|
if columns_hash[attr].is_a?(SpatialColumn)
|
42
43
|
if value.is_a?(Array)
|
43
44
|
attrs[attr.to_sym]= "BOX3D(" + value[0].join(" ") + "," + value[1].join(" ") + ")"
|
44
|
-
"#{table_name}.#{
|
45
|
+
"#{table_name}.#{column_name} && SetSRID(?::box3d, #{value[2] || DEFAULT_SRID} ) "
|
45
46
|
elsif value.is_a?(Envelope)
|
46
47
|
attrs[attr.to_sym]= "BOX3D(" + value.lower_corner.text_representation + "," + value.upper_corner.text_representation + ")"
|
47
|
-
"#{table_name}.#{
|
48
|
+
"#{table_name}.#{column_name} && SetSRID(?::box3d, #{value.srid} ) "
|
48
49
|
else
|
49
|
-
"#{table_name}.#{
|
50
|
+
"#{table_name}.#{column_name} && ? "
|
50
51
|
end
|
51
52
|
else
|
52
|
-
|
53
|
+
begin
|
54
|
+
"#{table_name}.#{attribute_condition(column_name, value)}"
|
55
|
+
rescue ArgumentError
|
56
|
+
"#{table_name}.#{column_name} #{attribute_condition(value)}"
|
57
|
+
end
|
53
58
|
end
|
54
59
|
end.join(' AND ')
|
55
60
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# #
|
2
|
+
# PostGIS Adapter
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# http://github.com/nofxx/postgis_adapter
|
6
|
+
#
|
7
|
+
module PostgisFunctions
|
8
|
+
def self.included(base)
|
9
|
+
base.send :extend, ClassMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
#
|
14
|
+
# class City
|
15
|
+
# has_geom :point, :bounds
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# @city.bounds.area #=> 12.456
|
19
|
+
# @city.point.distance_to(@p) #=> "1000"
|
20
|
+
# @product.tax_currency #=> "USD"
|
21
|
+
#
|
22
|
+
# Opts:
|
23
|
+
# :cents => "pennys" #=> @product.pennys
|
24
|
+
# :currency => "currency" #=> @product.currency
|
25
|
+
# :allow_nil => true
|
26
|
+
# :with_currency => true
|
27
|
+
#
|
28
|
+
def has_geom(*attributes)
|
29
|
+
config = {:with_currency => true, :converter => lambda { |m| m.to_money },
|
30
|
+
:allow_nil => false }.update(attributes.extract_options!)
|
31
|
+
|
32
|
+
attributes.each do |attr|
|
33
|
+
mapping = [[config[:cents] || "#{attr}_cents", 'cents']]
|
34
|
+
mapping << [config[:currency] || "#{attr}_currency", 'currency'] if config[:with_currency]
|
35
|
+
|
36
|
+
composed_of attr, :class_name => 'Money',:allow_nil => config[:allow_nil],
|
37
|
+
:mapping => mapping, :converter => config[:converter]
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
# acts_as_geom :geom
|
43
|
+
def acts_as_geom(*columns)
|
44
|
+
cattr_accessor :postgis_geoms
|
45
|
+
geoms = columns.map do |g|
|
46
|
+
geom_type = get_geom_type(g)
|
47
|
+
case geom_type
|
48
|
+
when :point
|
49
|
+
send :include, PointFunctions
|
50
|
+
when :polygon
|
51
|
+
send :include, PolygonFunctions
|
52
|
+
when :line_string
|
53
|
+
send :include, LineStringFunctions
|
54
|
+
end
|
55
|
+
g
|
56
|
+
end
|
57
|
+
self.postgis_geoms = {:columns => geoms}#, :opts => options}
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_geom_type(column)
|
61
|
+
self.columns.select { |c| c.name == column.to_s}.first.geometry_type
|
62
|
+
rescue ActiveRecord::StatementInvalid => e
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
ActiveRecord::Base.send :include, PostgisFunctions
|
69
|
+
|
data/postgis_adapter.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{postgis_adapter}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.3.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Marcos Piccinini"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-03-09}
|
10
10
|
s.description = %q{Postgis Adapter for Activer Record}
|
11
11
|
s.email = ["x@nofxx.com"]
|
12
12
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
|
13
|
-
s.files = ["History.txt", "MIT-LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "init.rb", "install.rb", "lib/postgis_adapter.rb", "lib/postgis_adapter/acts_as_geom.rb", "lib/postgis_adapter/common_spatial_adapter.rb", "lib/postgis_functions.rb", "lib/postgis_functions/bbox.rb", "lib/postgis_functions/class.rb", "lib/postgis_functions/common.rb", "postgis_adapter.gemspec", "rails/init.rb", "script/console", "script/destroy", "script/generate", "spec/db/database_postgis.yml", "spec/db/models_postgis.rb", "spec/db/schema_postgis.rb", "spec/postgis_adapter/acts_as_geom_spec.rb", "spec/postgis_adapter/common_spatial_adapter_spec.rb", "spec/postgis_adapter_spec.rb", "spec/postgis_functions/bbox_spec.rb", "spec/postgis_functions/class_spec.rb", "spec/postgis_functions/common_spec.rb", "spec/postgis_functions_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "uninstall.rb"]
|
13
|
+
s.files = ["History.txt", "MIT-LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "init.rb", "install.rb", "lib/postgis_adapter.rb", "lib/postgis_adapter/acts_as_geom.rb", "lib/postgis_adapter/acts_as_geom_flymake.rb", "lib/postgis_adapter/common_spatial_adapter.rb", "lib/postgis_functions.rb", "lib/postgis_functions/bbox.rb", "lib/postgis_functions/class.rb", "lib/postgis_functions/common.rb", "postgis_adapter.gemspec", "rails/init.rb", "script/console", "script/destroy", "script/generate", "spec/db/database_postgis.yml", "spec/db/models_postgis.rb", "spec/db/schema_postgis.rb", "spec/postgis_adapter/acts_as_geom_spec.rb", "spec/postgis_adapter/common_spatial_adapter_spec.rb", "spec/postgis_adapter_spec.rb", "spec/postgis_functions/bbox_spec.rb", "spec/postgis_functions/class_spec.rb", "spec/postgis_functions/common_spec.rb", "spec/postgis_functions_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "uninstall.rb"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://github.com/nofxx/postgis_adapter}
|
16
16
|
s.rdoc_options = ["--main", "README.rdoc"]
|
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.3.0
|
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: 2009-
|
12
|
+
date: 2009-03-09 00:00:00 -03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- install.rb
|
64
64
|
- lib/postgis_adapter.rb
|
65
65
|
- lib/postgis_adapter/acts_as_geom.rb
|
66
|
+
- lib/postgis_adapter/acts_as_geom_flymake.rb
|
66
67
|
- lib/postgis_adapter/common_spatial_adapter.rb
|
67
68
|
- lib/postgis_functions.rb
|
68
69
|
- lib/postgis_functions/bbox.rb
|