Select to view content in your preferred language

Better way to Calculate Geometry?

384
1
02-07-2012 08:14 PM
MikeMacRae
Frequent Contributor
Hey everyone,

I have a point feature class that has 2 double fields (field names are EASTING and NORTHING) that I use calculate geometry to get the x.y coordinates of the points from the coordinate system of the feature class using the tool in the attribute table. The tool isn't offered in the toolbox, so I developed a quick script.

I need the coordinate values in the 2 fields for a period of time and then I have a client who wants these coordinate values changed to a different coordinate system, but they want the feature classes coordinate system to remain unchanged. I've come up with a process in python that will do this for me:

1. Re-project feature class to new coordinate system (gives new output)
2. Add X,Y coordinates to the new FC using arcpy.AddXY_management
3. Join these 2 tables based on a unique identifier field
4. Field Calculate the EASTING and NORTHING fields based on the new X,Y coordinate fields in the re-projected FC
5. Delete the interim stuff, remove join, yadda, yadda

This works fine and I have no issue with it, but I've been reading through some field calculator VB scripts and I'm wondering of there's a way you can just calculate the EASTING and NORTHING fields in a code block based on a different coordinate system, without going though all the re-projecting and joining stuff. I have quite a few point files to process, so I thought a simpler method might be out there.

Any suggestions?

Thanks,
Mike
Tags (2)
0 Kudos
1 Reply
KimOllivier
Honored Contributor
You can set a Spatial reference on the cursor options.
Then when you get the x,y coordinates they will already be reprojected ready to add back into the fields.
You don't have to reproject the featureclass first.

For example I needed the extent of each polygon in a different projection:

   # 
    # WGS_1984 works for coverages defined with an equivalent custom Transverse projection definition
    gp.GeographicTransformations = 'NZGD_1949_To_WGS_1984_3_NTv2' 
   srOut = gp.CreateObject("SpatialReference")
   srOut.CreateFromFile("c:/arcgis/nzmg.prj")
   # this is a good on-the-fly switch for the searchcursor
    # srOut must be a com object, not a file ref or a factory code
    rows = gp.SearchCursor(ds+"/polygon",'"PAR_ID" > 0',srOut) 
    n = 0
    rows.Reset()
    row = rows.Next()
    while row  :
        print >> f1,"%d,%s" % (row.par_id,row.shape.Extent.replace(" ",","))
        row = rows.Next()
        n +=1
    del rows
0 Kudos