GeoRuby 1.1.2 → 1.2.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.
Files changed (40) hide show
  1. data/README +16 -13
  2. data/lib/geo_ruby/shp4r/dbf.rb +234 -0
  3. data/lib/geo_ruby/shp4r/shp.rb +301 -0
  4. data/lib/geo_ruby/simple_features/geometry.rb +1 -0
  5. data/lib/geo_ruby.rb +1 -1
  6. data/rakefile.rb +4 -4
  7. data/test/data/point.dbf +0 -0
  8. data/test/data/point.shp +0 -0
  9. data/test/data/point.shx +0 -0
  10. data/test/data/polygon.dbf +0 -0
  11. data/test/data/polygon.shp +0 -0
  12. data/test/data/polygon.shx +0 -0
  13. data/test/data/polyline.dbf +0 -0
  14. data/test/data/polyline.shp +0 -0
  15. data/test/data/polyline.shx +0 -0
  16. data/test/test_shp.rb +77 -0
  17. data/tools/db.yml +6 -0
  18. data/tools/lib/spatial_adapter/MIT-LICENSE +7 -0
  19. data/tools/lib/spatial_adapter/README +116 -0
  20. data/tools/lib/spatial_adapter/init.rb +10 -0
  21. data/tools/lib/spatial_adapter/lib/common_spatial_adapter.rb +175 -0
  22. data/tools/lib/spatial_adapter/lib/mysql_spatial_adapter.rb +143 -0
  23. data/tools/lib/spatial_adapter/lib/post_gis_adapter.rb +333 -0
  24. data/tools/lib/spatial_adapter/rakefile.rb +35 -0
  25. data/tools/lib/spatial_adapter/test/access_mysql_test.rb +87 -0
  26. data/tools/lib/spatial_adapter/test/access_postgis_test.rb +151 -0
  27. data/tools/lib/spatial_adapter/test/common/common_mysql.rb +18 -0
  28. data/tools/lib/spatial_adapter/test/common/common_postgis.rb +19 -0
  29. data/tools/lib/spatial_adapter/test/db/database_mysql.yml +5 -0
  30. data/tools/lib/spatial_adapter/test/db/database_postgis.yml +4 -0
  31. data/tools/lib/spatial_adapter/test/find_mysql_test.rb +64 -0
  32. data/tools/lib/spatial_adapter/test/find_postgis_test.rb +65 -0
  33. data/tools/lib/spatial_adapter/test/migration_mysql_test.rb +136 -0
  34. data/tools/lib/spatial_adapter/test/migration_postgis_test.rb +170 -0
  35. data/tools/lib/spatial_adapter/test/models/models_mysql.rb +25 -0
  36. data/tools/lib/spatial_adapter/test/models/models_postgis.rb +41 -0
  37. data/tools/lib/spatial_adapter/test/schema/schema_mysql.rb +40 -0
  38. data/tools/lib/spatial_adapter/test/schema/schema_postgis.rb +69 -0
  39. data/tools/shp2sql.rb +91 -0
  40. metadata +47 -4
@@ -0,0 +1,136 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require 'test/unit'
4
+ require 'common/common_mysql'
5
+
6
+ class Park < ActiveRecord::Base
7
+ end
8
+
9
+
10
+ class MigrationMysqlTest < Test::Unit::TestCase
11
+
12
+ def test_creation_modification
13
+ #creation
14
+ #add column
15
+ #remove column
16
+ #add index
17
+ #remove index
18
+
19
+ connection = ActiveRecord::Base.connection
20
+
21
+ #create a table with a geometric column
22
+ ActiveRecord::Schema.define() do
23
+ create_table "parks", :options => "ENGINE=MyISAM" , :force => true do |t|
24
+ t.column "data" , :string, :limit => 100
25
+ t.column "value", :integer
26
+ t.column "geom", :polygon,:null=>false
27
+ end
28
+ end
29
+
30
+ #TEST
31
+ assert_equal(4,connection.columns("parks").length) # the 3 defined + id
32
+ connection.columns("parks").each do |col|
33
+ if col.name == "geom"
34
+ assert(col.is_a?(SpatialColumn))
35
+ assert(:polygon,col.geometry_type)
36
+ assert(:geometry,col.type)
37
+ assert(col.null == false)
38
+ end
39
+ end
40
+
41
+ ActiveRecord::Schema.define() do
42
+ add_column "parks","geom2", :multi_point
43
+ end
44
+
45
+ #TEST
46
+ assert_equal(5,connection.columns("parks").length)
47
+ connection.columns("parks").each do |col|
48
+ if col.name == "geom2"
49
+ assert(col.is_a?(SpatialColumn))
50
+ assert(:multi_point,col.geometry_type)
51
+ assert(:geometry,col.type)
52
+ assert(col.null != false)
53
+ end
54
+ end
55
+
56
+ ActiveRecord::Schema.define() do
57
+ remove_column "parks","geom2"
58
+ end
59
+
60
+ #TEST
61
+ assert_equal(4,connection.columns("parks").length)
62
+ has_geom2= false
63
+ connection.columns("parks").each do |col|
64
+ if col.name == "geom2"
65
+ has_geom2=true
66
+ end
67
+ end
68
+ assert(!has_geom2)
69
+
70
+ #TEST
71
+ assert_equal(0,connection.indexes("parks").length) #index on id does not count
72
+
73
+ ActiveRecord::Schema.define() do
74
+ add_index "parks","geom",:spatial=>true,:name => "example_spatial_index"
75
+ end
76
+
77
+ #TEST
78
+ assert_equal(1,connection.indexes("parks").length)
79
+ assert(connection.indexes("parks")[0].spatial)
80
+ assert_equal("example_spatial_index",connection.indexes("parks")[0].name)
81
+
82
+ ActiveRecord::Schema.define() do
83
+ remove_index "parks",:name=> "example_spatial_index"
84
+ end
85
+
86
+ #TEST
87
+ assert_equal(0,connection.indexes("parks").length)
88
+
89
+ end
90
+
91
+
92
+ def test_dump
93
+ #Force the creation a table
94
+ ActiveRecord::Schema.define() do
95
+ create_table "parks", :options => "ENGINE=MyISAM" , :force => true do |t|
96
+ t.column "data" , :string, :limit => 100
97
+ t.column "value", :integer
98
+ t.column "geom", :polygon,:null=>false
99
+ end
100
+
101
+ add_index "parks","geom",:spatial=>true,:name => "example_spatial_index"
102
+
103
+ end
104
+
105
+ #dump it : tables from other tests will be dumped too but not a problem
106
+ File.open('schema.rb', "w") do |file|
107
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
108
+ end
109
+
110
+ #load it again
111
+ load('schema.rb')
112
+
113
+ File.delete('schema.rb')
114
+
115
+ #reset
116
+ connection = ActiveRecord::Base.connection
117
+
118
+ columns = connection.columns("parks")
119
+ assert(4,columns.length)
120
+
121
+ connection.columns("parks").each do |col|
122
+ if col.name == "geom"
123
+ assert(col.is_a?(SpatialColumn))
124
+ assert(:polygon,col.geometry_type)
125
+ assert(:geometry,col.type)
126
+ assert(col.null == false)
127
+ end
128
+ end
129
+
130
+ assert_equal(1,connection.indexes("parks").length)
131
+ assert(connection.indexes("parks")[0].spatial)
132
+ assert_equal("example_spatial_index",connection.indexes("parks")[0].name)
133
+ end
134
+
135
+
136
+ end
@@ -0,0 +1,170 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require 'test/unit'
4
+ require 'common/common_postgis'
5
+
6
+ class Park < ActiveRecord::Base
7
+ end
8
+
9
+
10
+ class MigrationPostgisTest < Test::Unit::TestCase
11
+
12
+ def test_creation_modification
13
+ #creation
14
+ #add column
15
+ #remove column
16
+ #add index
17
+ #remove index
18
+
19
+ connection = ActiveRecord::Base.connection
20
+
21
+ #create a table with a geometric column
22
+ ActiveRecord::Schema.define do
23
+ create_table "parks", :force => true do |t|
24
+ t.column "data" , :string, :limit => 100
25
+ t.column "value", :integer
26
+ t.column "geom", :polygon, :null=>false, :srid => 555 , :with_z => true,:with_m => true
27
+ end
28
+ end
29
+
30
+ #TEST
31
+ assert_equal(4,connection.columns("parks").length) # the 3 defined + id
32
+ connection.columns("parks").each do |col|
33
+ if col.name == "geom"
34
+ assert(col.is_a?(SpatialColumn))
35
+ assert(:polygon,col.geometry_type)
36
+ assert(:geometry,col.type)
37
+ assert(col.null == false)
38
+ assert(555,col.srid)
39
+ assert(col.with_z)
40
+ assert(col.with_m)
41
+ end
42
+ end
43
+
44
+ ActiveRecord::Schema.define do
45
+ add_column "parks","geom2", :multi_point
46
+ end
47
+
48
+ #TEST
49
+ assert_equal(5,connection.columns("parks").length)
50
+ connection.columns("parks").each do |col|
51
+ if col.name == "geom2"
52
+ assert(col.is_a?(SpatialColumn))
53
+ assert(:multi_point,col.geometry_type)
54
+ assert(:geometry,col.type)
55
+ assert(col.null != false)
56
+ assert(-1,col.srid)
57
+ assert(!col.with_z)
58
+ assert(!col.with_m)
59
+ end
60
+ end
61
+
62
+ ActiveRecord::Schema.define do
63
+ remove_column "parks","geom2"
64
+ end
65
+
66
+ #TEST
67
+ assert_equal(4,connection.columns("parks").length)
68
+ has_geom2= false
69
+ connection.columns("parks").each do |col|
70
+ if col.name == "geom2"
71
+ has_geom2=true
72
+ end
73
+ end
74
+ assert(!has_geom2)
75
+
76
+ #TEST
77
+ assert_equal(0,connection.indexes("parks").length) #index on id does not count
78
+
79
+ ActiveRecord::Schema.define do
80
+ add_index "parks","geom",:spatial=>true,:name => "example_spatial_index"
81
+ end
82
+
83
+ #TEST
84
+ assert_equal(1,connection.indexes("parks").length)
85
+ assert(connection.indexes("parks")[0].spatial)
86
+ assert_equal("example_spatial_index",connection.indexes("parks")[0].name)
87
+
88
+ ActiveRecord::Schema.define do
89
+ remove_index "parks",:name=> "example_spatial_index"
90
+ end
91
+
92
+ #TEST
93
+ assert_equal(0,connection.indexes("parks").length)
94
+
95
+ end
96
+
97
+ def test_keyword_column_name
98
+ ActiveRecord::Schema.define do
99
+ create_table "parks", :force => true do |t|
100
+ t.column "data" , :string, :limit => 100
101
+ t.column "value", :integer
102
+ #location is a postgreSQL keyword and is surrounded by double-quotes ("") when appearing in constraint descriptions ; tests a bug corrected in version 39
103
+ t.column "location", :point,:null=>false,:srid => 0, :with_m => true, :with_z => true
104
+ end
105
+ end
106
+
107
+ connection = ActiveRecord::Base.connection
108
+ columns = connection.columns("parks")
109
+
110
+ assert_equal(4,columns.length) # the 3 defined + id
111
+ columns.each do |col|
112
+ if col.name == "location"
113
+ assert(col.is_a?(SpatialColumn))
114
+ assert(:point,col.geometry_type)
115
+ assert(:geometry,col.type)
116
+ assert(col.null == false)
117
+ assert(0,col.srid)
118
+ assert(col.with_z)
119
+ assert(col.with_m)
120
+ end
121
+ end
122
+ end
123
+
124
+
125
+ def test_dump
126
+ #Force the creation of a table
127
+ ActiveRecord::Schema.define do
128
+ create_table "parks", :force => true do |t|
129
+ t.column "data" , :string, :limit => 100
130
+ t.column "value", :integer
131
+ t.column "geom", :multi_polygon,:null=>false,:srid => 0, :with_m => true, :with_z => true
132
+ end
133
+
134
+ add_index "parks","geom",:spatial=>true,:name => "example_spatial_index"
135
+
136
+ end
137
+
138
+ #dump it : tables from other tests will be dumped too but not a problem
139
+ File.open('schema.rb', "w") do |file|
140
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
141
+ end
142
+
143
+ #load it again
144
+ load('schema.rb')
145
+
146
+ #delete the schema file
147
+ File.delete('schema.rb')
148
+
149
+ connection = ActiveRecord::Base.connection
150
+ columns = connection.columns("parks")
151
+
152
+ assert_equal(4,columns.length) # the 3 defined + id
153
+ columns.each do |col|
154
+ if col.name == "geom"
155
+ assert(col.is_a?(SpatialColumn))
156
+ assert(:multi_polygon,col.geometry_type)
157
+ assert(:geometry,col.type)
158
+ assert(col.null == false)
159
+ assert(0,col.srid)
160
+ assert(col.with_z)
161
+ assert(col.with_m)
162
+ end
163
+ end
164
+
165
+ assert_equal(1,connection.indexes("parks").length)
166
+ assert(connection.indexes("parks")[0].spatial)
167
+ assert_equal("example_spatial_index",connection.indexes("parks")[0].name)
168
+ end
169
+
170
+ end
@@ -0,0 +1,25 @@
1
+ class TablePoint < ActiveRecord::Base
2
+ end
3
+
4
+ class TableLineString < ActiveRecord::Base
5
+ end
6
+
7
+ class TablePolygon < ActiveRecord::Base
8
+ end
9
+
10
+ class TableMultiPoint < ActiveRecord::Base
11
+ end
12
+
13
+ class TableMultiLineString < ActiveRecord::Base
14
+ end
15
+
16
+ class TableMultiPolygon < ActiveRecord::Base
17
+ end
18
+
19
+ class TableGeometry < ActiveRecord::Base
20
+ end
21
+
22
+ class TableGeometryCollection < ActiveRecord::Base
23
+ end
24
+
25
+
@@ -0,0 +1,41 @@
1
+ class TablePoint < ActiveRecord::Base
2
+ end
3
+
4
+ class TableKeywordColumnPoint < ActiveRecord::Base
5
+ end
6
+
7
+ class TableLineString < ActiveRecord::Base
8
+ end
9
+
10
+ class TablePolygon < ActiveRecord::Base
11
+ end
12
+
13
+ class TableMultiPoint < ActiveRecord::Base
14
+ end
15
+
16
+ class TableMultiLineString < ActiveRecord::Base
17
+ end
18
+
19
+ class TableMultiPolygon < ActiveRecord::Base
20
+ end
21
+
22
+ class TableGeometry < ActiveRecord::Base
23
+ end
24
+
25
+ class TableGeometryCollection < ActiveRecord::Base
26
+ end
27
+
28
+ class Table3dzPoint < ActiveRecord::Base
29
+ end
30
+
31
+ class Table3dmPoint < ActiveRecord::Base
32
+ end
33
+
34
+ class Table4dPoint < ActiveRecord::Base
35
+ end
36
+
37
+ class TableSridLineString < ActiveRecord::Base
38
+ end
39
+
40
+ class TableSrid4dPolygon < ActiveRecord::Base
41
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/../common/common_mysql.rb'
2
+
3
+ ActiveRecord::Schema.define() do
4
+
5
+ create_table "table_points", :options=> "ENGINE=MyISAM", :force => true do |t|
6
+ t.column "data", :string
7
+ t.column "geom", :point, :null=>false
8
+ end
9
+
10
+ create_table "table_line_strings", :options=> "ENGINE=MyISAM", :force => true do |t|
11
+ t.column "value", :integer
12
+ t.column "geom", :line_string, :null=>false
13
+ end
14
+
15
+ create_table "table_polygons", :options=> "ENGINE=MyISAM", :force => true do |t|
16
+ t.column "geom", :polygon, :null=>false
17
+ end
18
+
19
+ create_table "table_multi_points", :options=> "ENGINE=MyISAM", :force => true do |t|
20
+ t.column "geom", :multi_point, :null=>false
21
+ end
22
+
23
+ create_table "table_multi_line_strings", :options=> "ENGINE=MyISAM", :force => true do |t|
24
+ t.column "geom", :multi_line_string, :null=>false
25
+ end
26
+
27
+ create_table "table_multi_polygons", :options=> "ENGINE=MyISAM", :force => true do |t|
28
+ t.column "geom", :multi_polygon, :null=>false
29
+ end
30
+
31
+ create_table "table_geometries", :options=> "ENGINE=MyISAM", :force => true do |t|
32
+ t.column "geom", :geometry, :null=>false
33
+ end
34
+
35
+ create_table "table_geometry_collections", :options=> "ENGINE=MyISAM", :force => true do |t|
36
+ t.column "geom", :geometry_collection, :null=>false
37
+ end
38
+
39
+ end
40
+
@@ -0,0 +1,69 @@
1
+ require File.dirname(__FILE__) + '/../common/common_postgis.rb'
2
+
3
+ #add some postgis specific tables
4
+ ActiveRecord::Schema.define() do
5
+
6
+ create_table "table_points", :force => true do |t|
7
+ t.column "data", :string
8
+ t.column "geom", :point, :null=>false
9
+ end
10
+
11
+ create_table "table_keyword_column_points", :force => true do |t|
12
+ t.column "location", :point, :null => false
13
+ end
14
+
15
+ create_table "table_line_strings", :force => true do |t|
16
+ t.column "value", :integer
17
+ t.column "geom", :line_string, :null=>false
18
+ end
19
+
20
+ create_table "table_polygons", :force => true do |t|
21
+ t.column "geom", :polygon, :null=>false
22
+ end
23
+
24
+ create_table "table_multi_points", :force => true do |t|
25
+ t.column "geom", :multi_point, :null=>false
26
+ end
27
+
28
+ create_table "table_multi_line_strings", :force => true do |t|
29
+ t.column "geom", :multi_line_string, :null=>false
30
+ end
31
+
32
+ create_table "table_multi_polygons", :force => true do |t|
33
+ t.column "geom", :multi_polygon, :null=>false
34
+ end
35
+
36
+ create_table "table_geometries", :force => true do |t|
37
+ t.column "geom", :geometry, :null=>false
38
+ end
39
+
40
+ create_table "table_geometry_collections", :force => true do |t|
41
+ t.column "geom", :geometry_collection, :null=>false
42
+ end
43
+
44
+ create_table "table3dz_points", :force => true do |t|
45
+ t.column "data", :string
46
+ t.column "geom", :point, :null => false , :with_z => true
47
+ end
48
+
49
+ create_table "table3dm_points", :force => true do |t|
50
+ t.column "geom", :point, :null => false , :with_m => true
51
+ end
52
+
53
+ create_table "table4d_points", :force => true do |t|
54
+ t.column "geom", :point, :null => false, :with_m => true, :with_z => true
55
+ end
56
+
57
+ create_table "table_srid_line_strings", :force => true do |t|
58
+ t.column "geom", :line_string, :null => false , :srid => 123
59
+ end
60
+
61
+ create_table "table_srid4d_polygons", :force => true do |t|
62
+ t.column "geom", :polygon, :with_m => true, :with_z => true, :srid => 123
63
+ end
64
+
65
+ end
66
+
67
+
68
+
69
+