This the GEOS CAPI implementation of ::RGeo::Feature::Factory.
Create a new factory. Returns nil if the GEOS CAPI implementation is not supported.
See RGeo::Geos.factory for a list of supported options.
# File lib/rgeo/geos/capi_factory.rb, line 58 def create(opts_={}) # Make sure GEOS is available return nil unless respond_to?(:_create) # Get flags to pass to the C extension flags_ = 0 flags_ |= 1 if opts_[:uses_lenient_assertions] || opts_[:lenient_multi_polygon_assertions] || opts_[:uses_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 flags_ |= 8 unless opts_[:auto_prepare] == :disabled # Buffer resolution buffer_resolution_ = opts_[:buffer_resolution].to_i buffer_resolution_ = 1 if buffer_resolution_ < 1 # Interpret the generator options wkt_generator_ = opts_[:wkt_generator] case wkt_generator_ when :geos wkt_generator_ = nil 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 :geos wkb_generator_ = nil when ::Hash wkb_generator_ = WKRep::WKBGenerator.new(wkb_generator_) else wkb_generator_ = WKRep::WKBGenerator.new end # Coordinate system (srid, proj4, and coord_sys) 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_.authority_code if coord_sys_ # Create the factory and set instance variables result_ = _create(flags_, srid_.to_i, buffer_resolution_, wkt_generator_, wkb_generator_, proj4_, coord_sys_) # Interpret parser options wkt_parser_ = opts_[:wkt_parser] case wkt_parser_ when :geos wkt_parser_ = nil when ::Hash wkt_parser_ = WKRep::WKTParser.new(result_, wkt_parser_) else wkt_parser_ = WKRep::WKTParser.new(result_) end wkb_parser_ = opts_[:wkb_parser] case wkb_parser_ when :geos wkb_parser_ = nil when ::Hash wkb_parser_ = WKRep::WKBParser.new(result_, wkb_parser_) else wkb_parser_ = WKRep::WKBParser.new(result_) end result_._set_wkrep_parsers(wkt_parser_, wkb_parser_) # Return the result result_ end
Returns the resolution used by buffer calculations on geometries created by this factory
# File lib/rgeo/geos/capi_factory.rb, line 294 def buffer_resolution _buffer_resolution end
See RGeo::Feature::Factory#collection
# File lib/rgeo/geos/capi_factory.rb, line 394 def collection(elems_) elems_ = elems_.to_a unless elems_.kind_of?(::Array) CAPIGeometryCollectionImpl.create(self, elems_) rescue nil end
See RGeo::Feature::Factory#coord_sys
# File lib/rgeo/geos/capi_factory.rb, line 433 def coord_sys _coord_sys end
Factory equivalence test.
# File lib/rgeo/geos/capi_factory.rb, line 162 def eql?(rhs_) rhs_.is_a?(CAPIFactory) && rhs_.srid == _srid && rhs_._buffer_resolution == _buffer_resolution && rhs_._flags == _flags && rhs_.proj4 == _proj4 end
Standard hash code
# File lib/rgeo/geos/capi_factory.rb, line 172 def hash @hash ||= [_srid, _buffer_resolution, _flags, _proj4].hash end
Standard object inspection output
# File lib/rgeo/geos/capi_factory.rb, line 155 def inspect "#<#{self.class}:0x#{object_id.to_s(16)} srid=#{_srid} bufres=#{_buffer_resolution} flags=#{_flags}>" end
Returns true if this factory is lenient with MultiPolygon assertions
# File lib/rgeo/geos/capi_factory.rb, line 301 def lenient_multi_polygon_assertions? _flags & 0x1 != 0 end
See RGeo::Feature::Factory#line
# File lib/rgeo/geos/capi_factory.rb, line 371 def line(start_, end_) CAPILineImpl.create(self, start_, end_) rescue nil end
See RGeo::Feature::Factory#line_string
# File lib/rgeo/geos/capi_factory.rb, line 363 def line_string(points_) points_ = points_.to_a unless points_.kind_of?(::Array) CAPILineStringImpl.create(self, points_) rescue nil end
See RGeo::Feature::Factory#linear_ring
# File lib/rgeo/geos/capi_factory.rb, line 378 def linear_ring(points_) points_ = points_.to_a unless points_.kind_of?(::Array) CAPILinearRingImpl.create(self, points_) rescue nil end
See RGeo::Feature::Factory#multi_line_string
# File lib/rgeo/geos/capi_factory.rb, line 410 def multi_line_string(elems_) elems_ = elems_.to_a unless elems_.kind_of?(::Array) CAPIMultiLineStringImpl.create(self, elems_) rescue nil end
See RGeo::Feature::Factory#multi_point
# File lib/rgeo/geos/capi_factory.rb, line 402 def multi_point(elems_) elems_ = elems_.to_a unless elems_.kind_of?(::Array) CAPIMultiPointImpl.create(self, elems_) rescue nil end
See RGeo::Feature::Factory#multi_polygon
# File lib/rgeo/geos/capi_factory.rb, line 418 def multi_polygon(elems_) elems_ = elems_.to_a unless elems_.kind_of?(::Array) CAPIMultiPolygonImpl.create(self, elems_) rescue nil end
See RGeo::Feature::Factory#override_cast
# File lib/rgeo/geos/capi_factory.rb, line 440 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 CAPIGeometryMethods # 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 ZMGeometryMethods # 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
See RGeo::Feature::Factory#parse_wkb
# File lib/rgeo/geos/capi_factory.rb, line 341 def parse_wkb(str_) if (wkb_parser_ = self._wkb_parser) wkb_parser_.parse(str_) else _parse_wkb_impl(str_) end end
See RGeo::Feature::Factory#parse_wkt
# File lib/rgeo/geos/capi_factory.rb, line 330 def parse_wkt(str_) if (wkt_parser_ = self._wkt_parser) wkt_parser_.parse(str_) else _parse_wkt_impl(str_) end end
See RGeo::Feature::Factory#point
# File lib/rgeo/geos/capi_factory.rb, line 352 def point(x_, y_, *extra_) if extra_.length > (_flags & 6 == 0 ? 0 : 1) nil else CAPIPointImpl.create(self, x_, y_, extra_[0].to_f) rescue nil end end
See RGeo::Feature::Factory#polygon
# File lib/rgeo/geos/capi_factory.rb, line 386 def polygon(outer_ring_, inner_rings_=nil) inner_rings_ = inner_rings_.to_a unless inner_rings_.kind_of?(::Array) CAPIPolygonImpl.create(self, outer_ring_, inner_rings_) rescue nil end
See RGeo::Feature::Factory#proj4
# File lib/rgeo/geos/capi_factory.rb, line 426 def proj4 _proj4 end
See RGeo::Feature::Factory#property
# File lib/rgeo/geos/capi_factory.rb, line 308 def property(name_) case name_ when :has_z_coordinate _flags & 0x2 != 0 when :has_m_coordinate _flags & 0x4 != 0 when :is_cartesian true when :uses_lenient_multi_polygon_assertions _flags & 0x1 != 0 when :buffer_resolution _buffer_resolution when :auto_prepare _flags & 0x8 != 0 ? :simple : :disabled else nil end end
Returns the SRID of geometries created by this factory.
# File lib/rgeo/geos/capi_factory.rb, line 286 def srid _srid end