Problem with geometry methods - Within/Contains

Discussion created by trungtv on Mar 16, 2011
Latest reply on Mar 17, 2011 by trungtv
Hello everyone,
I am trying to check if a polygon is within a mask, which is another polygon. To do this, I use the method CONTAINS. However, this method seems to be wrong because it returns FALSE but in fact it should be TRUE.
I am attaching here the mask shapefile and below is the code.

def createPolygonCell(intCellsize, leftX, upperY):
    aPoint1 = arcpy.Point()
    aPoint2 = arcpy.Point()
    aPoint3 = arcpy.Point()
    aPoint4 = arcpy.Point()
    aPoint1.X = leftX
    aPoint1.Y = upperY

    aPoint2.X = leftX + intCellsize
    aPoint2.Y = upperY

    aPoint3.X = leftX + intCellsize
    aPoint3.Y = upperY - intCellsize

    aPoint4.X = leftX
    aPoint4.Y = upperY - intCellsize

    array= arcpy.Array()

    aPolygon = arcpy.Polygon(array)

    return aPolygon

rows = arcpy.SearchCursor(inMaskShp)  #inMaskShp is the input mask shapefile attached
row =
inMask = row.getValue("Shape")   #inMask is the first polygon of the inMaskShp

apoly = createPolygonCell(30, 565845, 3881985)
apoly.within(inMask)   #this returns FALSE although it should be TRUE

I do export inMask and apoly to shapefiles to double check whether apoly is within inMask.
Also, the method CONTAINS returns FALSE as well. And it is not correct.

In addition, interestingly, the four corners of the apoly (which is a little square) are within inMask when I use apoint.within(inMask).

Could anyone please shed a light on this (i.e. how to check a poly within another poly)?