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

Featureset.Features inconsistent behavior in Python #594

Closed
artemp opened this issue Oct 11, 2011 · 2 comments
Closed

Featureset.Features inconsistent behavior in Python #594

artemp opened this issue Oct 11, 2011 · 2 comments

Comments

@artemp
Copy link
Member

artemp commented Oct 11, 2011

So, I've been functionality of Featureset.Features to try to avoid using the iterator style of getting features at a point on a map, but it appears that this functionality, as it is exposed to Python, is still using an iterator internally and doesn't reset it after you call Featureset.Features for the first time. I've attached a test case that demonstrates that the len() of a feature list changes after checking it once.

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[springmeyer] ya, this is poorly exposed in python. the root issue is that the internal c++ call to a datasources next() is not a standard iterator, so its hard to know how to properly expose.

workaround is pull out a python list once and assign it to a new variable:

{{{
(Pdb) featureset = m.query_map_point(0,10,10)
(Pdb) features = featureset.features
(Pdb) len(features)
1
(Pdb) len(features)
1
}}}

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[tmcw] Okay, after bashing my head against this issue for an hour or two, I realized that I was totally missing why this is actually hard to do.

One possible solution: instead of exposing features as a list, it might be useful to expose features as an object with init exposed. This would make it a bit more similar to built-in iterators like when you can do

{{{
for x in file('blah.txt')
}}}

since actually assigning a name to that iterator and running it twice gives the same behavior as featureset, and running len(file('blah.txt')) correctly states that file doensn't support len.

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

No branches or pull requests

2 participants