RGeo / GeoJSON / LinearRing 环测试失败问题 / EPSG 3857 与 EPSG:4326

Issue with RGeo / GeoJSON / LinearRing failed ring test / EPSG 3857 vs EPSG: 4326

我的总体目标是回答“这个点是否与这个 geojson 对象相交”

我正在尝试使用以下代码执行此操作:

boundaries = {...} # geojson object
point = RGeo::Geographic.simple_mercator_factory.point(input_longitude, input_lat)
# this is the line that throws an error: 
feature_collection = RGeo::GeoJSON.decode(boundaries, geo_factory: RGeo::Geographic.simple_mercator_factory)
feature_collection.each do |feature|
  if feature.geometry.intersects?(point)
    return true
  end
end

对于特定的 geojson 对象,这会引发错误:LinearRing failed ring test (RGeo::Error::InvalidGeometry)

但是,如果我切换到一个类似但略有不同的工厂,则代码有效:

# slightly different factory 
factory = RGeo::Geographic.projected_factory(projection_proj4: "EPSG:4326", projection_srid: 4326)
boundaries = {...} # geojson object
point = factory.point(input_longitude, input_lat)
# no error this time! 
feature_collection = RGeo::GeoJSON.decode(boundaries, geo_factory: factory)
feature_collection.each do |feature|
  if feature.geometry.intersects?(point)
    return true
  end
end

有人知道为什么会这样吗?我的 geojson 无效吗?我是否使用了错误的工厂将 geojson 转换为 Geometry?

来自the documentation simple_mercator_factory应该支持两种投影。

我的预感是 geojson 可能是从原始 KMZ 文件错误创建的?

非常感谢任何指导!

更新:2021-11-05

我已经创建了一个拉取请求来解决这个问题。参见 #278

原版POST

我遇到了同样的问题,我创建了以下猴子补丁。我本来打算提出一个关于解决这个问题的拉取请求,但他们正在改造 gem,所以我想等待。

我从我的项目中提取了这个,所以它应该可以作为替代品。

# Monkey patch for issues with lenient assertions for RGeo.
#
# /lib/extensions/rgeo/factory.rb
#
# ruby '2.5.3'
# gem 'rails', '5.2.4.6'
# gem 'rgeo', '2.1.1'
#
# This will allow:
#   factory = RGeo::Geographic.simple_mercator_factory(uses_lenient_assertions: true, lenient_multi_polygon_assertions: true)
#   factory.set_property(:uses_lenient_assertions, true)
#
module RGeo
  module Geographic
    class Factory
      def set_property(prop, value)
        case prop
          when :has_z_coordinate
            @support_z = value
          when :has_m_coordinate
            @support_m = value
          when :uses_lenient_assertions
            @lenient_assertions = value
          when :buffer_resolution
            @buffer_resolution = value
          when :is_geographic
            value
        end
      end
    end
  end
end