From 01affe309cd8b275e4a998d1a4d571d08daa8fed Mon Sep 17 00:00:00 2001 From: Tim Neems Date: Sun, 14 Feb 2016 22:53:00 -0500 Subject: [PATCH] Force use of geos based wkb parsing --- .../postgis/oid/spatial.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/active_record/connection_adapters/postgis/oid/spatial.rb b/lib/active_record/connection_adapters/postgis/oid/spatial.rb index 9a292cae..14fd53ba 100644 --- a/lib/active_record/connection_adapters/postgis/oid/spatial.rb +++ b/lib/active_record/connection_adapters/postgis/oid/spatial.rb @@ -86,7 +86,16 @@ def cast_value(value) # convert WKT string into RGeo object def parse_wkt(string) - wkt_parser(string).parse(string) + factory = if spatial_factory.is_a?(::RGeo::Feature::Factory::Instance) + spatial_factory + else + spatial_factory.call(support_ewkb: true, support_ewkt: true) + end + if binary_string?(string) + factory.parse_wkb(string) + else + factory.parse_wkt(string) + end rescue RGeo::Error::ParseError nil end @@ -95,14 +104,6 @@ def binary_string?(string) string[0] == "\x00" || string[0] == "\x01" || string[0, 4] =~ /[0-9a-fA-F]{4}/ end - def wkt_parser(string) - if binary_string?(string) - RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: @srid) - else - RGeo::WKRep::WKTParser.new(spatial_factory, support_ewkt: true, default_srid: @srid) - end - end - def factory_attrs { geo_type: @geo_type.underscore,