rgeo 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/History.rdoc +6 -0
  2. data/Version +1 -1
  3. data/lib/rgeo.rb +80 -30
  4. data/lib/rgeo/all.rb +48 -0
  5. data/lib/rgeo/cartesian.rb +37 -12
  6. data/lib/rgeo/cartesian/calculations.rb +5 -0
  7. data/lib/rgeo/cartesian/{simple_factory.rb → factory.rb} +14 -17
  8. data/lib/rgeo/cartesian/{simple_feature_classes.rb → feature_classes.rb} +55 -55
  9. data/lib/rgeo/cartesian/{simple_feature_methods.rb → feature_methods.rb} +7 -3
  10. data/lib/rgeo/cartesian/interface.rb +7 -3
  11. data/lib/rgeo/errors.rb +4 -0
  12. data/lib/rgeo/features.rb +25 -20
  13. data/lib/rgeo/geo_json.rb +10 -8
  14. data/lib/rgeo/geography.rb +10 -16
  15. data/lib/rgeo/geography/all.rb +40 -0
  16. data/lib/rgeo/geography/factory.rb +2 -2
  17. data/lib/rgeo/geography/{factories.rb → interface.rb} +4 -2
  18. data/lib/rgeo/geography/simple_mercator.rb +69 -0
  19. data/lib/rgeo/geography/simple_mercator/feature_classes.rb +62 -62
  20. data/lib/rgeo/geography/simple_mercator/projector.rb +1 -1
  21. data/lib/rgeo/geography/simple_spherical.rb +68 -0
  22. data/lib/rgeo/geography/simple_spherical/calculations.rb +2 -2
  23. data/lib/rgeo/geography/simple_spherical/feature_classes.rb +44 -44
  24. data/lib/rgeo/geos.rb +12 -9
  25. data/lib/rgeo/impl_helpers.rb +14 -9
  26. data/lib/rgeo/impl_helpers/basic_geometry_collection_methods.rb +10 -0
  27. data/lib/rgeo/impl_helpers/basic_point_methods.rb +3 -0
  28. data/lib/rgeo/{geography/helper.rb → impl_helpers/math.rb} +3 -3
  29. data/lib/rgeo/wkrep.rb +32 -12
  30. data/lib/rgeo/wkrep/wkb_generator.rb +95 -9
  31. data/lib/rgeo/wkrep/wkb_parser.rb +117 -9
  32. data/lib/rgeo/wkrep/wkt_generator.rb +106 -18
  33. data/lib/rgeo/wkrep/wkt_parser.rb +203 -59
  34. data/tests/simple_cartesian/tc_calculations.rb +8 -8
  35. data/tests/wkrep/tc_wkt_generator.rb +362 -0
  36. data/tests/wkrep/tc_wkt_parser.rb +490 -0
  37. metadata +16 -8
@@ -65,7 +65,7 @@ module RGeo
65
65
  def unproject(geometry_)
66
66
  case geometry_
67
67
  when Features::Point
68
- dpr_ = Helper::DEGREES_PER_RADIAN
68
+ dpr_ = ::RGeo::ImplHelpers::Math::DEGREES_PER_RADIAN
69
69
  radius_ = EQUATORIAL_RADIUS
70
70
  @geography_factory.point(geometry_.x / radius_ * dpr_,
71
71
  (2.0 * ::Math.atan(::Math.exp(geometry_.y / radius_)) - ::Math::PI / 2.0) * dpr_)
@@ -0,0 +1,68 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Simple spherical geography implementation for RGeo
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
+ require 'rgeo/geography'
38
+
39
+
40
+ module RGeo
41
+
42
+ module Geography
43
+
44
+
45
+ # This namespace contains the simple spherical implementation.
46
+
47
+ module SimpleSpherical
48
+ end
49
+
50
+
51
+ end
52
+
53
+
54
+ end
55
+
56
+
57
+ # Dependency source files.
58
+ paths_ = [
59
+ 'features',
60
+ 'wkrep',
61
+ 'impl_helpers',
62
+ 'geography/simple_spherical/calculations',
63
+ 'geography/simple_spherical/feature_methods',
64
+ 'geography/simple_spherical/feature_classes',
65
+ 'geography/factory',
66
+ 'geography/projected_window',
67
+ ]
68
+ paths_.each{ |path_| require "rgeo/#{path_}" }
@@ -85,7 +85,7 @@ module RGeo
85
85
  def latlon
86
86
  lat_rad_ = ::Math.asin(@z)
87
87
  lon_rad_ = ::Math.atan2(@y, @x) rescue 0.0
88
- rpd_ = Helper::RADIANS_PER_DEGREE
88
+ rpd_ = ::RGeo::ImplHelpers::Math::RADIANS_PER_DEGREE
89
89
  [lat_rad_ / rpd_, lon_rad_ / rpd_]
90
90
  end
91
91
 
@@ -120,7 +120,7 @@ module RGeo
120
120
 
121
121
 
122
122
  def self.from_latlon(lat_, lon_)
123
- rpd_ = Helper::RADIANS_PER_DEGREE
123
+ rpd_ = ::RGeo::ImplHelpers::Math::RADIANS_PER_DEGREE
124
124
  lat_rad_ = rpd_ * lat_
125
125
  lon_rad_ = rpd_ * lon_
126
126
  z_ = ::Math.sin(lat_rad_)
@@ -44,10 +44,10 @@ module RGeo
44
44
  class PointImpl # :nodoc:
45
45
 
46
46
 
47
- include Features::Point
48
- include ImplHelpers::BasicGeometryMethods
49
- include SimpleSpherical::GeometryMethods
50
- include ImplHelpers::BasicPointMethods
47
+ include ::RGeo::Features::Point
48
+ include ::RGeo::ImplHelpers::BasicGeometryMethods
49
+ include ::RGeo::Geography::SimpleSpherical::GeometryMethods
50
+ include ::RGeo::ImplHelpers::BasicPointMethods
51
51
 
52
52
 
53
53
  def _validate_geometry
@@ -81,11 +81,11 @@ module RGeo
81
81
  class LineStringImpl # :nodoc:
82
82
 
83
83
 
84
- include Features::LineString
85
- include ImplHelpers::BasicGeometryMethods
86
- include SimpleSpherical::GeometryMethods
87
- include ImplHelpers::BasicLineStringMethods
88
- include SimpleSpherical::LineStringMethods
84
+ include ::RGeo::Features::LineString
85
+ include ::RGeo::ImplHelpers::BasicGeometryMethods
86
+ include ::RGeo::Geography::SimpleSpherical::GeometryMethods
87
+ include ::RGeo::ImplHelpers::BasicLineStringMethods
88
+ include ::RGeo::Geography::SimpleSpherical::LineStringMethods
89
89
 
90
90
 
91
91
  end
@@ -94,12 +94,12 @@ module RGeo
94
94
  class LineImpl # :nodoc:
95
95
 
96
96
 
97
- include Features::Line
98
- include ImplHelpers::BasicGeometryMethods
99
- include SimpleSpherical::GeometryMethods
100
- include ImplHelpers::BasicLineStringMethods
101
- include SimpleSpherical::LineStringMethods
102
- include ImplHelpers::BasicLineMethods
97
+ include ::RGeo::Features::Line
98
+ include ::RGeo::ImplHelpers::BasicGeometryMethods
99
+ include ::RGeo::Geography::SimpleSpherical::GeometryMethods
100
+ include ::RGeo::ImplHelpers::BasicLineStringMethods
101
+ include ::RGeo::Geography::SimpleSpherical::LineStringMethods
102
+ include ::RGeo::ImplHelpers::BasicLineMethods
103
103
 
104
104
 
105
105
  end
@@ -108,12 +108,12 @@ module RGeo
108
108
  class LinearRingImpl # :nodoc:
109
109
 
110
110
 
111
- include Features::Line
112
- include ImplHelpers::BasicGeometryMethods
113
- include SimpleSpherical::GeometryMethods
114
- include ImplHelpers::BasicLineStringMethods
115
- include SimpleSpherical::LineStringMethods
116
- include ImplHelpers::BasicLinearRingMethods
111
+ include ::RGeo::Features::Line
112
+ include ::RGeo::ImplHelpers::BasicGeometryMethods
113
+ include ::RGeo::Geography::SimpleSpherical::GeometryMethods
114
+ include ::RGeo::ImplHelpers::BasicLineStringMethods
115
+ include ::RGeo::Geography::SimpleSpherical::LineStringMethods
116
+ include ::RGeo::ImplHelpers::BasicLinearRingMethods
117
117
 
118
118
 
119
119
  end
@@ -122,10 +122,10 @@ module RGeo
122
122
  class PolygonImpl # :nodoc:
123
123
 
124
124
 
125
- include Features::Polygon
126
- include ImplHelpers::BasicGeometryMethods
127
- include SimpleSpherical::GeometryMethods
128
- include ImplHelpers::BasicPolygonMethods
125
+ include ::RGeo::Features::Polygon
126
+ include ::RGeo::ImplHelpers::BasicGeometryMethods
127
+ include ::RGeo::Geography::SimpleSpherical::GeometryMethods
128
+ include ::RGeo::ImplHelpers::BasicPolygonMethods
129
129
 
130
130
 
131
131
  end
@@ -134,10 +134,10 @@ module RGeo
134
134
  class GeometryCollectionImpl # :nodoc:
135
135
 
136
136
 
137
- include Features::GeometryCollection
138
- include ImplHelpers::BasicGeometryMethods
139
- include SimpleSpherical::GeometryMethods
140
- include ImplHelpers::BasicGeometryCollectionMethods
137
+ include ::RGeo::Features::GeometryCollection
138
+ include ::RGeo::ImplHelpers::BasicGeometryMethods
139
+ include ::RGeo::Geography::SimpleSpherical::GeometryMethods
140
+ include ::RGeo::ImplHelpers::BasicGeometryCollectionMethods
141
141
 
142
142
 
143
143
  end
@@ -146,11 +146,11 @@ module RGeo
146
146
  class MultiPointImpl # :nodoc:
147
147
 
148
148
 
149
- include Features::GeometryCollection
150
- include ImplHelpers::BasicGeometryMethods
151
- include SimpleSpherical::GeometryMethods
152
- include ImplHelpers::BasicGeometryCollectionMethods
153
- include ImplHelpers::BasicMultiPointMethods
149
+ include ::RGeo::Features::GeometryCollection
150
+ include ::RGeo::ImplHelpers::BasicGeometryMethods
151
+ include ::RGeo::Geography::SimpleSpherical::GeometryMethods
152
+ include ::RGeo::ImplHelpers::BasicGeometryCollectionMethods
153
+ include ::RGeo::ImplHelpers::BasicMultiPointMethods
154
154
 
155
155
 
156
156
  end
@@ -159,11 +159,11 @@ module RGeo
159
159
  class MultiLineStringImpl # :nodoc:
160
160
 
161
161
 
162
- include Features::GeometryCollection
163
- include ImplHelpers::BasicGeometryMethods
164
- include SimpleSpherical::GeometryMethods
165
- include ImplHelpers::BasicGeometryCollectionMethods
166
- include ImplHelpers::BasicMultiLineStringMethods
162
+ include ::RGeo::Features::GeometryCollection
163
+ include ::RGeo::ImplHelpers::BasicGeometryMethods
164
+ include ::RGeo::Geography::SimpleSpherical::GeometryMethods
165
+ include ::RGeo::ImplHelpers::BasicGeometryCollectionMethods
166
+ include ::RGeo::ImplHelpers::BasicMultiLineStringMethods
167
167
 
168
168
 
169
169
  end
@@ -172,11 +172,11 @@ module RGeo
172
172
  class MultiPolygonImpl # :nodoc:
173
173
 
174
174
 
175
- include Features::GeometryCollection
176
- include ImplHelpers::BasicGeometryMethods
177
- include SimpleSpherical::GeometryMethods
178
- include ImplHelpers::BasicGeometryCollectionMethods
179
- include ImplHelpers::BasicMultiPolygonMethods
175
+ include ::RGeo::Features::GeometryCollection
176
+ include ::RGeo::ImplHelpers::BasicGeometryMethods
177
+ include ::RGeo::Geography::SimpleSpherical::GeometryMethods
178
+ include ::RGeo::ImplHelpers::BasicGeometryCollectionMethods
179
+ include ::RGeo::ImplHelpers::BasicMultiPolygonMethods
180
180
 
181
181
 
182
182
  end
data/lib/rgeo/geos.rb CHANGED
@@ -34,6 +34,10 @@
34
34
  ;
35
35
 
36
36
 
37
+ # Parent file
38
+ require 'rgeo'
39
+
40
+
37
41
  module RGeo
38
42
 
39
43
 
@@ -61,12 +65,11 @@ module RGeo
61
65
  end
62
66
 
63
67
 
64
- # Dependency source files.
65
- paths_ = [
66
- 'features',
67
- 'geos/factory',
68
- 'geos/interface',
69
- 'geos/geos_c_impl',
70
- 'geos/impl_additions',
71
- ]
72
- paths_.each{ |path_| require "rgeo/#{path_}" }
68
+ # Dependency files
69
+ require 'rgeo/features'
70
+
71
+ # Implementation files
72
+ require 'rgeo/geos/factory'
73
+ require 'rgeo/geos/interface'
74
+ require 'rgeo/geos/geos_c_impl'
75
+ require 'rgeo/geos/impl_additions'
@@ -34,6 +34,10 @@
34
34
  ;
35
35
 
36
36
 
37
+ # Parent file
38
+ require 'rgeo'
39
+
40
+
37
41
  module RGeo
38
42
 
39
43
 
@@ -44,12 +48,13 @@ module RGeo
44
48
  end
45
49
 
46
50
 
47
- # Dependency source files.
48
- paths_ = [
49
- 'impl_helpers/basic_geometry_methods',
50
- 'impl_helpers/basic_geometry_collection_methods',
51
- 'impl_helpers/basic_point_methods',
52
- 'impl_helpers/basic_line_string_methods',
53
- 'impl_helpers/basic_polygon_methods',
54
- ]
55
- paths_.each{ |path_| require "rgeo/#{path_}" }
51
+ # Dependency files
52
+ require 'rgeo/features'
53
+
54
+ # Implementation files
55
+ require 'rgeo/impl_helpers/math'
56
+ require 'rgeo/impl_helpers/basic_geometry_methods'
57
+ require 'rgeo/impl_helpers/basic_geometry_collection_methods'
58
+ require 'rgeo/impl_helpers/basic_point_methods'
59
+ require 'rgeo/impl_helpers/basic_line_string_methods'
60
+ require 'rgeo/impl_helpers/basic_polygon_methods'
@@ -130,6 +130,11 @@ module RGeo
130
130
  end
131
131
 
132
132
 
133
+ def length
134
+ @elements.inject(0.0){ |sum_, obj_| sum_ + obj_.length }
135
+ end
136
+
137
+
133
138
  end
134
139
 
135
140
 
@@ -178,6 +183,11 @@ module RGeo
178
183
  end
179
184
 
180
185
 
186
+ def area
187
+ @elements.inject(0.0){ |sum_, obj_| sum_ + obj_.area }
188
+ end
189
+
190
+
181
191
  end
182
192
 
183
193
 
@@ -48,6 +48,9 @@ module RGeo
48
48
  @y = y_.to_f
49
49
  @z = factory_.has_capability?(:z_coordinate) ? extra_.shift.to_f : nil
50
50
  @m = factory_.has_capability?(:m_coordinate) ? extra_.shift.to_f : nil
51
+ if extra_.size > 0
52
+ raise ::ArgumentError, "Too many arguments for point initializer"
53
+ end
51
54
  _validate_geometry
52
55
  end
53
56
 
@@ -1,6 +1,6 @@
1
1
  # -----------------------------------------------------------------------------
2
2
  #
3
- # Helper for geography implementations
3
+ # Math constants and tools
4
4
  #
5
5
  # -----------------------------------------------------------------------------
6
6
  # Copyright 2010 Daniel Azuma
@@ -36,9 +36,9 @@
36
36
 
37
37
  module RGeo
38
38
 
39
- module Geography
39
+ module ImplHelpers # :nodoc:
40
40
 
41
- module Helper # :nodoc:
41
+ module Math # :nodoc:
42
42
 
43
43
  RADIANS_PER_DEGREE = ::Math::PI/180.0
44
44
  DEGREES_PER_RADIAN = 180.0/::Math::PI
data/lib/rgeo/wkrep.rb CHANGED
@@ -34,12 +34,33 @@
34
34
  ;
35
35
 
36
36
 
37
+ # Parent file
38
+ require 'rgeo'
39
+
40
+
37
41
  module RGeo
38
42
 
39
43
 
40
- # Implementations of the OpenGIS well-known representation
41
- # (i.e. the WKT/WKB) and its variants (e.g. the EWKT/EWKB used by
42
- # PostGIS). Provides generation and parsing facilities.
44
+ # This module contains implementations of the OpenGIS well-known
45
+ # representations: the WKT (well-known text representation) and the
46
+ # WKB (well-known binary representation), as defined in the Simple
47
+ # Features Specification, version 1.1. Facilities are provided to
48
+ # serialize any geometry into one of these formats, and to parse a
49
+ # serialized string back into a geometry. Support is also provided for
50
+ # the common extensions to these formats-- notably, the EWKT and EWKB
51
+ # formats used by PostGIS.
52
+ #
53
+ # To serialize a geometry into WKT (well-known text) format, use
54
+ # the WKRep::WKTGenerator class.
55
+ #
56
+ # To serialize a geometry into WKB (well-known binary) format, use
57
+ # the WKRep::WKBGenerator class.
58
+ #
59
+ # To parse a string in WKT (well-known text) format back into a
60
+ # geometry object, use the WKRep::WKTParser class.
61
+ #
62
+ # To parse a byte string in WKB (well-known binary) format back into a
63
+ # geometry object, use the WKRep::WKBParser class.
43
64
 
44
65
  module WKRep
45
66
  end
@@ -48,12 +69,11 @@ module RGeo
48
69
  end
49
70
 
50
71
 
51
- # Dependency source files.
52
- paths_ = [
53
- 'features',
54
- 'wkrep/wkt_parser',
55
- 'wkrep/wkt_generator',
56
- 'wkrep/wkb_parser',
57
- 'wkrep/wkb_generator',
58
- ]
59
- paths_.each{ |path_| require "rgeo/#{path_}" }
72
+ # Dependency files
73
+ require 'rgeo/features'
74
+
75
+ # Implementation files
76
+ require 'rgeo/wkrep/wkt_parser'
77
+ require 'rgeo/wkrep/wkt_generator'
78
+ require 'rgeo/wkrep/wkb_parser'
79
+ require 'rgeo/wkrep/wkb_generator'
@@ -39,9 +39,42 @@ module RGeo
39
39
  module WKRep
40
40
 
41
41
 
42
+ # This class provides the functionality of serializing a geometry as
43
+ # WKB (well-known binary) format. You may also customize the
44
+ # serializer to generate PostGIS EWKB extensions to the output, or to
45
+ # follow the Simple Features Specification 1.2 extensions for Z and M
46
+ # coordinates.
47
+ #
48
+ # To use this class, create an instance with the desired settings and
49
+ # customizations, and call the generate method.
50
+ #
51
+ # === Configuration options
52
+ #
53
+ # The following options are recognized. These can be passed to the
54
+ # constructor, or set on the object afterwards.
55
+ #
56
+ # <tt>:type_format</tt>::
57
+ # The format for type codes. Possible values are <tt>:wkb11</tt>,
58
+ # indicating SFS 1.1 WKB (i.e. no Z or M values); <tt>:ewkb</tt>,
59
+ # indicating the PostGIS EWKB extensions (i.e. Z and M presence
60
+ # flagged by the two high bits of the type code, and support for
61
+ # embedded SRID); or <tt>:wkb12</tt> (indicating SFS 1.2 WKB
62
+ # (i.e. Z and M presence flagged by adding 1000 and/or 2000 to
63
+ # the type code.) Default is <tt>:wkb11</tt>.
64
+ # <tt>:emit_ewkb_srid</tt>::
65
+ # If true, embed the SRID in the toplevel geometry. Available only
66
+ # if <tt>:type_format</tt> is <tt>:ewkb</tt>. Default is false.
67
+ # <tt>:hex_format</tt>::
68
+ # If true, output a hex string instead of a byte string.
69
+ # Default is false.
70
+ # <tt>:little_endian</tt>::
71
+ # If true, output little endian (NDR) byte order. If false, output
72
+ # big endian (XDR), or network byte order. Default is false.
73
+
42
74
  class WKBGenerator
43
75
 
44
76
 
77
+ # :stopdoc:
45
78
  TYPE_CODES = {
46
79
  Features::Point => 1,
47
80
  Features::LineString => 2,
@@ -53,15 +86,68 @@ module RGeo
53
86
  Features::MultiPolygon => 6,
54
87
  Features::GeometryCollection => 7,
55
88
  }
89
+ # :startdoc:
90
+
56
91
 
92
+ # Create and configure a WKB generator. See the WKBGenerator
93
+ # documentation for the options that can be passed.
57
94
 
58
95
  def initialize(opts_={})
59
- @type_format = opts_[:type_format]
60
- @emit_ewkb_srid = opts_[:emit_ewkb_srid] if @type_format == :ewkb
61
- @hex_format = opts_[:hex_format]
62
- @little_endian = opts_[:little_endian]
96
+ @type_format = opts_[:type_format] || :wkb11
97
+ @emit_ewkb_srid = opts_[:emit_ewkb_srid] ? true : false if @type_format == :ewkb
98
+ @hex_format = opts_[:hex_format] ? true : false
99
+ @little_endian = opts_[:little_endian] ? true : false
100
+ end
101
+
102
+
103
+ # Returns the format for type codes. See WKBGenerator for details.
104
+ def type_format
105
+ @type_format
106
+ end
107
+
108
+ # Sets the format for type codes. See WKBGenerator for details.
109
+ def type_format=(value_)
110
+ @type_format = value_
111
+ end
112
+
113
+ # Returns whether SRID is embedded. See WKBGenerator for details.
114
+ def emit_ewkb_srid?
115
+ @emit_ewkb_srid
116
+ end
117
+
118
+ # Sets whether SRID is embedded. Available only when the type_format
119
+ # is <tt>:ewkb</tt>. See WKBGenerator for details.
120
+ def emit_ewkb_srid=(value_)
121
+ @emit_ewkb_srid = @type_format == :ewkb && value_
63
122
  end
64
123
 
124
+ # Returns whether output is converted to hex.
125
+ # See WKBGenerator for details.
126
+ def hex_format?
127
+ @hex_format
128
+ end
129
+
130
+ # Sets whether output is converted to hex.
131
+ # See WKBGenerator for details.
132
+ def hex_format=(value_)
133
+ @hex_format = value_ ? true : false
134
+ end
135
+
136
+ # Returns whether output is little-endian (NDR).
137
+ # See WKBGenerator for details.
138
+ def little_endian?
139
+ @little_endian
140
+ end
141
+
142
+ # Sets whether output is little-endian (NDR).
143
+ # See WKBGenerator for details.
144
+ def little_endian=(value_)
145
+ @little_endian = value_ ? true : false
146
+ end
147
+
148
+
149
+ # Generate and return the WKB format for the given geometry object,
150
+ # according to the current settings.
65
151
 
66
152
  def generate(obj_)
67
153
  factory_ = obj_.factory
@@ -87,13 +173,13 @@ module RGeo
87
173
  raise Errors::ParseError, "Unrecognized Geometry Type: #{type_}"
88
174
  end
89
175
  emit_srid_ = false
90
- if @emit_ewkb_srid && toplevel_
91
- type_code |= 0x20000000
92
- emit_srid_ = true
93
- end
94
176
  if @type_format == :ewkb
95
177
  type_code_ |= 0x80000000 if @cur_has_z
96
178
  type_code_ |= 0x40000000 if @cur_has_m
179
+ if @emit_ewkb_srid && toplevel_
180
+ type_code |= 0x20000000
181
+ emit_srid_ = true
182
+ end
97
183
  elsif @type_format == :wkb12
98
184
  type_code_ += 1000 if @cur_has_z
99
185
  type_code_ += 2000 if @cur_has_m
@@ -169,7 +255,7 @@ module RGeo
169
255
  def _finish_emitter # :nodoc:
170
256
  str_ = @cur_array.join
171
257
  @cur_array = nil
172
- str_
258
+ @hex_format ? str_.unpack("H*")[0] : str_
173
259
  end
174
260
 
175
261