My overall goal is to answer, "Does this point intersect with this geojson object"
I am attempting to do this with the following code:
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
For a particular geojson object, this blows up with the error: LinearRing failed ring test (RGeo::Error::InvalidGeometry)
However, if I switch to a similar, but slightly different factory, the code works:
# 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
Does anyone have an idea of why this may be? Is my geojson invalid? Am I using the wrong factory to convert geojson to a Geometry?
From the documentation simple_mercator_factory
should support both projection.
One hunch I have is that the geojson was perhaps incorrectly created from an original KMZ file?
Any guidance is greatly appreciated!