nofxx-georuby 1.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/History.txt +4 -0
  2. data/LICENSE +21 -0
  3. data/README.txt +59 -0
  4. data/Rakefile +49 -0
  5. data/VERSION.yml +4 -0
  6. data/lib/geo_ruby.rb +21 -0
  7. data/lib/geo_ruby/base/envelope.rb +167 -0
  8. data/lib/geo_ruby/base/ewkb_parser.rb +216 -0
  9. data/lib/geo_ruby/base/ewkt_parser.rb +336 -0
  10. data/lib/geo_ruby/base/geometry.rb +234 -0
  11. data/lib/geo_ruby/base/geometry_collection.rb +136 -0
  12. data/lib/geo_ruby/base/geometry_factory.rb +81 -0
  13. data/lib/geo_ruby/base/georss_parser.rb +135 -0
  14. data/lib/geo_ruby/base/helper.rb +18 -0
  15. data/lib/geo_ruby/base/line_string.rb +184 -0
  16. data/lib/geo_ruby/base/linear_ring.rb +12 -0
  17. data/lib/geo_ruby/base/multi_line_string.rb +39 -0
  18. data/lib/geo_ruby/base/multi_point.rb +41 -0
  19. data/lib/geo_ruby/base/multi_polygon.rb +37 -0
  20. data/lib/geo_ruby/base/point.rb +310 -0
  21. data/lib/geo_ruby/base/polygon.rb +150 -0
  22. data/lib/geo_ruby/shp4r/dbf.rb +180 -0
  23. data/lib/geo_ruby/shp4r/shp.rb +701 -0
  24. data/spec/data/multipoint.dbf +0 -0
  25. data/spec/data/multipoint.shp +0 -0
  26. data/spec/data/multipoint.shx +0 -0
  27. data/spec/data/point.dbf +0 -0
  28. data/spec/data/point.shp +0 -0
  29. data/spec/data/point.shx +0 -0
  30. data/spec/data/polygon.dbf +0 -0
  31. data/spec/data/polygon.shp +0 -0
  32. data/spec/data/polygon.shx +0 -0
  33. data/spec/data/polyline.dbf +0 -0
  34. data/spec/data/polyline.shp +0 -0
  35. data/spec/data/polyline.shx +0 -0
  36. data/spec/geo_ruby/base/envelope_spec.rb +45 -0
  37. data/spec/geo_ruby/base/ewkb_parser_spec.rb +158 -0
  38. data/spec/geo_ruby/base/ewkt_parser_spec.rb +179 -0
  39. data/spec/geo_ruby/base/geometry_collection_spec.rb +55 -0
  40. data/spec/geo_ruby/base/geometry_factory_spec.rb +11 -0
  41. data/spec/geo_ruby/base/geometry_spec.rb +32 -0
  42. data/spec/geo_ruby/base/georss_parser_spec.rb +218 -0
  43. data/spec/geo_ruby/base/line_string_spec.rb +208 -0
  44. data/spec/geo_ruby/base/linear_ring_spec.rb +14 -0
  45. data/spec/geo_ruby/base/multi_line_string_spec.rb +35 -0
  46. data/spec/geo_ruby/base/multi_point_spec.rb +29 -0
  47. data/spec/geo_ruby/base/multi_polygon_spec.rb +35 -0
  48. data/spec/geo_ruby/base/point_spec.rb +275 -0
  49. data/spec/geo_ruby/base/polygon_spec.rb +108 -0
  50. data/spec/geo_ruby/shp4r/shp_spec.rb +238 -0
  51. data/spec/geo_ruby_spec.rb +27 -0
  52. data/spec/spec.opts +6 -0
  53. data/spec/spec_helper.rb +12 -0
  54. metadata +123 -0
@@ -0,0 +1,238 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ include GeoRuby::Shp4r
4
+ include GeoRuby::Base
5
+
6
+ describe Shp4r do
7
+
8
+ describe "Point" do
9
+ before(:each) do
10
+ @shpfile = ShpFile.open(File.dirname(__FILE__) + '/../../data/point.shp')
11
+ end
12
+
13
+ it "should parse ok" do
14
+ @shpfile.record_count.should eql(2)
15
+ @shpfile.should have(1).fields
16
+ @shpfile.shp_type.should eql(ShpType::POINT)
17
+ end
18
+
19
+ it "should parse fields" do
20
+ field = @shpfile.fields.first
21
+ field.name.should eql("Hoyoyo")
22
+ field.type.should eql("N")
23
+ end
24
+
25
+ it "should parse record 1" do
26
+ rec = @shpfile.first
27
+ rec.geometry.should be_kind_of Point
28
+ rec.geometry.x.should be_close(-90.08375, 0.00001)
29
+ rec.geometry.y.should be_close(34.39996, 0.00001)
30
+ rec.data["Hoyoyo"].should eql(6)
31
+ end
32
+
33
+ it "should parse record 2" do
34
+ rec = @shpfile[1]
35
+ rec.geometry.should be_kind_of Point
36
+ rec.geometry.x.should be_close(-87.82580, 0.00001)
37
+ rec.geometry.y.should be_close(33.36416, 0.00001)
38
+ rec.data["Hoyoyo"].should eql(9)
39
+ end
40
+
41
+ end
42
+
43
+ describe "Polyline" do
44
+ before(:each) do
45
+ @shpfile = ShpFile.open(File.dirname(__FILE__) + '/../../data/polyline.shp')
46
+ end
47
+
48
+ it "should parse ok" do
49
+ @shpfile.record_count.should eql(1)
50
+ @shpfile.should have(1).fields
51
+ @shpfile.shp_type.should eql(ShpType::POLYLINE)
52
+ end
53
+
54
+ it "should parse fields" do
55
+ field = @shpfile.fields.first
56
+ field.name.should eql("Chipoto")
57
+ field.type.should eql("F")
58
+ end
59
+
60
+ it "should parse record 1" do
61
+ rec = @shpfile.first
62
+ rec.geometry.should be_kind_of MultiLineString
63
+ rec.geometry.length.should eql(1)
64
+ rec.geometry[0].length.should eql(6)
65
+ rec.data["Chipoto"].should eql(5.678)
66
+ end
67
+
68
+ end
69
+
70
+ describe "Polygon" do
71
+ before(:each) do
72
+ @shpfile = ShpFile.open(File.dirname(__FILE__) + '/../../data/polygon.shp')
73
+ end
74
+
75
+ it "should parse ok" do
76
+ @shpfile.record_count.should eql(1)
77
+ @shpfile.should have(1).fields
78
+ @shpfile.shp_type.should eql(ShpType::POLYGON)
79
+ end
80
+
81
+ it "should parse fields" do
82
+ field = @shpfile.fields.first
83
+ field.name.should eql("Hello")
84
+ field.type.should eql("C")
85
+ end
86
+
87
+ it "should parse record 1" do
88
+ rec = @shpfile.first
89
+ rec.geometry.should be_kind_of MultiPolygon
90
+ rec.geometry.length.should eql(1)
91
+ rec.geometry[0].length.should eql(1)
92
+ rec.geometry[0][0].length.should eql(7)
93
+ rec.data["Hello"].should eql("Bouyoul!")
94
+ end
95
+ end
96
+
97
+ describe "Write" do
98
+ def cp_all_shp(file1,file2)
99
+ FileUtils.copy(file1 + ".shp",file2 + ".shp")
100
+ FileUtils.copy(file1 + ".shx",file2 + ".shx")
101
+ FileUtils.copy(file1 + ".dbf",file2 + ".dbf")
102
+ end
103
+
104
+ def rm_all_shp(file)
105
+ FileUtils.rm(file + ".shp")
106
+ FileUtils.rm(file + ".shx")
107
+ FileUtils.rm(file + ".dbf")
108
+ end
109
+
110
+ it "test_point" do
111
+ cp_all_shp(File.dirname(__FILE__) + '/../../data/point',
112
+ File.dirname(__FILE__) + '/../../data/point2')
113
+ shpfile = ShpFile.open(File.dirname(__FILE__) + '/../../data/point2.shp')
114
+
115
+ shpfile.transaction do |tr|
116
+ tr.should be_instance_of ShpTransaction
117
+ tr.add(ShpRecord.new(Point.from_x_y(123.4,123.4),'Hoyoyo' => 5))
118
+ tr.add(ShpRecord.new(Point.from_x_y(-16.67,16.41),'Hoyoyo' => -7))
119
+ tr.delete(1)
120
+ end
121
+
122
+ shpfile.record_count.should eql(3)
123
+
124
+ shpfile.close
125
+ rm_all_shp(File.dirname(__FILE__) + '/../../data/point2')
126
+ end
127
+
128
+ it "test_linestring" do
129
+ cp_all_shp(File.dirname(__FILE__) + '/../../data/polyline',
130
+ File.dirname(__FILE__) + '/../../data/polyline2')
131
+
132
+ shpfile = ShpFile.open(File.dirname(__FILE__) + '/../../data/polyline2.shp')
133
+
134
+ shpfile.transaction do |tr|
135
+ tr.should be_instance_of ShpTransaction
136
+ tr.add(ShpRecord.new(LineString.from_coordinates([[123.4,123.4],[45.6,12.3]]),'Chipoto' => 5.6778))
137
+ tr.add(ShpRecord.new(LineString.from_coordinates([[23.4,13.4],[45.6,12.3],[12,-67]]),'Chipoto' => -7.1))
138
+ tr.delete(0)
139
+ end
140
+
141
+ shpfile.record_count.should eql(2)
142
+ shpfile.close
143
+ rm_all_shp(File.dirname(__FILE__) + '/../../data/polyline2')
144
+ end
145
+
146
+ it "test_polygon" do
147
+ cp_all_shp(File.dirname(__FILE__) + '/../../data/polygon',
148
+ File.dirname(__FILE__) + '/../../data/polygon2')
149
+ shpfile = ShpFile.open(File.dirname(__FILE__) + '/../../data/polygon2.shp')
150
+
151
+ shpfile.transaction do |tr|
152
+ tr.should be_instance_of ShpTransaction
153
+ tr.delete(0)
154
+ tr.add(ShpRecord.new(Polygon.from_coordinates([[[0,0],[40,0],[40,40],[0,40],[0,0]],[[10,10],[10,20],[20,20],[10,10]]]),'Hello' => "oook"))
155
+ end
156
+
157
+ shpfile.record_count.should eql(1)
158
+
159
+ shpfile.close
160
+ rm_all_shp(File.dirname(__FILE__) + '/../../data/polygon2')
161
+ end
162
+
163
+ it "test_multipoint" do
164
+ cp_all_shp(File.dirname(__FILE__) + '/../../data/multipoint',
165
+ File.dirname(__FILE__) + '/../../data/multipoint2')
166
+ shpfile = ShpFile.open(File.dirname(__FILE__) + '/../../data/multipoint2.shp')
167
+
168
+ shpfile.transaction do |tr|
169
+ tr.should be_instance_of ShpTransaction
170
+ tr.add(ShpRecord.new(MultiPoint.from_coordinates([[45.6,-45.1],[12.4,98.2],[51.2,-0.12],[156.12345,56.109]]),'Hello' => 5,"Hoyoyo" => "AEZAE"))
171
+ end
172
+
173
+ shpfile.record_count.should eql(2)
174
+
175
+ shpfile.close
176
+ rm_all_shp(File.dirname(__FILE__) + '/../../data/multipoint2')
177
+ end
178
+
179
+ it "test_multi_polygon" do
180
+ cp_all_shp(File.dirname(__FILE__) + '/../../data/polygon',
181
+ File.dirname(__FILE__) + '/../../data/polygon4')
182
+
183
+ shpfile = ShpFile.open(File.dirname(__FILE__) + '/../../data/polygon4.shp')
184
+
185
+ shpfile.transaction do |tr|
186
+ tr.should be_instance_of ShpTransaction
187
+ tr.add(ShpRecord.new(MultiPolygon.from_polygons([Polygon.from_coordinates([[[0,0],[40,0],[40,40],[0,40],[0,0]],[[10,10],[10,20],[20,20],[10,10]]])]),'Hello' => "oook"))
188
+ end
189
+
190
+ shpfile.record_count.should eql(2)
191
+
192
+ shpfile.close
193
+
194
+ rm_all_shp(File.dirname(__FILE__) + '/../../data/polygon4')
195
+ end
196
+
197
+ it "test_rollback" do
198
+ cp_all_shp(File.dirname(__FILE__) + '/../../data/polygon',
199
+ File.dirname(__FILE__) + '/../../data/polygon5')
200
+
201
+ shpfile = ShpFile.open(File.dirname(__FILE__) + '/../../data/polygon5.shp')
202
+
203
+ shpfile.transaction do |tr|
204
+ tr.should be_instance_of ShpTransaction
205
+ tr.add(ShpRecord.new(MultiPolygon.from_polygons([Polygon.from_coordinates([[[0,0],[40,0],[40,40],[0,40],[0,0]],[[10,10],[10,20],[20,20],[10,10]]])]),'Hello' => "oook"))
206
+ tr.rollback
207
+ end
208
+ shpfile.record_count.should eql(1)
209
+
210
+ shpfile.close
211
+
212
+ rm_all_shp(File.dirname(__FILE__) + '/../../data/polygon5')
213
+
214
+ end
215
+
216
+ it "test_creation" do
217
+ shpfile = ShpFile.create(File.dirname(__FILE__) + '/../../data/point3.shp',ShpType::POINT,[Dbf::Field.new("Hoyoyo","C",10,0)])
218
+ shpfile.transaction do |tr|
219
+ tr.add(ShpRecord.new(Point.from_x_y(123,123.4),'Hoyoyo' => "HJHJJ"))
220
+ end
221
+ shpfile.record_count.should eql(1)
222
+ shpfile.close
223
+ rm_all_shp(File.dirname(__FILE__) + '/../../data/point3')
224
+ end
225
+
226
+ it "test_creation_multipoint" do
227
+ shpfile = ShpFile.create(File.dirname(__FILE__) + '/../../data/multipoint3.shp',ShpType::MULTIPOINT,[Dbf::Field.new("Hoyoyo","C",10),Dbf::Field.new("Hello","N",10)])
228
+ shpfile.transaction do |tr|
229
+ tr.add(ShpRecord.new(MultiPoint.from_coordinates([[123,123.4],[345,12.2]]),'Hoyoyo' => "HJHJJ","Hello" => 5))
230
+ end
231
+ shpfile.record_count.should eql(1)
232
+ shpfile.close
233
+ rm_all_shp(File.dirname(__FILE__) + '/../../data/multipoint3')
234
+ end
235
+
236
+ end
237
+
238
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ # Time to add your specs!
4
+ # http://rspec.info/
5
+ describe "GeoRuby Stuff" do
6
+
7
+ it "should instantiate Geometry" do
8
+ @geo = GeoRuby::Base::Geometry.new
9
+ @geo.class.should eql(Geometry)
10
+ end
11
+
12
+ it "should instantiate from SimpleFeatures for compatibility" do
13
+ @geo = GeoRuby::SimpleFeatures::Geometry.new
14
+ @geo.class.should eql(Geometry)
15
+ end
16
+
17
+ it "should instantiate Point" do
18
+ @point = Point.new
19
+ @point.should be_instance_of(Point)
20
+ end
21
+
22
+ it "should instantiate Line" do
23
+ @line = LineString.new
24
+ @line.should be_instance_of(LineString)
25
+ end
26
+
27
+ end
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ profile
4
+ --timeout
5
+ 20
6
+ --diff
@@ -0,0 +1,12 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'geo_ruby'
11
+ include GeoRuby
12
+ include Base
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nofxx-georuby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.7
5
+ platform: ruby
6
+ authors:
7
+ - Guilhem Vellut
8
+ - Marcos Augusto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-05-02 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: GeoRuby provides geometric data types from the OGC 'Simple Features' specification.
18
+ email: x@nofxx.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - LICENSE
25
+ - README.txt
26
+ files:
27
+ - History.txt
28
+ - LICENSE
29
+ - README.txt
30
+ - Rakefile
31
+ - VERSION.yml
32
+ - lib/geo_ruby.rb
33
+ - lib/geo_ruby/base/envelope.rb
34
+ - lib/geo_ruby/base/ewkb_parser.rb
35
+ - lib/geo_ruby/base/ewkt_parser.rb
36
+ - lib/geo_ruby/base/geometry.rb
37
+ - lib/geo_ruby/base/geometry_collection.rb
38
+ - lib/geo_ruby/base/geometry_factory.rb
39
+ - lib/geo_ruby/base/georss_parser.rb
40
+ - lib/geo_ruby/base/helper.rb
41
+ - lib/geo_ruby/base/line_string.rb
42
+ - lib/geo_ruby/base/linear_ring.rb
43
+ - lib/geo_ruby/base/multi_line_string.rb
44
+ - lib/geo_ruby/base/multi_point.rb
45
+ - lib/geo_ruby/base/multi_polygon.rb
46
+ - lib/geo_ruby/base/point.rb
47
+ - lib/geo_ruby/base/polygon.rb
48
+ - lib/geo_ruby/shp4r/dbf.rb
49
+ - lib/geo_ruby/shp4r/shp.rb
50
+ - spec/data/multipoint.dbf
51
+ - spec/data/multipoint.shp
52
+ - spec/data/multipoint.shx
53
+ - spec/data/point.dbf
54
+ - spec/data/point.shp
55
+ - spec/data/point.shx
56
+ - spec/data/polygon.dbf
57
+ - spec/data/polygon.shp
58
+ - spec/data/polygon.shx
59
+ - spec/data/polyline.dbf
60
+ - spec/data/polyline.shp
61
+ - spec/data/polyline.shx
62
+ - spec/geo_ruby/base/envelope_spec.rb
63
+ - spec/geo_ruby/base/ewkb_parser_spec.rb
64
+ - spec/geo_ruby/base/ewkt_parser_spec.rb
65
+ - spec/geo_ruby/base/geometry_collection_spec.rb
66
+ - spec/geo_ruby/base/geometry_factory_spec.rb
67
+ - spec/geo_ruby/base/geometry_spec.rb
68
+ - spec/geo_ruby/base/georss_parser_spec.rb
69
+ - spec/geo_ruby/base/line_string_spec.rb
70
+ - spec/geo_ruby/base/linear_ring_spec.rb
71
+ - spec/geo_ruby/base/multi_line_string_spec.rb
72
+ - spec/geo_ruby/base/multi_point_spec.rb
73
+ - spec/geo_ruby/base/multi_polygon_spec.rb
74
+ - spec/geo_ruby/base/point_spec.rb
75
+ - spec/geo_ruby/base/polygon_spec.rb
76
+ - spec/geo_ruby/shp4r/shp_spec.rb
77
+ - spec/geo_ruby_spec.rb
78
+ - spec/spec.opts
79
+ - spec/spec_helper.rb
80
+ has_rdoc: true
81
+ homepage: http://github.com/nofxx/georuby
82
+ post_install_message:
83
+ rdoc_options:
84
+ - --charset=UTF-8
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: "0"
92
+ version:
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ version:
99
+ requirements: []
100
+
101
+ rubyforge_project:
102
+ rubygems_version: 1.2.0
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Ruby data holder for OGC Simple Features
106
+ test_files:
107
+ - spec/geo_ruby/shp4r/shp_spec.rb
108
+ - spec/geo_ruby/base/polygon_spec.rb
109
+ - spec/geo_ruby/base/linear_ring_spec.rb
110
+ - spec/geo_ruby/base/geometry_factory_spec.rb
111
+ - spec/geo_ruby/base/geometry_spec.rb
112
+ - spec/geo_ruby/base/georss_parser_spec.rb
113
+ - spec/geo_ruby/base/multi_point_spec.rb
114
+ - spec/geo_ruby/base/ewkt_parser_spec.rb
115
+ - spec/geo_ruby/base/line_string_spec.rb
116
+ - spec/geo_ruby/base/multi_line_string_spec.rb
117
+ - spec/geo_ruby/base/geometry_collection_spec.rb
118
+ - spec/geo_ruby/base/ewkb_parser_spec.rb
119
+ - spec/geo_ruby/base/multi_polygon_spec.rb
120
+ - spec/geo_ruby/base/point_spec.rb
121
+ - spec/geo_ruby/base/envelope_spec.rb
122
+ - spec/geo_ruby_spec.rb
123
+ - spec/spec_helper.rb