I'm trying to shift a set of rectangle polygons over an area of interest (AOI). I thought it would be as easy as setting the SHAPE@TRUECENTROID of the polygon area of interest to the shapefile/featureclass of the rectangles. When multiple polygons are selected in Arcmap, the centroid of the collection of polygons appears.
When attempting to pass the shapefile in to an update cursor, each polygon overlaps over the AOI coordinates instead. Is there a simple, Arcpy, way of sifting the entire set of polygons in a shapefile to be centered over said area of interest? Or put another way, maintain the spatial relationship each rectangle has with one another while shifting the entire set over the AOI.
I should add that I am first rotating the polygons with Arcpy. When running the script it doesn't keep the rotation expected. I would expect setting the centroid would merely shift, not rotate.
Here is the rotate code (this was adapted from another post on here dealing with rotating polygons)
def RotateAxis(AnchorX,AnchorY,inputx,inputy, rAngle): x = inputx - AnchorX y = inputy - AnchorY resultx = ((x * math.cos(rAngle)) + (y * math.sin(rAngle))) + AnchorX resulty = ((x * math.sin(rAngle)) - (y * math.cos(rAngle))) + AnchorY return (resultx,resulty)
I update the geometry from this then finally after each polygon has been rotated I attempt to perform the shift.
XC and YC are the anchor points which are the SHAPE@XY from my AOI.
Updated Code to reflect bottom picture.
memFC = "in_memory\\dissolvedPoly" arcpy.Dissolve_management(inFC, memFC,"PageNumber") with arcpy.da.SearchCursor(memFC, ["SHAPE@XY"]) as oFeature: for row in oFeature: memX, memY = row xShift = float(XC) - float(memX) yShift = float(YC) - float(memY) print "Shift x " + str(xShift) + " ; Shift y " + str(yShift) with arcpy.da.UpdateCursor(inFC, ["SHAPE@XY"]) as cfeature: for row in cfeature: print "Shifting polygons..." print "" print "x = " + str(x), " y = " + str(y) cfeature.updateRow([[row + (xShift), row + (yShift)]])
Before Shifting Polygons(What I start with)
After Shifting Polygons (What I Want)
What I actually get.
What I get with the shift x, shift y code.