GeoRuby 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,5 +1,5 @@
1
1
  =GeoRuby
2
- This is GeoRuby 1.2.0. It is intended as a holder for data returned from PostGIS and the Spatial Extensions of MySql. The data model roughly follows the OGC "Simple Features for SQL" specification (see http://www.opengis.org/docs/99-049.pdf), although without any kind of advanced functionalities (such as geometric operators or reprojections).
2
+ This is GeoRuby 1.2.1. It is intended as a holder for data returned from PostGIS and the Spatial Extensions of MySql. The data model roughly follows the OGC "Simple Features for SQL" specification (see http://www.opengis.org/docs/99-049.pdf), although without any kind of advanced functionalities (such as geometric operators or reprojections).
3
3
 
4
4
  ===Available data types
5
5
  The following geometric data types are provided :
@@ -281,7 +281,7 @@ module GeoRuby
281
281
 
282
282
  #A SHP record : contains both the geometry and the data fields (from the DBF)
283
283
  class ShpRecord
284
- attr_accessor :geometry , :data
284
+ attr_reader :geometry , :data
285
285
 
286
286
  def initialize(geometry, data)
287
287
  @geometry = geometry
@@ -113,7 +113,7 @@ module GeoRuby
113
113
 
114
114
  #creates a new GeometryCollection from an array of geometries
115
115
  def self.from_geometries(geometries,srid=DEFAULT_SRID,with_z=false,with_m=false)
116
- geometry_collection = GeometryCollection::new(srid,with_z,with_m)
116
+ geometry_collection = new(srid,with_z,with_m)
117
117
  geometry_collection.concat(geometries)
118
118
  geometry_collection
119
119
  end
@@ -131,14 +131,14 @@ module GeoRuby
131
131
 
132
132
  #Creates a new line string. Accept an array of points as argument
133
133
  def self.from_points(points,srid=DEFAULT_SRID,with_z=false,with_m=false)
134
- line_string = LineString::new(srid,with_z,with_m)
134
+ line_string = new(srid,with_z,with_m)
135
135
  line_string.concat(points)
136
136
  line_string
137
137
  end
138
138
 
139
139
  #Creates a new line string. Accept a sequence of points as argument : ((x,y)...(x,y))
140
140
  def self.from_coordinates(points,srid=DEFAULT_SRID,with_z=false,with_m=false)
141
- line_string = LineString::new(srid,with_z,with_m)
141
+ line_string = new(srid,with_z,with_m)
142
142
  line_string.concat( points.collect{|point_coords| Point.from_coordinates(point_coords,srid,with_z,with_m) } )
143
143
  line_string
144
144
  end
@@ -2,26 +2,11 @@ require 'geo_ruby/simple_features/line_string'
2
2
 
3
3
  module GeoRuby
4
4
  module SimpleFeatures
5
- #Represents a linear ring, which is a closed line string (see LineString). No check is performed to verify if the linear ring is really closed.
5
+ #Represents a linear ring, which is a closed line string (see LineString). Currently, no check is performed to verify if the linear ring is really closed.
6
6
  class LinearRing < LineString
7
7
  def initialize(srid= DEFAULT_SRID,with_z=false,with_m=false)
8
8
  super(srid,with_z,with_m)
9
9
  end
10
-
11
- #creates a new linear ring from an array of points. The first and last points should be equal, although no check is performed here.
12
- def self.from_points(points,srid=DEFAULT_SRID,with_z=false,with_m=false)
13
- linear_ring = LinearRing::new(srid,with_z,with_m)
14
- linear_ring.concat(points)
15
- linear_ring
16
- end
17
-
18
- #creates a new linear ring from a sequence of points : ((x,y)...(x,y)).
19
- def self.from_coordinates(points,srid=DEFAULT_SRID,with_z=false,with_m=false)
20
- linear_ring = LinearRing::new(srid,with_z,with_m)
21
- linear_ring.concat( points.collect{|point_coords| Point.from_coordinates(point_coords,srid,with_z,with_m) } )
22
- linear_ring
23
- end
24
-
25
10
  end
26
11
  end
27
12
  end
@@ -23,14 +23,14 @@ module GeoRuby
23
23
 
24
24
  #Creates a new multi line string from an array of line strings
25
25
  def self.from_line_strings(line_strings,srid=DEFAULT_SRID,with_z=false,with_m=false)
26
- multi_line_string = MultiLineString::new(srid,with_z,with_m)
26
+ multi_line_string = new(srid,with_z,with_m)
27
27
  multi_line_string.concat(line_strings)
28
28
  multi_line_string
29
29
  end
30
30
 
31
31
  #Creates a new multi line string from sequences of points : (((x,y)...(x,y)),((x,y)...(x,y)))
32
32
  def self.from_coordinates(point_sequences,srid=DEFAULT_SRID,with_z=false,with_m=false)
33
- multi_line_string = MultiLineString::new(srid,with_z,with_m)
33
+ multi_line_string = new(srid,with_z,with_m)
34
34
  multi_line_string.concat(point_sequences.collect {|points| LineString.from_coordinates(points,srid,with_z,with_m) })
35
35
  multi_line_string
36
36
  end
@@ -24,14 +24,14 @@ module GeoRuby
24
24
 
25
25
  #Creates a new multi point from an array of points
26
26
  def self.from_points(points,srid= DEFAULT_SRID,with_z=false,with_m=false)
27
- multi_point= MultiPoint::new(srid,with_z,with_m)
27
+ multi_point= new(srid,with_z,with_m)
28
28
  multi_point.concat(points)
29
29
  multi_point
30
30
  end
31
31
 
32
32
  #Creates a new multi point from a list of point coordinates : ((x,y)...(x,y))
33
33
  def self.from_coordinates(points,srid= DEFAULT_SRID,with_z=false,with_m=false)
34
- multi_point= MultiPoint::new(srid,with_z,with_m)
34
+ multi_point= new(srid,with_z,with_m)
35
35
  multi_point.concat(points.collect {|point| Point.from_coordinates(point,srid,with_z,with_m)})
36
36
  multi_point
37
37
  end
@@ -23,13 +23,13 @@ module GeoRuby
23
23
 
24
24
  #Creates a multi polygon from an array of polygons
25
25
  def self.from_polygons(polygons,srid=DEFAULT_SRID,with_z=false,with_m=false)
26
- multi_polygon = MultiPolygon::new(srid,with_z,with_m)
26
+ multi_polygon = new(srid,with_z,with_m)
27
27
  multi_polygon.concat(polygons)
28
28
  multi_polygon
29
29
  end
30
30
  #Creates a multi polygon from sequences of points : ((((x,y)...(x,y)),((x,y)...(x,y)),((x,y)...(x,y)))
31
31
  def self.from_coordinates(point_sequence_sequences,srid= DEFAULT_SRID,with_z=false,with_m=false)
32
- multi_polygon = MultiPolygon::new(srid,with_z,with_m)
32
+ multi_polygon = new(srid,with_z,with_m)
33
33
  multi_polygon.concat( point_sequence_sequences.collect {|point_sequences| Polygon.from_coordinates(point_sequences,srid,with_z,with_m) } )
34
34
  multi_polygon
35
35
  end
@@ -23,6 +23,7 @@ module GeoRuby
23
23
  @x=x
24
24
  @y=y
25
25
  @z=z
26
+ self
26
27
  end
27
28
  alias :set_lon_lat_z :set_x_y_z
28
29
 
@@ -30,6 +31,7 @@ module GeoRuby
30
31
  def set_x_y(x,y)
31
32
  @x=x
32
33
  @y=y
34
+ self
33
35
  end
34
36
  alias :set_lon_lat :set_x_y
35
37
 
@@ -193,33 +195,29 @@ module GeoRuby
193
195
 
194
196
  #creates a point from the X and Y coordinates
195
197
  def self.from_x_y(x,y,srid=DEFAULT_SRID)
196
- point= Point::new(srid)
198
+ point= new(srid)
197
199
  point.set_x_y(x,y)
198
- point
199
200
  end
200
201
 
201
202
  #creates a point from the X, Y and Z coordinates
202
203
  def self.from_x_y_z(x,y,z,srid=DEFAULT_SRID)
203
- point= Point::new(srid,true)
204
+ point= new(srid,true)
204
205
  point.set_x_y_z(x,y,z)
205
- point
206
206
  end
207
207
 
208
208
 
209
209
  #creates a point from the X, Y and M coordinates
210
210
  def self.from_x_y_m(x,y,m,srid=DEFAULT_SRID)
211
- point= Point::new(srid,false,true)
212
- point.set_x_y(x,y)
211
+ point= new(srid,false,true)
213
212
  point.m=m
214
- point
213
+ point.set_x_y(x,y)
215
214
  end
216
215
 
217
216
  #creates a point from the X, Y, Z and M coordinates
218
217
  def self.from_x_y_z_m(x,y,z,m,srid=DEFAULT_SRID)
219
- point= Point::new(srid,true,true)
220
- point.set_x_y_z(x,y,z)
218
+ point= new(srid,true,true)
221
219
  point.m=m
222
- point
220
+ point.set_x_y_z(x,y,z)
223
221
  end
224
222
 
225
223
  #aliasing the constructors in case you want to use lat/lon instead of y/x
@@ -111,18 +111,26 @@ module GeoRuby
111
111
 
112
112
  #creates a new polygon. Accepts an array of linear strings as argument
113
113
  def self.from_linear_rings(linear_rings,srid = DEFAULT_SRID,with_z=false,with_m=false)
114
- polygon = Polygon::new(srid,with_z,with_m)
114
+ polygon = new(srid,with_z,with_m)
115
115
  polygon.concat(linear_rings)
116
116
  polygon
117
117
  end
118
118
 
119
119
  #creates a new polygon. Accepts a sequence of points as argument : ((x,y)....(x,y)),((x,y).....(x,y))
120
120
  def self.from_coordinates(point_sequences,srid=DEFAULT_SRID,with_z=false,with_m=false)
121
- polygon = Polygon::new(srid,with_z,with_m)
121
+ polygon = new(srid,with_z,with_m)
122
122
  polygon.concat( point_sequences.collect {|points| LinearRing.from_coordinates(points,srid,with_z,with_m) } )
123
123
  polygon
124
124
  end
125
125
 
126
+ #creates a new polygon from a list of Points (pt1....ptn),(pti....ptj)
127
+ def self.from_points(point_sequences, srid=DEFAULT_SRID,with_z=false,with_m=false)
128
+ polygon = new(srid,with_z,with_m)
129
+ polygon.concat( point_sequences.collect {|points| LinearRing.from_points(points,srid,with_z,with_m) } )
130
+ polygon
131
+
132
+ end
133
+
126
134
  end
127
135
  end
128
136
  end
data/rakefile.rb CHANGED
@@ -24,7 +24,7 @@ spec = Gem::Specification::new do |s|
24
24
  s.platform = Gem::Platform::RUBY
25
25
 
26
26
  s.name = 'GeoRuby'
27
- s.version = "1.2.0"
27
+ s.version = "1.2.1"
28
28
  s.summary = "Ruby data holder for OGC Simple Features"
29
29
  s.description = <<EOF
30
30
  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)
@@ -145,8 +145,12 @@ class TestSimpleFeatures < Test::Unit::TestCase
145
145
  assert_in_delta(554058.924,point1.ellipsoidal_distance(point2),0.001)
146
146
 
147
147
  assert_in_delta(555811.68,point1.spherical_distance(point2),0.01)
148
-
149
-
148
+ end
149
+
150
+ def point_subclassable
151
+ place = Class.new(Point)
152
+ p = place.from_x_y(0.0,0.0)
153
+ assert p.is_a?(place)
150
154
  end
151
155
 
152
156
  def test_line_string_creation
@@ -245,7 +249,15 @@ class TestSimpleFeatures < Test::Unit::TestCase
245
249
  #no test of the binary representation for linear_rings : always with polygons and like line_string
246
250
  def test_polygon_creation
247
251
  linear_ring1 = LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],256)
248
- linear_ring2 = LinearRing.from_coordinates([[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]],256)
252
+ linear_ring2 = LinearRing.from_coordinates([[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]],256)
253
+ point1 = Point.from_x_y(12.4,-45.3,256)
254
+ point2 = Point.from_x_y(45.4,41.6,256)
255
+ point3 = Point.from_x_y(4.456,1.0698,256)
256
+ point4 = Point.from_x_y(12.4,-45.3,256)
257
+ point5 = Point.from_x_y(2.4,5.3,256)
258
+ point6 = Point.from_x_y(5.4,1.4263,256)
259
+ point7 = Point.from_x_y(14.46,1.06,256)
260
+ point8 = Point.from_x_y(2.4,5.3,256)
249
261
 
250
262
  polygon = Polygon::new(256)
251
263
  assert_equal(0,polygon.length)
@@ -271,7 +283,11 @@ class TestSimpleFeatures < Test::Unit::TestCase
271
283
  assert_equal(linear_ring1,polygon[0])
272
284
  assert_equal(linear_ring2,polygon[1])
273
285
 
274
-
286
+ polygon = Polygon.from_points([[point1,point2,point3,point4],[point5,point6,point7,point8]],256)
287
+ assert_equal(2,polygon.length)
288
+ assert_equal(linear_ring1,polygon[0])
289
+ assert_equal(linear_ring2,polygon[1])
290
+
275
291
  polygon = Polygon.from_coordinates([[[12.4,-45.3,15.2],[45.4,41.6,2.4],[4.456,1.0698,5.6],[12.4,-45.3,6.1]],[[2.4,5.3,4.5],[5.4,1.4263,4.2],[14.46,1.06,123.1],[2.4,5.3,4.4]]],256,true)
276
292
  assert_equal(Polygon,polygon.class)
277
293
  assert_equal(2,polygon.length)
@@ -286,6 +302,8 @@ class TestSimpleFeatures < Test::Unit::TestCase
286
302
  assert_equal(2,bbox.length)
287
303
  assert_equal(Point.from_x_y_z(4.456,-45.3,2.4),bbox[0])
288
304
  assert_equal(Point.from_x_y_z(45.4,41.6,123.1),bbox[1])
305
+
306
+
289
307
 
290
308
  end
291
309
  def test_polygon_equal
data/tools/shp2sql.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  $:.unshift("lib/spatial_adapter/","lib/spatial_adapter/lib")
2
2
 
3
+ require 'rubygems'
3
4
  require 'geo_ruby'
4
5
  include GeoRuby::Shp4r
5
6
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: GeoRuby
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.2.0
7
- date: 2007-01-20 00:00:00 +01:00
6
+ version: 1.2.1
7
+ date: 2007-02-20 00:00:00 +01:00
8
8
  summary: Ruby data holder for OGC Simple Features
9
9
  require_paths:
10
10
  - lib