Class: GeoRuby::SimpleFeatures::EWKTParser

Inherits:
Object
  • Object
show all
Defined in:
lib/geo_ruby/ewk/ewkt_parser.rb

Overview

Parses EWKT strings and notifies of events (such as the beginning of the definition of geometry, the value of the SRID…) the factory passed as argument to the constructor.

Example

factory = GeometryFactory::new ewkt_parser = EWKTParser::new(factory) ewkt_parser.parse(<EWKT String>) geometry = @factory.geometry

You can also use directly the static method Geometry.from_ewkt

Instance Method Summary collapse

Constructor Details

#initialize(factory) ⇒ EWKTParser

Returns a new instance of EWKTParser.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/geo_ruby/ewk/ewkt_parser.rb', line 19

def initialize(factory)
  @factory = factory
  @parse_options = {
    'POINT' => method(:parse_point),
    'LINESTRING' => method(:parse_line_string),
    'POLYGON' => method(:parse_polygon),
    'MULTIPOINT' => method(:parse_multi_point),
    'MULTILINESTRING' => method(:parse_multi_line_string),
    'MULTIPOLYGON' => method(:parse_multi_polygon),
    'GEOMETRYCOLLECTION' => method(:parse_geometry_collection)
  }
end

Instance Method Details

#parse(ewkt) ⇒ Object

Parses the ewkt string passed as argument and notifies the factory of events



33
34
35
36
37
38
39
40
41
# File 'lib/geo_ruby/ewk/ewkt_parser.rb', line 33

def parse(ewkt)
  @factory.reset
  @tokenizer_structure = TokenizerStructure.new(ewkt)
  @with_z = false
  @with_m = false
  @is_3dm = false
  parse_geometry(true)
  @srid = nil
end