rgeo/rgeo-geojson

How can I check element type?

matkoniecz opened this issue · 2 comments

Lets say that I have a geojson file and want to iterate over elements to ensure that only areas are there (no lines).

  geojson_text = File.open(input_geojson_file).read
  geom = RGeo::GeoJSON.decode(geojson_text)
  geom.each do |element|
    puts element
  end

how can I get type of a give element?

element.class gives RGeo::GeoJSON::Feature what is not useful

I see nothing relevant in https://rdoc.info/gems/rgeo-geojson/RGeo/GeoJSON/Feature

@matkoniecz the documentation on feature comparison is in the main repo (https://github.com/rgeo/geo). You are interested in type comparison, which you will find here: https://rdoc.info/gems/rgeo/RGeo/Feature/Type. So in your case you may want to puts element.geometry_type.type_name.

However, there maybe another issue in your case, could you show and example input file to have the full reproduction ? The issue i am refering too is that geojsons that are not geometry at root but within a feature will not be geometries so to speak, you'll have to do element.geometry to access it. We'll be working on that in the next RGeo major to hopefully make it seemless. See more on that in the related issue: rgeo/rgeo#247 (comment).

You may be interested in that example (#34 (comment)) to help on your final goal of filtering on areas.

Hope this help 🙂

Closing for lack of response, feel free to open another issue if there is still a problem, or contribute to the documentation (we have a doc folder on the core repository, and we could consider having an examples folder here).