I am using ArcGIS Desktop 10.4.1.

After converting the existing polygons to points, we moved the points to the desired point using Network Analyst.

Here, the FID value of the existing polygon and the moved point SHP file are the same.

I want to use this to move the coordinates of the existing polygon center to the coordinates of the moved point.

The reason for this is that I want to keep the rotation angle of the existing polygon anyway.

If you make the point back to polygon, the angle will be 0 degree in a lump.

The coordinates of the points are obtained with Arcgis's "Add x y coordinates", and I'm wondering how I can change the position of the polygons.

That is, if you define it briefly, I want to move to the coordinate value of the point, not the existing coordinates of the polygon.

Is there a way?

  • 2
    I think that this is easy to do using arcpy.da.UpdateCursor() and its @SHAPE token. – PolyGeo Mar 7 '17 at 6:54
  • Please edit the question to contain a graphic explaining your meaning. – Vince Mar 7 '17 at 9:07

If you just shift x,y of polygon centroid all the rotation should stay the same. I had a script that moved points to corresponding polygon centroid. flipped it around and it seems to work ok.

pointLayer = "pointLyr"
arcpy.MakeFeatureLayer_management(pointFC, pointLayer)
pointShapeName = arcpy.Describe(pointFC).ShapeFieldName
with arcpy.da.UpdateCursor(polyFC, ["SHAPE@XY", "MyID"]) as polyFeat:
    for row in polyFeat:
        #get poly ID and center coords
        polyID = row[1]
        centerpoint = arcpy.Point()
        centerpoint.X = row[0][0]
        centerpoint.Y = row[0][1]

        #get cooresponding point coords
        q = '"MyID" = ' + str(polyID)
        arcpy.SelectLayerByAttribute_management(pointLayer, "NEW_SELECTION", q)
        pointCursor = arcpy.SearchCursor(pointLayer)
        for pnt in pointCursor:
            targetPoint = pnt.getValue(pointShapeName).getPart()
            xTarget = targetPoint.X
            yTarget = targetPoint.Y

        #calculate shift
        xShift = xTarget - centerpoint.X
        yShift = yTarget - centerpoint.Y

        #shift poly centerpoint
        row[0] = [centerpoint.X + xShift, centerpoint.Y + yShift]
  • Nesting a select layer by attribute and search cursor inside a for loop is going to be pretty slow. I'd suggest creating a dictionary of {myID: <shape>} and making calls to that. – Paul Mar 9 '17 at 23:16
  • Good point @Paul. my sets are usually smaller so performance hasnt been a concern. – Michael Nelson Mar 10 '17 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.