0

I generated a buffer using this question: Creating buffer circle x kilometers from point using Python?

I did an intersection with this buffer and a shapefile using:

intersection_origem = shp_geom.intersection(Polygon(buffer_origem))

The "intersection_origem" looks like above: enter image description here

Apparently nothing wrong with it, but I need just the not null values like it's from 2595 to 2597. Is there a "filter" that can do what I need?

I tried the code above but with no success:

for i in range(0,intersection_origem.length):
    if (intersection_origem[i] != ""):
        print(intersection_origem[i])
  • None is the usual Python equivalent of NULL -- Empty string is a valid string with length zero. You should always debug the type of the data when in doubt. – Vince Jun 30 at 2:01
1

Try this:

for i in range(0,intersection_origem.length):
    if intersection_origem[i]:
        print(intersection_origem[i])

empty strings and None both evaluate to false. See here for more info about what is truthy and falsey in Python.

By the way, it is not recommended to iterate through lists the way you are doing in Python. A more "pythonic" way of doing it would be like this:

for intersection in intersection_origem:
    if intersection:
        print(intersection)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.