nofxx-georuby 1.6.2 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.txt CHANGED
@@ -35,36 +35,36 @@ Georuby has support for reading ESRI shapefiles (http://www.esri.com/library/whi
35
35
 
36
36
  Here is an example of Shapefile reading, that goes through all the geometries in a file and disaply the values of the attributes :
37
37
 
38
- require 'geo_ruby/shp'
39
-
40
- ShpFile.open(shpfile) do |shp|
41
- shp.each do |shape|
42
- geom = shape.geometry #a GeoRuby SimpleFeature
43
- att_data = shape.data #a Hash
44
- shp.fields.each do |field|
45
- puts att_data[field.name]
46
- end
47
- end
38
+ require 'geo_ruby/shp'
39
+
40
+ ShpFile.open(shpfile) do |shp|
41
+ shp.each do |shape|
42
+ geom = shape.geometry #a GeoRuby SimpleFeature
43
+ att_data = shape.data #a Hash
44
+ shp.fields.each do |field|
45
+ puts att_data[field.name]
46
+ end
48
47
  end
48
+ end
49
49
 
50
50
  Support for ESRI shapefile creation and modification has been added as well. New shapefiles can be created given a geometry type and specifications for the DBF fields. Data can be added and removed from an existing shapefile. An update operation is also provided for convenience : it just performs a 'delete' and an 'add', which means the index of the modified record will change. Note that once a shapefile has been created, GeoRuby does not allow the modification of the schema (it will probably be done in a subsequent version).
51
51
 
52
52
  Here is an example of how to create a new Shapefile with 2 fields :
53
-
54
- shpfile = ShpFile.create('hello.shp',ShpType::POINT,[Dbf::Field.new("Hoyoyo","C",10),Dbf::Field.new("Boyoul","N",10,0)])
53
+
54
+ shpfile = ShpFile.create('hello.shp',ShpType::POINT,[Dbf::Field.new("Hoyoyo","C",10),Dbf::Field.new("Boyoul","N",10,0)])
55
55
 
56
56
  The file is then open for reading and writing.
57
57
 
58
58
  Here is an example of how to write to a shapefile (created or not with GeoRuby) :
59
59
 
60
- shpfile = ShpFile.open('places.shp')
61
- shpfile.transaction do |tr|
62
- tr.add(ShpRecord.new(Point.from_x_y(123.4,123.4),'Hoyoyo' => "AEZ",'Bouyoul' => 45))
63
- tr.update(4,ShpRecord.new(Point.from_x_y(-16.67,16.41),'Hoyoyo' => "EatMe",'Bouyoul' => 42))
64
- tr.delete(1)
65
- end
66
- shpfile.close
67
-
60
+ shpfile = ShpFile.open('places.shp')
61
+ shpfile.transaction do |tr|
62
+ tr.add(ShpRecord.new(Point.from_x_y(123.4,123.4),'Hoyoyo' => "AEZ",'Bouyoul' => 45))
63
+ tr.update(4,ShpRecord.new(Point.from_x_y(-16.67,16.41),'Hoyoyo' => "EatMe",'Bouyoul' => 42))
64
+ tr.delete(1)
65
+ end
66
+ shpfile.close
67
+
68
68
  Note the transaction is just there so the operations on the files can be buffered. Nothing happens on the original files until the block has finished executing. Calling <tt>tr.rollback</tt> at anytime during the execution will prevent the modifications.
69
69
 
70
70
  Also currently, error reporting is minimal and it has not been tested that thoroughly so caveat emptor and backup before performing any destructive operation.
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rake'
4
4
  begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
- gem.name = "georuby"
7
+ gem.name = "nofxx-georuby"
8
8
  gem.summary = "Ruby data holder for OGC Simple Features"
9
9
  gem.description = "GeoRuby provides geometric data types from the OGC 'Simple Features' specification."
10
10
  gem.email = "x@nofxx.com"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.2
1
+ 1.7.1
@@ -75,7 +75,7 @@ module GeoRuby
75
75
  # If the GPX isn't closed, a line from the first
76
76
  # to the last point will be created to close it.
77
77
  def as_polygon
78
- Polygon.from_points([@points[0] == @points[-1] ? @points : @points << @points[0] ])
78
+ Polygon.from_points([@points[0] == @points[-1] ? @points : @points.push(@points[0].clone)])
79
79
  end
80
80
 
81
81
  # Return GPX Envelope
@@ -1,7 +1,11 @@
1
1
  # Uses the dbf lib, Copyright 2006 Keith Morrison (http://infused.org)
2
2
  # Modified to work as external gem now
3
3
  require 'rubygems'
4
- require 'dbf'
4
+ begin
5
+ require 'dbf'
6
+ rescue LoadError
7
+ puts "Unable to find gem 'dbf'. Please install."
8
+ end
5
9
 
6
10
  module GeoRuby
7
11
  module Shp4r
@@ -7,7 +7,7 @@ module GeoRuby
7
7
  attr_accessor :srid, :with_z, :zoom
8
8
 
9
9
  #Creates a enw Envelope with +lower_corner+ as the first element of the corners array and +upper_corner+ as the second element
10
- def initialize(srid = @@default_srid, with_z = false)
10
+ def initialize(srid = DEFAULT_SRID, with_z = false)
11
11
  @srid = srid
12
12
  @with_z = with_z
13
13
  end
@@ -148,7 +148,7 @@ module GeoRuby
148
148
  end
149
149
 
150
150
  #Creates a new envelope. Accept an array of 2 points as argument
151
- def self.from_points(points,srid=@@default_srid,with_z=false)
151
+ def self.from_points(points,srid=DEFAULT_SRID,with_z=false)
152
152
  raise "Not an array" unless points.class == Array
153
153
  e = Envelope.new(srid,with_z)
154
154
  e.lower_corner, e.upper_corner = points
@@ -156,7 +156,7 @@ module GeoRuby
156
156
  end
157
157
 
158
158
  #Creates a new envelope. Accept a sequence of point coordinates as argument : ((x,y),(x,y))
159
- def self.from_coordinates(points,srid=@@default_srid,with_z=false)
159
+ def self.from_coordinates(points,srid=DEFAULT_SRID,with_z=false)
160
160
  e = Envelope.new(srid,with_z)
161
161
  e.lower_corner, e.upper_corner = points.collect{|point_coords| Point.from_coordinates(point_coords,srid,with_z)}
162
162
  e
@@ -67,7 +67,7 @@ module GeoRuby
67
67
  @geometry_type = @geometry_type & ~SRID_MASK
68
68
  else
69
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
70
+ @srid= @srid || DEFAULT_SRID
71
71
  end
72
72
 
73
73
  if @parse_options.has_key? @geometry_type
@@ -68,7 +68,7 @@ module GeoRuby
68
68
 
69
69
  else
70
70
  #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
71
- @srid= @srid || @@default_srid
71
+ @srid= @srid || DEFAULT_SRID
72
72
  geom_type = token
73
73
  end
74
74
 
@@ -1,14 +1,8 @@
1
1
  module GeoRuby#:nodoc:
2
2
  module SimpleFeatures
3
3
  #arbitrary default SRID
4
- @@default_srid = 4326
4
+ DEFAULT_SRID = 4326 unless defined? DEFAULT_SRID
5
5
 
6
- def self.default_srid
7
- @@default_srid
8
- end
9
- def self.srid=(srid)
10
- @@default_srid = srid
11
- end
12
6
 
13
7
  #Root of all geometric data classes.
14
8
  #Objects of class Geometry should not be instantiated.
@@ -22,7 +16,7 @@ module GeoRuby#:nodoc:
22
16
  attr_accessor :with_m
23
17
  alias :with_m? :with_m
24
18
 
25
- def initialize(srid=@@default_srid,with_z=false,with_m=false)
19
+ def initialize(srid=DEFAULT_SRID,with_z=false,with_m=false)
26
20
  @srid=srid
27
21
  @with_z=with_z
28
22
  @with_m=with_m
@@ -6,7 +6,7 @@ module GeoRuby
6
6
  class GeometryCollection < Geometry
7
7
  attr_reader :geometries
8
8
 
9
- def initialize(srid = @@default_srid,with_z=false,with_m=false)
9
+ def initialize(srid = DEFAULT_SRID,with_z=false,with_m=false)
10
10
  super(srid,with_z,with_m)
11
11
  @geometries = []
12
12
  end
@@ -126,7 +126,7 @@ module GeoRuby
126
126
  end
127
127
 
128
128
  #creates a new GeometryCollection from an array of geometries
129
- def self.from_geometries(geometries,srid=@@default_srid,with_z=false,with_m=false)
129
+ def self.from_geometries(geometries,srid=DEFAULT_SRID,with_z=false,with_m=false)
130
130
  geometry_collection = new(srid,with_z,with_m)
131
131
  geometry_collection.concat(geometries)
132
132
  geometry_collection
@@ -59,7 +59,7 @@ module GeoRuby
59
59
  xyzm.each_slice(4) {|slice| add_point_x_y_z_m(*slice)}
60
60
  end
61
61
  #begin a geometry of type +geometry_type+
62
- def begin_geometry(geometry_type,srid=@@default_srid)
62
+ def begin_geometry(geometry_type,srid=DEFAULT_SRID)
63
63
  geometry= geometry_type::new(srid)
64
64
  @geometry= geometry if @geometry.nil?
65
65
  @geometry_stack << geometry
@@ -7,7 +7,7 @@ module GeoRuby
7
7
  #the list of points forming the line string
8
8
  attr_reader :points
9
9
 
10
- def initialize(srid= @@default_srid,with_z=false,with_m=false)
10
+ def initialize(srid= DEFAULT_SRID,with_z=false,with_m=false)
11
11
  super(srid,with_z,with_m)
12
12
  @points=[]
13
13
  end
@@ -167,14 +167,14 @@ module GeoRuby
167
167
  end
168
168
 
169
169
  #Creates a new line string. Accept an array of points as argument
170
- def self.from_points(points,srid=@@default_srid,with_z=false,with_m=false)
170
+ def self.from_points(points,srid=DEFAULT_SRID,with_z=false,with_m=false)
171
171
  line_string = new(srid,with_z,with_m)
172
172
  line_string.concat(points)
173
173
  line_string
174
174
  end
175
175
 
176
176
  #Creates a new line string. Accept a sequence of points as argument : ((x,y)...(x,y))
177
- def self.from_coordinates(points,srid=@@default_srid,with_z=false,with_m=false)
177
+ def self.from_coordinates(points,srid=DEFAULT_SRID,with_z=false,with_m=false)
178
178
  line_string = new(srid,with_z,with_m)
179
179
  line_string.concat( points.map {|p| Point.from_coordinates(p,srid,with_z,with_m) } )
180
180
  line_string
@@ -4,7 +4,7 @@ module GeoRuby
4
4
  module SimpleFeatures
5
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
- def initialize(srid= @@default_srid,with_z=false,with_m=false)
7
+ def initialize(srid= DEFAULT_SRID,with_z=false,with_m=false)
8
8
  super(srid,with_z,with_m)
9
9
  end
10
10
  end
@@ -1,10 +1,13 @@
1
1
  require 'geo_ruby/simple_features/geometry_collection'
2
2
 
3
3
  module GeoRuby
4
+
4
5
  module SimpleFeatures
6
+
5
7
  #Represents a group of line strings (see LineString).
6
8
  class MultiLineString < GeometryCollection
7
- def initialize(srid = @@default_srid,with_z=false,with_m=false)
9
+
10
+ def initialize(srid = DEFAULT_SRID,with_z=false,with_m=false)
8
11
  super(srid)
9
12
  end
10
13
 
@@ -12,24 +15,33 @@ module GeoRuby
12
15
  5
13
16
  end
14
17
 
18
+ def points
19
+ geometries.map(&:points).flatten
20
+ end
21
+
15
22
  #Text representation of a multi line string
16
23
  def text_representation(allow_z=true,allow_m=true) #:nodoc:
17
24
  @geometries.collect{|line_string| "(" + line_string.text_representation(allow_z,allow_m) + ")" }.join(",")
18
25
  end
26
+
19
27
  #WKT geometry type
20
28
  def text_geometry_type #:nodoc:
21
29
  "MULTILINESTRING"
22
30
  end
23
31
 
32
+ def to_line_string(join = true)
33
+ LineString.from_points(points)
34
+ end
35
+
24
36
  #Creates a new multi line string from an array of line strings
25
- def self.from_line_strings(line_strings,srid=@@default_srid,with_z=false,with_m=false)
37
+ def self.from_line_strings(line_strings,srid=DEFAULT_SRID,with_z=false,with_m=false)
26
38
  multi_line_string = new(srid,with_z,with_m)
27
39
  multi_line_string.concat(line_strings)
28
40
  multi_line_string
29
41
  end
30
42
 
31
43
  #Creates a new multi line string from sequences of points : (((x,y)...(x,y)),((x,y)...(x,y)))
32
- def self.from_coordinates(point_sequences,srid=@@default_srid,with_z=false,with_m=false)
44
+ def self.from_coordinates(point_sequences,srid=DEFAULT_SRID,with_z=false,with_m=false)
33
45
  multi_line_string = new(srid,with_z,with_m)
34
46
  multi_line_string.concat(point_sequences.collect {|points| LineString.from_coordinates(points,srid,with_z,with_m) })
35
47
  multi_line_string
@@ -5,7 +5,7 @@ module GeoRuby
5
5
  #Represents a group of points (see Point).
6
6
  class MultiPoint < GeometryCollection
7
7
 
8
- def initialize(srid= @@default_srid,with_z=false,with_m=false)
8
+ def initialize(srid= DEFAULT_SRID,with_z=false,with_m=false)
9
9
  super(srid,with_z,with_m)
10
10
  end
11
11
 
@@ -13,24 +13,29 @@ module GeoRuby
13
13
  4
14
14
  end
15
15
 
16
+ def points
17
+ @geometries
18
+ end
19
+
16
20
  #Text representation of a MultiPoint
17
21
  def text_representation(allow_z=true,allow_m=true) #:nodoc:
18
22
  "(" + @geometries.collect{|point| point.text_representation(allow_z,allow_m)}.join("),(") + ")"
19
23
  end
24
+
20
25
  #WKT geoemtry type
21
26
  def text_geometry_type #:nodoc:
22
27
  "MULTIPOINT"
23
28
  end
24
29
 
25
30
  #Creates a new multi point from an array of points
26
- def self.from_points(points,srid= @@default_srid,with_z=false,with_m=false)
31
+ def self.from_points(points,srid= DEFAULT_SRID,with_z=false,with_m=false)
27
32
  multi_point= new(srid,with_z,with_m)
28
33
  multi_point.concat(points)
29
34
  multi_point
30
35
  end
31
36
 
32
37
  #Creates a new multi point from a list of point coordinates : ((x,y)...(x,y))
33
- def self.from_coordinates(points,srid= @@default_srid,with_z=false,with_m=false)
38
+ def self.from_coordinates(points,srid= DEFAULT_SRID,with_z=false,with_m=false)
34
39
  multi_point= new(srid,with_z,with_m)
35
40
  multi_point.concat(points.collect {|point| Point.from_coordinates(point,srid,with_z,with_m)})
36
41
  multi_point
@@ -1,37 +1,52 @@
1
1
  require 'geo_ruby/simple_features/geometry_collection'
2
2
 
3
3
  module GeoRuby
4
+
4
5
  module SimpleFeatures
6
+
5
7
  #Represents a group of polygons (see Polygon).
6
- class MultiPolygon < GeometryCollection
7
- def initialize(srid = @@default_srid,with_z=false,with_m=false)
8
+ class MultiPolygon < GeometryCollection
9
+
10
+ def initialize(srid = DEFAULT_SRID,with_z=false,with_m=false)
8
11
  super(srid)
9
12
  end
10
13
 
11
14
  def binary_geometry_type #:nodoc:
12
15
  6
13
16
  end
17
+
18
+ def points
19
+ @points ||= geometries.inject([]) do |arr, r|
20
+ arr.concat(r.rings.map(&:points).flatten)
21
+ end
22
+ end
23
+
14
24
  #Text representation of a MultiPolygon
15
25
  def text_representation(allow_z=true,allow_m=true) #:nodoc:
16
- @geometries.collect{|polygon| "(" + polygon.text_representation(allow_z,allow_m) + ")"}.join(",")
26
+ @geometries.map {|polygon| "(" + polygon.text_representation(allow_z,allow_m) + ")"}.join(",")
17
27
  end
28
+
18
29
  #WKT geometry type
19
30
  def text_geometry_type #:nodoc:
20
31
  "MULTIPOLYGON"
21
32
  end
22
33
 
23
34
  #Creates a multi polygon from an array of polygons
24
- def self.from_polygons(polygons,srid=@@default_srid,with_z=false,with_m=false)
35
+ def self.from_polygons(polygons,srid=DEFAULT_SRID,with_z=false,with_m=false)
25
36
  multi_polygon = new(srid,with_z,with_m)
26
37
  multi_polygon.concat(polygons)
27
38
  multi_polygon
28
39
  end
40
+
29
41
  #Creates a multi polygon from sequences of points : ((((x,y)...(x,y)),((x,y)...(x,y)),((x,y)...(x,y)))
30
- def self.from_coordinates(point_sequence_sequences,srid= @@default_srid,with_z=false,with_m=false)
42
+ def self.from_coordinates(point_sequence_sequences,srid= DEFAULT_SRID,with_z=false,with_m=false)
31
43
  multi_polygon = new(srid,with_z,with_m)
32
44
  multi_polygon.concat( point_sequence_sequences.collect {|point_sequences| Polygon.from_coordinates(point_sequences,srid,with_z,with_m) } )
33
45
  multi_polygon
34
46
  end
47
+
35
48
  end
49
+
36
50
  end
51
+
37
52
  end
@@ -17,7 +17,7 @@ module GeoRuby
17
17
  alias :tet :t
18
18
  alias :tetha :t
19
19
 
20
- def initialize(srid=@@default_srid,with_z=false,with_m=false)
20
+ def initialize(srid=DEFAULT_SRID,with_z=false,with_m=false)
21
21
  super(srid,with_z,with_m)
22
22
  @x = @y = 0.0
23
23
  @z=0.0 #default value : meaningful if with_z
@@ -261,7 +261,7 @@ module GeoRuby
261
261
  end
262
262
 
263
263
  #creates a point from an array of coordinates
264
- def self.from_coordinates(coords,srid=@@default_srid,with_z=false,with_m=false)
264
+ def self.from_coordinates(coords,srid=DEFAULT_SRID,with_z=false,with_m=false)
265
265
  if ! (with_z or with_m)
266
266
  from_x_y(coords[0],coords[1],srid)
267
267
  elsif with_z and with_m
@@ -274,26 +274,26 @@ module GeoRuby
274
274
  end
275
275
 
276
276
  #creates a point from the X and Y coordinates
277
- def self.from_x_y(x,y,srid=@@default_srid)
277
+ def self.from_x_y(x,y,srid=DEFAULT_SRID)
278
278
  point= new(srid)
279
279
  point.set_x_y(x,y)
280
280
  end
281
281
 
282
282
  #creates a point from the X, Y and Z coordinates
283
- def self.from_x_y_z(x,y,z,srid=@@default_srid)
283
+ def self.from_x_y_z(x,y,z,srid=DEFAULT_SRID)
284
284
  point= new(srid,true)
285
285
  point.set_x_y_z(x,y,z)
286
286
  end
287
287
 
288
288
  #creates a point from the X, Y and M coordinates
289
- def self.from_x_y_m(x,y,m,srid=@@default_srid)
289
+ def self.from_x_y_m(x,y,m,srid=DEFAULT_SRID)
290
290
  point= new(srid,false,true)
291
291
  point.m=m
292
292
  point.set_x_y(x,y)
293
293
  end
294
294
 
295
295
  #creates a point from the X, Y, Z and M coordinates
296
- def self.from_x_y_z_m(x,y,z,m,srid=@@default_srid)
296
+ def self.from_x_y_z_m(x,y,z,m,srid=DEFAULT_SRID)
297
297
  point= new(srid,true,true)
298
298
  point.m=m
299
299
  point.set_x_y_z(x,y,z)
@@ -301,7 +301,7 @@ module GeoRuby
301
301
 
302
302
  #creates a point using polar coordinates
303
303
  #r and theta(degrees)
304
- def self.from_r_t(r,t,srid=@@default_srid)
304
+ def self.from_r_t(r,t,srid=DEFAULT_SRID)
305
305
  t *= DEG2RAD
306
306
  x = r * Math.cos(t)
307
307
  y = r * Math.sin(t)
@@ -310,7 +310,7 @@ module GeoRuby
310
310
  end
311
311
 
312
312
  #creates a point using coordinates like 22`34 23.45N
313
- def self.from_latlong(lat,lon,srid=@@default_srid)
313
+ def self.from_latlong(lat,lon,srid=DEFAULT_SRID)
314
314
  p = [lat,lon].map do |l|
315
315
  sig, deg, min, sec, cen = l.scan(/(-)?(\d{1,2})\D*(\d{2})\D*(\d{2})(\D*(\d{1,3}))?/).flatten
316
316
  sig = true if l =~ /W|S/
@@ -1,13 +1,15 @@
1
1
  require 'geo_ruby/simple_features/geometry'
2
2
 
3
3
  module GeoRuby
4
+
4
5
  module SimpleFeatures
6
+
5
7
  #Represents a polygon as an array of linear rings (see LinearRing). No check is performed regarding the validity of the geometries forming the polygon.
6
8
  class Polygon < Geometry
7
9
  #the list of rings forming the polygon
8
10
  attr_reader :rings
9
11
 
10
- def initialize(srid = @@default_srid,with_z=false,with_m=false)
12
+ def initialize(srid = DEFAULT_SRID,with_z=false,with_m=false)
11
13
  super(srid,with_z,with_m)
12
14
  @rings = []
13
15
  end
@@ -64,12 +66,14 @@ module GeoRuby
64
66
  true
65
67
  end
66
68
  end
69
+
67
70
  #binary representation of a polygon, without the headers neccessary for a valid WKB string
68
71
  def binary_representation(allow_z=true,allow_m=true)
69
72
  rep = [length].pack("V")
70
73
  each {|linear_ring| rep << linear_ring.binary_representation(allow_z,allow_m)}
71
74
  rep
72
75
  end
76
+
73
77
  #WKB geometry type
74
78
  def binary_geometry_type
75
79
  3
@@ -79,6 +83,7 @@ module GeoRuby
79
83
  def text_representation(allow_z=true,allow_m=true)
80
84
  @rings.collect{|line_string| "(" + line_string.text_representation(allow_z,allow_m) + ")" }.join(",")
81
85
  end
86
+
82
87
  #WKT geometry type
83
88
  def text_geometry_type
84
89
  "POLYGON"
@@ -90,6 +95,7 @@ module GeoRuby
90
95
  geom_attr = options[:geom_attr]
91
96
  "<#{georss_ns}:polygon#{geom_attr}>" + self[0].georss_poslist + "</#{georss_ns}:polygon>\n"
92
97
  end
98
+
93
99
  #georss w3c representation : outputs the first point of the outer ring
94
100
  def georss_w3cgeo_representation(options)
95
101
  w3cgeo_ns = options[:w3cgeo_ns] || "geo"
@@ -124,27 +130,28 @@ module GeoRuby
124
130
  end
125
131
 
126
132
  #creates a new polygon. Accepts an array of linear strings as argument
127
- def self.from_linear_rings(linear_rings,srid = @@default_srid,with_z=false,with_m=false)
133
+ def self.from_linear_rings(linear_rings,srid = DEFAULT_SRID,with_z=false,with_m=false)
128
134
  polygon = new(srid,with_z,with_m)
129
135
  polygon.concat(linear_rings)
130
136
  polygon
131
137
  end
132
138
 
133
139
  #creates a new polygon. Accepts a sequence of points as argument : ((x,y)....(x,y)),((x,y).....(x,y))
134
- def self.from_coordinates(point_sequences,srid=@@default_srid,with_z=false,with_m=false)
140
+ def self.from_coordinates(point_sequences,srid=DEFAULT_SRID,with_z=false,with_m=false)
135
141
  polygon = new(srid,with_z,with_m)
136
- polygon.concat( point_sequences.collect {|points| LinearRing.from_coordinates(points,srid,with_z,with_m) } )
142
+ polygon.concat( point_sequences.map {|points| LinearRing.from_coordinates(points,srid,with_z,with_m) } )
137
143
  polygon
138
144
  end
139
145
 
140
146
  #creates a new polygon from a list of Points (pt1....ptn),(pti....ptj)
141
- def self.from_points(point_sequences, srid=@@default_srid,with_z=false,with_m=false)
147
+ def self.from_points(point_sequences, srid=DEFAULT_SRID,with_z=false,with_m=false)
142
148
  polygon = new(srid,with_z,with_m)
143
- polygon.concat( point_sequences.collect {|points| LinearRing.from_points(points,srid,with_z,with_m) } )
149
+ polygon.concat( point_sequences.map {|points| LinearRing.from_points(points,srid,with_z,with_m) } )
144
150
  polygon
145
-
146
151
  end
147
152
 
148
153
  end
154
+
149
155
  end
156
+
150
157
  end
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{georuby}
8
- s.version = "1.6.2"
7
+ s.name = %q{nofxx-georuby}
8
+ s.version = "1.7.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Guilhem Vellut", "Marcos Augusto"]
12
- s.date = %q{2009-08-16}
12
+ s.date = %q{2010-01-28}
13
13
  s.description = %q{GeoRuby provides geometric data types from the OGC 'Simple Features' specification.}
14
14
  s.email = %q{x@nofxx.com}
15
15
  s.extra_rdoc_files = [
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
23
23
  "README.txt",
24
24
  "Rakefile",
25
25
  "VERSION",
26
- "georuby.gemspec",
27
26
  "lib/geo_ruby.rb",
28
27
  "lib/geo_ruby/gpx.rb",
29
28
  "lib/geo_ruby/gpx4r/gpx.rb",
@@ -45,6 +44,7 @@ Gem::Specification.new do |s|
45
44
  "lib/geo_ruby/simple_features/multi_polygon.rb",
46
45
  "lib/geo_ruby/simple_features/point.rb",
47
46
  "lib/geo_ruby/simple_features/polygon.rb",
47
+ "nofxx-georuby.gemspec",
48
48
  "script/console",
49
49
  "script/destroy",
50
50
  "script/generate",
@@ -94,24 +94,24 @@ Gem::Specification.new do |s|
94
94
  s.rubygems_version = %q{1.3.5}
95
95
  s.summary = %q{Ruby data holder for OGC Simple Features}
96
96
  s.test_files = [
97
- "spec/geo_ruby_spec.rb",
98
- "spec/spec_helper.rb",
99
- "spec/geo_ruby/gpx4r/gpx_spec.rb",
97
+ "spec/geo_ruby/gpx4r/gpx_spec.rb",
100
98
  "spec/geo_ruby/shp4r/shp_spec.rb",
101
- "spec/geo_ruby/simple_features/point_spec.rb",
102
- "spec/geo_ruby/simple_features/geometry_factory_spec.rb",
103
99
  "spec/geo_ruby/simple_features/envelope_spec.rb",
104
- "spec/geo_ruby/simple_features/polygon_spec.rb",
105
- "spec/geo_ruby/simple_features/line_string_spec.rb",
106
- "spec/geo_ruby/simple_features/multi_line_string_spec.rb",
107
- "spec/geo_ruby/simple_features/ewkt_parser_spec.rb",
108
100
  "spec/geo_ruby/simple_features/ewkb_parser_spec.rb",
109
- "spec/geo_ruby/simple_features/linear_ring_spec.rb",
101
+ "spec/geo_ruby/simple_features/ewkt_parser_spec.rb",
110
102
  "spec/geo_ruby/simple_features/geometry_collection_spec.rb",
111
- "spec/geo_ruby/simple_features/multi_polygon_spec.rb",
112
- "spec/geo_ruby/simple_features/multi_point_spec.rb",
103
+ "spec/geo_ruby/simple_features/geometry_factory_spec.rb",
104
+ "spec/geo_ruby/simple_features/geometry_spec.rb",
113
105
  "spec/geo_ruby/simple_features/georss_parser_spec.rb",
114
- "spec/geo_ruby/simple_features/geometry_spec.rb"
106
+ "spec/geo_ruby/simple_features/line_string_spec.rb",
107
+ "spec/geo_ruby/simple_features/linear_ring_spec.rb",
108
+ "spec/geo_ruby/simple_features/multi_line_string_spec.rb",
109
+ "spec/geo_ruby/simple_features/multi_point_spec.rb",
110
+ "spec/geo_ruby/simple_features/multi_polygon_spec.rb",
111
+ "spec/geo_ruby/simple_features/point_spec.rb",
112
+ "spec/geo_ruby/simple_features/polygon_spec.rb",
113
+ "spec/geo_ruby_spec.rb",
114
+ "spec/spec_helper.rb"
115
115
  ]
116
116
 
117
117
  if s.respond_to? :specification_version then
@@ -124,3 +124,4 @@ Gem::Specification.new do |s|
124
124
  else
125
125
  end
126
126
  end
127
+
@@ -72,14 +72,6 @@ describe Gpx4r do
72
72
  @gpxfile3.as_polyline.should be_instance_of LineString
73
73
  end
74
74
 
75
- it "should return it as a polygon" do
76
- @gpxfile.as_polygon.should be_instance_of Polygon
77
- end
78
-
79
- it "should return it as a polygon 3" do
80
- @gpxfile3.as_polygon.should be_instance_of Polygon
81
- end
82
-
83
75
  it "should return a envelope" do
84
76
  @gpxfile.envelope.should be_instance_of Envelope
85
77
  @gpxfile.envelope.lower_corner.x.should be_close(9.08128, 0.001)
@@ -92,6 +84,15 @@ describe Gpx4r do
92
84
  @gpxfile3.envelope.lower_corner.y.should be_close(-17.547636, 0.001)
93
85
  end
94
86
 
87
+ it "should return it as a polygon" do
88
+ [@gpxfile, @gpxfile2, @gpxfile3].each do |g|
89
+ g.as_polygon.should be_instance_of Polygon
90
+ g.as_polygon[0].should be_instance_of LinearRing
91
+ g.as_polygon[0].should be_closed
92
+ g.as_polygon[1].should be_nil
93
+ end
94
+ end
95
+
95
96
  it "should close the polygon" do
96
97
  se = Point.from_x_y(-44, -23)
97
98
  sw = Point.from_x_y(-42, -22)
@@ -23,7 +23,7 @@ describe Shp4r do
23
23
  end
24
24
 
25
25
  it "should parse record 1" do
26
- rec = @shpfile.first
26
+ rec = @shpfile[0]
27
27
  rec.geometry.should be_kind_of Point
28
28
  rec.geometry.x.should be_close(-90.08375, 0.00001)
29
29
  rec.geometry.y.should be_close(34.39996, 0.00001)
@@ -60,7 +60,7 @@ describe Shp4r do
60
60
  end
61
61
 
62
62
  it "should parse record 1" do
63
- rec = @shpfile.first
63
+ rec = @shpfile[0]
64
64
  rec.geometry.should be_kind_of MultiLineString
65
65
  rec.geometry.length.should eql(1)
66
66
  rec.geometry[0].length.should eql(6)
@@ -87,7 +87,7 @@ describe Shp4r do
87
87
  end
88
88
 
89
89
  it "should parse record 1" do
90
- rec = @shpfile.first
90
+ rec = @shpfile[0]
91
91
  rec.geometry.should be_kind_of MultiPolygon
92
92
  rec.geometry.length.should eql(1)
93
93
  rec.geometry[0].length.should eql(1)
@@ -4,12 +4,12 @@ describe MultiLineString do
4
4
 
5
5
  it "test_multi_line_string_creation" do
6
6
  multi_line_string1 = MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256)
7
- multi_line_string1.should be_instance_of MultiLineString
7
+ multi_line_string1.should be_instance_of(MultiLineString)
8
8
  multi_line_string1.length.should eql(2)
9
9
  multi_line_string1[0].should == LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256)
10
10
 
11
11
  multi_line_string2= MultiLineString.from_coordinates([[[1.5,45.2],[-54.12312,-0.012]],[[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]]],256);
12
- multi_line_string1.should be_instance_of MultiLineString
12
+ multi_line_string1.should be_instance_of(MultiLineString)
13
13
  multi_line_string1.length.should eql(2)
14
14
  multi_line_string2[0].should == LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256)
15
15
 
@@ -32,4 +32,23 @@ describe MultiLineString do
32
32
  multi_line_string.as_ewkt.should eql("SRID=256;MULTILINESTRING((1.5 45.2 1.3 1.2,-54.12312 -0.012 1.2 4.5),(1.5 45.2 5.1 -4.5,-54.12312 -0.012 -6.8 3.4,45.123 123.3 4.5 -5.3))")
33
33
  end
34
34
 
35
+ describe "Some More" do
36
+ before do
37
+ @mls = MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256)
38
+ end
39
+
40
+ it "should have a accessor to all points" do
41
+ @mls.points.should be_instance_of(Array)
42
+ end
43
+
44
+ it "should flatten the array" do
45
+ @mls.should have(5).points
46
+ end
47
+
48
+ it "should simplify to linestring" do
49
+ ls = @mls.to_line_string
50
+ ls.should be_instance_of(LineString)
51
+ ls.should have(5).points
52
+ end
53
+ end
35
54
  end
@@ -4,7 +4,7 @@ describe MultiPoint do
4
4
 
5
5
  it "test_multi_point_creation" do
6
6
  multi_point = MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444)
7
- multi_point.should be_instance_of MultiPoint
7
+ multi_point.should be_instance_of(MultiPoint)
8
8
  multi_point.length.should eql(3)
9
9
  multi_point[0].should == Point.from_x_y(12.4,-123.3,444)
10
10
  multi_point[2].should == Point.from_x_y(123.55555555,123,444)
@@ -26,4 +26,10 @@ describe MultiPoint do
26
26
  multi_point.as_ewkt.should eql("SRID=444;MULTIPOINT((12.4 -123.3 4.5),(-65.1 123.4 6.7),(123.55555555 123 7.8))")
27
27
  end
28
28
 
29
+ it "should respond to points" do
30
+ mp = MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444)
31
+ mp.should have(3).geometries
32
+ mp.should have(3).points
33
+ end
34
+
29
35
  end
@@ -4,12 +4,12 @@ describe MultiPolygon do
4
4
 
5
5
  it "test_multi_polygon_creation" do
6
6
  multi_polygon1 = 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]]],256),Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256)
7
- multi_polygon1.should be_instance_of MultiPolygon
7
+ multi_polygon1.should be_instance_of(MultiPolygon)
8
8
  multi_polygon1.length.should eql(2)
9
9
  multi_polygon1[0].should == 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]]],256)
10
10
 
11
11
  multi_polygon2 = MultiPolygon.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]]],[[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]]],256)
12
- multi_polygon1.should be_instance_of MultiPolygon
12
+ multi_polygon1.should be_instance_of(MultiPolygon)
13
13
  multi_polygon1.length.should eql(2)
14
14
 
15
15
  multi_polygon2[0].should == 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]]],256)
@@ -32,4 +32,19 @@ describe MultiPolygon do
32
32
  multi_polygon.as_ewkt.should eql("SRID=4326;MULTIPOLYGON(((12.4 -45.3 2,45.4 41.6 3,4.456 1.0698 4,12.4 -45.3 2),(2.4 5.3 1,5.4 1.4263 3.44,14.46 1.06 4.5,2.4 5.3 1)),((0 0 5.6,4 0 5.4,4 4 1,0 4 23,0 0 5.6),(1 1 2.3,3 1 4,3 3 5,1 3 6,1 1 2.3)))")
33
33
  end
34
34
 
35
+ describe "Counting" do
36
+
37
+ before do
38
+ @mp = 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]]],256),Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256)
39
+ end
40
+
41
+ it "should have a points method" do
42
+ @mp.points[0].should be_instance_of(Point)
43
+ end
44
+
45
+ it "should flatten it right" do
46
+ @mp.should have(18).points
47
+ end
48
+
49
+ end
35
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nofxx-georuby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilhem Vellut
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-08-16 00:00:00 -07:00
13
+ date: 2010-01-28 00:00:00 -02:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -30,7 +30,6 @@ files:
30
30
  - README.txt
31
31
  - Rakefile
32
32
  - VERSION
33
- - georuby.gemspec
34
33
  - lib/geo_ruby.rb
35
34
  - lib/geo_ruby/gpx.rb
36
35
  - lib/geo_ruby/gpx4r/gpx.rb
@@ -52,6 +51,7 @@ files:
52
51
  - lib/geo_ruby/simple_features/multi_polygon.rb
53
52
  - lib/geo_ruby/simple_features/point.rb
54
53
  - lib/geo_ruby/simple_features/polygon.rb
54
+ - nofxx-georuby.gemspec
55
55
  - script/console
56
56
  - script/destroy
57
57
  - script/generate
@@ -94,9 +94,10 @@ files:
94
94
  - spec/geo_ruby_spec.rb
95
95
  - spec/spec.opts
96
96
  - spec/spec_helper.rb
97
- has_rdoc: false
97
+ has_rdoc: true
98
98
  homepage: http://github.com/nofxx/georuby
99
- licenses:
99
+ licenses: []
100
+
100
101
  post_install_message:
101
102
  rdoc_options:
102
103
  - --charset=UTF-8
@@ -122,21 +123,21 @@ signing_key:
122
123
  specification_version: 3
123
124
  summary: Ruby data holder for OGC Simple Features
124
125
  test_files:
125
- - spec/geo_ruby_spec.rb
126
- - spec/spec_helper.rb
127
126
  - spec/geo_ruby/gpx4r/gpx_spec.rb
128
127
  - spec/geo_ruby/shp4r/shp_spec.rb
129
- - spec/geo_ruby/simple_features/point_spec.rb
130
- - spec/geo_ruby/simple_features/geometry_factory_spec.rb
131
128
  - spec/geo_ruby/simple_features/envelope_spec.rb
132
- - spec/geo_ruby/simple_features/polygon_spec.rb
133
- - spec/geo_ruby/simple_features/line_string_spec.rb
134
- - spec/geo_ruby/simple_features/multi_line_string_spec.rb
135
- - spec/geo_ruby/simple_features/ewkt_parser_spec.rb
136
129
  - spec/geo_ruby/simple_features/ewkb_parser_spec.rb
137
- - spec/geo_ruby/simple_features/linear_ring_spec.rb
130
+ - spec/geo_ruby/simple_features/ewkt_parser_spec.rb
138
131
  - spec/geo_ruby/simple_features/geometry_collection_spec.rb
139
- - spec/geo_ruby/simple_features/multi_polygon_spec.rb
140
- - spec/geo_ruby/simple_features/multi_point_spec.rb
141
- - spec/geo_ruby/simple_features/georss_parser_spec.rb
132
+ - spec/geo_ruby/simple_features/geometry_factory_spec.rb
142
133
  - spec/geo_ruby/simple_features/geometry_spec.rb
134
+ - spec/geo_ruby/simple_features/georss_parser_spec.rb
135
+ - spec/geo_ruby/simple_features/line_string_spec.rb
136
+ - spec/geo_ruby/simple_features/linear_ring_spec.rb
137
+ - spec/geo_ruby/simple_features/multi_line_string_spec.rb
138
+ - spec/geo_ruby/simple_features/multi_point_spec.rb
139
+ - spec/geo_ruby/simple_features/multi_polygon_spec.rb
140
+ - spec/geo_ruby/simple_features/point_spec.rb
141
+ - spec/geo_ruby/simple_features/polygon_spec.rb
142
+ - spec/geo_ruby_spec.rb
143
+ - spec/spec_helper.rb