Skip to main content
added 129 characters in body
Source Link
amasephy
  • 1.2k
  • 1
  • 10
  • 21

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[0]

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([[XC[[row[0][0] + (xShift),YC]] row[0][1] + (yShift)]])
with arcpy.da.UpdateCursor(inFC, ["SHAPE@XY"]) as cfeature:
             for row in cfeature:
               cfeature.updateRow([[XC,YC]])

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[0]

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[0][0] + (xShift), row[0][1] + (yShift)]])
added 129 characters in body
Source Link
amasephy
  • 1.2k
  • 1
  • 10
  • 21

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.

EDIT.
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.

with arcpy.da.UpdateCursor(inFC, ["SHAPE@XY"]) as cfeature:
            for row in cfeature:
               cfeature.updateRow([[XC,YC]])

Before Shifting Polygons(What I start with) Before Shift

After Shifting Polygons (What I Want)

After Shift

What I actually get.

What I Get

EDIT 2:

What I get with the shift x, shift y code.

With Shift Code

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.

EDIT.
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.

with arcpy.da.UpdateCursor(inFC, ["SHAPE@XY"]) as cfeature:
            for row in cfeature:
               cfeature.updateRow([[XC,YC]])

Before Shifting Polygons(What I start with) Before Shift

After Shifting Polygons (What I Want)

After Shift

What I actually get.

What I Get

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.

EDIT.
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.

with arcpy.da.UpdateCursor(inFC, ["SHAPE@XY"]) as cfeature:
            for row in cfeature:
               cfeature.updateRow([[XC,YC]])

Before Shifting Polygons(What I start with) Before Shift

After Shifting Polygons (What I Want)

After Shift

What I actually get.

What I Get

EDIT 2:

What I get with the shift x, shift y code.

With Shift Code

added 1108 characters in body
Source Link
amasephy
  • 1.2k
  • 1
  • 10
  • 21

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.

EDIT.
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.

with arcpy.da.UpdateCursor(inFC, ["SHAPE@XY"]) as cfeature:
            for row in cfeature:
               cfeature.updateRow([[XC,YC]])

Before Shifting Polygons(What I start with) Before Shift

After Shifting Polygons (What I Want)

After Shift

What I actually get.

What I Get

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.

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.

EDIT.
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.

with arcpy.da.UpdateCursor(inFC, ["SHAPE@XY"]) as cfeature:
            for row in cfeature:
               cfeature.updateRow([[XC,YC]])

Before Shifting Polygons(What I start with) Before Shift

After Shifting Polygons (What I Want)

After Shift

What I actually get.

What I Get

Source Link
amasephy
  • 1.2k
  • 1
  • 10
  • 21
Loading