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.
One approach would be to read the XY file line by line and use the data in an InsertCursor. Perhaps something like:
<SPAN class="comment token"># =========== CHANGE AS NEEDED ==========</SPAN> xy_file <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Path\to\xy_test.csv'</SPAN> feature <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Path\to\Test.gdb\XY_test'</SPAN> <SPAN class="comment token"># dictionary to match feature field name to csv column name</SPAN> <SPAN class="comment token"># { featureField : csvColumn, ... }</SPAN> <SPAN class="comment token"># first 2 fields are x and y coordinates</SPAN> fld <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="string token">'SHAPE@X'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'X'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="comment token"># SHAPE@X is special token for x coordinate</SPAN> <SPAN class="string token">'SHAPE@Y'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'Y'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="comment token"># SHAPE@Y is special token for y coordinate</SPAN> <SPAN class="string token">'Field1'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'Field1'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Field2'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'Field2'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Field3'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'AnotherFld'</SPAN> <SPAN class="comment token"># add field pairs as needed</SPAN> <SPAN class="punctuation token">}</SPAN> inSR <SPAN class="operator token">=</SPAN> <SPAN class="number token">4326</SPAN> <SPAN class="comment token"># WGS 1984 (lon, lat)</SPAN> outSR <SPAN class="operator token">=</SPAN> <SPAN class="number token">3857</SPAN> <SPAN class="comment token"># Web Mercator</SPAN> <SPAN class="comment token"># ==================================</SPAN> <SPAN class="keyword token">import</SPAN> arcpy <SPAN class="keyword token">import</SPAN> csv fields <SPAN class="operator token">=</SPAN> fld<SPAN class="punctuation token">.</SPAN>keys<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> cursor <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>InsertCursor<SPAN class="punctuation token">(</SPAN>feature<SPAN class="punctuation token">,</SPAN>fields<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">with</SPAN> open<SPAN class="punctuation token">(</SPAN>xy_file<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'rb'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> ff<SPAN class="punctuation token">:</SPAN> reader <SPAN class="operator token">=</SPAN> csv<SPAN class="punctuation token">.</SPAN>DictReader<SPAN class="punctuation token">(</SPAN>ff<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># (f, delimiter='\t', quoting=csv.QUOTE_NONE)</SPAN> <SPAN class="keyword token">for</SPAN> r <SPAN class="keyword token">in</SPAN> reader<SPAN class="punctuation token">:</SPAN> values <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN> f<SPAN class="punctuation token">:</SPAN>r<SPAN class="punctuation token">[</SPAN>fld<SPAN class="punctuation token">[</SPAN>f<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> fields <SPAN class="punctuation token">}</SPAN> <SPAN class="comment token"># pair csv file values with feature field names</SPAN> <SPAN class="comment token"># project x y coordinates as required</SPAN> ptXY <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>PointGeometry<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN>values<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'SHAPE@X'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>values<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'SHAPE@Y'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SpatialReference<SPAN class="punctuation token">(</SPAN>inSR<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>projectAs<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>SpatialReference<SPAN class="punctuation token">(</SPAN>outSR<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> values<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'SHAPE@X'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> values<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'SHAPE@Y'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> ptXY<SPAN class="punctuation token">.</SPAN>firstPoint<SPAN class="punctuation token">.</SPAN>X<SPAN class="punctuation token">,</SPAN> ptXY<SPAN class="punctuation token">.</SPAN>firstPoint<SPAN class="punctuation token">.</SPAN>Y <SPAN class="comment token"># print values # print for debugging</SPAN> cursor<SPAN class="punctuation token">.</SPAN>insertRow<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>values<SPAN class="punctuation token">[</SPAN>f<SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> fields<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">del</SPAN> reader <SPAN class="keyword token">del</SPAN> cursor ff<SPAN class="punctuation token">.</SPAN>close<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Of course, you will probably need to make tweaks for your particular case.
Are you able to the xy table directly into ArcCatalog without some type of odbc connection?
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.
Well its appears its going to take more effort and time then I expected.
Thanks for your quick response and help.
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
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..
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
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.