rgeo 0.1.13 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. data/History.rdoc +11 -0
  2. data/Version +1 -1
  3. data/ext/geos_c_impl/factory.c +35 -40
  4. data/ext/geos_c_impl/factory.h +4 -1
  5. data/ext/geos_c_impl/geometry_collection.c +5 -5
  6. data/ext/geos_c_impl/geometry_collection.h +1 -1
  7. data/ext/geos_c_impl/line_string.c +129 -116
  8. data/ext/geos_c_impl/point.c +22 -33
  9. data/ext/geos_c_impl/point.h +1 -6
  10. data/ext/geos_c_impl/polygon.c +4 -4
  11. data/ext/geos_c_impl/polygon.h +1 -1
  12. data/lib/rgeo.rb +1 -0
  13. data/lib/rgeo/cartesian/simple_factory.rb +20 -4
  14. data/lib/rgeo/errors.rb +8 -0
  15. data/lib/rgeo/features/factory.rb +35 -1
  16. data/lib/rgeo/features/point.rb +22 -0
  17. data/lib/rgeo/features/polygon.rb +1 -2
  18. data/lib/rgeo/features/types.rb +70 -16
  19. data/lib/rgeo/geography/factories.rb +40 -3
  20. data/lib/rgeo/geography/factory.rb +25 -5
  21. data/lib/rgeo/geography/simple_mercator/feature_methods.rb +2 -6
  22. data/lib/rgeo/geography/simple_mercator/projector.rb +1 -1
  23. data/lib/rgeo/geos/factory.rb +40 -46
  24. data/lib/rgeo/geos/interface.rb +10 -0
  25. data/lib/rgeo/impl_helpers.rb +0 -1
  26. data/lib/rgeo/impl_helpers/basic_geometry_methods.rb +2 -2
  27. data/lib/rgeo/impl_helpers/basic_point_methods.rb +12 -14
  28. data/lib/rgeo/wkrep.rb +59 -0
  29. data/lib/rgeo/wkrep/wkb_generator.rb +181 -0
  30. data/lib/rgeo/wkrep/wkb_parser.rb +205 -0
  31. data/lib/rgeo/wkrep/wkt_generator.rb +187 -0
  32. data/lib/rgeo/wkrep/wkt_parser.rb +321 -0
  33. data/tests/common/line_string_tests.rb +26 -2
  34. data/tests/common/point_tests.rb +26 -0
  35. data/tests/geos/tc_point.rb +1 -20
  36. data/tests/simple_cartesian/tc_point.rb +1 -0
  37. data/tests/simple_mercator/tc_point.rb +1 -0
  38. data/tests/simple_spherical/tc_point.rb +1 -0
  39. data/tests/tc_oneoff.rb +3 -2
  40. metadata +8 -4
  41. data/lib/rgeo/impl_helpers/serialization.rb +0 -130
@@ -44,16 +44,24 @@ module RGeo
44
44
  module LineStringTests # :nodoc:
45
45
 
46
46
 
47
- def test_creation_success
47
+ def test_creation_points2
48
48
  point1_ = @factory.point(0, 0)
49
49
  point2_ = @factory.point(0, 1)
50
- point3_ = @factory.point(1, 0)
51
50
  line1_ = @factory.line_string([point1_, point2_])
52
51
  assert_not_nil(line1_)
53
52
  assert_equal(::RGeo::Features::LineString, line1_.geometry_type)
54
53
  assert_equal(2, line1_.num_points)
55
54
  assert_equal(point1_, line1_.point_n(0))
56
55
  assert_equal(point2_, line1_.point_n(1))
56
+ assert_equal(point1_, line1_.start_point)
57
+ assert_equal(point2_, line1_.end_point)
58
+ end
59
+
60
+
61
+ def test_creation_points3
62
+ point1_ = @factory.point(0, 0)
63
+ point2_ = @factory.point(0, 1)
64
+ point3_ = @factory.point(1, 0)
57
65
  line2_ = @factory.line_string([point1_, point2_, point3_])
58
66
  assert_not_nil(line2_)
59
67
  assert_equal(::RGeo::Features::LineString, line2_.geometry_type)
@@ -61,16 +69,32 @@ module RGeo
61
69
  assert_equal(point1_, line2_.point_n(0))
62
70
  assert_equal(point2_, line2_.point_n(1))
63
71
  assert_equal(point3_, line2_.point_n(2))
72
+ assert_nil(line2_.point_n(3))
73
+ assert_equal(point1_, line2_.start_point)
74
+ assert_equal(point3_, line2_.end_point)
75
+ end
76
+
77
+
78
+ def test_creation_points2_degenerate
79
+ point1_ = @factory.point(0, 0)
64
80
  line3_ = @factory.line_string([point1_, point1_])
65
81
  assert_not_nil(line3_)
66
82
  assert_equal(::RGeo::Features::LineString, line3_.geometry_type)
67
83
  assert_equal(2, line3_.num_points)
68
84
  assert_equal(point1_, line3_.point_n(0))
69
85
  assert_equal(point1_, line3_.point_n(1))
86
+ assert_equal(point1_, line3_.start_point)
87
+ assert_equal(point1_, line3_.end_point)
88
+ end
89
+
90
+
91
+ def test_creation_points_empty
70
92
  line4_ = @factory.line_string([])
71
93
  assert_not_nil(line4_)
72
94
  assert_equal(::RGeo::Features::LineString, line4_.geometry_type)
73
95
  assert_equal(0, line4_.num_points)
96
+ assert_nil(line4_.start_point)
97
+ assert_nil(line4_.end_point)
74
98
  end
75
99
 
76
100
 
@@ -272,6 +272,32 @@ module RGeo
272
272
  end
273
273
 
274
274
 
275
+ def test_3d_creation
276
+ point_ = @zfactory.point(11, 12, 13)
277
+ assert_equal(11, point_.x)
278
+ assert_equal(12, point_.y)
279
+ assert_equal(13, point_.z)
280
+ point2_ = @zfactory.point(21, 22)
281
+ assert_equal(21, point2_.x)
282
+ assert_equal(22, point2_.y)
283
+ assert_equal(0, point2_.z)
284
+ end
285
+
286
+
287
+ def test_wkt_creation_3d
288
+ point2_ = @zfactory.parse_wkt('POINT(11 12 13)')
289
+ assert_equal(11, point2_.x)
290
+ assert_equal(12, point2_.y)
291
+ assert_equal(13, point2_.z)
292
+ point1_ = @zfactory.parse_wkt('POINT(21 22)')
293
+ assert_equal(21, point1_.x)
294
+ assert_equal(22, point1_.y)
295
+ # Z is undefined in this case.
296
+ # We'd like to define it to be 0, but the GEOS
297
+ # parser doesn't behave that way.
298
+ end
299
+
300
+
275
301
  end
276
302
 
277
303
  end
@@ -49,6 +49,7 @@ module RGeo
49
49
 
50
50
  def setup
51
51
  @factory = ::RGeo::Geos.factory
52
+ @zfactory = ::RGeo::Geos.factory(:support_z_coordinate => true)
52
53
  end
53
54
 
54
55
 
@@ -61,26 +62,6 @@ module RGeo
61
62
  end
62
63
 
63
64
 
64
- def test_3d_creation
65
- point_ = @factory.point3d(11, 12, 13)
66
- assert_equal(11, point_.x)
67
- assert_equal(12, point_.y)
68
- assert_equal(13, point_.z)
69
- point2_ = @factory.point(21, 22)
70
- assert_nil(point2_.z)
71
- end
72
-
73
-
74
- def test_wkt_creation_3d
75
- point1_ = @factory.parse_wkt('POINT(21 22)')
76
- assert_nil(point1_.z)
77
- point2_ = @factory.parse_wkt('POINT(11 12 13)')
78
- assert_equal(11, point2_.x)
79
- assert_equal(12, point2_.y)
80
- assert_equal(13, point2_.z)
81
- end
82
-
83
-
84
65
  def test_srid
85
66
  point_ = @factory.point(11, 12)
86
67
  assert_equal(0, point_.srid)
@@ -49,6 +49,7 @@ module RGeo
49
49
 
50
50
  def setup
51
51
  @factory = ::RGeo::Cartesian.simple_factory(:srid => 1)
52
+ @zfactory = ::RGeo::Cartesian.simple_factory(:srid => 1, :support_z_coordinate => true)
52
53
  end
53
54
 
54
55
 
@@ -49,6 +49,7 @@ module RGeo
49
49
 
50
50
  def setup
51
51
  @factory = ::RGeo::Geography.simple_mercator
52
+ @zfactory = ::RGeo::Geography.simple_mercator(:support_z_coordinate => true)
52
53
  end
53
54
 
54
55
 
@@ -49,6 +49,7 @@ module RGeo
49
49
 
50
50
  def setup
51
51
  @factory = ::RGeo::Geography.simple_spherical
52
+ @zfactory = ::RGeo::Geography.simple_spherical(:support_z_coordinate => true)
52
53
  end
53
54
 
54
55
 
data/tests/tc_oneoff.rb CHANGED
@@ -46,8 +46,9 @@ module RGeo
46
46
 
47
47
  def setup
48
48
  @mercator_factory = ::RGeo::Geography.simple_mercator
49
- @spherical_factory = ::RGeo::Geography.simple_spherical
50
- @geos_factory = ::RGeo::Geos.factory(:srid => 4326)
49
+ @spherical_factory = ::RGeo::Geography.simple_spherical(:support_z_coordinate => true)
50
+ @geos_factory = ::RGeo::Geos.factory(:srid => 4326, :support_z_coordinate => true)
51
+ @cartesian_factory = ::RGeo::Cartesian.simple_factory(:srid => 1, :support_z_coordinate => true)
51
52
  @entity_factory = ::RGeo::GeoJSON::EntityFactory.instance
52
53
  end
53
54
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 13
9
- version: 0.1.13
8
+ - 14
9
+ version: 0.1.14
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Azuma
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-26 00:00:00 -07:00
17
+ date: 2010-11-04 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -90,9 +90,13 @@ files:
90
90
  - lib/rgeo/impl_helpers/basic_line_string_methods.rb
91
91
  - lib/rgeo/impl_helpers/basic_point_methods.rb
92
92
  - lib/rgeo/impl_helpers/basic_polygon_methods.rb
93
- - lib/rgeo/impl_helpers/serialization.rb
94
93
  - lib/rgeo/impl_helpers.rb
95
94
  - lib/rgeo/version.rb
95
+ - lib/rgeo/wkrep/wkb_generator.rb
96
+ - lib/rgeo/wkrep/wkb_parser.rb
97
+ - lib/rgeo/wkrep/wkt_generator.rb
98
+ - lib/rgeo/wkrep/wkt_parser.rb
99
+ - lib/rgeo/wkrep.rb
96
100
  - lib/rgeo.rb
97
101
  - History.rdoc
98
102
  - README.rdoc
@@ -1,130 +0,0 @@
1
- # -----------------------------------------------------------------------------
2
- #
3
- # Basic methods used by geometry objects
4
- #
5
- # -----------------------------------------------------------------------------
6
- # Copyright 2010 Daniel Azuma
7
- #
8
- # All rights reserved.
9
- #
10
- # Redistribution and use in source and binary forms, with or without
11
- # modification, are permitted provided that the following conditions are met:
12
- #
13
- # * Redistributions of source code must retain the above copyright notice,
14
- # this list of conditions and the following disclaimer.
15
- # * Redistributions in binary form must reproduce the above copyright notice,
16
- # this list of conditions and the following disclaimer in the documentation
17
- # and/or other materials provided with the distribution.
18
- # * Neither the name of the copyright holder, nor the names of any other
19
- # contributors to this software, may be used to endorse or promote products
20
- # derived from this software without specific prior written permission.
21
- #
22
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
- # POSSIBILITY OF SUCH DAMAGE.
33
- # -----------------------------------------------------------------------------
34
- ;
35
-
36
-
37
- module RGeo
38
-
39
- module ImplHelpers # :nodoc:
40
-
41
-
42
- module Serialization # :nodoc:
43
-
44
- @helper_factory = false
45
-
46
- class << self
47
-
48
-
49
- def _helper_factory
50
- if @helper_factory == false
51
- if Geos.supported?
52
- @helper_factory = Geos.factory(:srid => 0)
53
- else
54
- @helper_factory = nil
55
- end
56
- end
57
- @helper_factory
58
- end
59
-
60
-
61
- def parse_wkt(str_, factory_)
62
- helper_factory_ = _helper_factory
63
- if helper_factory_
64
- obj_ = helper_factory_.parse_wkt(str_)
65
- obj_ ? Features.cast(obj_, factory_) : nil
66
- else
67
- default_parse_wkt(str_, factory_)
68
- end
69
- end
70
-
71
-
72
- def parse_wkb(str_, factory_)
73
- helper_factory_ = _helper_factory
74
- if helper_factory_
75
- obj_ = helper_factory_.parse_wkb(str_)
76
- obj_ ? Features.cast(obj_, factory_) : nil
77
- else
78
- default_parse_wkb(str_, factory_)
79
- end
80
- end
81
-
82
-
83
- def unparse_wkt(obj_)
84
- helper_factory_ = _helper_factory
85
- if helper_factory_
86
- Features.cast(obj_, helper_factory_).as_text
87
- else
88
- default_unparse_wkt(obj_)
89
- end
90
- end
91
-
92
-
93
- def unparse_wkb(obj_)
94
- helper_factory_ = _helper_factory
95
- if helper_factory_
96
- Features.cast(obj_, helper_factory_).as_binary
97
- else
98
- default_unparse_wkb(obj_)
99
- end
100
- end
101
-
102
-
103
- def default_parse_wkt(str_, factory_)
104
- nil # TODO
105
- end
106
-
107
-
108
- def default_parse_wkb(str_, factory_)
109
- nil # TODO
110
- end
111
-
112
-
113
- def default_unparse_wkt(obj_)
114
- nil # TODO
115
- end
116
-
117
-
118
- def default_unparse_wkb(obj_)
119
- nil # TODO
120
- end
121
-
122
-
123
- end
124
-
125
- end
126
-
127
-
128
- end
129
-
130
- end