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
Decode returns empty geometry collection for non-empty geojson #27
Comments
Would be cool to have this fixed |
Just fixed this on the usage side by defining a geo_factory like this: geo_factory = RGeo::Cartesian.simple_factory(srid: 4326)
RGeo::GeoJSON.decode(geojson_string, geo_factory: geo_factory, json_parser: :json)
=> #<RGeo::Cartesian::GeometryCollectionImpl:0x3fc223fdb428 "GEOMETRYCOLLECTION (MULTIPOLYGON (((9.4834096 48.7080301, 9.4834569 48.7079371, ... |
Well, this didn't really solve the problem. I still can't convert the cartesian factory version to a Geos factory which I need though in order to use methods like it "reproduces the issue for fetching data via GeoJSON" do
geojson_data = HTTP.get("http://polygons.openstreetmap.fr/get_geojson.py?id=51477¶ms=0.010000-0.005000-0.005000").to_s.strip
geo_factory = ::RGeo::Cartesian.preferred_factory(srid: 4326)
geom_collection = RGeo::GeoJSON.decode(geojson_data, geo_factory: geo_factory, json_parser: :json)
germany = geom_collection.first
%w(62518 191645).map do |osm_id| # Karlsruhe, Dresden
geojson_data = HTTP.get("http://polygons.openstreetmap.fr/get_geojson.py?id=#{osm_id}¶ms=0").to_s.strip
geom_collection = RGeo::GeoJSON.decode(geojson_data, geo_factory: geo_factory, json_parser: :json)
expect(geom_collection.is_empty?).to be false
end
end Note that this test includes two regions, one of them (Karlsruhe) working just fine and the other (Dresden) failing. I don't know what the issue is, but it would be great if this could be fixed. My guess is that too big GeoJSON data (like Dresden with >5k points) could to be the problem. |
@Dschee I ran into this same problem using data from Airbnb, and solved it like so: geo_factory = RGeo::Cartesian.simple_factory(uses_lenient_assertions: true)
feature_collection = RGeo::GeoJSON.decode(data, json_parser: :json, geo_factory: geo_factory) I have some areas like Chelsea, NY which don't satisfy the validations that rgeo is performing in https://github.com/rgeo/rgeo/blob/master/lib/rgeo/impl_helper/basic_line_string_methods.rb#L135-L137 I'm not actually sure what the end impact of disabling assertions but seems rgeo is overly strict. The |
@superslau Thank you for sharing your solution. I will consider adding it as a fallback option – broken data should be still better than no data at all. ;) |
Edited |
@Jeehut thanks for the clear and reproducible test ! However, it looks like I'm too late to the party, and now the polygons work. And it seems like indeed @superslau's solution is the way to go, for now. I'm closing this PR in favor |
@BuonOmo Thanks for taking a look at this, but since this is 4 years old, I don't even remember which project I came across this problem. But good to hear that it's probably solved. :) |
When decoding the geojson from this OpenStreetMap region with the following code I receive an empty collection although there's a lot of data:
Would be great to see this fixed! 👍
The text was updated successfully, but these errors were encountered: