def pointInPolygon(pt, poly, bbox=None):
    """Returns `True` if the point is inside the polygon.
    If `bbox` is passed in (as ``(x0,y0,x1,y1)``), that's used for a quick check first.
    Main code adapted from http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
    """
    x, y = pt
    if bbox:
        x0, y0, x1, y1 = bbox
        if not (x0 <= x <= x1) or not (y0 <= y <= y1): return 0
    c = 0
    i = 0
    nvert = len(poly)
    j = nvert-1
    while i < nvert:
        if (((poly[i][1]>y) != (poly[j][1]>y)) and (x < (poly[j][0]-poly[i][0]) * (y-poly[i][1]) / (poly[j][1]-poly[i][1]) + poly[i][0])):
            c = not c
        j = i
        i += 1
    return c