class GeoRuby::SimpleFeatures::EWKBParser
Parses EWKB 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 ewkb_parser = EWKBParser::new(factory) ewkb_parser.parse(<EWKB String>) geometry = @factory.geometry
You can also use directly the static method GeoRuby::SimpleFeatures::Geometry.from_ewkb
Public Class Methods
new(factory)
click to toggle source
# File lib/geo_ruby/simple_features/ewkb_parser.rb, line 28 def initialize(factory) @factory = factory @parse_options ={ 1 => method(:parse_point), 2 => method(:parse_line_string), 3 => method(:parse_polygon), 4 => method(:parse_multi_point), 5 => method(:parse_multi_line_string), 6 => method(:parse_multi_polygon), 7 => method(:parse_geometry_collection) } end
Public Instance Methods
parse(ewkb)
click to toggle source
Parses the ewkb string passed as argument and notifies the factory of events
# File lib/geo_ruby/simple_features/ewkb_parser.rb, line 42 def parse(ewkb) @factory.reset @unpack_structure=UnpackStructure::new(ewkb) @with_z = false @with_m = false parse_geometry @unpack_structure.done @srid=nil end
Private Instance Methods
parse_geometry()
click to toggle source
# File lib/geo_ruby/simple_features/ewkb_parser.rb, line 53 def parse_geometry @unpack_structure.endianness=@unpack_structure.read_byte @geometry_type = @unpack_structure.read_uint if (@geometry_type & Z_MASK) != 0 @with_z=true @geometry_type = @geometry_type & ~Z_MASK end if (@geometry_type & M_MASK) != 0 @with_m=true @geometry_type = @geometry_type & ~M_MASK end if (@geometry_type & SRID_MASK) != 0 @srid = @unpack_structure.read_uint @geometry_type = @geometry_type & ~SRID_MASK else #to manage multi geometries : the srid is not present in sub_geometries, therefore we take the srid of the parent ; if it is the root, we take the default srid @srid= @srid || DEFAULT_SRID end if @parse_options.has_key? @geometry_type @parse_options[@geometry_type].call else raise EWKBFormatError::new("Unknown geometry type") end end
parse_geometry_collection()
click to toggle source
# File lib/geo_ruby/simple_features/ewkb_parser.rb, line 80 def parse_geometry_collection parse_multi_geometries(GeometryCollection) end
parse_line_string()
click to toggle source
# File lib/geo_ruby/simple_features/ewkb_parser.rb, line 114 def parse_line_string parse_point_list(LineString) end
parse_linear_ring()
click to toggle source
# File lib/geo_ruby/simple_features/ewkb_parser.rb, line 110 def parse_linear_ring parse_point_list(LinearRing) end
parse_multi_geometries(geometry_type)
click to toggle source
# File lib/geo_ruby/simple_features/ewkb_parser.rb, line 96 def parse_multi_geometries(geometry_type) @factory.begin_geometry(geometry_type,@srid) num_geometries = @unpack_structure.read_uint 1.upto(num_geometries) { parse_geometry } @factory.end_geometry(@with_z,@with_m) end
parse_multi_line_string()
click to toggle source
# File lib/geo_ruby/simple_features/ewkb_parser.rb, line 88 def parse_multi_line_string parse_multi_geometries(MultiLineString) end
parse_multi_point()
click to toggle source
# File lib/geo_ruby/simple_features/ewkb_parser.rb, line 92 def parse_multi_point parse_multi_geometries(MultiPoint) end
parse_multi_polygon()
click to toggle source
# File lib/geo_ruby/simple_features/ewkb_parser.rb, line 84 def parse_multi_polygon parse_multi_geometries(MultiPolygon) end
parse_point()
click to toggle source
# File lib/geo_ruby/simple_features/ewkb_parser.rb, line 126 def parse_point @factory.begin_geometry(Point,@srid) x = @unpack_structure.read_double y = @unpack_structure.read_double if ! (@with_z or @with_m) #most common case probably @factory.add_point_x_y(x,y) elsif @with_m and @with_z z = @unpack_structure.read_double m = @unpack_structure.read_double @factory.add_point_x_y_z_m(x,y,z,m) elsif @with_z z = @unpack_structure.read_double @factory.add_point_x_y_z(x,y,z) else m = @unpack_structure.read_double @factory.add_point_x_y_m(x,y,m) end @factory.end_geometry(@with_z,@with_m) end
parse_point_list(geometry_type)
click to toggle source
used to parse line_strings and linear_rings
# File lib/geo_ruby/simple_features/ewkb_parser.rb, line 119 def parse_point_list(geometry_type) @factory.begin_geometry(geometry_type,@srid) num_points = @unpack_structure.read_uint 1.upto(num_points) {parse_point} @factory.end_geometry(@with_z,@with_m) end
parse_polygon()
click to toggle source
# File lib/geo_ruby/simple_features/ewkb_parser.rb, line 103 def parse_polygon @factory.begin_geometry(Polygon,@srid) num_linear_rings = @unpack_structure.read_uint 1.upto(num_linear_rings) {parse_linear_ring} @factory.end_geometry(@with_z,@with_m) end