Changing the centroid of a geometry object

282
1
10-08-2012 06:52 AM
ChrisMathers
Occasional Contributor III
Whats the easiest way to move one geometry to the center of another geometry? That attribute is read only. Im generating polygons and writing them out to a row in a script. Right now the first point of my geometry object is the centroid of a parcel which means the drawings intersect the correct parcel but are not centered on it. I just tried adding the difference between the parcel centroid and the geometry centroid but while that moved the new geometry it didnt move it to the centroid as
I had hoped. Below is what I tried, parcelLookup is a nested dictionary that has all of the parcel numbers with their centroids.

def addGeometry(inGeometry,parcelID,buildingNum,row):     diffX = (parcelLookup[parcelID]['x'] - arcpy.Geometry('polygon',inGeometry).centroid.X)     diffY = (parcelLookup[parcelID]['y'] - arcpy.Geometry('polygon',inGeometry).centroid.Y)     for i in range(0,inGeometry.count):         oldPoint = inGeometry.getObject(i)         newPoint = arcpy.Point(oldPoint.X + diffX, oldPoint.Y + diffY)         inGeometry.replace(i,newPoint)     row.shape = arcpy.Geometry('polygon',inGeometry)     row.PID = parcelID     row.Id = buildingNum     rows.insertRow(row)


Edit: I was subtracting the centroid of the parcel from the centroid of the geometry. Thats backwards. Subtracting the geometry from the parcel is the right order. Cursed be all typos.
Tags (2)
0 Kudos
1 Reply
nimitz
by
Occasional Contributor
Chris,
I'm trying to do something similar to what you're doing, BUT I just need to create a point shapefile from the centroid of a grid index I already created.
I'm trying to "copy" some of your example code in the python window, but the syntax error keeps popping up.

I guess, you did this in PYTHON IDLE environment. But, does the parcel layer need to be existing. I'm using my existing grid I created, but the syntax is messing me up.

Thanks for any help
0 Kudos