def isPolyValid(polypoints, output=True):
    #-- Number of points of the polygon (including the doubled first/last point)
    npolypoints = len(polypoints)
    #-- Assume that it is valid, and try to disprove the assumption
    valid = True
    #-- Check if last point equal
    if polypoints[0] != polypoints[-1]:
        if output:
            print "\t\tA degenerate polygon. First and last points do not match."
        valid = False
    #-- Check if it has at least three points
    if npolypoints < 4: #-- Four because the first point is doubled as the last one in the ring
        if output:
            print "\t\tA degenerate polygon. The number of points is smaller than 3."
        valid = False
    #-- Check if the points are planar
    if not isPolyPlanar(polypoints):
        if output:
            print "\t\tA degenerate polygon. The points are not planar."
        valid = False
    #-- Check if some of the points are repeating
    for i in range (1, npolypoints):
        if polypoints[i] == polypoints[i-1]:
            if output:
                print "\t\tA degenerate polygon. There are identical points."
            valid = False
    #-- Check if the polygon does not have self-intersections
    #-- Disabled, something doesn't work here, will work on this later.
    #if not isPolySimple(polypoints):
    #    print "A degenerate polygon. The edges are intersecting."
    #    valid = False
    return valid
Checks if a polygon is valid. Second option is to supress output.
dataset/ETHPy150Open tudelft3d/CityGML2OBJs/polygon3dmodule.py/isPolyValid