dsjones

Convert centroid to GPIN

Discussion created by dsjones on Aug 25, 2011
Latest reply on Sep 15, 2011 by dsjones
Hello all,

I've been working on converting our VBA code for GPIN calculation to python.  I can create a single instance GPIN via python, though really inelegant, but processing more than one is causing me a problem. I've created X and Y fields in our Feature Class. 

Our original code, used in Field Calculator, is:

Dim dblX As Double
Dim dblY As Double
Dim strX As String
Dim strY As String
Dim strGPIN As String
Dim pArea As IArea
Set pArea = [Shape]
dblX = pArea.Centroid.X
dblY = pArea.Centroid.Y
strX = CStr(dblX)
strY = CStr(dblY)
strGPIN = Mid(strX,3,1)+Mid(strY,2,1)+Mid(strX,4,1)+Mid(strY,3,1)+"-"+Mid(strX,5,1)+Mid(strY,4,1)+"-"+Mid(strX,6,1)+Mid(strY,5,1)+Mid(strX,7,1)+Mid(strY,6,1)

My solution, so far, is:

import arcpy
from arcpy import env
import os

env.workspace=r"***\Default.gdb"
#set local variables
inFeatures = "FeatureClass"
XCentroid="xCentroid"
YCentroid="yCentroid"
tableField="GPIN2"
#Load values into Variables
scurfc=arcpy.SearchCursor(inFeatures)
for sf in scurfc:
X=sf.getValue(XCentroid)
strX=repr(X)
Y=sf.getValue(YCentroid)
strY=repr(Y)
GPIN=(strX[2:3]+strY[1:2]+strX[3:4]+strY[2:3]+"-"+strX[4:5]+strY[3:4]+"-"+strX[5:6]+strY[4:5]+strX[6:7]+strY[5:6])

#Delete variables
del tableField, scurfc, X, Y, strX, strY, XCentroid, YCentroid, GPIN

I have tried the CalculateField_management route, but it fails because my GPIN variable isn't a SQL statement.  Can anyone give me a push in the right direction?  The online code examples do not reflect a SearchCursor and an UpdateCursor function in the same listing.


Thanks in advance

Outcomes