rgeo 0.3.12 → 0.3.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ === 0.3.13 / 2012-05-04
2
+
3
+ * The spherical factory and the simple cartesian factory now support buffers around points (but not around other types). Accordingly, those factories now take the :buffer_resolution property argument.
4
+ * The :uses_lenient_assertions and parser/generator arguments to RGeo::Geographic.spherical_factory did not have their advertised effect. Fixed.
5
+ * The parser/generator arguments to projected geographic factories did not have their advertised effect. Fixed.
6
+
1
7
  === 0.3.12 / 2012-04-24
2
8
 
3
9
  * Geos::FFIFactory collection constructors sometimes modified arguments in place, which caused problems for the ZMFactory among other things. Fixed.
data/Version CHANGED
@@ -1 +1 @@
1
- 0.3.12
1
+ 0.3.13
@@ -71,7 +71,7 @@ else
71
71
  header_dirs_, lib_dirs_ = dir_config('geos', header_dirs_, lib_dirs_)
72
72
  if have_header('geos_c.h')
73
73
  $libs << ' -lgeos -lgeos_c'
74
- if have_func('initGEOS_r', 'geos_c.h')
74
+ if have_func('GEOSSetSRID_r', 'geos_c.h')
75
75
  found_geos_ = true
76
76
  else
77
77
  $libs.gsub!(' -lgeos -lgeos_c', '')
@@ -36,7 +36,7 @@
36
36
 
37
37
 
38
38
  #ifdef HAVE_GEOS_C_H
39
- #ifdef HAVE_INITGEOS_R
39
+ #ifdef HAVE_GEOSSETSRID_R
40
40
  #define RGEO_GEOS_SUPPORTED
41
41
  #endif
42
42
  #endif
@@ -77,6 +77,8 @@ module RGeo
77
77
  srid_ ||= @coord_sys.authority_code if @coord_sys
78
78
  @srid = srid_.to_i
79
79
  @lenient_assertions = opts_[:uses_lenient_assertions] ? true : false
80
+ @buffer_resolution = opts_[:buffer_resolution].to_i
81
+ @buffer_resolution = 1 if @buffer_resolution < 1
80
82
 
81
83
  wkt_generator_ = opts_[:wkt_generator]
82
84
  case wkt_generator_
@@ -129,6 +131,7 @@ module RGeo
129
131
  'wktp' => @wkt_parser._properties,
130
132
  'wkbp' => @wkb_parser._properties,
131
133
  'lena' => @lenient_assertions,
134
+ 'bufr' => @buffer_resolution,
132
135
  }
133
136
  hash_['proj4'] = @proj4.marshal_dump if @proj4
134
137
  hash_['cs'] = @coord_sys.to_wkt if @coord_sys
@@ -156,6 +159,7 @@ module RGeo
156
159
  :wkt_parser => ImplHelper::Utils.symbolize_hash(data_['wktp']),
157
160
  :wkb_parser => ImplHelper::Utils.symbolize_hash(data_['wkbp']),
158
161
  :uses_lenient_assertions => data_['lena'],
162
+ :buffer_resolution => data_['bufr'],
159
163
  :proj4 => proj4_,
160
164
  :coord_sys => coord_sys_
161
165
  )
@@ -169,6 +173,7 @@ module RGeo
169
173
  coder_['has_m_coordinate'] = @has_m
170
174
  coder_['srid'] = @srid
171
175
  coder_['lenient_assertions'] = @lenient_assertions
176
+ coder_['buffer_resolution'] = @buffer_resolution
172
177
  coder_['wkt_generator'] = @wkt_generator._properties
173
178
  coder_['wkb_generator'] = @wkb_generator._properties
174
179
  coder_['wkt_parser'] = @wkt_parser._properties
@@ -204,6 +209,7 @@ module RGeo
204
209
  :wkt_parser => ImplHelper::Utils.symbolize_hash(coder_['wkt_parser']),
205
210
  :wkb_parser => ImplHelper::Utils.symbolize_hash(coder_['wkb_parser']),
206
211
  :uses_lenient_assertions => coder_['lenient_assertions'],
212
+ :buffer_resolution => coder_['buffer_resolution'],
207
213
  :proj4 => proj4_,
208
214
  :coord_sys => coord_sys_
209
215
  )
@@ -227,6 +233,8 @@ module RGeo
227
233
  @has_m
228
234
  when :uses_lenient_assertions
229
235
  @lenient_assertions
236
+ when :buffer_resolution
237
+ @buffer_resolution
230
238
  when :is_cartesian
231
239
  true
232
240
  else
@@ -71,6 +71,17 @@ module RGeo
71
71
  end
72
72
 
73
73
 
74
+ def buffer(distance_)
75
+ point_count_ = factory.property(:buffer_resolution) * 4
76
+ angle_ = -::Math::PI * 2.0 / point_count_
77
+ points_ = (0...point_count_).map do |i_|
78
+ r_ = angle_ * i_
79
+ factory.point(@x + distance_ * ::Math.cos(r_), @y + distance_ * ::Math.sin(r_))
80
+ end
81
+ factory.polygon(factory.linear_ring(points_))
82
+ end
83
+
84
+
74
85
  end
75
86
 
76
87
 
@@ -75,6 +75,8 @@ module RGeo
75
75
  @coord_sys = CoordSys::CS.create_from_wkt(@coord_sys) rescue nil
76
76
  end
77
77
  @lenient_assertions = opts_[:uses_lenient_assertions] ? true : false
78
+ @buffer_resolution = opts_[:buffer_resolution].to_i
79
+ @buffer_resolution = 1 if @buffer_resolution < 1
78
80
 
79
81
  wkt_generator_ = opts_[:wkt_generator]
80
82
  case wkt_generator_
@@ -138,6 +140,7 @@ module RGeo
138
140
  'wktp' => @wkt_parser._properties,
139
141
  'wkbp' => @wkb_parser._properties,
140
142
  'lena' => @lenient_assertions,
143
+ 'bufr' => @buffer_resolution,
141
144
  }
142
145
  hash_['proj4'] = @proj4.marshal_dump if @proj4
143
146
  hash_['cs'] = @coord_sys.to_wkt if @coord_sys
@@ -169,6 +172,7 @@ module RGeo
169
172
  :wkt_parser => ImplHelper::Utils.symbolize_hash(data_['wktp']),
170
173
  :wkb_parser => ImplHelper::Utils.symbolize_hash(data_['wkbp']),
171
174
  :uses_lenient_assertions => data_['lena'],
175
+ :buffer_resolution => data_['bufr'],
172
176
  :proj4 => proj4_,
173
177
  :coord_sys => coord_sys_
174
178
  )
@@ -195,6 +199,7 @@ module RGeo
195
199
  coder_['wkt_parser'] = @wkt_parser._properties
196
200
  coder_['wkb_parser'] = @wkb_parser._properties
197
201
  coder_['lenient_assertions'] = @lenient_assertions
202
+ coder_['buffer_resolution'] = @buffer_resolution
198
203
  if @proj4
199
204
  str_ = @proj4.original_str || @proj4.canonical_str
200
205
  coder_['proj4'] = @proj4.radians? ? {'proj4' => str_, 'radians' => true} : str_
@@ -230,6 +235,7 @@ module RGeo
230
235
  :wkt_parser => ImplHelper::Utils.symbolize_hash(coder_['wkt_parser']),
231
236
  :wkb_parser => ImplHelper::Utils.symbolize_hash(coder_['wkb_parser']),
232
237
  :uses_lenient_assertions => coder_['lenient_assertions'],
238
+ :buffer_resolution => coder_['buffer_resolution'],
233
239
  :proj4 => proj4_,
234
240
  :coord_sys => coord_sys_
235
241
  )
@@ -334,6 +340,8 @@ module RGeo
334
340
  @support_m
335
341
  when :uses_lenient_assertions
336
342
  @lenient_assertions
343
+ when :buffer_resolution
344
+ @buffer_resolution
337
345
  when :is_geographic
338
346
  true
339
347
  else
@@ -92,6 +92,16 @@ module RGeo
92
92
  # Polygon and MultiPolygon. This may speed up creation of certain
93
93
  # objects, at the expense of not doing the proper checking for
94
94
  # OGC compliance. Default is false.
95
+ # [<tt>:buffer_resolution</tt>]
96
+ # The resolution of buffers around geometries created by this
97
+ # factory. This controls the number of line segments used to
98
+ # approximate curves. The default is 1, which causes, for
99
+ # example, the buffer around a point to be approximated by a
100
+ # 4-sided polygon. A resolution of 2 would cause that buffer
101
+ # to be approximated by an 8-sided polygon. The exact behavior
102
+ # for different kinds of buffers is not specified precisely,
103
+ # but in general the value is taken as the number of segments
104
+ # per 90-degree curve.
95
105
  # [<tt>:proj4</tt>]
96
106
  # Provide the coordinate system in Proj4 format. You may pass
97
107
  # either an RGeo::CoordSys::Proj4 object, or a string or hash
@@ -153,6 +163,12 @@ module RGeo
153
163
  :has_m_coordinate => opts_[:has_m_coordinate],
154
164
  :proj4 => proj4_ || _proj4_4055,
155
165
  :coord_sys => coord_sys_ || _coordsys_4055,
166
+ :uses_lenient_assertions => opts_[:uses_lenient_assertions],
167
+ :buffer_resolution => opts_[:buffer_resolution],
168
+ :wkt_parser => opts_[:wkt_parser],
169
+ :wkb_parser => opts_[:wkb_parser],
170
+ :wkt_generator => opts_[:wkt_generator],
171
+ :wkb_generator => opts_[:wkb_generator],
156
172
  :srid => (srid_ || 4055).to_i)
157
173
  end
158
174
 
@@ -234,6 +250,10 @@ module RGeo
234
250
  :proj4 => _proj4_4326,
235
251
  :coord_sys => _coordsys_4326,
236
252
  :srid => 4326,
253
+ :wkt_parser => opts_[:wkt_parser],
254
+ :wkb_parser => opts_[:wkb_parser],
255
+ :wkt_generator => opts_[:wkt_generator],
256
+ :wkb_generator => opts_[:wkb_generator],
237
257
  :has_z_coordinate => opts_[:has_z_coordinate],
238
258
  :has_m_coordinate => opts_[:has_m_coordinate])
239
259
  projector_ = Geographic::SimpleMercatorProjector.new(factory_,
@@ -96,6 +96,26 @@ module RGeo
96
96
  end
97
97
 
98
98
 
99
+ def buffer(distance_)
100
+ radius_ = distance_ / SphericalMath::RADIUS
101
+ radius_ = 1.5 if radius_ > 1.5
102
+ cos_ = ::Math.cos(radius_)
103
+ sin_ = ::Math.sin(radius_)
104
+ point_count_ = factory.property(:buffer_resolution) * 4
105
+ p0_ = _xyz
106
+ p1_ = p0_.create_perpendicular
107
+ p2_ = p1_ % p0_
108
+ angle_ = ::Math::PI * 2.0 / point_count_
109
+ points_ = (0...point_count_).map do |i_|
110
+ r_ = angle_ * i_
111
+ pi_ = SphericalMath::PointXYZ.weighted_combination(p1_, ::Math.cos(r_), p2_, ::Math.sin(r_))
112
+ p_ = SphericalMath::PointXYZ.weighted_combination(p0_, cos_, pi_, sin_)
113
+ factory.point(*p_.lonlat)
114
+ end
115
+ factory.polygon(factory.linear_ring(points_))
116
+ end
117
+
118
+
99
119
  alias_method :longitude, :x
100
120
  alias_method :lon, :x
101
121
  alias_method :latitude, :y
@@ -90,6 +90,14 @@ module RGeo
90
90
  end
91
91
 
92
92
 
93
+ def lonlat
94
+ lat_rad_ = ::Math.asin(@z)
95
+ lon_rad_ = ::Math.atan2(@y, @x) rescue 0.0
96
+ rpd_ = ImplHelper::Math::RADIANS_PER_DEGREE
97
+ [lon_rad_ / rpd_, lat_rad_ / rpd_]
98
+ end
99
+
100
+
93
101
  def *(rhs_)
94
102
  val_ = @x * rhs_.x + @y * rhs_.y + @z * rhs_.z
95
103
  val_ = 1.0 if val_ > 1.0
@@ -119,6 +127,17 @@ module RGeo
119
127
  end
120
128
 
121
129
 
130
+ # Creates some point that is perpendicular to this point
131
+
132
+ def create_perpendicular
133
+ p1dot_ = self * P1
134
+ p2dot_ = self * P2
135
+ p1dot_ = -p1dot_ if p1dot_ < 0
136
+ p2dot_ = -p2dot_ if p2dot_ < 0
137
+ p1dot_ < p2dot_ ? (self % P1) : (self % P2)
138
+ end
139
+
140
+
122
141
  def self.from_latlon(lat_, lon_)
123
142
  rpd_ = ImplHelper::Math::RADIANS_PER_DEGREE
124
143
  lat_rad_ = rpd_ * lat_
@@ -130,6 +149,15 @@ module RGeo
130
149
  new(x_, y_, z_)
131
150
  end
132
151
 
152
+
153
+ def self.weighted_combination(p1_, w1_, p2_, w2_)
154
+ new(p1_.x * w1_ + p2_.x * w2_, p1_.y * w1_ + p2_.y * w2_, p1_.z * w1_ + p2_.z * w2_)
155
+ end
156
+
157
+
158
+ P1 = new(1, 0, 0)
159
+ P2 = new(0, 1, 0)
160
+
133
161
  end
134
162
 
135
163
 
@@ -286,6 +286,7 @@ module RGeo
286
286
  point_ = @factory.point(11, 12)
287
287
  buffer_ = point_.buffer(4)
288
288
  assert_equal(::RGeo::Feature::Polygon, buffer_.geometry_type)
289
+ assert_equal(33, buffer_.exterior_ring.num_points)
289
290
  end
290
291
 
291
292
 
@@ -48,7 +48,7 @@ module RGeo
48
48
 
49
49
 
50
50
  def setup
51
- @factory = ::RGeo::Geos.factory
51
+ @factory = ::RGeo::Geos.factory(:buffer_resolution => 8)
52
52
  @zfactory = ::RGeo::Geos.factory(:has_z_coordinate => true)
53
53
  @mfactory = ::RGeo::Geos.factory(:has_m_coordinate => true)
54
54
  @zmfactory = ::RGeo::Geos.factory(:has_z_coordinate => true, :has_m_coordinate => true)
@@ -48,7 +48,7 @@ module RGeo
48
48
 
49
49
 
50
50
  def setup
51
- @factory = ::RGeo::Geos.factory(:native_interface => :ffi)
51
+ @factory = ::RGeo::Geos.factory(:native_interface => :ffi, :buffer_resolution => 8)
52
52
  @zfactory = ::RGeo::Geos.factory(:has_z_coordinate => true, :native_interface => :ffi)
53
53
  @mfactory = ::RGeo::Geos.factory(:has_m_coordinate => true, :native_interface => :ffi)
54
54
  @zmfactory = ::RGeo::Geos.factory(:has_z_coordinate => true, :has_m_coordinate => true,
@@ -48,7 +48,7 @@ module RGeo
48
48
 
49
49
 
50
50
  def setup
51
- @factory = ::RGeo::Geographic.projected_factory(:projection_proj4 => '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs', :projection_srid => 3857)
51
+ @factory = ::RGeo::Geographic.projected_factory(:buffer_resolution => 8, :projection_proj4 => '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs', :projection_srid => 3857)
52
52
  @zfactory = ::RGeo::Geographic.projected_factory(:has_z_coordinate => true, :projection_proj4 => '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs', :projection_srid => 3857)
53
53
  @mfactory = ::RGeo::Geographic.projected_factory(:has_m_coordinate => true, :projection_proj4 => '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs', :projection_srid => 3857)
54
54
  @zmfactory = ::RGeo::Geographic.projected_factory(:has_z_coordinate => true, :has_m_coordinate => true, :projection_proj4 => '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs', :projection_srid => 3857)
@@ -48,7 +48,7 @@ module RGeo
48
48
 
49
49
 
50
50
  def setup
51
- @factory = ::RGeo::Cartesian.simple_factory(:srid => 1)
51
+ @factory = ::RGeo::Cartesian.simple_factory(:srid => 1, :buffer_resolution => 8)
52
52
  @zfactory = ::RGeo::Cartesian.simple_factory(:srid => 1, :has_z_coordinate => true)
53
53
  @mfactory = ::RGeo::Cartesian.simple_factory(:srid => 1, :has_m_coordinate => true)
54
54
  @zmfactory = ::RGeo::Cartesian.simple_factory(:srid => 1, :has_z_coordinate => true, :has_m_coordinate => true)
@@ -82,7 +82,6 @@ module RGeo
82
82
  undef_method :test_union
83
83
  undef_method :test_difference
84
84
  undef_method :test_sym_difference
85
- undef_method :test_buffer
86
85
 
87
86
 
88
87
  end
@@ -48,7 +48,7 @@ module RGeo
48
48
 
49
49
 
50
50
  def setup
51
- @factory = ::RGeo::Geographic.simple_mercator_factory
51
+ @factory = ::RGeo::Geographic.simple_mercator_factory(:buffer_resolution => 8)
52
52
  @zfactory = ::RGeo::Geographic.simple_mercator_factory(:has_z_coordinate => true)
53
53
  @mfactory = ::RGeo::Geographic.simple_mercator_factory(:has_m_coordinate => true)
54
54
  @zmfactory = ::RGeo::Geographic.simple_mercator_factory(:has_z_coordinate => true, :has_m_coordinate => true)
@@ -48,7 +48,7 @@ module RGeo
48
48
 
49
49
 
50
50
  def setup
51
- @factory = ::RGeo::Geographic.spherical_factory
51
+ @factory = ::RGeo::Geographic.spherical_factory(:buffer_resolution => 8)
52
52
  @zfactory = ::RGeo::Geographic.spherical_factory(:has_z_coordinate => true)
53
53
  @mfactory = ::RGeo::Geographic.spherical_factory(:has_m_coordinate => true)
54
54
  @zmfactory = ::RGeo::Geographic.spherical_factory(:has_z_coordinate => true, :has_m_coordinate => true)
@@ -100,7 +100,6 @@ module RGeo
100
100
  undef_method :test_union
101
101
  undef_method :test_difference
102
102
  undef_method :test_sym_difference
103
- undef_method :test_buffer
104
103
 
105
104
 
106
105
  end
@@ -46,10 +46,10 @@ module RGeo
46
46
 
47
47
  def setup
48
48
  # @mercator_factory = ::RGeo::Geographic.simple_mercator_factory
49
- # @spherical_factory = ::RGeo::Geographic.spherical_factory(:has_z_coordinate => true)
49
+ # @spherical_factory = ::RGeo::Geographic.spherical_factory(:buffer_resolution => 2)
50
50
  # @projected_factory = ::RGeo::Geographic.projected_factory(:projection_proj4 => '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs', :projection_srid => 3857, :has_z_coordinate => true)
51
- # @geos_factory = ::RGeo::Geos.factory(:buffer_resolution => 8)
52
- # @cartesian_factory = ::RGeo::Cartesian.simple_factory(:srid => 1, :has_z_coordinate => true)
51
+ # @geos_factory = ::RGeo::Geos.factory(:buffer_resolution => 2)
52
+ # @cartesian_factory = ::RGeo::Cartesian.simple_factory(:buffer_resolution => 2)
53
53
  end
54
54
 
55
55
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgeo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.12
4
+ version: 0.3.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-24 00:00:00.000000000 Z
12
+ date: 2012-05-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: RGeo is a geospatial data library for Ruby. It provides an implementation
15
15
  of the Open Geospatial Consortium's Simple Features Specification, used by most
@@ -221,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
221
  version: 1.3.1
222
222
  requirements: []
223
223
  rubyforge_project: virtuoso
224
- rubygems_version: 1.8.19
224
+ rubygems_version: 1.8.24
225
225
  signing_key:
226
226
  specification_version: 3
227
227
  summary: RGeo is a geospatial data library for Ruby.