In the vein of the last post but with polygons this time. Draw it out and see what you think the answers should be.
import arcpy
import os
square = [[0.0,0.0],[0.0,1.0],[1.0,1.0],[1.0,0.0]]
small_square = [[0.1, 0.1],[0.1, 0.9], [0.9,0.9], [0.9,0.1]]
pnt = arcpy.Point()
array = arcpy.Array()
prjFile = os.path.join(arcpy.GetInstallInfo()['InstallDir'],
"Coordinate Systems/Geographic Coordinate Systems/World/WGS 1984.prj")
SR = arcpy.SpatialReference(prjFile)
for a_pnt in square:
pnt.X = a_pnt[0]; pnt.Y = a_pnt[1]
array.add(pnt)
poly1 = arcpy.Polygon(array, SR)
array.removeAll()
for a_pnt in small_square:
pnt.X = a_pnt[0]; pnt.Y = a_pnt[1]
array.add(pnt)
poly2 = arcpy.Polygon(array, SR)
array.removeAll()
pnt1 = arcpy.PointGeometry(arcpy.Point(0.0, 0.0), SR) #note
print "poly 1 contains poly2 :", poly1.contains(poly2)
print "poly 2 contains poly1 :", poly2.contains(poly1)
print "pnt1 within poly1", pnt1.within(poly1)
print "poly1 overlaps pnt1", poly1.overlaps(pnt1)
print "pnt1 touches poly1 ", pnt1.touches(poly1)
No comments:
Post a Comment