rgeo 0.3.16 → 0.3.17

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc CHANGED
@@ -1,6 +1,10 @@
1
+ === 0.3.17 / 2012-08-21
2
+
3
+ * Geos-based implementations crashed when an operation resulted in an empty point, e.g. taking the centroid of an empty MultiPolygon on recent versions of Geos. Fixed. Such operations now return the empty GeometryCollection for the time being, to match the behavior of older versions of Geos. (Reported by Ben Hughes)
4
+
1
5
  === 0.3.16 / 2012-08-19
2
6
 
3
- * Added /usr/lib64 to the list of libraries searched. (Thanks to hunterae.)
7
+ * Added /usr/lib64 to the list of libraries searched. (Thanks to hunterae)
4
8
  * Re-added Geos::Factory as an alias of Geos::CAPIFactory, for compatibility with old serializations.
5
9
 
6
10
  === 0.3.15 / 2012-08-02
data/README.rdoc CHANGED
@@ -32,7 +32,6 @@ Several optional modules are currently available:
32
32
  * Extend ActiveRecord to handle spatial data in MySQL Spatial, SpatiaLite,
33
33
  and PostGIS using RGeo's spatial ActiveRecord adapters. These are
34
34
  available via the gems:
35
- * <b>activerecord-mysqlspatial-adapter</b>
36
35
  * <b>activerecord-mysql2spatial-adapter</b>
37
36
  * <b>activerecord-spatialite-adapter</b>
38
37
  * <b>activerecord-postgis-adapter</b>
@@ -53,17 +52,24 @@ RGeo is known to work with the following Ruby implementations:
53
52
 
54
53
  Some features also require the following:
55
54
 
56
- * GEOS 3.2 or later is highly recommended. Some functions will not be
57
- available without it. This C/C++ library may be available via your
58
- operating system's package manager, or you can download it from
59
- http://trac.osgeo.org/geos
55
+ * GEOS 3.2 or later is highly recommended. (3.3.3 or later preferred.)
56
+ Some functions will not be available without it.
57
+ This C/C++ library may be available via your operating system's package
58
+ manager, or you can download it from http://trac.osgeo.org/geos
60
59
  * Proj 4.7 or later is also recommended. This library is needed if you
61
60
  want to translate coordinates between geographic projections. It also
62
61
  may be available via your operating system's package manager, or from
63
62
  http://trac.osgeo.org/proj
63
+ * On some platforms, you should install the ffi-geos gem (version 0.0.6
64
+ or later recommended.) JRuby requires this gem to properly link with
65
+ Geos, and Windows builds probably do as well.
64
66
 
65
67
  Note: The build system assumes a unix-like environment. Windows builds
66
- may be possible, but not likely "out of the box".
68
+ may be possible, but not likely "out of the box". I have heard that
69
+ some Windows users have had success getting the ffi-geos implementation
70
+ working, after suitably installing the Geos library. However, since I'm
71
+ not a Windows user myself, I can't provide any direct support for this
72
+ configuration.
67
73
 
68
74
  === Installation
69
75
 
data/Version CHANGED
@@ -1 +1 @@
1
- 0.3.16
1
+ 0.3.17
@@ -696,9 +696,20 @@ VALUE rgeo_wrap_geos_geometry(VALUE factory, GEOSGeometry* geom, VALUE klass)
696
696
  if (geom || !NIL_P(klass)) {
697
697
  factory_data = NIL_P(factory) ? NULL : RGEO_FACTORY_DATA_PTR(factory);
698
698
  factory_context = factory_data ? factory_data->geos_context : NULL;
699
+ globals = factory_data ? factory_data->globals : NULL;
700
+
701
+ // We don't allow "empty" points, so replace such objects with
702
+ // an empty collection.
703
+ if (geom && factory) {
704
+ if (GEOSGeomTypeId_r(factory_context, geom) == GEOS_POINT && GEOSGetNumCoordinates_r(factory_context, geom) == 0) {
705
+ GEOSGeom_destroy_r(factory_context, geom);
706
+ geom = GEOSGeom_createCollection_r(factory_context, GEOS_GEOMETRYCOLLECTION, NULL, 0);
707
+ klass = globals->geos_geometry_collection;
708
+ }
709
+ }
710
+
699
711
  klasses = Qnil;
700
712
  if (TYPE(klass) != T_CLASS) {
701
- globals = factory_data->globals;
702
713
  inferred_klass = Qnil;
703
714
  is_collection = 0;
704
715
  switch (GEOSGeomTypeId_r(factory_context, geom)) {
@@ -254,14 +254,7 @@ static VALUE method_geometry_envelope(VALUE self)
254
254
  if (self_geom) {
255
255
  geos_context = self_data->geos_context;
256
256
  envelope = GEOSEnvelope_r(geos_context, self_geom);
257
- // GEOS returns an "empty" point for an empty collection's envelope.
258
- // We don't allow that type, so we replace it with an empty collection.
259
- if (!envelope ||
260
- GEOSGeomTypeId_r(geos_context, envelope) == GEOS_POINT &&
261
- GEOSGetNumCoordinates_r(geos_context, envelope) == 0) {
262
- if (envelope) {
263
- GEOSGeom_destroy_r(geos_context, envelope);
264
- }
257
+ if (!envelope) {
265
258
  envelope = GEOSGeom_createCollection_r(geos_context, GEOS_GEOMETRYCOLLECTION, NULL, 0);
266
259
  }
267
260
  result = rgeo_wrap_geos_geometry(self_data->factory, envelope, Qnil);
data/lib/rgeo.rb CHANGED
@@ -94,7 +94,8 @@
94
94
  #
95
95
  # * <b>mysqlspatial</b>, an adapter for MySQL spatial extensions based on
96
96
  # the mysql adapter. Available as the activerecord-mysqlspatial-adapter
97
- # gem.
97
+ # gem. <i>This adapter is deprecated due to bugs in the legacy mysql
98
+ # gem. You should use the mysql2spatial adapter instead.</i>
98
99
  #
99
100
  # * <b>mysql2spatial</b>, an adapter for MySQL spatial extensions based on
100
101
  # the mysql2 adapter. Available as the activerecord-mysql2spatial-adapter
@@ -56,6 +56,14 @@ module RGeo
56
56
  # class method (or === operator) defined in the Type module.
57
57
  #
58
58
  # Some implementations may support higher dimensional points.
59
+ #
60
+ # Some libraries, such as GEOS, support "empty" points. Such objects
61
+ # might be returned as, for example, the centroid of an empty
62
+ # MultiPolygon. The SFS does not clearly define or even acknowledge
63
+ # the existence of such a type, so RGeo will currently generally
64
+ # replace them with empty GeometryCollection objects. Therefore,
65
+ # currently, every RGeo Point object represents an actual location
66
+ # with real coordinates.
59
67
 
60
68
  module Point
61
69
 
@@ -528,6 +528,14 @@ module RGeo
528
528
 
529
529
  def _wrap_fg_geom(fg_geom_, klass_) # :nodoc:
530
530
  klasses_ = nil
531
+
532
+ # We don't allow "empty" points, so replace such objects with
533
+ # an empty collection.
534
+ if fg_geom_.type_id == ::Geos::GeomTypes::GEOS_POINT && fg_geom_.empty?
535
+ fg_geom_ = ::Geos::Utils.create_geometry_collection
536
+ klass_ = FFIGeometryCollectionImpl
537
+ end
538
+
531
539
  unless klass_.kind_of?(::Class)
532
540
  is_collection_ = false
533
541
  case fg_geom_.type_id
@@ -135,13 +135,7 @@ module RGeo
135
135
 
136
136
 
137
137
  def envelope
138
- fg_geom_ = @fg_geom.envelope
139
- # GEOS returns an "empty" point for an empty collection's envelope.
140
- # We don't allow that type, so we replace it with an empty collection.
141
- if fg_geom_.type_id == ::Geos::GeomTypes::GEOS_POINT && fg_geom_.empty?
142
- fg_geom_ = ::Geos::Utils.create_geometry_collection
143
- end
144
- @factory._wrap_fg_geom(fg_geom_, nil)
138
+ @factory._wrap_fg_geom(@fg_geom.envelope, nil)
145
139
  end
146
140
 
147
141
 
@@ -56,6 +56,13 @@ module RGeo
56
56
  include ::RGeo::Tests::Common::MultiPolygonTests
57
57
 
58
58
 
59
+ # Centroid of an empty should return an empty collection rather than crash
60
+
61
+ def test_empty_centroid
62
+ assert_equal(@factory.collection([]), @factory.multi_polygon([]).centroid)
63
+ end
64
+
65
+
59
66
  end
60
67
 
61
68
  end
@@ -57,6 +57,14 @@ module RGeo
57
57
  include ::RGeo::Tests::Common::MultiPolygonTests
58
58
 
59
59
 
60
+ # Centroid of an empty should return an empty collection
61
+ # rather than throw a weird exception out of ffi-geos
62
+
63
+ def test_empty_centroid
64
+ assert_equal(@factory.collection([]), @factory.multi_polygon([]).centroid)
65
+ end
66
+
67
+
60
68
  end
61
69
 
62
70
  end
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.16
4
+ version: 0.3.17
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-08-20 00:00:00.000000000 Z
12
+ date: 2012-08-22 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