GeoRuby 1.3.2 → 1.3.3

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.
@@ -1,4 +1,4 @@
1
1
  adapter: postgresql
2
2
  database: spatial_adapter_plugin_test
3
- username: gvellut
4
- password:
3
+ username: postgres
4
+ password:
@@ -11,8 +11,8 @@ class FindPostgisTest < Test::Unit::TestCase
11
11
  def setup
12
12
  ActiveRecord::Schema.define() do
13
13
  create_table "parks", :force => true do |t|
14
- t.column "data" , :string, :limit => 100
15
- t.column "geom", :point,:null=>false,:srid=>123
14
+ t.string "data", :limit => 100
15
+ t.point "geom", :null=>false,:srid=>123
16
16
  end
17
17
  add_index "parks","geom",:spatial=>true,:name => "example_spatial_index"
18
18
  end
@@ -6,6 +6,9 @@ require 'common/common_mysql'
6
6
  class Park < ActiveRecord::Base
7
7
  end
8
8
 
9
+ class CxGeographiclocation < ActiveRecord::Base
10
+ set_table_name "cx_geographiclocation"
11
+ end
9
12
 
10
13
  class MigrationMysqlTest < Test::Unit::TestCase
11
14
 
@@ -131,5 +134,71 @@ class MigrationMysqlTest < Test::Unit::TestCase
131
134
  assert_equal("example_spatial_index",connection.indexes("parks")[0].name)
132
135
  end
133
136
 
137
+ def test_teresa
138
+ connection = ActiveRecord::Base.connection
139
+
140
+ #creation
141
+ ActiveRecord::Schema.define() do
142
+ create_table(:cx_geographiclocation, :primary_key => "GeographicLocationID", :options=>"ENGINE=MyISAM", :force => true ) do |t|
143
+ t.column "CountryID", :integer, :null => false
144
+ t.column "AddressLine1", :string, :limit => 100, :null => false
145
+ t.column "AddressLine2", :string, :limit => 100
146
+ t.column "AddressLine3", :string, :limit => 50
147
+ t.column "City", :string, :limit => 50
148
+ t.column "StateProvince", :string, :limit => 50
149
+ t.column "PostalCode", :string, :limit => 30
150
+ t.column "Geocode", :point, :null => false
151
+ end
152
+ end
153
+
154
+ #test creation
155
+ assert_equal(9,connection.columns("cx_geographiclocation").length)
156
+ connection.columns("cx_geographiclocation").each do |col|
157
+ if col.name == "Geocode"
158
+ assert(col.is_a?(SpatialColumn))
159
+ assert(:geometry,col.type)
160
+ assert(:point,col.geometry_type)
161
+ assert(! col.null)
162
+ end
163
+ end
164
+
165
+ #creation index
166
+ ActiveRecord::Schema.define() do
167
+ add_index "cx_geographiclocation", ["addressline1"], :name => "ix_cx_geographiclocation_addressline1"
168
+ add_index "cx_geographiclocation", ["countryid"], :name => "ix_cx_geographiclocation_countryid"
169
+ add_index "cx_geographiclocation", "Geocode", :spatial=>true
170
+ end
171
+
172
+ #test index
173
+ assert_equal(3,connection.indexes("cx_geographiclocation").length)
174
+ assert(connection.indexes("cx_geographiclocation")[2].spatial)
175
+
176
+ #insertion points
177
+ 1.upto(1000) do |i|
178
+ pt = CxGeographiclocation.new("CountryID" => i, "AddressLine1" =>"Bouyoul", "Geocode" => Point.from_x_y(-180 + rand(360) + rand(),-90 + rand(180) + rand())) #insert floats
179
+ assert(pt.save)
180
+ end
181
+
182
+ #should be outside the fetch by MBR
183
+ pt = CxGeographiclocation.new("CountryID" => 1337, "AddressLine1" =>"Bouyoul", "Geocode" => Point.from_x_y(-185,-90)) #insert floats
184
+ assert(pt.save)
185
+
186
+ #fetch point and test
187
+ pt = CxGeographiclocation.find(:first)
188
+ assert(pt)
189
+ assert_equal("Bouyoul",pt.attributes["AddressLine1"])
190
+
191
+
192
+ #fetch by MBR and test
193
+ pts = CxGeographiclocation.find_all_by_Geocode([[-181 + rand(),-91 + rand()],[181 + rand(),91 + rand()]]) #selects all : range limits are float
194
+ assert(pts)
195
+ assert(pts.is_a?(Array))
196
+ assert_equal(1000,pts.length)
197
+ assert_equal("Bouyoul",pts[0].attributes["AddressLine1"])
198
+
199
+ end
200
+
201
+
202
+
134
203
 
135
204
  end
@@ -21,9 +21,9 @@ class MigrationPostgisTest < Test::Unit::TestCase
21
21
  #create a table with a geometric column
22
22
  ActiveRecord::Schema.define do
23
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
24
+ t.string "data", :limit => 100
25
+ t.integer "value"
26
+ t.polygon "geom", :null=>false, :srid => 555 , :with_z => true,:with_m => true
27
27
  end
28
28
  end
29
29
 
@@ -115,10 +115,10 @@ class MigrationPostgisTest < Test::Unit::TestCase
115
115
  def test_keyword_column_name
116
116
  ActiveRecord::Schema.define do
117
117
  create_table "parks", :force => true do |t|
118
- t.column "data" , :string, :limit => 100
119
- t.column "value", :integer
118
+ t.string "data", :limit => 100
119
+ t.integer "value"
120
120
  #location is a postgreSQL keyword and is surrounded by double-quotes ("") when appearing in constraint descriptions ; tests a bug corrected in version 39
121
- t.column "location", :point,:null=>false,:srid => 0, :with_m => true, :with_z => true
121
+ t.point "location", :null=>false,:srid => 0, :with_m => true, :with_z => true
122
122
  end
123
123
  end
124
124
 
@@ -144,9 +144,9 @@ class MigrationPostgisTest < Test::Unit::TestCase
144
144
  #Force the creation of a table
145
145
  ActiveRecord::Schema.define do
146
146
  create_table "parks", :force => true do |t|
147
- t.column "data" , :string, :limit => 100
148
- t.column "value", :integer
149
- t.column "geom", :multi_polygon,:null=>false,:srid => 0, :with_m => true, :with_z => true
147
+ t.string "data" , :limit => 100
148
+ t.integer "value"
149
+ t.multi_polygon "geom", :null=>false,:srid => 0, :with_m => true, :with_z => true
150
150
  end
151
151
 
152
152
  add_index "parks","geom",:spatial=>true,:name => "example_spatial_index"
@@ -4,66 +4,62 @@ require File.dirname(__FILE__) + '/../common/common_postgis.rb'
4
4
  ActiveRecord::Schema.define() do
5
5
 
6
6
  create_table "table_points", :force => true do |t|
7
- t.column "data", :string
8
- t.column "geom", :point, :null=>false
7
+ t.string "data"
8
+ t.point "geom", :null=>false
9
9
  end
10
10
 
11
11
  create_table "table_keyword_column_points", :force => true do |t|
12
- t.column "location", :point, :null => false
12
+ t.point "location", :null => false
13
13
  end
14
14
 
15
15
  create_table "table_line_strings", :force => true do |t|
16
- t.column "value", :integer
17
- t.column "geom", :line_string, :null=>false
16
+ t.integer "value"
17
+ t.line_string "geom", :null=>false
18
18
  end
19
19
 
20
20
  create_table "table_polygons", :force => true do |t|
21
- t.column "geom", :polygon, :null=>false
21
+ t.polygon "geom", :null=>false
22
22
  end
23
23
 
24
24
  create_table "table_multi_points", :force => true do |t|
25
- t.column "geom", :multi_point, :null=>false
25
+ t.multi_point "geom", :null=>false
26
26
  end
27
27
 
28
28
  create_table "table_multi_line_strings", :force => true do |t|
29
- t.column "geom", :multi_line_string, :null=>false
29
+ t.multi_line_string "geom", :null=>false
30
30
  end
31
31
 
32
32
  create_table "table_multi_polygons", :force => true do |t|
33
- t.column "geom", :multi_polygon, :null=>false
33
+ t.multi_polygon "geom", :null=>false
34
34
  end
35
35
 
36
36
  create_table "table_geometries", :force => true do |t|
37
- t.column "geom", :geometry, :null=>false
37
+ t.geometry "geom", :null=>false
38
38
  end
39
39
 
40
40
  create_table "table_geometry_collections", :force => true do |t|
41
- t.column "geom", :geometry_collection, :null=>false
41
+ t.geometry_collection "geom", :null=>false
42
42
  end
43
43
 
44
44
  create_table "table3dz_points", :force => true do |t|
45
45
  t.column "data", :string
46
- t.column "geom", :point, :null => false , :with_z => true
46
+ t.point "geom", :null => false , :with_z => true
47
47
  end
48
48
 
49
49
  create_table "table3dm_points", :force => true do |t|
50
- t.column "geom", :point, :null => false , :with_m => true
50
+ t.point "geom", :null => false , :with_m => true
51
51
  end
52
52
 
53
53
  create_table "table4d_points", :force => true do |t|
54
- t.column "geom", :point, :null => false, :with_m => true, :with_z => true
54
+ t.point "geom", :null => false, :with_m => true, :with_z => true
55
55
  end
56
56
 
57
57
  create_table "table_srid_line_strings", :force => true do |t|
58
- t.column "geom", :line_string, :null => false , :srid => 123
58
+ t.line_string "geom", :null => false , :srid => 123
59
59
  end
60
60
 
61
61
  create_table "table_srid4d_polygons", :force => true do |t|
62
- t.column "geom", :polygon, :with_m => true, :with_z => true, :srid => 123
62
+ t.polygon "geom", :with_m => true, :with_z => true, :srid => 123
63
63
  end
64
64
 
65
65
  end
66
-
67
-
68
-
69
-
data/tools/shp2sql.rb CHANGED
@@ -20,7 +20,7 @@ end
20
20
  def shp_geom_type_2_rails(type)
21
21
  case type
22
22
  when ShpType::POINT then :point
23
- when ShpType::POLYLINE then :mlti_line_string
23
+ when ShpType::POLYLINE then :multi_line_string
24
24
  when ShpType::POLYGON then :multi_polygon
25
25
  when ShpType::MULTIPOINT then :multi_point
26
26
  end
metadata CHANGED
@@ -1,33 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
3
- specification_version: 1
4
2
  name: GeoRuby
5
3
  version: !ruby/object:Gem::Version
6
- version: 1.3.2
7
- date: 2007-09-14 00:00:00 +02:00
8
- summary: Ruby data holder for OGC Simple Features
9
- require_paths:
10
- - lib
11
- email: guilhem.vellut@gmail.com
12
- homepage: http://thepochisuperstarmegashow.com/projects/
13
- rubyforge_project:
14
- description: GeoRuby is intended as a holder for data returned from PostGIS and MySQL Spatial queries. The data model roughly follows the OGC "Simple Features for SQL" specification (see www.opengis.org/docs/99-049.pdf), although without any kind of advanced functionalities (such as geometric operators or reprojections)
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 1.3.3
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Guilhem Vellut
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-03-02 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: GeoRuby is intended as a holder for data returned from PostGIS and MySQL Spatial queries. The data model roughly follows the OGC "Simple Features for SQL" specification (see www.opengis.org/docs/99-049.pdf), although without any kind of advanced functionalities (such as geometric operators or reprojections)
17
+ email: guilhem.vellut@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
31
24
  files:
32
25
  - lib/geo_ruby/shp4r/dbf.rb
33
26
  - lib/geo_ruby/shp4r/shp.rb
@@ -39,11 +32,8 @@ files:
39
32
  - lib/geo_ruby/simple_features/geometry_factory.rb
40
33
  - lib/geo_ruby/simple_features/georss_parser.rb
41
34
  - lib/geo_ruby/simple_features/helper.rb
42
- - lib/geo_ruby/simple_features/io/ewkb_parser.rb
43
- - lib/geo_ruby/simple_features/io/ewkt_parser.rb
44
- - lib/geo_ruby/simple_features/io/geometry_factory.rb
45
- - lib/geo_ruby/simple_features/linear_ring.rb
46
35
  - lib/geo_ruby/simple_features/line_string.rb
36
+ - lib/geo_ruby/simple_features/linear_ring.rb
47
37
  - lib/geo_ruby/simple_features/multi_line_string.rb
48
38
  - lib/geo_ruby/simple_features/multi_point.rb
49
39
  - lib/geo_ruby/simple_features/multi_polygon.rb
@@ -101,6 +91,33 @@ files:
101
91
  - tools/lib/spatial_adapter/test/db
102
92
  - tools/lib/spatial_adapter/test/models
103
93
  - tools/lib/spatial_adapter/test/schema
94
+ has_rdoc: true
95
+ homepage: http://thepochisuperstarmegashow.com/projects/
96
+ post_install_message:
97
+ rdoc_options:
98
+ - --main
99
+ - README
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: "0"
107
+ version:
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: "0"
113
+ version:
114
+ requirements:
115
+ - none
116
+ rubyforge_project:
117
+ rubygems_version: 1.0.1
118
+ signing_key:
119
+ specification_version: 2
120
+ summary: Ruby data holder for OGC Simple Features
104
121
  test_files:
105
122
  - test/test_ewkb_parser.rb
106
123
  - test/test_ewkt_parser.rb
@@ -108,16 +125,3 @@ test_files:
108
125
  - test/test_shp.rb
109
126
  - test/test_shp_write.rb
110
127
  - test/test_simple_features.rb
111
- rdoc_options:
112
- - --main
113
- - README
114
- extra_rdoc_files:
115
- - README
116
- executables: []
117
-
118
- extensions: []
119
-
120
- requirements:
121
- - none
122
- dependencies: []
123
-
@@ -1,213 +0,0 @@
1
- require 'geo_ruby/simple_features/point'
2
- require 'geo_ruby/simple_features/line_string'
3
- require 'geo_ruby/simple_features/linear_ring'
4
- require 'geo_ruby/simple_features/polygon'
5
- require 'geo_ruby/simple_features/multi_point'
6
- require 'geo_ruby/simple_features/multi_line_string'
7
- require 'geo_ruby/simple_features/multi_polygon'
8
- require 'geo_ruby/simple_features/geometry_collection'
9
-
10
- module GeoRuby
11
- module SimpleFeatures
12
- module Io
13
- #Raised when an error in the EWKB string is detected
14
- class EWKBFormatError < StandardError
15
- end
16
-
17
- #Parses EWKB strings and notifies of events (such as the beginning of the definition of geometry, the value of the SRID...) the factory passed as argument to the constructor.
18
- #
19
- #=Example
20
- # factory = GeometryFactory::new
21
- # ewkb_parser = EWKBParser::new(factory)
22
- # ewkb_parser.parse(<EWKB String>)
23
- # geometry = @factory.geometry
24
- #
25
- #You can also use directly the static method Geometry.from_ewkb
26
- class EWKBParser
27
-
28
- def initialize(factory)
29
- @factory = factory
30
- @parse_options ={
31
- 1 => method(:parse_point),
32
- 2 => method(:parse_line_string),
33
- 3 => method(:parse_polygon),
34
- 4 => method(:parse_multi_point),
35
- 5 => method(:parse_multi_line_string),
36
- 6 => method(:parse_multi_polygon),
37
- 7 => method(:parse_geometry_collection)
38
- }
39
- end
40
-
41
- #Parses the ewkb string passed as argument and notifies the factory of events
42
- def parse(ewkb)
43
- @factory.reset
44
- @unpack_structure=UnpackStructure::new(ewkb)
45
- @with_z = false
46
- @with_m = false
47
- parse_geometry
48
- @unpack_structure.done
49
- @srid=nil
50
- end
51
-
52
- private
53
- def parse_geometry
54
- @unpack_structure.endianness=@unpack_structure.read_byte
55
- @geometry_type = @unpack_structure.read_uint
56
-
57
- if (@geometry_type & Z_MASK) != 0
58
- @with_z=true
59
- @geometry_type = @geometry_type & ~Z_MASK
60
- end
61
- if (@geometry_type & M_MASK) != 0
62
- @with_m=true
63
- @geometry_type = @geometry_type & ~M_MASK
64
- end
65
- if (@geometry_type & SRID_MASK) != 0
66
- @srid = @unpack_structure.read_uint
67
- @geometry_type = @geometry_type & ~SRID_MASK
68
- else
69
- #to manage multi geometries : the srid is not present in sub_geometries, therefore we take the srid of the parent ; if it is the root, we take the default srid
70
- @srid= @srid || DEFAULT_SRID
71
- end
72
-
73
- if @parse_options.has_key? @geometry_type
74
- @parse_options[@geometry_type].call
75
- else
76
- raise EWKBFormatError::new("Unknown geometry type")
77
- end
78
- end
79
-
80
- def parse_geometry_collection
81
- parse_multi_geometries(GeometryCollection)
82
- end
83
-
84
- def parse_multi_polygon
85
- parse_multi_geometries(MultiPolygon)
86
- end
87
-
88
- def parse_multi_line_string
89
- parse_multi_geometries(MultiLineString)
90
- end
91
-
92
- def parse_multi_point
93
- parse_multi_geometries(MultiPoint)
94
- end
95
-
96
- def parse_multi_geometries(geometry_type)
97
- @factory.begin_geometry(geometry_type,@srid)
98
- num_geometries = @unpack_structure.read_uint
99
- 1.upto(num_geometries) { parse_geometry }
100
- @factory.end_geometry(@with_z,@with_m)
101
- end
102
-
103
- def parse_polygon
104
- @factory.begin_geometry(Polygon,@srid)
105
- num_linear_rings = @unpack_structure.read_uint
106
- 1.upto(num_linear_rings) {parse_linear_ring}
107
- @factory.end_geometry(@with_z,@with_m)
108
- end
109
-
110
- def parse_linear_ring
111
- parse_point_list(LinearRing)
112
- end
113
-
114
- def parse_line_string
115
- parse_point_list(LineString)
116
- end
117
-
118
- #used to parse line_strings and linear_rings
119
- def parse_point_list(geometry_type)
120
- @factory.begin_geometry(geometry_type,@srid)
121
- num_points = @unpack_structure.read_uint
122
- 1.upto(num_points) {parse_point}
123
- @factory.end_geometry(@with_z,@with_m)
124
- end
125
-
126
- def parse_point
127
- @factory.begin_geometry(Point,@srid)
128
- x = @unpack_structure.read_double
129
- y = @unpack_structure.read_double
130
- if ! (@with_z or @with_m) #most common case probably
131
- @factory.add_point_x_y(x,y)
132
- elsif @with_m and @with_z
133
- z = @unpack_structure.read_double
134
- m = @unpack_structure.read_double
135
- @factory.add_point_x_y_z_m(x,y,z,m)
136
- elsif @with_z
137
- z = @unpack_structure.read_double
138
- @factory.add_point_x_y_z(x,y,z)
139
- else
140
- m = @unpack_structure.read_double
141
- @factory.add_point_x_y_m(x,y,m)
142
- end
143
-
144
- @factory.end_geometry(@with_z,@with_m)
145
- end
146
- end
147
-
148
- #Parses HexEWKB strings. In reality, it just transforms the HexEWKB string into the equivalent EWKB string and lets the EWKBParser do the actual parsing.
149
- class HexEWKBParser < EWKBParser
150
- def initialize(factory)
151
- super(factory)
152
- end
153
- #parses an HexEWKB string
154
- def parse(hexewkb)
155
- super(decode_hex(hexewkb))
156
- end
157
- #transforms a HexEWKB string into an EWKB string
158
- def decode_hex(hexewkb)
159
- temp_hexewkb= hexewkb.clone
160
- result=""
161
- while c = temp_hexewkb.slice!(0,2) do
162
- break if c.length==0
163
- result << c.hex
164
- end
165
- result
166
- end
167
-
168
- end
169
-
170
- class UnpackStructure #:nodoc:
171
- NDR=1
172
- XDR=0
173
- def initialize(ewkb)
174
- @position=0
175
- @ewkb=ewkb
176
- end
177
- def done
178
- raise EWKBFormatError::new("Trailing data") if @position != @ewkb.length
179
- end
180
- def read_double
181
- i=@position
182
- @position += 8
183
- packed_double = @ewkb[i...@position]
184
- raise EWKBFormatError::new("Truncated data") if packed_double.nil? or packed_double.length < 8
185
- packed_double.unpack(@double_mark)[0]
186
- end
187
- def read_uint
188
- i=@position
189
- @position += 4
190
- packed_uint = @ewkb[i...@position]
191
- raise EWKBFormatError::new("Truncated data") if packed_uint.nil? or packed_uint.length < 4
192
- packed_uint.unpack(@uint_mark)[0]
193
- end
194
- def read_byte
195
- i = @position
196
- @position += 1
197
- packed_byte = @ewkb[i...@position]
198
- raise EWKBFormatError::new("Truncated data") if packed_byte.nil? or packed_byte.length < 1
199
- packed_byte.unpack("C")[0]
200
- end
201
- def endianness=(byte_order)
202
- if(byte_order == NDR)
203
- @uint_mark="V"
204
- @double_mark="E"
205
- elsif(byte_order == XDR)
206
- @uint_mark="N"
207
- @double_mark="G"
208
- end
209
- end
210
- end
211
- end
212
- end
213
- end