Class: RGeo::Geos::Factory
- Inherits:
-
Object
- Object
- RGeo::Geos::Factory
- Includes:
- Feature::Factory::Instance
- Defined in:
- lib/rgeo/geos/factory.rb,
lib/rgeo/geos/impl_additions.rb
Overview
This the GEOS implementation of ::RGeo::Feature::Factory.
Constant Summary collapse
- IMPL_CLASSES =
{ Feature::Point => PointImpl, Feature::LineString => LineStringImpl, Feature::LinearRing => LinearRingImpl, Feature::Line => LineImpl, Feature::GeometryCollection => GeometryCollectionImpl, Feature::MultiPoint => MultiPointImpl, Feature::MultiLineString => MultiLineStringImpl, Feature::MultiPolygon => MultiPolygonImpl, }
Class Method Summary collapse
-
.create(opts_ = {}) ⇒ Object
(also: new)
Create a new factory.
Instance Method Summary collapse
-
#buffer_resolution ⇒ Object
Returns the resolution used by buffer calculations on geometries created by this factory.
-
#collection(elems_) ⇒ Object
See ::RGeo::Feature::Factory#collection.
-
#coord_sys ⇒ Object
See ::RGeo::Feature::Factory#coord_sys.
-
#eql?(rhs_) ⇒ Boolean
(also: #==)
Factory equivalence test.
-
#inspect ⇒ Object
:nodoc:.
-
#lenient_multi_polygon_assertions? ⇒ Boolean
Returns true if this factory is lenient with MultiPolygon assertions.
-
#line(start_, end_) ⇒ 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.
-
#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.
-
#override_cast(original_, ntype_, flags_) ⇒ Object
See ::RGeo::Feature::Factory#override_cast.
-
#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.
-
#proj4 ⇒ Object
See ::RGeo::Feature::Factory#proj4.
-
#property(name_) ⇒ Object
See ::RGeo::Feature::Factory#property.
-
#srid ⇒ Object
Returns the SRID of geometries created by this factory.
Class Method Details
.create(opts_ = {}) ⇒ Object Also known as: new
Create a new factory. Returns nil if the GEOS implementation is not supported.
See ::RGeo::Geos::factory for a list of supported options.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rgeo/geos/factory.rb', line 58 def create(opts_={}) return nil unless respond_to?(:_create) flags_ = 0 flags_ |= 1 if opts_[:lenient_multi_polygon_assertions] flags_ |= 2 if opts_[:has_z_coordinate] flags_ |= 4 if opts_[:has_m_coordinate] if flags_ & 6 == 6 raise Error::UnsupportedOperation, "GEOS cannot support both Z and M coordinates at the same time." end buffer_resolution_ = opts_[:buffer_resolution].to_i buffer_resolution_ = 1 if buffer_resolution_ < 1 srid_ = opts_[:srid] proj4_ = opts_[:proj4] if CoordSys::Proj4.supported? if proj4_.kind_of?(::String) || proj4_.kind_of?(::Hash) proj4_ = CoordSys::Proj4.create(proj4_) end else proj4_ = nil end coord_sys_ = opts_[:coord_sys] if coord_sys_.kind_of?(::String) coord_sys_ = CoordSys::CS.create_from_wkt(coord_sys_) rescue nil 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_ result_ = _create(flags_, srid_.to_i, buffer_resolution_) result_.instance_variable_set(:@proj4, proj4_) result_.instance_variable_set(:@coord_sys, coord_sys_) result_ end |
Instance Method Details
#buffer_resolution ⇒ Object
Returns the resolution used by buffer calculations on geometries created by this factory
124 125 126 |
# File 'lib/rgeo/geos/factory.rb', line 124 def buffer_resolution _buffer_resolution end |
#collection(elems_) ⇒ Object
See ::RGeo::Feature::Factory#collection
210 211 212 213 |
# File 'lib/rgeo/geos/factory.rb', line 210 def collection(elems_) elems_ = elems_.to_a unless elems_.kind_of?(::Array) GeometryCollectionImpl.create(self, elems_) rescue nil end |
#coord_sys ⇒ Object
See ::RGeo::Feature::Factory#coord_sys
249 250 251 |
# File 'lib/rgeo/geos/factory.rb', line 249 def coord_sys @coord_sys end |
#eql?(rhs_) ⇒ Boolean Also known as: ==
Factory equivalence test.
108 109 110 |
# File 'lib/rgeo/geos/factory.rb', line 108 def eql?(rhs_) rhs_.is_a?(Factory) && rhs_.srid == _srid && rhs_._buffer_resolution == _buffer_resolution && rhs_._flags == _flags && rhs_.proj4 == @proj4 end |
#inspect ⇒ Object
:nodoc:
101 102 103 |
# File 'lib/rgeo/geos/factory.rb', line 101 def inspect # :nodoc: "#<#{self.class}:0x#{object_id.to_s(16)} srid=#{_srid} bufres=#{_buffer_resolution} flags=#{_flags}>" end |
#lenient_multi_polygon_assertions? ⇒ Boolean
Returns true if this factory is lenient with MultiPolygon assertions
131 132 133 |
# File 'lib/rgeo/geos/factory.rb', line 131 def lenient_multi_polygon_assertions? _flags & 0x1 != 0 end |
#line(start_, end_) ⇒ Object
See ::RGeo::Feature::Factory#line
187 188 189 |
# File 'lib/rgeo/geos/factory.rb', line 187 def line(start_, end_) LineImpl.create(self, start_, end_) rescue nil end |
#line_string(points_) ⇒ Object
See ::RGeo::Feature::Factory#line_string
179 180 181 182 |
# File 'lib/rgeo/geos/factory.rb', line 179 def line_string(points_) points_ = points_.to_a unless points_.kind_of?(::Array) LineStringImpl.create(self, points_) rescue nil end |
#linear_ring(points_) ⇒ Object
See ::RGeo::Feature::Factory#linear_ring
194 195 196 197 |
# File 'lib/rgeo/geos/factory.rb', line 194 def linear_ring(points_) points_ = points_.to_a unless points_.kind_of?(::Array) LinearRingImpl.create(self, points_) rescue nil end |
#multi_line_string(elems_) ⇒ Object
See ::RGeo::Feature::Factory#multi_line_string
226 227 228 229 |
# File 'lib/rgeo/geos/factory.rb', line 226 def multi_line_string(elems_) elems_ = elems_.to_a unless elems_.kind_of?(::Array) MultiLineStringImpl.create(self, elems_) rescue nil end |
#multi_point(elems_) ⇒ Object
See ::RGeo::Feature::Factory#multi_point
218 219 220 221 |
# File 'lib/rgeo/geos/factory.rb', line 218 def multi_point(elems_) elems_ = elems_.to_a unless elems_.kind_of?(::Array) MultiPointImpl.create(self, elems_) rescue nil end |
#multi_polygon(elems_) ⇒ Object
See ::RGeo::Feature::Factory#multi_polygon
234 235 236 237 |
# File 'lib/rgeo/geos/factory.rb', line 234 def multi_polygon(elems_) elems_ = elems_.to_a unless elems_.kind_of?(::Array) MultiPolygonImpl.create(self, elems_) rescue nil end |
#override_cast(original_, ntype_, flags_) ⇒ Object
See ::RGeo::Feature::Factory#override_cast
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/rgeo/geos/factory.rb', line 256 def override_cast(original_, ntype_, flags_) return nil unless Geos.supported? keep_subtype_ = flags_[:keep_subtype] force_new_ = flags_[:force_new] project_ = flags_[:project] type_ = original_.geometry_type ntype_ = type_ if keep_subtype_ && type_.include?(ntype_) case original_ when GeometryImpl # Optimization if we're just changing factories, but the # factories are zm-compatible and proj4-compatible. if original_.factory != self && ntype_ == type_ && original_.factory._flags & 0x6 == _flags & 0x6 && (!project_ || original_.factory.proj4 == @proj4) then result_ = original_.dup result_._set_factory(self) return result_ end # LineString conversion optimization. if (original_.factory != self || ntype_ != type_) && original_.factory._flags & 0x6 == _flags & 0x6 && (!project_ || original_.factory.proj4 == @proj4) && type_.subtype_of?(Feature::LineString) && ntype_.subtype_of?(Feature::LineString) then return IMPL_CLASSES[ntype_]._copy_from(self, original_) end when ZMGeometryImpl # Optimization for just removing a coordinate from an otherwise # compatible factory if _flags & 0x6 == 0x2 && self == original_.factory.z_factory return Feature.cast(original_.z_geometry, ntype_, flags_) elsif _flags & 0x6 == 0x4 && self == original_.factory.m_factory return Feature.cast(original_.m_geometry, ntype_, flags_) end end false end |
#parse_wkb(str_) ⇒ Object
See ::RGeo::Feature::Factory#parse_wkb
161 162 163 |
# File 'lib/rgeo/geos/factory.rb', line 161 def parse_wkb(str_) _parse_wkb_impl(str_) end |
#parse_wkt(str_) ⇒ Object
See ::RGeo::Feature::Factory#parse_wkt
154 155 156 |
# File 'lib/rgeo/geos/factory.rb', line 154 def parse_wkt(str_) _parse_wkt_impl(str_) end |
#point(x_, y_, *extra_) ⇒ Object
See ::RGeo::Feature::Factory#point
168 169 170 171 172 173 174 |
# File 'lib/rgeo/geos/factory.rb', line 168 def point(x_, y_, *extra_) if extra_.length > (_flags & 6 == 0 ? 0 : 1) nil else PointImpl.create(self, x_, y_, extra_[0].to_f) rescue nil end end |
#polygon(outer_ring_, inner_rings_ = nil) ⇒ Object
See ::RGeo::Feature::Factory#polygon
202 203 204 205 |
# File 'lib/rgeo/geos/factory.rb', line 202 def polygon(outer_ring_, inner_rings_=nil) inner_rings_ = inner_rings_.to_a unless inner_rings_.kind_of?(::Array) PolygonImpl.create(self, outer_ring_, inner_rings_) rescue nil end |
#proj4 ⇒ Object
See ::RGeo::Feature::Factory#proj4
242 243 244 |
# File 'lib/rgeo/geos/factory.rb', line 242 def proj4 @proj4 end |
#property(name_) ⇒ Object
See ::RGeo::Feature::Factory#property
138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/rgeo/geos/factory.rb', line 138 def property(name_) case name_ when :has_z_coordinate _flags & 0x2 != 0 when :has_m_coordinate _flags & 0x4 != 0 when :is_cartesian true else nil end end |
#srid ⇒ Object
Returns the SRID of geometries created by this factory.
116 117 118 |
# File 'lib/rgeo/geos/factory.rb', line 116 def srid _srid end |