boxTop = circleY + circleRadius
boxBottom = circleY - circleRadius

sCircle = Point(circleX, circleY)
sCircle = sCircle.buffer(circleRadius, 16)

shapePoints = []
pointList = []
for i in range(numberOfPoints):
    x = random.randint(0, gridWidth)
    y = random.randint(0, gridHeight)
    # Add the points to a python list of lists
    pointList.append((x, y))
    # Create a Shapely point object
    iPoint = Point(x, y)
    iPoint.idx = i  # set our custom attribute. (if this doesnt work I have other ways)
    shapePoints.append(iPoint)

    # Add the point to an RTREE index
    # index.add(id=id, (left, bottom, right, top))
    # Note that this would work if the
    RtreeIndex.add(i, (x, y, x, y))

matchingPoints = []
searchBench = time.time()
for idx, point in enumerate(shapePoints):
    if sCircle.contains(point):
        matchingPoints.append(idx)

searchBench = time.time() - searchBench
shapePoints = []

circleRadius = random.randint(500, 1500)
circleX = random.randint(0, gridWidth)
circleY = random.randint(0, gridHeight)

sCircle = Point(circleX, circleY)
sCircle = sCircle.buffer(circleRadius, 16)

pointList = []
for i in range(numberOfPoints):
	x = random.randint(0, gridWidth)
	y = random.randint(0, gridHeight)
	pointList.append((x, y))
	iPoint = Point(x, y)
	iPoint.idx = i # set our custom attribute. (if this doesnt work I have other ways)
	shapePoints.append(iPoint)

matchingPoints = []
searchBench = time.time()
for idx, point in enumerate(shapePoints):
	if sCircle.contains(point):
		matchingPoints.append(idx)

searchBench = time.time() - searchBench

print "There were %d points within the circle [%d, %d] - r[%d]\n" % (len(matchingPoints), circleX, circleY, circleRadius)
print "Calculation Took %s seconds for %s points" % (searchBench, numberOfPoints)
print "Saving Graph to %s" % (filename)

'''
Because shapely api objects are in fact objects we should be able to set
arbitrary properties on the objects. This is useful if you want the shapely
object to relate back to a OBJECT_ID or an arbitrary index that references
the object the geometric point/object corresponds to.
'''

from shapely import *
from shapely.geometry import Point
myPoint = Point(1.2, 3.0)
myPoint.idx = 'custom_idx'
# Performing operations that creates a new object or modifies the object will
# cause your custom attribute to be lost...
circle = myPoint.buffer(3.0, 16)
circle.idx = myPoint.idx
print circle.idx