Are you looking to suppress the message completely (because I haven't be able to do that), or are you looking to be able to output the message to some place under your control? If it is the latter, you could do the following:
>>> import shapely.validation >>> shapely.validation.explain_validity(g2) 'Self-intersection[0 0]' >>> shapely.validation.explain_validity(g1) 'Valid Geometry' Oddly enouogh, when I rain your example, I didn't get that message printed to my screen (skipping the sys.stderr part). I know this used to be an issue, but maybe it is fixed depending on your version of libgeos_c? The reason why it has been difficult in the past to deal with the message is because it isn't coming from python, it is coming from libgeos_c. Maybe it got fixed? Ben Root P.S. - looking at my version of shapely (v1.3.0), I see in shapely.geos some functions regarding error handlers. Maybe something there could help? On Fri, Aug 19, 2016 at 9:18 AM, Michal Seidl <michal.se...@gmail.com> wrote: > Hello, > I am not sure if it is question about Python itself but I use shapely > 1.5.16 version and I am facing behavior of geometry.is_valid property. > I want to catch is_valid messages but not mix with other stderr. > Redirecting stderr does not help. > > This code: > ============ > > import shapely.wkt > import sys > > s1 = '''POLYGON ((0 0,0 1,2 2,0 0))''' > s2 = '''POLYGON ((0 0,1 1,2 2,0 0))''' > > g1 = shapely.wkt.loads(s1) > g2 = shapely.wkt.loads(s2) > > sys.stderr = open('/is_valid_err.log','w') > > a = g1.is_valid > b = g2.is_valid > > print(a) > print(b) > > Returns: > =========== > > Self-intersection at or near point 0 0 > True > False > > Is there any way to suppress writing to stderr by 'is_valid'? > > Thanks Michal > _______________________________________________ > Community mailing list > Community@lists.gispython.org > http://lists.gispython.org/mailman/listinfo/community >
_______________________________________________ Community mailing list Community@lists.gispython.org http://lists.gispython.org/mailman/listinfo/community