Ah, I see. In this case, it would be easiest to simply select by attributes where GPS_X is not null and GPS_Y is not null then perform the field calc you have and it will only affect the selected records.
Thanks Blake for the response! But I was wondering how I could write that in a Field Calculator. Currently I'm using this script:
I was wondering how I could write to leave all blank values alone and only calculate points that have a value. Thanks again for any help!
Before you assign the new X and Y values to the point, just check if they have values.
<SPAN class="keyword token">if</SPAN> row<SPAN class="punctuation token">.</SPAN>GPS_X <SPAN class="operator token">and</SPAN> row<SPAN class="punctuation token">.</SPAN>GPS_Y<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># continue processing new XY coordinate</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># handle null XY coordinate values</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
EDIT:
Or better yet, use a where_clause parameter to just ignore the null values at the very beginning when creating the cursor.
where_clause <SPAN class="operator token">=</SPAN> <SPAN class="string token">"GPS_X is not null and GPS_Y is not null"</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
UpdateCursor—Help | ArcGIS Desktop
Alan and Jake,
The Python script works great, but unfortunately I have some Null Values in my GPS Data(we had to digitize some data). Is there any way to use the python script you provided and have it leave all Null or blank values alone? When I use the python script it will remove any points with no GPS data thus I'm losing points, any help would be appreciated thank you!
It appears this is a bug, NIM097273.
Hi Alan,You can place the code within a function and execute it using the field calculator. Ex:def update(): fc = r"C:\temp\python\test.gdb\Vehicle" pnt = arcpy.Point() rows = arcpy.UpdateCursor(fc) for row in rows: pnt.X = row.GPS_X pnt.Y = row.GPS_Y row.shape = pnt rows.updateRow(row) del row, rowsBe sure that you have 'Python' checked at the top of the field calculator, and you will want to specify 'update()' under the Pre-logic script code dialog. Ex:[ATTACH=CONFIG]33269[/ATTACH]
def update(): fc = r"C:\temp\python\test.gdb\Vehicle" pnt = arcpy.Point() rows = arcpy.UpdateCursor(fc) for row in rows: pnt.X = row.GPS_X pnt.Y = row.GPS_Y row.shape = pnt rows.updateRow(row) del row, rows
import arcpy from arcpy import env env.overwriteOutput = True env.workspace = r"C:\Temp\Python\test.gdb" fc = "swManhole" fc2 = "swGravityMain" pnt = arcpy.Point() # Move Manholes to GPS location rows = arcpy.UpdateCursor(fc) for row in rows: pnt.X = row.POINT_X pnt.Y = row.POINT_Y row.shape = pnt rows.updateRow(row) del row, rows # Convert Main endpoints to points feature class arcpy.FeatureVerticesToPoints_management(fc2, "Main_EndPts", "END") # Find all Main endpoints within 5 feet of manholes arcpy.Near_analysis("Main_EndPts", fc, "5") # Create a layer of all Main endpoints within 5 feet of manholes lyr = arcpy.MakeFeatureLayer_management("Main_EndPts", "Main_EndPts_Lyr", "NEAR_DIST > 0") list = [] # Append X & Y values of Main endpoints to list rows = arcpy.SearchCursor(lyr) for row in rows: list.append(float(row.shape.centroid.X) + float(row.shape.centroid.Y)) del row, rows OBJECTIDs = [] # Find OBJECTIDs of the Mains that need to be moved rows = arcpy.SearchCursor(fc2) for row in rows: geom = row.shape XY = float(geom.lastPoint.X) + float(geom.lastPoint.Y) if XY in list: OBJECTIDs.append(row.OBJECTID) del row, rows arcpy.Delete_management("Main_EndPts") print OBJECTIDs
import arcpy from arcpy import env env.workspace = "C:/Temp/Python/test.gdb" fc = "Parker_R6_Manhole_1" pnt = arcpy.Point() rows = arcpy.UpdateCursor(fc) for row in rows: pnt.X = row.GPS_X pnt.Y = row.GPS_Y row.shape = pnt rows.updateRow(row) del row, rows
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.