This class provides the functionality of serializing a geometry as WKT (well-known text) format. You may also customize the serializer to generate PostGIS EWKT extensions to the output, or to follow the Simple Features Specification 1.2 extensions for Z and M.
To use this class, create an instance with the desired settings and customizations, and call the generate method.
The following options are recognized. These can be passed to the constructor, or set on the object afterwards.
:tag_format
The format for tags. Possible values are :wkt11
, indicating
SFS 1.1 WKT (i.e. no Z or M markers in the tags) but with Z and/or M values
added in if they are present; :wkt11_strict
, indicating SFS
1.1 WKT with Z and M dropped from the output (since WKT strictly does not
support the Z or M dimensions); :ewkt
, indicating the PostGIS
EWKT extensions (i.e. “M” appended to tag names if M but not Z is present);
or :wkt12
, indicating SFS 1.2 WKT tags that indicate the
presence of Z and M in a separate token. Default is :wkt11
.
This option can also be specified as :type_format
.
:emit_ewkt_srid
If true, embed the SRID of the toplevel geometry. Available only if
:tag_format
is :ewkt
. Default is false.
:square_brackets
If true, uses square brackets rather than parentheses. Default is false.
:convert_case
Possible values are :upper
, which changes all letters in the
output to ALL CAPS; :lower
, which changes all letters to lower
case; or nil, indicating no case changes from the default (which is not
specified exactly, but is chosen by the generator to emphasize
readability.) Default is nil.
Create and configure a WKT generator. See the WKTGenerator documentation for the options that can be passed.
# File lib/rgeo/wkrep/wkt_generator.rb, line 86 def initialize(opts_={}) @tag_format = opts_[:tag_format] || opts_[:type_format] || :wkt11 @emit_ewkt_srid = @tag_format == :ewkt ? (opts_[:emit_ewkt_srid] ? true : false) : nil @square_brackets = opts_[:square_brackets] ? true : false @convert_case = opts_[:convert_case] end
Returns the case for output. See WKTGenerator for details.
# File lib/rgeo/wkrep/wkt_generator.rb, line 113 def convert_case @convert_case end
Returns whether SRID is embedded. See WKTGenerator for details.
# File lib/rgeo/wkrep/wkt_generator.rb, line 102 def emit_ewkt_srid? @emit_ewkt_srid end
Generate and return the WKT format for the given geometry object, according to the current settings.
# File lib/rgeo/wkrep/wkt_generator.rb, line 131 def generate(obj_) @begin_bracket = @square_brackets ? '[' : '(' @end_bracket = @square_brackets ? ']' : ')' factory_ = obj_.factory if @tag_format == :wkt11_strict @cur_support_z = nil @cur_support_m = nil else @cur_support_z = factory_.property(:has_z_coordinate) @cur_support_m = factory_.property(:has_m_coordinate) end str_ = _generate_feature(obj_, true) if @convert_case == :upper str_.upcase elsif @convert_case == :lower str_.downcase else str_ end end
Returns whether square brackets rather than parens are output. See WKTGenerator for details.
# File lib/rgeo/wkrep/wkt_generator.rb, line 108 def square_brackets? @square_brackets end
Returns the format for type tags. See WKTGenerator for details.
# File lib/rgeo/wkrep/wkt_generator.rb, line 96 def tag_format @tag_format end