def moveGeomToPoint(geometry, x, y): """Returns a geometry whose coordinates are shifted such that the new centroid is located at the coordinates x and y""" # Get the current centroid oldCentroid = geometry.TrueCentroid # Get the delta x and y factors dX = x - oldCentroid.x dY = y - oldCentroid.y # Print details of translation print "Current Centroid: (%.12F, %.12F)" % (oldCentroid.x, oldCentroid.y) print "New Centroid: (%.12F, %.12F)" % (x, y) print "dX, dY: (%.12F, %.12F)" % (dX, dY) # Check if geometry is point first if geometry.type == "point": # Get the existing point object pnt = geometry.GetPart() # Create a new point object and assign to it the new translated coordinates newPnt = gp.CreateObject("Point") newPnt.x = pnt.x + dX newPnt.y = pnt.y + dY # Return the new point instead of going through all the parts return newPnt # Keep track of where we are in the geometry array partnum = 0 partcount = geometry.PartCount # Create a new geometry array -- this is what we are ultimately going to return newGeom = gp.CreateObject("Array") # Loop through all of the parts in the geometry array while partnum < partcount: print "Part " + str(partnum) + ":" part = geometry.GetPart(partnum) # Create a new array just for the part we are currently on newPart = gp.CreateObject("Array") # Get the first vertex of the current part pnt = part.Next() pntcount = 0 # Enter while loop for each vertex while pnt: # Print x,y coordinates of current point and new point oldX = pnt.x oldY = pnt.y newX = oldX + dX newY = oldY + dY print "%.12F, %.12F --> %.12F, %.12F" % (oldX, oldY, newX, newY) # Create a new point object and assign to it the new translated coordinates newPnt = gp.CreateObject("Point") newPnt.x = newX newPnt.y = newY # Add the new point object to the new part array newPart.add(newPnt) pnt = part.Next() pntcount += 1 # If pnt is null, either the part is finished or there is an interior ring if not pnt: pnt = part.Next() if pnt: print "Interior Ring:" # Add the new part to the new geometry array newGeom.add(newPart) partnum += 1 return newGeom
import arcgisscripting global gp gp = arcgisscripting.create(9.3) fc = "c:/temp/geomTest3.shp" rows = gp.UpdateCursor(fc) row = rows.Next() while row: row.shape = moveGeomToPoint(row.shape, 8, -8) rows.updateRow(row) row = rows.Next() del row del rows
Hello,I am working on the same problem. did you by chance resolve this? if so, could you post your solution?...thanks for your time. --Daniel
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.