Select to view content in your preferred language

Need help with simple translation (VBA -> Pyhton)

948
2
07-16-2012 12:44 PM
JordanWalker
New Contributor
Hello,

I need help from someone to translate a small piece of code from VBA to Phython, due to the fact that the company I am working for has upgraded from ArcGIS 9.3.1 to 10.0 and VBA is no longer supported.  The code block is as follows:



static x0 as double, y0 as double
dim pPoint as IPoint
set pPoint = [Shape]

x = pPoint.X
y = pPoint.Y
d = sqr((x-x0)^2 + (y-y0)^2)
x0 = x
y0= y


This is used with the calculate field tool inside model builder and as far as I can tell retrieves info about two points and calculates the difference in distance between them. I have attempted a few translations on my own with little success using !shape.firstpoint.x!, !shape.firstpoint.y!

Unfortunately my knowledge is lacking and I need some assistance.  If you are able to help, that would be greatly appreciated!

Thanks,

Jordan
Tags (2)
0 Kudos
2 Replies
MathewCoyle
Honored Contributor
Are they multipart features? You may need to strip out each part first to access the X,Y geometry. If you are translating anyways, I would suggest using cursors instead of field calculator.

Also, VBA is supported in 10.0 still, you just need to authorize the VBA license. It's a good idea to start switching though, since 10.1 will be the last version you can even use VBA from what I understand; after which it will be fully deprecated.
0 Kudos
JordanWalker
New Contributor
They are point files with thousands of GPS fixes from cattle collars.  However, I think I may be onto something with the following:

def calc_distance(shape, x0, y0):
    point = shape.getPart(0)
    X = point.X
    Y = point.Y
    d = math.sqrt(pow(X-x0,2) + pow(Y-y0,2))
    return d


Expression:

calc_distance(!SHAPE!, 0, 0)


I will try it out today.
0 Kudos