Select to view content in your preferred language

How to choose between data frame coordinate or data source coordianate to calculate geometry?

5038
17
07-13-2015 11:54 AM
SaidAkif
Occasional Contributor


Hi

I looked on the web for a way to calculate geometry ("shape.area@hectares!") with an easy way to choose between the data frame coordinate or data source coordiane to complete this thast with arcpy (python). Unfortunatly, I fourd something related to the use or the sursor (updateCursor).

is there an easy way to do so?

Thanks

0 Kudos
17 Replies
SaidAkif
Occasional Contributor

Hi

It is for processing several feature calsses at a time. But the real reason is some time you want to process mutilple feature calsses that have different characteristics as projection. instead of reprojecting and calculating areas for example you have just to base your calculation on the data frame projection which is easier (time and memory reducing)

0 Kudos
XanderBakker
Esri Esteemed Contributor

From a user's perspective, I can imagine that this can be easier.

There is a catch though. If the data has a different projection then the dataframe and no transformation is defined the on-the-fly projection might not be so accurate and will cause errors in the area calculation.

I did a little test:

  • myAREA1: Calculate Geometry using the coordinate system of the dataframe (Web Mercator Aux Sphere) while the source data is in GCS_MAGNA and no geographic transformation defined (very bad!)
  • myAREA2: Calculate Geometry using the coordinate system of the dataframe (Web Mercator Aux Sphere) while the source data is in GCS_MAGNA and the geographic transformation defined (less bad)
  • myAREA3: Calculate Geometry after projecting the data to Web Mercator Aux Sphere using a transformation (correct)

Although the differences in area (ha) are small, they are all different. Maybe a tool that would project in memory to the output sr (using the transformation defined in the dataframe) and calculate the area and then link it back to the input featureclass would be an option...

0 Kudos
SaidAkif
Occasional Contributor

Thanks

That is interesting and the option 2 will wor for me

0 Kudos
WesMiller
Deactivated User

I've not tested this code but are you talking about something like below?

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
dfsr = df.spatialReference
for row in arcpy.da.UpdateCursor(fc, ["SHAPE@XY","Xfield","Yfield"],"",dfsr):
    row[1],row[2] = row[0]
    updateRow(row)
0 Kudos
WesMiller
Deactivated User

Right click the field you want to calculate choose "Calculate Geometry" you'll find the choices your looking for there. The field must be Type "Double"

0 Kudos
SaidAkif
Occasional Contributor

Thanks but I want to do exactly what you described in Python

0 Kudos
WesMiller
Deactivated User

Do you want to do it in python or do you want the tool that does it?

If you want to do it in python use the code above as a starting point pluck out some sample data and work through it.

If it's the tool follow the instructions above and you'll find it to be very easy.

0 Kudos
WesMiller
Deactivated User

You may also be interested in this tool ArcGIS Help (10.2, 10.2.1, and 10.2.2)

0 Kudos