【发布时间】:2021-12-18 00:14:54
【问题描述】:
我的总体目标是回答“这个点是否与这个 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 文件错误地创建的?
非常感谢任何指导!
【问题讨论】:
标签: ruby geojson kml wgs84 rgeo