PythonAnywhere Forums

Shapely: Option to Turn off Intersection Warnings!

Hi All,

I’m using shapely in Python (3.6) running afffinity.transform many times where I expect intersections. Now, the “Self-intersection at or near point x y” warning is filling up my console unnecessarily. I tried blocking printing (which only stopped my print statements and not Shapely’s) and suppressing warnings (both snippets below) with no luck. Is there any way to stop Shapely from printing warnings to the console?

# Stop all printing
def blockPrint():
sys.stdout = open(os.devnull, w);

# Re-enable printing
def enablePrint():
sys.stdout = sys.__stdout__;

with warnings.catch_warnings():
warnings.simplefilter(ignore)
blockPrint()
p_i = shapely.affinity.translate(p_i, xoff=0, yoff=-2, zoff=0.0)
enablePrint()

There's some info here https://github.com/Toblerity/Shapely/issues/447 that might be helpful depending on the version you're using.

I'm glad someone else has seen this problem (https://xkcd.com/979/); now this begs the question, how do I disable INFO printing?

There's a code segment on that page that shows how.

I'm not sure how to de-awkward that level of not seeing something obvious, so.... thanks!

(I had scrolled right past it to the bottom then concluded it didn't exist, thanks again!)