Module: OvertureMaps::GeometryParser
- Defined in:
- lib/overture_maps/geometry_parser.rb
Overview
Parses the geometry encodings Overture data shows up in: WKB (binary or hex, from parquet), WKT (from DuckDB text output), and GeoJSON (hash or string). Returns RGeo features on the spherical WGS84 factory.
Class Method Summary collapse
Class Method Details
.factory ⇒ Object
13 14 15 |
# File 'lib/overture_maps/geometry_parser.rb', line 13 def factory @factory ||= RGeo::Geographic.spherical_factory(srid: 4326) end |
.parse(geom) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/overture_maps/geometry_parser.rb', line 17 def parse(geom) return nil if geom.nil? return geom if geom.is_a?(RGeo::Feature::Instance) case geom when Hash RGeo::GeoJSON.decode(geom, geo_factory: factory) when String parse_string(geom) end end |
.parse_string(geom) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/overture_maps/geometry_parser.rb', line 29 def parse_string(geom) stripped = geom.strip if stripped.start_with?("{") RGeo::GeoJSON.decode(stripped, geo_factory: factory) elsif stripped.match?(/\A[A-Za-z]/) factory.parse_wkt(stripped) else # Binary or hex WKB; RGeo's parser auto-detects hex strings. factory.parse_wkb(geom) end end |