Class: RGeo::Cartesian::Factory
- Inherits:
-
Object
- Object
- RGeo::Cartesian::Factory
- 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
-
#coord_sys ⇒ Object
readonly
See RGeo::Feature::Factory#coord_sys.
-
#proj4 ⇒ Object
readonly
See RGeo::Feature::Factory#proj4.
-
#srid ⇒ Object
readonly
Returns the SRID.
Instance Method Summary collapse
-
#collection(elems) ⇒ Object
See RGeo::Feature::Factory#collection.
-
#encode_with(coder) ⇒ Object
Psych support.
-
#eql?(rhs) ⇒ Boolean
(also: #==)
Equivalence test.
- #generate_wkb(obj) ⇒ Object
- #generate_wkt(obj) ⇒ Object
-
#hash ⇒ Object
Standard hash code.
-
#init_with(coder) ⇒ Object
:nodoc:.
-
#initialize(opts = {}) ⇒ Factory
constructor
Create a new simple cartesian factory.
-
#line(start, stop) ⇒ Object
See RGeo::Feature::Factory#line.
-
#line_string(points) ⇒ Object
See RGeo::Feature::Factory#line_string.
-
#linear_ring(points) ⇒ Object
See RGeo::Feature::Factory#linear_ring.
-
#marshal_dump ⇒ Object
Marshal support.
-
#marshal_load(data) ⇒ Object
:nodoc:.
- #marshal_wkb_generator ⇒ Object
- #marshal_wkb_parser ⇒ Object
-
#multi_line_string(elems) ⇒ Object
See RGeo::Feature::Factory#multi_line_string.
-
#multi_point(elems) ⇒ Object
See RGeo::Feature::Factory#multi_point.
-
#multi_polygon(elems) ⇒ Object
See RGeo::Feature::Factory#multi_polygon.
-
#parse_wkb(str) ⇒ Object
See RGeo::Feature::Factory#parse_wkb.
-
#parse_wkt(str) ⇒ Object
See RGeo::Feature::Factory#parse_wkt.
-
#point(x, y, *extra) ⇒ Object
See RGeo::Feature::Factory#point.
-
#polygon(outer_ring, inner_rings = nil) ⇒ Object
See RGeo::Feature::Factory#polygon.
-
#property(name) ⇒ Object
See RGeo::Feature::Factory#property.
- #psych_wkt_generator ⇒ Object
- #psych_wkt_parser ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Factory
Create a new simple cartesian factory.
See RGeo::Cartesian.simple_factory for a list of supported options.
22 23 24 25 26 27 28 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 77 |
# File 'lib/rgeo/cartesian/factory.rb', line 22 def initialize(opts = {}) @has_z = opts[:has_z_coordinate] ? true : false @has_m = opts[:has_m_coordinate] ? true : false @proj4 = opts[:proj4] if @proj4 && CoordSys.check!(:proj4) if @proj4.is_a?(String) || @proj4.is_a?(Hash) @proj4 = CoordSys::Proj4.create(@proj4) end end srid = opts[:srid] @coord_sys = opts[:coord_sys] if @coord_sys.is_a?(String) @coord_sys = CoordSys::CS.create_from_wkt(@coord_sys) end if (!@proj4 || !@coord_sys) && srid && (db = opts[:srs_database]) entry = db.get(srid.to_i) if entry @proj4 ||= entry.proj4 @coord_sys ||= entry.coord_sys end end srid ||= @coord_sys. if @coord_sys @srid = srid.to_i @lenient_assertions = opts[:uses_lenient_assertions] ? true : false @buffer_resolution = opts[:buffer_resolution].to_i @buffer_resolution = 1 if @buffer_resolution < 1 wkt_generator = opts[:wkt_generator] case wkt_generator when Hash @wkt_generator = WKRep::WKTGenerator.new(wkt_generator) else @wkt_generator = WKRep::WKTGenerator.new(convert_case: :upper) end wkb_generator = opts[:wkb_generator] case wkb_generator when Hash @wkb_generator = WKRep::WKBGenerator.new(wkb_generator) else @wkb_generator = WKRep::WKBGenerator.new end wkt_parser = opts[:wkt_parser] case wkt_parser when Hash @wkt_parser = WKRep::WKTParser.new(self, wkt_parser) else @wkt_parser = WKRep::WKTParser.new(self) end wkb_parser = opts[:wkb_parser] case wkb_parser when Hash @wkb_parser = WKRep::WKBParser.new(self, wkb_parser) else @wkb_parser = WKRep::WKBParser.new(self) end end |
Instance Attribute Details
#coord_sys ⇒ Object (readonly)
See RGeo::Feature::Factory#coord_sys
283 284 285 |
# File 'lib/rgeo/cartesian/factory.rb', line 283 def coord_sys @coord_sys end |
#proj4 ⇒ Object (readonly)
See RGeo::Feature::Factory#proj4
279 280 281 |
# File 'lib/rgeo/cartesian/factory.rb', line 279 def proj4 @proj4 end |
#srid ⇒ Object (readonly)
Returns the SRID.
192 193 194 |
# File 'lib/rgeo/cartesian/factory.rb', line 192 def srid @srid end |
Instance Method Details
#collection(elems) ⇒ Object
See RGeo::Feature::Factory#collection
255 256 257 |
# File 'lib/rgeo/cartesian/factory.rb', line 255 def collection(elems) GeometryCollectionImpl.new(self, elems) end |
#encode_with(coder) ⇒ Object
Psych support
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/rgeo/cartesian/factory.rb', line 143 def encode_with(coder) # :nodoc: coder["has_z_coordinate"] = @has_z coder["has_m_coordinate"] = @has_m coder["srid"] = @srid coder["lenient_assertions"] = @lenient_assertions 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 if @proj4 str = @proj4.original_str || @proj4.canonical_str coder["proj4"] = @proj4.radians? ? { "proj4" => str, "radians" => true } : str end coder["coord_sys"] = @coord_sys.to_wkt if @coord_sys end |
#eql?(rhs) ⇒ Boolean Also known as: ==
Equivalence test.
81 82 83 84 85 86 |
# File 'lib/rgeo/cartesian/factory.rb', line 81 def eql?(rhs) rhs.is_a?(self.class) && @srid == rhs.srid && @has_z == rhs.property(:has_z_coordinate) && @has_m == rhs.property(:has_m_coordinate) && @proj4.eql?(rhs.proj4) end |
#generate_wkb(obj) ⇒ Object
289 290 291 |
# File 'lib/rgeo/cartesian/factory.rb', line 289 def generate_wkb(obj) @wkb_generator.generate(obj) end |
#generate_wkt(obj) ⇒ Object
285 286 287 |
# File 'lib/rgeo/cartesian/factory.rb', line 285 def generate_wkt(obj) @wkt_generator.generate(obj) end |
#hash ⇒ Object
Standard hash code
91 92 93 |
# File 'lib/rgeo/cartesian/factory.rb', line 91 def hash @hash ||= [@srid, @has_z, @has_m, @proj4].hash end |
#init_with(coder) ⇒ Object
:nodoc:
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/rgeo/cartesian/factory.rb', line 160 def init_with(coder) # :nodoc: if (proj4_data = coder["proj4"]) && CoordSys.check!(:proj4) if proj4_data.is_a?(Hash) proj4 = CoordSys::Proj4.create(proj4_data["proj4"], radians: proj4_data["radians"]) else proj4 = CoordSys::Proj4.create(proj4_data.to_s) end else proj4 = nil end if (coord_sys_data = coder["cs"]) coord_sys = CoordSys::CS.create_from_wkt(coord_sys_data.to_s) else coord_sys = nil end 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"]), uses_lenient_assertions: coder["lenient_assertions"], buffer_resolution: coder["buffer_resolution"], proj4: proj4, coord_sys: coord_sys ) end |
#line(start, stop) ⇒ Object
See RGeo::Feature::Factory#line
237 238 239 |
# File 'lib/rgeo/cartesian/factory.rb', line 237 def line(start, stop) LineImpl.new(self, start, stop) end |
#line_string(points) ⇒ Object
See RGeo::Feature::Factory#line_string
231 232 233 |
# File 'lib/rgeo/cartesian/factory.rb', line 231 def line_string(points) LineStringImpl.new(self, points) end |
#linear_ring(points) ⇒ Object
See RGeo::Feature::Factory#linear_ring
243 244 245 |
# File 'lib/rgeo/cartesian/factory.rb', line 243 def linear_ring(points) LinearRingImpl.new(self, points) end |
#marshal_dump ⇒ Object
Marshal support
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rgeo/cartesian/factory.rb', line 97 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, "lena" => @lenient_assertions, "bufr" => @buffer_resolution } hash_["proj4"] = @proj4.marshal_dump if @proj4 hash_["cs"] = @coord_sys.to_wkt if @coord_sys hash_ end |
#marshal_load(data) ⇒ Object
:nodoc:
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/rgeo/cartesian/factory.rb', line 114 def marshal_load(data) # :nodoc: if (proj4_data = data["proj4"]) && CoordSys.check!(:proj4) proj4 = CoordSys::Proj4.allocate proj4.marshal_load(proj4_data) else proj4 = nil end if (coord_sys_data = data["cs"]) coord_sys = CoordSys::CS.create_from_wkt(coord_sys_data) else coord_sys = nil end 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"]), uses_lenient_assertions: data["lena"], buffer_resolution: data["bufr"], proj4: proj4, coord_sys: coord_sys ) end |
#marshal_wkb_generator ⇒ Object
293 294 295 |
# File 'lib/rgeo/cartesian/factory.rb', line 293 def marshal_wkb_generator @marshal_wkb_generator ||= RGeo::WKRep::WKBGenerator.new(type_format: :wkb12) end |
#marshal_wkb_parser ⇒ Object
297 298 299 |
# File 'lib/rgeo/cartesian/factory.rb', line 297 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
267 268 269 |
# File 'lib/rgeo/cartesian/factory.rb', line 267 def multi_line_string(elems) MultiLineStringImpl.new(self, elems) end |
#multi_point(elems) ⇒ Object
See RGeo::Feature::Factory#multi_point
261 262 263 |
# File 'lib/rgeo/cartesian/factory.rb', line 261 def multi_point(elems) MultiPointImpl.new(self, elems) end |
#multi_polygon(elems) ⇒ Object
See RGeo::Feature::Factory#multi_polygon
273 274 275 |
# File 'lib/rgeo/cartesian/factory.rb', line 273 def multi_polygon(elems) MultiPolygonImpl.new(self, elems) end |
#parse_wkb(str) ⇒ Object
See RGeo::Feature::Factory#parse_wkb
219 220 221 |
# File 'lib/rgeo/cartesian/factory.rb', line 219 def parse_wkb(str) @wkb_parser.parse(str) end |
#parse_wkt(str) ⇒ Object
See RGeo::Feature::Factory#parse_wkt
213 214 215 |
# File 'lib/rgeo/cartesian/factory.rb', line 213 def parse_wkt(str) @wkt_parser.parse(str) end |
#point(x, y, *extra) ⇒ Object
See RGeo::Feature::Factory#point
225 226 227 |
# File 'lib/rgeo/cartesian/factory.rb', line 225 def point(x, y, *extra) PointImpl.new(self, x, y, *extra) end |
#polygon(outer_ring, inner_rings = nil) ⇒ Object
See RGeo::Feature::Factory#polygon
249 250 251 |
# File 'lib/rgeo/cartesian/factory.rb', line 249 def polygon(outer_ring, inner_rings = nil) PolygonImpl.new(self, outer_ring, inner_rings) end |
#property(name) ⇒ Object
See RGeo::Feature::Factory#property
196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/rgeo/cartesian/factory.rb', line 196 def property(name) case name when :has_z_coordinate @has_z when :has_m_coordinate @has_m when :uses_lenient_assertions @lenient_assertions when :buffer_resolution @buffer_resolution when :is_cartesian true end end |
#psych_wkt_generator ⇒ Object
301 302 303 |
# File 'lib/rgeo/cartesian/factory.rb', line 301 def psych_wkt_generator @psych_wkt_generator ||= RGeo::WKRep::WKTGenerator.new(tag_format: :wkt12) end |