Skip to content

Force use of geos based wkb parsing #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions lib/active_record/connection_adapters/postgis/oid/spatial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down