achirkunov-spatial_adapter 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +193 -0
- data/VERSION +1 -0
- data/lib/spatial_adapter.rb +37 -0
- data/lib/spatial_adapter/common/raw_geom_info.rb +23 -0
- data/lib/spatial_adapter/common/schema_definitions.rb +11 -0
- data/lib/spatial_adapter/common/schema_dumper.rb +136 -0
- data/lib/spatial_adapter/common/spatial_column.rb +75 -0
- data/lib/spatial_adapter/common/table_definition.rb +14 -0
- data/lib/spatial_adapter/mysql.rb +98 -0
- data/lib/spatial_adapter/postgresql.rb +388 -0
- data/rails/init.rb +16 -0
- data/spec/README.txt +16 -0
- data/spec/db/mysql_raw.rb +70 -0
- data/spec/db/postgis_raw.rb +190 -0
- data/spec/models/common.rb +65 -0
- data/spec/mysql/connection_adapter_spec.rb +106 -0
- data/spec/mysql/migration_spec.rb +64 -0
- data/spec/mysql/models_spec.rb +104 -0
- data/spec/mysql/schema_dumper_spec.rb +56 -0
- data/spec/postgresql/connection_adapter_spec.rb +230 -0
- data/spec/postgresql/migration_spec.rb +351 -0
- data/spec/postgresql/models_spec.rb +258 -0
- data/spec/postgresql/schema_dumper_spec.rb +79 -0
- data/spec/spec_helper.rb +74 -0
- metadata +113 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'spatial_adapter/postgresql'
|
3
|
+
|
4
|
+
describe "Spatially-enabled Schema Dumps" do
|
5
|
+
before :all do
|
6
|
+
postgis_connection
|
7
|
+
@connection = ActiveRecord::Base.connection
|
8
|
+
|
9
|
+
# Create a new table
|
10
|
+
ActiveRecord::Schema.define do
|
11
|
+
create_table :migrated_geometry_models, :force => true do |t|
|
12
|
+
t.integer :extra
|
13
|
+
t.point :geom, :with_m => true, :with_z => true, :srid => 4326
|
14
|
+
end
|
15
|
+
add_index :migrated_geometry_models, :geom, :spatial => true, :name => 'test_spatial_index'
|
16
|
+
|
17
|
+
create_table :migrated_geography_models, :force => true do |t|
|
18
|
+
t.integer :extra
|
19
|
+
t.point :geom, :with_m => true, :with_z => true, :geographic => true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
File.open('schema.rb', "w") do |file|
|
24
|
+
ActiveRecord::SchemaDumper.dump(@connection, file)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Drop the original tables
|
28
|
+
@connection.drop_table "migrated_geometry_models"
|
29
|
+
@connection.drop_table "migrated_geography_models"
|
30
|
+
|
31
|
+
# Load the dumped schema
|
32
|
+
load('schema.rb')
|
33
|
+
end
|
34
|
+
|
35
|
+
after :all do
|
36
|
+
# delete the schema file
|
37
|
+
File.delete('schema.rb')
|
38
|
+
|
39
|
+
# Drop the new tables
|
40
|
+
@connection.drop_table "migrated_geometry_models"
|
41
|
+
@connection.drop_table "migrated_geography_models"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should preserve spatial attributes of geometry tables" do
|
45
|
+
columns = @connection.columns("migrated_geometry_models")
|
46
|
+
|
47
|
+
columns.should have(3).items
|
48
|
+
geom_column = columns.select{|c| c.name == 'geom'}.first
|
49
|
+
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
50
|
+
geom_column.geometry_type.should == :point
|
51
|
+
geom_column.type.should == :string
|
52
|
+
geom_column.with_z.should == true
|
53
|
+
geom_column.with_m.should == true
|
54
|
+
geom_column.srid.should == 4326
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should preserve spatial attributes of geography tables" do
|
58
|
+
columns = @connection.columns("migrated_geography_models")
|
59
|
+
|
60
|
+
columns.should have(3).items
|
61
|
+
geom_column = columns.select{|c| c.name == 'geom'}.first
|
62
|
+
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
63
|
+
geom_column.geometry_type.should == :point
|
64
|
+
geom_column.type.should == :string
|
65
|
+
geom_column.with_z.should == true
|
66
|
+
geom_column.with_m.should == true
|
67
|
+
geom_column.should be_geographic
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should preserve spatial indexes" do
|
71
|
+
indexes = @connection.indexes("migrated_geometry_models")
|
72
|
+
|
73
|
+
indexes.should have(1).item
|
74
|
+
|
75
|
+
indexes.first.name.should == 'test_spatial_index'
|
76
|
+
indexes.first.columns.should == ["geom"]
|
77
|
+
indexes.first.spatial.should == true
|
78
|
+
end
|
79
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
require 'geo_ruby'
|
4
|
+
gem 'activerecord', '=3.0.0.beta3'
|
5
|
+
require 'active_record'
|
6
|
+
|
7
|
+
$:.unshift((File.join(File.dirname(__FILE__), '..', 'lib')))
|
8
|
+
|
9
|
+
include GeoRuby::SimpleFeatures
|
10
|
+
|
11
|
+
|
12
|
+
def postgis_connection
|
13
|
+
ActiveRecord::Base.establish_connection(
|
14
|
+
:adapter => 'postgresql',
|
15
|
+
:database => 'spatial_adapter'
|
16
|
+
)
|
17
|
+
# Turn off those annoying NOTICE messages
|
18
|
+
ActiveRecord::Base.connection.execute 'set client_min_messages = warning'
|
19
|
+
ActiveRecord::Migration.verbose = false
|
20
|
+
end
|
21
|
+
|
22
|
+
def mysql_connection
|
23
|
+
ActiveRecord::Base.establish_connection(
|
24
|
+
:adapter => 'mysql',
|
25
|
+
:database => 'spatial_adapter',
|
26
|
+
:username => 'root',
|
27
|
+
:host => 'localhost'
|
28
|
+
)
|
29
|
+
ActiveRecord::Migration.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
class GeometryFactory
|
33
|
+
class << self
|
34
|
+
def point
|
35
|
+
Point.from_x_y(1, 2, 4326)
|
36
|
+
end
|
37
|
+
|
38
|
+
def line_string
|
39
|
+
LineString.from_coordinates([[1.4,2.5],[1.5,6.7]], 4326)
|
40
|
+
end
|
41
|
+
|
42
|
+
def polygon
|
43
|
+
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)
|
44
|
+
end
|
45
|
+
|
46
|
+
def multi_point
|
47
|
+
MultiPoint.from_coordinates([[12.4,-23.3],[-65.1,23.4],[23.55555555,23]], 4326)
|
48
|
+
end
|
49
|
+
|
50
|
+
def multi_line_string
|
51
|
+
MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]]),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,23.3]])], 4326)
|
52
|
+
end
|
53
|
+
|
54
|
+
def multi_polygon
|
55
|
+
MultiPolygon.from_polygons([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]]]),Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]])], 4326)
|
56
|
+
end
|
57
|
+
|
58
|
+
def geometry_collection
|
59
|
+
GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4),LineString.from_coordinates([[5.7,12.45],[67.55,54]])], 4326)
|
60
|
+
end
|
61
|
+
|
62
|
+
def pointz
|
63
|
+
Point.from_x_y_z(1, 2, 3, 4326)
|
64
|
+
end
|
65
|
+
|
66
|
+
def pointm
|
67
|
+
Point.from_x_y_m(1, 2, 3, 4326)
|
68
|
+
end
|
69
|
+
|
70
|
+
def point4
|
71
|
+
Point.from_x_y_z_m(1, 2, 3, 4, 4326)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: achirkunov-spatial_adapter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Pete Deffendol
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-20 00:00:00 +04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activerecord
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 3
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
- beta3
|
32
|
+
version: 3.0.0.beta3
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: GeoRuby
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 3
|
45
|
+
- 0
|
46
|
+
version: 1.3.0
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
description: Provides enhancements to ActiveRecord to handle spatial datatypes in PostgreSQL and MySQL.
|
50
|
+
email: pete@fragility.us
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- README.rdoc
|
57
|
+
files:
|
58
|
+
- MIT-LICENSE
|
59
|
+
- README.rdoc
|
60
|
+
- VERSION
|
61
|
+
- lib/spatial_adapter.rb
|
62
|
+
- lib/spatial_adapter/common/raw_geom_info.rb
|
63
|
+
- lib/spatial_adapter/common/schema_definitions.rb
|
64
|
+
- lib/spatial_adapter/common/schema_dumper.rb
|
65
|
+
- lib/spatial_adapter/common/spatial_column.rb
|
66
|
+
- lib/spatial_adapter/common/table_definition.rb
|
67
|
+
- lib/spatial_adapter/mysql.rb
|
68
|
+
- lib/spatial_adapter/postgresql.rb
|
69
|
+
- rails/init.rb
|
70
|
+
has_rdoc: true
|
71
|
+
homepage: http://github.com/achirkunov/spatial_adapter
|
72
|
+
licenses: []
|
73
|
+
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options:
|
76
|
+
- --charset=UTF-8
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
requirements: []
|
94
|
+
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 1.3.6
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: Spatial Adapter for ActiveRecord
|
100
|
+
test_files:
|
101
|
+
- spec/db/mysql_raw.rb
|
102
|
+
- spec/db/postgis_raw.rb
|
103
|
+
- spec/models/common.rb
|
104
|
+
- spec/mysql/connection_adapter_spec.rb
|
105
|
+
- spec/mysql/migration_spec.rb
|
106
|
+
- spec/mysql/models_spec.rb
|
107
|
+
- spec/mysql/schema_dumper_spec.rb
|
108
|
+
- spec/postgresql/connection_adapter_spec.rb
|
109
|
+
- spec/postgresql/migration_spec.rb
|
110
|
+
- spec/postgresql/models_spec.rb
|
111
|
+
- spec/postgresql/schema_dumper_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
- spec/README.txt
|