Select to view content in your preferred language

.PYT sample success anyone?

1626
5
10-12-2011 01:59 PM
KevinBell
Deactivated User
http://resourcesbeta.arcgis.com/en/help/main/10.1/index.html#//001500000022000000.htm

I copied the code from this page into notepad, changed the .txt to .pyt and clicked it in the catalog but it does nothing.  It looks like a toolbox with a red X.
Tags (2)
0 Kudos
5 Replies
MoragHawkins
Emerging Contributor
Cannot try this out just now, but looks like it is missing the following code in the copy/paste section
class Toolbox:
    def __init__(self):
        self.alias  = "sinuosity"
        self.label =  "Sinuosity toolbox"
        self.description = ""

        # List of tool classes associated with this toolbox
        self.tools = [CalculateSinuosity]

See python toolbox template - http://resourcesbeta.arcgis.com/en/help/main/10.1/index.html#/The_Python_toolbox_template/0015000000...

I am also not too sure why it is explicitly stating PYTHON_9.3 for the expression
0 Kudos
KevinBell
Deactivated User
silly me. That did the trick.  Thanks!

I really like where this is going!
0 Kudos
MoragHawkins
Emerging Contributor
Has anyone logged this via that page feedback thingy, am happy to do so if not.
0 Kudos
KevinBell
Deactivated User
Has anyone logged this via that page feedback thingy, am happy to do so if not.


I just did. thanks.
0 Kudos
HarryBowman
Deactivated User
"Sinuosity measures the amount that a river meanders within its valley, calculated by dividing total stream length by valley length."

Am I wrong in saying the function is returning the inverse of sinuousity? It looks like that to me.

def getSinuosity(shape):
    length = shape.length
    d = math.sqrt((shape.firstPoint.X - shape.lastPoint.X) ** 2 +
                  (shape.firstPoint.Y - shape.lastPoint.Y) ** 2)
    return d/length
0 Kudos