Arcpy Update points with info from Polygon

639
4
Jump to solution
08-23-2016 12:40 PM
BillChappell
Occasional Contributor II

I have a featureclass of points and one of parcel polygons, my task was write some python code to put the parcel_ID back into the point. Without Arcpy, I just create a spatialJoin and then join the new fc back to the old one and field calc the data over and then blow away the temp spatialjoin fc.

I thought this would be easy in python, except you cannot join to a featureclass you have to create a feature layer to join to. Since I'm allowed to modify the point feature class but not delete and replace, a join is out of question. I have roughly 11 thousand points to update.  Since I have to do this with the county poly, municipal poly, zipcode pole, etc, the manual method is not an option, they need a tool.

I imaging I could create a cusror to step though each point and then do an intersect to get a field value and update a record but is their a better way?

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Esteemed Contributor

effectively you can do whatever you want in arcpy using the tools that exist in arctoolbox... otherwise it is cursors.  So if you can emulate your workflow using just the tools in arctoolbox, then you don't need cursors.  If you can't, then you do.

View solution in original post

4 Replies
DanPatterson_Retired
MVP Esteemed Contributor

effectively you can do whatever you want in arcpy using the tools that exist in arctoolbox... otherwise it is cursors.  So if you can emulate your workflow using just the tools in arctoolbox, then you don't need cursors.  If you can't, then you do.

ChrisDonohue__GISP
MVP Frequent Contributor

Question - is the ability to affect the point data constrained by being in a Versioned environment (Enterprise Geodatabase/SDE)?

Also, you may already know this, but I will toss this out in case it helps:

To add to what Dan Patterson  proposed, if the goal is to end up specifically with Python Code to do this process and you it can already be manually accomplished with geoprocessing tools without any issues, there are several ways to figure out the equivalent Python coding.

One possibility is to run through each Geoprocessing tool you would use to do this process manually, look at the sample Python Code for that tool, then put all the code together.  For example, Spatial Join (Analysis) has some example code in the Tool Help that one could modify to match your data ArcGIS Help (10.2, 10.2.1, and 10.2.2)

Even easier, one could also just run your process with the tool manually, then dump out a code snippet for that process after it was run manually by checking the Geoprocessing Results and capturing a Python Snippet.  The advantage of this is that the exact files used are already coded in as the inputs and outputs.  Here's an example that shows how to extract the Python Snippet used in a tool run:

Another option is to string together all the processes in Modelbuilder, then dump out the entire Python code from that after getting it all to work.  One caveat here, though - there are some processes in Modelbuilder that don't work outside Modelbuilder (i.e. they don't translate to Python).

Exporting a model to a Python script—Help | ArcGIS for Desktop 

Chris Donohue, GISP

BillChappell
Occasional Contributor II

I'm going the cursor route for now, as the spatial join works well but the table join takes A + B = C and I need a A + B = A+ like a standard join in the TOC. My constraint of not being able to delete/replace the data is it's in SDE and used for ArcServer and a standard REST service.

0 Kudos
XanderBakker
Esri Esteemed Contributor

When you are going to update data in SDE used by a AGS service, be sure to use an edit session: Editor—Help | ArcGIS for Desktop 

... and that the service does not generate an exclusive schema lock, since this will not allow you to update the data: Disabling schema locking on a map service—Documentation (10.4) | ArcGIS for Server