Class: RGeo::Cartesian::Factory

Inherits:
Object
  • Object
show all
Includes:
Feature::Factory::Instance, ImplHelper::Utils
Defined in:
lib/rgeo/cartesian/factory.rb

Overview

This class implements the factory for the simple cartesian implementation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ImplHelper::Utils

setup_coord_sys

Constructor Details

#initialize(opts = {}) ⇒ Factory

Create a new simple cartesian factory.

See RGeo::Cartesian.simple_factory for a list of supported options.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rgeo/cartesian/factory.rb', line 29

def initialize(opts = {})
  @has_z = opts[:has_z_coordinate] ? true : false
  @has_m = opts[:has_m_coordinate] ? true : false
  @coordinate_dimension = 2
  @coordinate_dimension += 1 if @has_z
  @coordinate_dimension += 1 if @has_m
  @spatial_dimension = @has_z ? 3 : 2

  coord_sys_info = ImplHelper::Utils.setup_coord_sys(opts[:srid], opts[:coord_sys], opts[:coord_sys_class])
  @coord_sys = coord_sys_info[:coord_sys]
  @srid = coord_sys_info[:srid]

  @buffer_resolution = opts[:buffer_resolution].to_i
  @buffer_resolution = 1 if @buffer_resolution < 1

  wkt_generator = opts[:wkt_generator]
  @wkt_generator =
    case wkt_generator
    when Hash
      WKRep::WKTGenerator.new(wkt_generator)
    else
      WKRep::WKTGenerator.new(convert_case: :upper)
    end
  wkb_generator = opts[:wkb_generator]
  @wkb_generator =
    case wkb_generator
    when Hash
      WKRep::WKBGenerator.new(wkb_generator)
    else
      WKRep::WKBGenerator.new
    end
  wkt_parser = opts[:wkt_parser]
  @wkt_parser =
    case wkt_parser
    when Hash
      WKRep::WKTParser.new(self, wkt_parser)
    else
      WKRep::WKTParser.new(self)
    end
  wkb_parser = opts[:wkb_parser]
  @wkb_parser =
    case wkb_parser
    when Hash
      WKRep::WKBParser.new(self, wkb_parser)
    else
      WKRep::WKBParser.new(self)
    end
end

Instance Attribute Details

#coord_sysObject (readonly)

See RGeo::Feature::Factory#coord_sys



23
24
25
# File 'lib/rgeo/cartesian/factory.rb', line 23

def coord_sys
  @coord_sys
end

#coordinate_dimensionObject (readonly)

Returns the value of attribute coordinate_dimension.



17
18
19
# File 'lib/rgeo/cartesian/factory.rb', line 17

def coordinate_dimension
  @coordinate_dimension
end

#spatial_dimensionObject (readonly)

Returns the value of attribute spatial_dimension.



17
18
19
# File 'lib/rgeo/cartesian/factory.rb', line 17

def spatial_dimension
  @spatial_dimension
end

#sridObject (readonly)

Returns the SRID.



20
21
22
# File 'lib/rgeo/cartesian/factory.rb', line 20

def srid
  @srid
end

Instance Method Details

#collection(elems) ⇒ Object

See RGeo::Feature::Factory#collection



218
219
220
# File 'lib/rgeo/cartesian/factory.rb', line 218

def collection(elems)
  GeometryCollectionImpl.new(self, elems)
end

#encode_with(coder) ⇒ Object

Psych support



130
131
132
133
134
135
136
137
138
139
140
# File 'lib/rgeo/cartesian/factory.rb', line 130

def encode_with(coder) # :nodoc:
  coder["has_z_coordinate"] = @has_z
  coder["has_m_coordinate"] = @has_m
  coder["srid"] = @srid
  coder["buffer_resolution"] = @buffer_resolution
  coder["wkt_generator"] = @wkt_generator.properties
  coder["wkb_generator"] = @wkb_generator.properties
  coder["wkt_parser"] = @wkt_parser.properties
  coder["wkb_parser"] = @wkb_parser.properties
  coder["coord_sys"] = @coord_sys.to_wkt if @coord_sys
end

#eql?(other) ⇒ Boolean Also known as: ==

Equivalence test.

Returns:

  • (Boolean)


80
81
82
83
84
85
# File 'lib/rgeo/cartesian/factory.rb', line 80

def eql?(other)
  other.is_a?(self.class) && @srid == other.srid &&
    @has_z == other.property(:has_z_coordinate) &&
    @has_m == other.property(:has_m_coordinate) &&
    @coord_sys == other.instance_variable_get(:@coord_sys)
end

#generate_wkb(obj) ⇒ Object



244
245
246
# File 'lib/rgeo/cartesian/factory.rb', line 244

def generate_wkb(obj)
  @wkb_generator.generate(obj)
end

#generate_wkt(obj) ⇒ Object



240
241
242
# File 'lib/rgeo/cartesian/factory.rb', line 240

def generate_wkt(obj)
  @wkt_generator.generate(obj)
end

#hashObject

Standard hash code



90
91
92
# File 'lib/rgeo/cartesian/factory.rb', line 90

def hash
  @hash ||= [@srid, @has_z, @has_m, @coord_sys].hash
end

#init_with(coder) ⇒ Object

:nodoc:



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/rgeo/cartesian/factory.rb', line 142

def init_with(coder) # :nodoc:
  cs_class = CoordSys::CONFIG.default_coord_sys_class
  coord_sys = coder["cs"]&.then { |cs| cs_class.create_from_wkt(cs) }

  initialize(
    has_z_coordinate: coder["has_z_coordinate"],
    has_m_coordinate: coder["has_m_coordinate"],
    srid: coder["srid"],
    wkt_generator: symbolize_hash(coder["wkt_generator"]),
    wkb_generator: symbolize_hash(coder["wkb_generator"]),
    wkt_parser: symbolize_hash(coder["wkt_parser"]),
    wkb_parser: symbolize_hash(coder["wkb_parser"]),
    buffer_resolution: coder["buffer_resolution"],
    coord_sys: coord_sys
  )
end

#line(start, stop) ⇒ Object

See RGeo::Feature::Factory#line



200
201
202
# File 'lib/rgeo/cartesian/factory.rb', line 200

def line(start, stop)
  LineImpl.new(self, start, stop)
end

#line_string(points) ⇒ Object

See RGeo::Feature::Factory#line_string



194
195
196
# File 'lib/rgeo/cartesian/factory.rb', line 194

def line_string(points)
  LineStringImpl.new(self, points)
end

#linear_ring(points) ⇒ Object

See RGeo::Feature::Factory#linear_ring



206
207
208
# File 'lib/rgeo/cartesian/factory.rb', line 206

def linear_ring(points)
  LinearRingImpl.new(self, points)
end

#marshal_dumpObject

Marshal support



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/rgeo/cartesian/factory.rb', line 96

def marshal_dump # :nodoc:
  hash_ = {
    "hasz" => @has_z,
    "hasm" => @has_m,
    "srid" => @srid,
    "wktg" => @wkt_generator.properties,
    "wkbg" => @wkb_generator.properties,
    "wktp" => @wkt_parser.properties,
    "wkbp" => @wkb_parser.properties,
    "bufr" => @buffer_resolution
  }
  hash_["cs"] = @coord_sys.to_wkt if @coord_sys
  hash_
end

#marshal_load(data) ⇒ Object

:nodoc:



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/rgeo/cartesian/factory.rb', line 111

def marshal_load(data) # :nodoc:
  cs_class = CoordSys::CONFIG.default_coord_sys_class
  coord_sys = data["cs"]&.then { |cs| cs_class.create_from_wkt(cs) }

  initialize(
    has_z_coordinate: data["hasz"],
    has_m_coordinate: data["hasm"],
    srid: data["srid"],
    wkt_generator: symbolize_hash(data["wktg"]),
    wkb_generator: symbolize_hash(data["wkbg"]),
    wkt_parser: symbolize_hash(data["wktp"]),
    wkb_parser: symbolize_hash(data["wkbp"]),
    buffer_resolution: data["bufr"],
    coord_sys: coord_sys
  )
end

#marshal_wkb_generatorObject



248
249
250
# File 'lib/rgeo/cartesian/factory.rb', line 248

def marshal_wkb_generator
  @marshal_wkb_generator ||= RGeo::WKRep::WKBGenerator.new(type_format: :wkb12)
end

#marshal_wkb_parserObject



252
253
254
# File 'lib/rgeo/cartesian/factory.rb', line 252

def marshal_wkb_parser
  @marshal_wkb_parser ||= RGeo::WKRep::WKBParser.new(self, support_wkb12: true)
end

#multi_line_string(elems) ⇒ Object

See RGeo::Feature::Factory#multi_line_string



230
231
232
# File 'lib/rgeo/cartesian/factory.rb', line 230

def multi_line_string(elems)
  MultiLineStringImpl.new(self, elems)
end

#multi_point(elems) ⇒ Object

See RGeo::Feature::Factory#multi_point



224
225
226
# File 'lib/rgeo/cartesian/factory.rb', line 224

def multi_point(elems)
  MultiPointImpl.new(self, elems)
end

#multi_polygon(elems) ⇒ Object

See RGeo::Feature::Factory#multi_polygon



236
237
238
# File 'lib/rgeo/cartesian/factory.rb', line 236

def multi_polygon(elems)
  MultiPolygonImpl.new(self, elems)
end

#parse_wkb(str) ⇒ Object

See RGeo::Feature::Factory#parse_wkb



182
183
184
# File 'lib/rgeo/cartesian/factory.rb', line 182

def parse_wkb(str)
  @wkb_parser.parse(str)
end

#parse_wkt(str) ⇒ Object

See RGeo::Feature::Factory#parse_wkt



176
177
178
# File 'lib/rgeo/cartesian/factory.rb', line 176

def parse_wkt(str)
  @wkt_parser.parse(str)
end

#point(x, y, *extra) ⇒ Object

See RGeo::Feature::Factory#point



188
189
190
# File 'lib/rgeo/cartesian/factory.rb', line 188

def point(x, y, *extra)
  PointImpl.new(self, x, y, *extra)
end

#polygon(outer_ring, inner_rings = nil) ⇒ Object

See RGeo::Feature::Factory#polygon



212
213
214
# File 'lib/rgeo/cartesian/factory.rb', line 212

def polygon(outer_ring, inner_rings = nil)
  PolygonImpl.new(self, outer_ring, inner_rings)
end

#property(name) ⇒ Object

See RGeo::Feature::Factory#property



161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/rgeo/cartesian/factory.rb', line 161

def property(name)
  case name
  when :has_z_coordinate
    @has_z
  when :has_m_coordinate
    @has_m
  when :buffer_resolution
    @buffer_resolution
  when :is_cartesian
    true
  end
end

#psych_wkt_generatorObject



256
257
258
# File 'lib/rgeo/cartesian/factory.rb', line 256

def psych_wkt_generator
  @psych_wkt_generator ||= RGeo::WKRep::WKTGenerator.new(tag_format: :wkt12)
end

#psych_wkt_parserObject



260
261
262
# File 'lib/rgeo/cartesian/factory.rb', line 260

def psych_wkt_parser
  @psych_wkt_parser ||= RGeo::WKRep::WKTParser.new(self, support_wkt12: true, support_ewkt: true)
end