How to update xy table to feature class

02-24-2020 09:34 AM
New Contributor III

I have an XY table from a Third Party software for Police Calls. To get more functionality I used (from ArcCatalog) Create Feature from XY Table.. I need to take it one step further so the New Feature is updated when new calls are entered from the XY table.

Tags (1)
0 Kudos
7 Replies
MVP Esteemed Contributor

There is no updating an existing file with new data except 

Append—Data Management toolbox | Documentation 

or if you want to create a new one from existing ones

Merge—Data Management toolbox | Documentation 

But it won't shortcut your xytable step

0 Kudos
New Contributor III

I reviewed the functionality of the Append tool and it will not allow me to append my feature class with the XY table.. Error saying the two datasets must be the same type or format.

In case I didn't describe my issue properly.... I was given a table with XY coordinates to map calls from our Police software.. Then from ArcCatalog I created a feature class from the XY table.. Working perfectly.. But I need a way to update the feature class automatically. A script or tool to periodically update or overwrite my feature class calls with new calls..

Thank you for being patience with me.. I create a lot of content but lack experience with manipulating tables on the run..   

0 Kudos
MVP Esteemed Contributor

Chet,  my last line says exactly that.  The xy table will have to be converted to a featureclass, then either append or merge will have to be used to get existing and new data together.  The two are slightly different in how they do things.  Sounds like you could put together a model to do this, simply by using one of those two tools and

XY Table To Point—Data Management toolbox | Documentation 

New Contributor III

Well its appears its going to take more effort and time then I expected.

Thanks for your quick response and help.

0 Kudos
MVP Esteemed Contributor

Honestly, it shouldn't be that much "more time" to get this to work, especially since you are talking about automating through models or scripting.  If you don't want to create a bunch of temporary/intermediate feature classes on disk, just use the in-memory or memory workspace to create a temporary table that is then used to append.

Esteemed Contributor

Are you able to the xy table directly into ArcCatalog without some type of odbc connection?

0 Kudos
MVP Regular Contributor

One approach would be to read the XY file line by line and use the data in an InsertCursor.  Perhaps something like:

# =========== CHANGE AS NEEDED ==========
xy_file = r'C:\Path\to\xy_test.csv'
feature = r'C:\Path\to\Test.gdb\XY_test'

# dictionary to match feature field name to csv column name
# { featureField : csvColumn, ... }
# first 2 fields are x and y coordinates
fld = { 'SHAPE@X' : 'X', # SHAPE@X is special token for x coordinate
'SHAPE@Y' : 'Y', # SHAPE@Y is special token for y coordinate
'Field1' : 'Field1',
'Field2' : 'Field2',
'Field3' : 'AnotherFld' # add field pairs as needed

inSR = 4326 # WGS 1984 (lon, lat)
outSR = 3857 # Web Mercator
# ==================================

import arcpy
import csv

fields = fld.keys()

cursor = arcpy.da.InsertCursor(feature,fields)
with open(xy_file, 'rb') as ff:
reader = csv.DictReader(ff) # (f, delimiter='\t', quoting=csv.QUOTE_NONE)
for r in reader:
values = { f:r[fld[f]] for f in fields } # pair csv file values with feature field names
# project x y coordinates as required
ptXY = arcpy.PointGeometry(arcpy.Point(values['SHAPE@X'],values['SHAPE@Y']),
values['SHAPE@X'], values['SHAPE@Y'] = ptXY.firstPoint.X, ptXY.firstPoint.Y
# print values # print for debugging
cursor.insertRow([values[f] for f in fields])

del reader
del cursor

Of course, you will probably need to make tweaks for your particular case.