decoder returns nil on valid GeoJson with duplicate point
renemeye opened this issue · 2 comments
If you got two exact same points in a polygon, then the parser returns nil. Is this my fault? Or is it a Bug in the parser?
I parse them with:
RGeo::GeoJSON.decode(geo_json_string, json_parser: :json)
returns nil:
{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[11.64,52.14],[11.65,52.15],[11.65,52.15],[11.63,52.17],[11.64,52.14]]]}}
returns RGeo::GeoJSON::Feature:
{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[11.64,52.14],[11.65,52.15],[11.65,52.16],[11.63,52.17],[11.64,52.14]]]}}
I can confirm that is the current behavior.
This might help: http://postgis.net/docs/ST_RemoveRepeatedPoints.html
In general, it would be nice to validate & clean up polygons with RGeo. What are the best ways to do that?
It seems like this issue has been handled already:
geojson1 = <<~JSON
{"type":"Feature","properties":{},"geometry":{
"type":"Polygon","coordinates":[[
[11.64,52.14],[11.65,52.15],[11.65,52.15],[11.63,52.17],[11.64,52.14]
]]}}
JSON
geojson2 = <<~JSON
{"type":"Feature","properties":{},"geometry":{
"type":"Polygon","coordinates":[[
[11.64,52.14],[11.65,52.15],[11.65,52.16],[11.63,52.17],[11.64,52.14]
]]}}
JSON
[geojson1, geojson2].product([RGeo::Cartesian.simple_factory, RGeo::Cartesian.preferred_factory]).each do |geojson, factory|
polygon = RGeo::GeoJSON.decode(geojson, geo_factory: factory)
p polygon
end
Moreover, you can see that the simple_factory is cleaning polygons, hence I'm closing this issue. Feel free to reference it in a new one if the problem persists.