0

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
  • 2
    I think that this is easy to do using arcpy.da.UpdateCursor() and its @SHAPE token.
    – PolyGeo
    Commented Mar 7, 2017 at 6:54
  • Please edit the question to contain a graphic explaining your meaning.
    – Vince
    Commented Mar 7, 2017 at 9:07

1 Answer 1

0

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]
        polyFeat.updateRow(row)
2
  • 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
    Commented Mar 9, 2017 at 23:16
  • Good point @Paul. my sets are usually smaller so performance hasnt been a concern. Commented Mar 10, 2017 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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