clarisma / geodesk-py

Fast and storage-efficient spatial database engine for OpenStreetMap data
https://docs.geodesk.com/python
GNU Lesser General Public License v3.0
36 stars 0 forks source link

Creating feature set from features #21

Open osmuser63783 opened 11 months ago

osmuser63783 commented 11 months ago

Suppose I’ve done some filtering that I couldn’t do in Geodesk and GQOL, so I’ve done some version of [a for a in list(areas) if xyz]. Now I want to do an operation on the resulting set that I would know how to do if I had a feature set.

I can’t figure out how to get my list of nodes back into a Features object so I can use contains and other things I can do with feature sets.

There could be many ways to solve my problem.. if there was, for example,

It looks like none of these options exist (yet)? Sorry I may have overlooked something obvious.

clarisma commented 11 months ago

You are correct, these capabilities don't currently exist. We've considered adding them, here are some thoughts:

osmuser63783 commented 11 months ago

Thanks for considering this!

It's true that I can use [ f for f in features if <your condition> ] or (lazy version) filter(<my function>, features). But these return a list and an iterator, respectively. It means I no longer have access to the convenient functions that feature sets have. For example if I want to map the results I can't just do results.map, I have to write a loop; if I want to write to GeoJSON I can't just to results.geojson.save, I have to look up the GeoJSON syntax and write a helper function. This is not the end of the world but it would be more convenient if I was able to do this in one line with something like features.filter(<my function>).map etc.

clarisma commented 11 months ago

Yes, you raised some very good points. I've created two individual enhancement items:

Both have different challenges and limitations, but we should be able to at least implement one of these in the next major release.