Select to view content in your preferred language

Calculate Geometry in Model Builder

36062
20
08-19-2011 01:43 PM
CaseyBentz
Frequent Contributor
I am looking for an easy method, similar to how you do it in ArcMap, to calculate geometry for two fields.  I want to add the lat and long to a point feature class that I have.  The coordinate system of the point feature class is not in geographic coordinates.  Any ideas.

Casey
0 Kudos
20 Replies
MarkEnglish
Deactivated User
Richard:
Do you know the syntax to calculate area in Square Miles?  Thanks in advance for your time...
Mark
0 Kudos
RichardFairhurst
MVP Honored Contributor
Richard:
Do you know the syntax to calculate area in Square Miles?  Thanks in advance for your time...
Mark


!SHAPE.AREA@SQUAREMILES!

Here is the help topic I am consulting on the topic: Using the Calculate Field tool
0 Kudos
DavidTreering
Emerging Contributor

In the Calculate Field tool, use the following python expression.

def find(shape):
  point = shape.getPart(0)
  return point.X

find(!Shape!)


(sub point.Y to get the Y coordinates)


This works beautifully.  Thank you!
0 Kudos
LewSovocool
Deactivated User
!SHAPE.AREA@SQUAREMILES!

Here is the help topic I am consulting on the topic: Using the Calculate Field tool


I'm trying to use the Calculate Field tool to calculate the 3D Length of an interpolated line and I can't seem to figure out the correct syntax for the expression. I've tried !shape.3Dlength@miles!, !shape.length3D@miles!, !shape.3D_length@miles!, and !shape.3D length@miles! but I keep getting an error. Any thoughts?
0 Kudos
RichardFairhurst
MVP Honored Contributor
I'm trying to use the Calculate Field tool to calculate the 3D Length of an interpolated line and I can't seem to figure out the correct syntax for the expression. I've tried !shape.3Dlength@miles!, !shape.length3D@miles!, !shape.3D_length@miles!, and !shape.3D length@miles! but I keep getting an error. Any thoughts?


I think 3D length is not supported using the field calculator (at least not this syntax).  The only listed defined keywords for the shape components are:  type, extent, centroid, firstPoint, lastPoint, area, length, isMultipart, and partCount.

I believe you are limited to using the LENGTH_3D option of the Add Z Information tool.  Then you would have to apply a unit conversion from your base units to miles.

No guarantee this will work, but since the 3D Analyst tool uses the term LENGTH_3D as the keyword and I don't see that variant listed above, you could try: !shape.length_3D@miles!
0 Kudos
LewSovocool
Deactivated User
I think 3D length is not supported using the field calculator (at least not this syntax).  The only listed defined keywords for the shape components are:  type, extent, centroid, firstPoint, lastPoint, area, length, isMultipart, and partCount.

I believe you are limited to using the LENGTH_3D option of the Add Z Information tool.  Then you would have to apply a unit conversion from your base units to miles.

No guarantee this will work, but since the 3D Analyst tool uses the term LENGTH_3D as the keyword and I don't see that variant listed above, you could try: !shape.length_3D@miles!


Thanks Richard, but I think you were correct that 3D length is not supported using the field calculator tool in this context. I tried !shape.length_3D@miles! and received the same error. Thanks for your help though!
0 Kudos
CarolKraemer1
Occasional Contributor
On the same field (Double) of a shapefile, I used both the Calculate Geometry (in attribute table) and Calculate Field (in Model Builder) using the !shape.area@acres! to calculate Acres. The goal is to have Acres calculated within a model. My question is, why would I get slightly different results when using the two methods?

Using Field Calculator (in attribute table) and Calculate Field (in Model Builder):
[ATTACH=CONFIG]32745[/ATTACH]

Using Calculate Geometry (in attribute table):
[ATTACH=CONFIG]32746[/ATTACH]

I know the difference is small but it's still a difference that makes me wonder which is correct.

I'm using ArcMap version 10.2.0.3348 64-bit on Windows 8, in case that helps.

Thank you in advance for any knowledge you share!
-Carol
0 Kudos
RichardFairhurst
MVP Honored Contributor
On the same field (Double) of a shapefile, I used both the Calculate Geometry (in attribute table) and Calculate Field (in Model Builder) using the !shape.area@acres! to calculate Acres. The goal is to have Acres calculated within a model. My question is, why would I get slightly different results when using the two methods?

Using Field Calculator (in attribute table) and Calculate Field (in Model Builder):
[ATTACH=CONFIG]32745[/ATTACH]

Using Calculate Geometry (in attribute table):
[ATTACH=CONFIG]32746[/ATTACH]

I know the difference is small but it's still a difference that makes me wonder which is correct.

I'm using ArcMap version 10.2.0.3348 64-bit on Windows 8, in case that helps.

Thank you in advance for any knowledge you share!
-Carol


It could have to do with any number of factors.  ArcObjects (Geometry Calculator) and Python (Field Calculator) may handle geometry differently, although I would consider that a better candidate if this was a geodatabase with true curves rather than a shapefile with densified curves.  The Spatial Reference may be accessed differently by the two methods.  Are you sure your data frame is using the coordinate system of the polygons you are calculating for the Geometry Calculator?  You could also try specifying the coordinate system explicitly in the environment setting of the Field Calculator tool to see if that made any difference.

It is a black box, so no one but the programmers involved could say for sure how the calculation processes differ and what factors could produce the results you are seeing.  Most likely both results are correct according to the method applied.  Insufficient information exists to determine which method you would prefer to apply or how to remove the discrepancy in the methods.
0 Kudos
CarolKraemer1
Occasional Contributor
It could have to do with any number of factors.  ArcObjects (Geometry Calculator) and Python (Field Calculator) may handle geometry differently, although I would consider that a better candidate if this was a geodatabase with true curves rather than a shapefile with densified curves.  The Spatial Reference may be accessed differently by the two methods.  Are you sure your data frame is using the coordinate system of the polygons you are calculating for the Geometry Calculator?  You could also try specifying the coordinate system explicitly in the environment setting of the Field Calculator tool to see if that made any difference.

It is a black box, so no one but the programmers involved could say for sure how the calculation processes differ and what factors could produce the results you are seeing.  Most likely both results are correct according to the method applied.  Insufficient information exists to determine which method you would prefer to apply or how to remove the discrepancy in the methods.


Thank you for your reply, Richard. Yes, I'm certain about the Spatial References both for the files and the dataframe I'm using. It must be the dreaded black box. I've run across this issue before using things like Raster Calculator and ArcSWAT tools (don't judge, it was during my senior year in college 🙂 ).

The differences won't have an impact on my current task at hand but it would be nice to know in case it would in the future, for me or anyone else.

Happy GISing!
0 Kudos
TonySalomone
Emerging Contributor
Does anyone know if line mid-points  (not centroid) can be programmatically calculated outside of the Calculate Geometry tool in the attribute table?  I need mid XY values calculated as part of a model builder process. 

Any ideas would be great....thanks!
0 Kudos