Discussion:
[Community] geometry is_valid property in shapely
Michal Seidl
2016-08-19 13:18:00 UTC
Permalink
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
Benjamin Root
2016-08-19 13:59:54 UTC
Permalink
This post might be inappropriate. Click to display it.
Sean Gillies
2016-08-19 14:21:28 UTC
Permalink
Hi Michal,

Shapely does use logging, but this looks like your GEOS library may have
been compiled with GEOS_DEBUG defined, which results in debug messages
printed to stderr. Can you tell me how you installed Shapely and GEOS?
Post by Benjamin Root
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
Post by Michal Seidl
import shapely.validation
shapely.validation.explain_validity(g2)
'Self-intersection[0 0]'
Post by Michal Seidl
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?
Post by Michal Seidl
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.
============
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)
===========
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
http://lists.gispython.org/mailman/listinfo/community
_______________________________________________
Community mailing list
http://lists.gispython.org/mailman/listinfo/community
--
Sean Gillies
Michal Seidl
2016-08-22 08:46:14 UTC
Permalink
Hi,
the GEOS was probably installed with other packages such as
GDAL,Postgis,Qgis I did not install it manually. The output from dpkg

ii libgeos-3.4.2 3.4.2-4ubuntu1
amd64 Geometry engine for Geographic
Information Systems - C++ Library
ii libgeos-c1 3.4.2-4ubuntu1
amd64 Geometry engine for Geographic
Information Systems - C Library

and it is from standard Ubuntu Trusty repository.

The Shapely I install with pip.

Thanks for help Michal
Post by Sean Gillies
Hi Michal,
Shapely does use logging, but this looks like your GEOS library may have
been compiled with GEOS_DEBUG defined, which results in debug messages
printed to stderr. Can you tell me how you installed Shapely and GEOS?
Loading...