Populating Latitude/Longitude Field in Edit Session (python expression default value)

2190
2
07-19-2013 06:00 AM
PatrickMcKinney
New Contributor II
I am trying to figure out if there is a way to set a latitude and longitude field to auto-populate when a feature is added in an editing session?  The purpose is for our field crew editing point data using mobile phones and the ArcGIS app, utilizing a feature service.

I'm wondering if setting the default value to !shape.firstpoint.x! would make this happen.  Is it even possible to set a default value for a double field to a python expression?

Thanks for any help,

Patrick
Tags (2)
0 Kudos
2 Replies
by Anonymous User
Not applicable
Hi Patrick,

I believe a Python" rel="nofollow" target="_blank">http://resources.arcgis.com/en/help/main/10.1/index.html#/Wha... Add-In could achieve the functionality you are looking for.  You can apply arcpy functionality on mouse click events such as populate the x,y coords whenever a point is drawn. 

They are a little tricky at first and are more difficult to debug.  However, when testing the add-in inside ArcMap, if you leave the Python window open it will print out any exceptions/messages to the window.  Good luck!

Also, I just found this thread" rel="nofollow" target="_blank">http://forums.arcgis.com/threads/49273-Getting-XY-from-mouse-... on Getting XY from a mouse click

EDIT: I need to start reading questions more thoroughly...An Add-In will only work inside of ArcMap and not a mobile device.
0 Kudos
by Anonymous User
Not applicable
In case anyone is interested, I tested an Add-In to do this inside ArcMap (I needed the Add-In practice anyways 🙂 😞

import arcpy
import pythonaddins
from arcpy import mapping as m


class AddFeatureWithXY(object):
    # Implement the add in
    def __init__(self):
        self.enabled = True
        self.cursor = 3  # cross

    def onMouseDownMap(self, x, y, button, shift):
        # listens for mouse down event
        mxd = m.MapDocument("current")
        df = m.ListDataFrames(mxd)[0]
        lyr = m.ListLayers(mxd, 'Addresses', df)[0]

        # Get XY from click
        pt=arcpy.PointGeometry(arcpy.Point(x,y))
        insert = tuple([pt, x, y])

        # insert rows
        coord_fields = ['SHAPE@','POINT_X','POINT_Y']
        with arcpy.da.InsertCursor(lyr, coord_fields) as irows:
            irows.insertRow(insert)
        arcpy.RefreshActiveView()
        pythonaddins.MessageBox('Added X,Y coords to table', 'Message', '0')

0 Kudos