Module: RGeo::Feature::FactoryGenerator

Defined in:
lib/rgeo/feature/factory_generator.rb

Overview

A FactoryGenerator is a callable object (usually a Proc) that takes a configuration as a hash and returns a factory. These are often used, e.g., by parsers to determine what factory the parsed geometry should have.

See the call method for a list of common configuration parameters. Different generators will support different parameters. There is no mechanism defined to reflect on the parameters understood by a factory generator.

Many of the implementations provide a factory method for creating factories. For example, RGeo::Cartesian.preferred_factory can be called to create a factory using the preferred Cartesian implementation. Thus, to get a corresponding factory generator, you can use the method method. e.g.

factory_generator = ::RGeo::Cartesian.method(:preferred_factory)

FactoryGenerator is defined as a module and is provided primarily for the sake of documentation. Implementations need not necessarily include this module itself. Therefore, you should not depend on the kind_of? method to determine if an object is a factory generator.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.decorate(delegate_, default_config_ = {}, force_config_ = {}) ⇒ Object

Return a new FactoryGenerator that calls the given delegate, but modifies the configuration passed to it. You can provide defaults for configuration values not explicitly specified, and you can force certain values to override the given configuration.



91
92
93
# File 'lib/rgeo/feature/factory_generator.rb', line 91

def self.decorate(delegate_, default_config_ = {}, force_config_ = {})
  ::Proc.new { |c_| delegate_.call(default_config_.merge(c_).merge(force_config_)) }
end

.single(factory_) ⇒ Object

Return a new FactoryGenerator that always returns the given factory.



82
83
84
# File 'lib/rgeo/feature/factory_generator.rb', line 82

def self.single(factory_)
  ::Proc.new { |_c_| factory_ }
end

Instance Method Details

#call(_config_ = {}) ⇒ Object

Generate a factory given a configuration as a hash.

If the generator does not recognize or does not support a given configuration value, the behavior is usually determined by the :strict configuration element. If strict is set to true, the generator should fail fast by returning nil or raising an exception. If it is set to false, the generator should attempt to do the best it can, even if it means returning a factory that does not match the requested configuration.

Common parameters are as follows. These are intended as a recommendation only. There is no hard requirement for any particular factory generator to support them.

:strict

If true, return nil or raise an exception if any configuration was not recognized or not supportable. Otherwise, if false, the generator should attempt to do its best to return some viable factory, even if it does not strictly match the requested configuration. Default is usually false.

:srid

The SRID for the factory and objects it creates. Default is usually 0.

:proj4

The coordinate system in Proj4 format, either as a CoordSys::Proj4 object or as a string or hash representing the proj4 format. This is usually an optional parameter; the default is usually nil.

:coord_sys

The coordinate system in OGC form, either as a subclass of CoordSys::CS::CoordinateSystem, or as a string in WKT format. This is usually an optional parameter; the default is usually nil.

:srs_database

If provided, look up the Proj4 and OGC coordinate systems from the given database and SRID.

:has_z_coordinate

Support Z coordinates. Default is usually false.

:has_m_coordinate

Support M coordinates. Default is usually false.



75
76
77
# File 'lib/rgeo/feature/factory_generator.rb', line 75

def call(_config_ = {})
  nil
end