Select to view content in your preferred language

VB formula to python

813
5
Jump to solution
11-21-2018 09:23 AM
PeterVersteeg
Frequent Contributor

Hello,

I am trying to get the tools Tree Points from LAS dataset and NAIP to work in ArcgisPro.

there is a calculate field with the formula "2 * Sqr (([Accum] * %Pixel Size% * %Pixel Size%) /3.14159265)"

how do i get this to work in ArcgisPro with python

Greetings,

Peter

0 Kudos
1 Solution

Accepted Solutions
ArthurCrawford
Esri Contributor

2 * math.sqrt (( !Accum! * %Pixel Size% * %Pixel Size%) / 3.14159265) - this is from the Pro version of Trees from Lidar.

View solution in original post

5 Replies
curtvprice
MVP Esteemed Contributor

I am not familiar with this tool. If it is published somewhere, please provide a link.

It looks like this is in Model Builder (with the model variable %Pixel Size% in it).

This should work okay. I used a code block.

# VBA Calculate Field expression
# "2 * Sqr (([Accum] * %Pixel Size% * %Pixel Size%) /3.14159265)"

# Calculate Field Python expression
f(!Accum!, %Pixel Size%)

# Calculate Field Python code block
import math
def f(accum, pix):
    return 2 * (((accum * pix * pix) / math.pi) ** 2‍‍‍‍‍‍‍‍‍‍)

# Use PYTHON_9.3‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Calculate Field expression in Python

PeterVersteeg
Frequent Contributor

thank you for your help.

this is the tool

https://www.arcgis.com/home/item.html?id=d280e1c023084992b98088d9f14d3252 

i still have a error:

file "<string>", line 1

   f(!Accum!, %pixel size%)

syntax error: invalid systax

i am working in arcgis pro so python 3

DanPatterson_Retired
MVP Emeritus

Are your fields names as such? and is %pixel size% title cased? (%Pixel Size%)? 

curtvprice
MVP Esteemed Contributor

I agree %Pixel Size% would be better as that's what the value field is named in the model.

You also may have to do this to force data type (VB kind of doesn't care)

f(!Accum!, float(%Pixel Size%))

The author of the tool unwisely left his email address so you may want to check with him and see if he any plans to upgrade to Pro. He may want a copy of your model!

0 Kudos
ArthurCrawford
Esri Contributor

2 * math.sqrt (( !Accum! * %Pixel Size% * %Pixel Size%) / 3.14159265) - this is from the Pro version of Trees from Lidar.