Module: RGeo::Geos
- Defined in:
- lib/rgeo/geos.rb,
lib/rgeo/geos/factory.rb,
lib/rgeo/geos/zm_impl.rb,
lib/rgeo/geos/interface.rb,
lib/rgeo/geos/zm_factory.rb,
lib/rgeo/geos/impl_additions.rb
Overview
The Geos module provides general tools for creating and manipulating a GEOS-backed implementation of the SFS. This is a full implementation of the SFS using a Cartesian coordinate system. It uses the GEOS C++ library to perform most operations, and hence is available only if GEOS version 3.2 or later is installed and accessible when the rgeo gem is installed. RGeo feature calls are translated into appropriate GEOS calls and directed to the library’s C api. RGeo also corrects a few cases of missing or non-standard behavior in GEOS.
This module also provides a namespace for the implementation classes themselves; however, those classes are meant to be opaque and are therefore not documented.
To use the Geos implementation, first obtain a factory using the ::RGeo::Geos::factory method. You may then call any of the standard factory methods on the resulting object.
Defined Under Namespace
Classes: Factory, GeometryImpl, ZMFactory, ZMGeometryCollectionImpl, ZMGeometryImpl, ZMLineStringImpl, ZMMultiLineStringImpl, ZMMultiPolygonImpl, ZMPointImpl, ZMPolygonImpl
Class Method Summary collapse
-
.factory(opts_ = {}) ⇒ Object
Returns a factory for the GEOS implementation.
-
.factory_generator(defaults_ = {}) ⇒ Object
Returns a Feature::FactoryGenerator that creates Geos-backed factories.
-
.is_geos?(object_) ⇒ Boolean
Returns true if the given feature is a GEOS feature, or if the given factory is a GEOS factory.
-
.supported? ⇒ Boolean
Returns true if GEOS implementation is supported.
Class Method Details
.factory(opts_ = {}) ⇒ Object
Returns a factory for the GEOS implementation. Returns nil if the GEOS implementation is not supported.
Note that GEOS does not natively support 4-dimensional data (i.e. both z and m values). However, RGeo’s GEOS wrapper does provide a 4-dimensional factory that utilizes an extra native GEOS object to handle the extra coordinate. Hence, a factory configured with both Z and M support will work, but will be slower than a 2-dimensional or 3-dimensional factory.
Options include:
:lenient_multi_polygon_assertions
-
If set to true, assertion checking on MultiPolygon is disabled. This may speed up creation of MultiPolygon objects, at the expense of not doing the proper checking for OGC MultiPolygon compliance. See RGeo::Feature::MultiPolygon for details on the MultiPolygon assertions. Default is false.
:buffer_resolution
-
The resolution of buffers around geometries created by this factory. This controls the number of line segments used to approximate curves. The default is 1, which causes, for example, the buffer around a point to be approximated by a 4-sided polygon. A resolution of 2 would cause that buffer to be approximated by an 8-sided polygon. The exact behavior for different kinds of buffers is defined by GEOS.
:srid
-
Set the SRID returned by geometries created by this factory. Default is 0.
:proj4
-
The coordinate system in Proj4 format, either as a CoordSys::Proj4 object or as a string or hash representing the proj4 format. Optional.
:coord_sys
-
The coordinate system in OGC form, either as a subclass of CoordSys::CS::CoordinateSystem, or as a string in WKT format. Optional.
:srs_database
-
Optional. If provided, the value should be an implementation of CoordSys::SRSDatabase::Interface. If both this and an SRID are provided, they are used to look up the proj4 and coord_sys objects from a spatial reference system database.
:has_z_coordinate
-
Support
z_coordinate
. Default is false. :has_m_coordinate
-
Support
m_coordinate
. Default is false.
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/rgeo/geos/interface.rb', line 109 def factory(opts_={}) if supported? if opts_[:has_z_coordinate] && opts_[:has_m_coordinate] ZMFactory.new(opts_) else Factory.create(opts_) end else nil end end |
.factory_generator(defaults_ = {}) ⇒ Object
Returns a Feature::FactoryGenerator that creates Geos-backed factories. The given options are used as the default options.
A common case for this is to provide the :srs_database
as a default. Then, the factory generator need only be passed an SRID and it will automatically fetch the appropriate Proj4 and CoordSys objects.
130 131 132 |
# File 'lib/rgeo/geos/interface.rb', line 130 def factory_generator(defaults_={}) ::Proc.new{ |c_| factory(defaults_.merge(c_)) } end |
.is_geos?(object_) ⇒ Boolean
Returns true if the given feature is a GEOS feature, or if the given factory is a GEOS factory.
57 58 59 |
# File 'lib/rgeo/geos/interface.rb', line 57 def is_geos?(object_) supported? && (Factory === object_ || GeometryImpl === object_ || ZMFactory === object_ || ZMGeometryImpl === object_) end |
.supported? ⇒ Boolean
Returns true if GEOS implementation is supported. If this returns false, GEOS features are not available.
49 50 51 |
# File 'lib/rgeo/geos/interface.rb', line 49 def supported? @supported.nil? ? (@supported = Factory.respond_to?(:_create)) : @supported end |