Skip to content
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

Closed
Jeehut opened this issue Jun 29, 2016 · 8 comments
Closed

Decode returns empty geometry collection for non-empty geojson #27

Jeehut opened this issue Jun 29, 2016 · 8 comments
Labels

Comments

@Jeehut
Copy link

Jeehut commented Jun 29, 2016

When decoding the geojson from this OpenStreetMap region with the following code I receive an empty collection although there's a lot of data:

RGeo::GeoJSON.decode(geojson_string, json_parser: :json)
 => #<RGeo::Geos::CAPIGeometryCollectionImpl:0x3febdfd71198 "GEOMETRYCOLLECTION EMPTY">

Would be great to see this fixed! 👍

@pnull
Copy link

pnull commented Jun 29, 2016

Would be cool to have this fixed

@Jeehut
Copy link
Author

Jeehut commented Jul 5, 2016

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, ...

@Jeehut Jeehut closed this as completed Jul 5, 2016
@Jeehut
Copy link
Author

Jeehut commented Jul 28, 2016

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 contains?. Here's a rspec test case where I can reproduce the problem:

it "reproduces the issue for fetching data via GeoJSON" do
  geojson_data = HTTP.get("http://polygons.openstreetmap.fr/get_geojson.py?id=51477&params=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}&params=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.

@Jeehut Jeehut reopened this Jul 28, 2016
@superslau
Copy link

@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 RGeo::Cartesian::Factory hides all exceptions interestingly

@Jeehut
Copy link
Author

Jeehut commented Aug 15, 2016

@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. ;)

@bradcrawford
Copy link

bradcrawford commented Mar 15, 2017

Edited

@BuonOmo BuonOmo added the bug label Nov 4, 2020
@BuonOmo
Copy link
Member

BuonOmo commented Nov 4, 2020

@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
of #33, because they look like the same issue ! If not, please open a new PR 🙂

@BuonOmo BuonOmo closed this as completed Nov 4, 2020
@Jeehut
Copy link
Author

Jeehut commented Nov 5, 2020

@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. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants