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

How can I check element type? #51

Closed
matkoniecz opened this issue Feb 22, 2021 · 2 comments
Closed

How can I check element type? #51

matkoniecz opened this issue Feb 22, 2021 · 2 comments

Comments

@matkoniecz
Copy link

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

@BuonOmo
Copy link
Member

BuonOmo commented Feb 27, 2021

@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 🙂

@BuonOmo
Copy link
Member

BuonOmo commented Jun 23, 2021

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

@BuonOmo BuonOmo closed this as completed Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants