POST
|
I have a feature class that has a related table that tracks user edits. The manual way to perform the task is: 1.The user performs an edit on the polygon 2.The user adds a new record to the related table and updates attributes accordingly (type, edited by, edited date, etc.). This is done in the Attribute Editor window using the interface provided for adding a related record. The relationship is tracked via the polygon ID, which the user copies into the new related record. I have written a Python script that automates the record creation tasks. It works as follows: 1.User edits one or more polygons 2.User runs the script 3.Script creates the new records in the edit table, enters the polygon ID and the script dialog provides the remaining update info for the script to fill in the other necessary fields What I need to know is how, in Python, to update the relationship for the newly created records to relate them back to their respective poly using the poly ID. Currently, when the updated poly is selected and viewed the newly added record is not shown in the Attribute Editor dialog as a related record. Can anyone provide to me where to go for the missing link? The usual Google search didn't really yield the secret to me when I started digging yesterday. Here's the code as it exists now: ************************************** import arcpy, arcgisscripting, sys, os, time, datetime, getpass, shutil, smtplib from arcpy import env from time import strftime mxd = arcpy.mapping.MapDocument("CURRENT") # From dialog, get the table field default values. To set different defaults, use the # parameters dialog inside ArcMap/toolbox interface. structuresFC = arcpy.GetParameterAsText(0) structureEditLogTable = arcpy.GetParameterAsText(1) qcFlag = arcpy.GetParameterAsText(2) userComments = arcpy.GetParameterAsText(3) modifiedBy = arcpy.GetParameterAsText(4) modifiedDate = arcpy.GetParameterAsText(5) lastEditedUser = arcpy.GetParameterAsText(6) lastEditedDate = arcpy.GetParameterAsText(7) clearSelected = arcpy.GetParameterAsText(8) # Determine query date queryDate = datetime.datetime.strptime(lastEditedDate, '%m/%d/%Y').strftime('%Y-%m-%d') # Determine if any edits have been performed on the Structure Edit Log today; if so, determine the latest time of the updates timeQuery = "LAST_EDITED_USER = '" + lastEditedUser + "' and LAST_EDITED_DATE > timestamp '" + queryDate + " 00:00:00' and MODIFIED_BY = '" + modifiedBy + "'" arcpy.SelectLayerByAttribute_management(structureEditLogTable, "NEW_SELECTION", timeQuery) # Determine if there is a selection; if there is, edits have been made today describeTable = arcpy.Describe(structureEditLogTable) if describeTable.FIDSet == '': anyEdits = "No" timestampList = [] # Set the timestamp for the list to Midnight today - no edits have taken place yet timestampList.append("00:00:00") queryTime = "00:00:00" else: # Edits have been made, read the times of the selection set into a list fieldsSEL = ["LAST_EDITED_DATE"] timestampList = [] with arcpy.da.SearchCursor(structureEditLogTable, fieldsSEL) as srchCursor: for row in srchCursor: timestamp = (row[0]) timestampList.append(timestamp) lastEditTime = max(timestampList) queryTime = (lastEditTime).strftime('%H:%M:%S') # Clear the selections to prep for next phase arcpy.SelectLayerByAttribute_management(structuresFC, "CLEAR_SELECTION") arcpy.SelectLayerByAttribute_management(structureEditLogTable, "CLEAR_SELECTION") # Create select query based on current user being last edited user and edit time being greater than 00:00:00 selectionQuery = "LAST_EDITED_USER = '" + lastEditedUser + "' and LAST_EDITED_DATE > timestamp '" + queryDate + " " + queryTime + "'" # Select records from the Structure Edit Log table that were edited by the user in this edit session arcpy.SelectLayerByAttribute_management(structuresFC, "NEW_SELECTION", selectionQuery) arcpy.RefreshActiveView() # Describe the table state to determine if records are selected describeTable = arcpy.Describe(structuresFC) try: # Test to see that there is a selection set first. If not, message the user and exit. if describeTable.FIDSet == '': arcpy.AddMessage("No features are selected in the Structures Feature Class; exiting!") else: # Set the parameters for the selected features *only* fieldsFC = ["STRUCTUREID"] fieldsSEL = ["STRUCTUREID", "QC_FLAG", "COMMENTS", "MODIFIED_BY", "MODIFIED_DATE"] try: # Set up a cursor to get the current StructureID in the FC with arcpy.da.SearchCursor(structuresFC, fieldsFC) as srchCursor: for row in srchCursor: currentStructureID = row[0] with arcpy.da.InsertCursor(structureEditLogTable, fieldsSEL) as insertCursor: insertCursor.insertRow((currentStructureID, "Y", userComments, modifiedBy, modifiedDate)) del insertCursor del srchCursor, row except RuntimeError as err: # This will run if the user is not currently in an edit session if "cannot be updated outside an edit session" in err.message: arcpy.AddMessage("Not currently in an edit session. Exit tool, start an edit session and rerun the tool!") else: raise err selectionQuery = "LAST_EDITED_USER = '" + lastEditedUser + "' and LAST_EDITED_DATE > timestamp '" + queryDate + " 00:00:00' and EDIT_ID IS NULL" arcpy.SelectLayerByAttribute_management(structureEditLogTable, "NEW_SELECTION", selectionQuery) arcpy.RefreshActiveView() fieldsSEL = ["OBJECTID","EDIT_ID"] with arcpy.da.UpdateCursor(structureEditLogTable, fieldsSEL) as updateCursor: for row in updateCursor: row[1] = row[0] updateCursor.updateRow(row) del updateCursor, row except Exception as e: arcpy.AddMessage("Exception") arcpy.AddError(e.args[0]) if clearSelected == "true": # Clear selection and refresh the map arcpy.SelectLayerByAttribute_management(structuresFC, "CLEAR_SELECTION") arcpy.SelectLayerByAttribute_management(structureEditLogTable, "CLEAR_SELECTION") arcpy.RefreshActiveView() else: arcpy.RefreshActiveView() End code*********** I think I may have answered my own question, but here's my sanity check...in case anyone is reading or has read this: I need to add the requisite records to the relationship table providing the structure ID and its new related Edit_ID. I'm assuming like any other table in SDE, there shouldn't be a problem doing this via the Insert cursor, probably in the next line of my code. I'll be giving this a try, but if anyone has any caveats to this I'd appreciate your input!
... View more
08-13-2019
09:55 AM
|
0
|
1
|
941
|
POST
|
I think I may have answered my own question, but here's my sanity check...in case anyone is reading or has read this: I need to add the requisite records to the relationship table providing the structure ID and its new related Edit_ID. I'm assuming like any other table in SDE, there shouldn't be a problem doing this via the Insert cursor, probably in the next line of my code. I'll be giving this a try, but if anyone has any caveats to this I'd appreciate your input! Thanks! Brad
... View more
08-13-2019
09:46 AM
|
0
|
1
|
721
|
POST
|
I have a feature class that has a related table that tracks user edits. The manual way to perform the task is: The user performs an edit on the polygon The user adds a new record to the related table and updates attributes accordingly (type, edited by, edited date, etc.). This is done in the Attribute Editor window using the interface provided for adding a related record. The relationship is tracked via the polygon ID, which the user copies into the new related record. I have written a Python script that automates the record creation tasks. It works as follows: User edits one or more polygons User runs the script Script creates the new records in the edit table, enters the polygon ID and the script dialog provides the remaining update info for the script to fill in the other necessary fields What I need to know is how, in Python, to update the relationship for the newly created records to relate them back to their respective poly using the poly ID. Currently, when the updated poly is selected and viewed the newly added record is not shown in the Attribute Editor dialog as a related record. Can anyone provide to me where to go for the missing link? The usual Google search didn't really yield the secret to me when I started digging yesterday. Here's the code as it exists now: ************************************** import arcpy, arcgisscripting, sys, os, time, datetime, getpass, shutil, smtplib from arcpy import env from time import strftime mxd = arcpy.mapping.MapDocument("CURRENT") # From dialog, get the table field default values. To set different defaults, use the # parameters dialog inside ArcMap/toolbox interface. structuresFC = arcpy.GetParameterAsText(0) structureEditLogTable = arcpy.GetParameterAsText(1) qcFlag = arcpy.GetParameterAsText(2) userComments = arcpy.GetParameterAsText(3) modifiedBy = arcpy.GetParameterAsText(4) modifiedDate = arcpy.GetParameterAsText(5) lastEditedUser = arcpy.GetParameterAsText(6) lastEditedDate = arcpy.GetParameterAsText(7) clearSelected = arcpy.GetParameterAsText(8) # Determine query date queryDate = datetime.datetime.strptime(lastEditedDate, '%m/%d/%Y').strftime('%Y-%m-%d') # Determine if any edits have been performed on the Structure Edit Log today; if so, determine the latest time of the updates timeQuery = "LAST_EDITED_USER = '" + lastEditedUser + "' and LAST_EDITED_DATE > timestamp '" + queryDate + " 00:00:00' and MODIFIED_BY = '" + modifiedBy + "'" arcpy.SelectLayerByAttribute_management(structureEditLogTable, "NEW_SELECTION", timeQuery) # Determine if there is a selection; if there is, edits have been made today describeTable = arcpy.Describe(structureEditLogTable) if describeTable.FIDSet == '': anyEdits = "No" timestampList = [] # Set the timestamp for the list to Midnight today - no edits have taken place yet timestampList.append("00:00:00") queryTime = "00:00:00" else: # Edits have been made, read the times of the selection set into a list fieldsSEL = ["LAST_EDITED_DATE"] timestampList = [] with arcpy.da.SearchCursor(structureEditLogTable, fieldsSEL) as srchCursor: for row in srchCursor: timestamp = (row[0]) timestampList.append(timestamp) lastEditTime = max(timestampList) queryTime = (lastEditTime).strftime('%H:%M:%S') # Clear the selections to prep for next phase arcpy.SelectLayerByAttribute_management(structuresFC, "CLEAR_SELECTION") arcpy.SelectLayerByAttribute_management(structureEditLogTable, "CLEAR_SELECTION") # Create select query based on current user being last edited user and edit time being greater than 00:00:00 selectionQuery = "LAST_EDITED_USER = '" + lastEditedUser + "' and LAST_EDITED_DATE > timestamp '" + queryDate + " " + queryTime + "'" # Select records from the Structure Edit Log table that were edited by the user in this edit session arcpy.SelectLayerByAttribute_management(structuresFC, "NEW_SELECTION", selectionQuery) arcpy.RefreshActiveView() # Describe the table state to determine if records are selected describeTable = arcpy.Describe(structuresFC) try: # Test to see that there is a selection set first. If not, message the user and exit. if describeTable.FIDSet == '': arcpy.AddMessage("No features are selected in the Structures Feature Class; exiting!") else: # Set the parameters for the selected features *only* fieldsFC = ["STRUCTUREID"] fieldsSEL = ["STRUCTUREID", "QC_FLAG", "COMMENTS", "MODIFIED_BY", "MODIFIED_DATE"] try: # Set up a cursor to get the current StructureID in the FC with arcpy.da.SearchCursor(structuresFC, fieldsFC) as srchCursor: for row in srchCursor: currentStructureID = row[0] with arcpy.da.InsertCursor(structureEditLogTable, fieldsSEL) as insertCursor: insertCursor.insertRow((currentStructureID, "Y", userComments, modifiedBy, modifiedDate)) del insertCursor del srchCursor, row except RuntimeError as err: # This will run if the user is not currently in an edit session if "cannot be updated outside an edit session" in err.message: arcpy.AddMessage("Not currently in an edit session. Exit tool, start an edit session and rerun the tool!") else: raise err selectionQuery = "LAST_EDITED_USER = '" + lastEditedUser + "' and LAST_EDITED_DATE > timestamp '" + queryDate + " 00:00:00' and EDIT_ID IS NULL" arcpy.SelectLayerByAttribute_management(structureEditLogTable, "NEW_SELECTION", selectionQuery) arcpy.RefreshActiveView() fieldsSEL = ["OBJECTID","EDIT_ID"] with arcpy.da.UpdateCursor(structureEditLogTable, fieldsSEL) as updateCursor: for row in updateCursor: row[1] = row[0] updateCursor.updateRow(row) del updateCursor, row except Exception as e: arcpy.AddMessage("Exception") arcpy.AddError(e.args[0]) if clearSelected == "true": # Clear selection and refresh the map arcpy.SelectLayerByAttribute_management(structuresFC, "CLEAR_SELECTION") arcpy.SelectLayerByAttribute_management(structureEditLogTable, "CLEAR_SELECTION") arcpy.RefreshActiveView() else: arcpy.RefreshActiveView()
... View more
08-13-2019
08:55 AM
|
0
|
2
|
757
|
POST
|
Update - I also received the same cryptic error when just trying to CREATE a file GDB, so I'm not sure what the issue is. I then tried the checkout using a PGDB and the checkout works fine. So, any ESRI peeps want to chime in with what the issue might be? Is there a problem with the file geodatabase? I'd prefer to not use PGDBs, but can initially until the other issue is solved. Brad
... View more
06-11-2013
10:53 AM
|
0
|
0
|
1369
|
POST
|
All - I've googled this and seen a few issues and responses, but nothing that spells out what the problem is or how to solve. Creating a checkout replica (file GDB) from an Oracle 11g ArcSDE instance, ArcGIS 10.1, SP 1: ArcGIS begins the replication process but then returns the following error: Create Replica failed. The item was not found. [Item Type: {747371149-DCB5-4257-8904-B9724E32A530}] In my case it seems to be the same "Item Type" each time. All data is registered as versioned, has global IDs, is being checked out by data owner in a version that is owned by the data owner. I've opened a clean ArcMap document and tried that. What is the issue here? TIA... Brad
... View more
06-10-2013
09:34 AM
|
0
|
4
|
4831
|
POST
|
Thanks, Marco - I will set the data frame to the data projection and see if that helps. I don't think it is a precision issue because the topology layers come in with the correct errors found during validation, and whatever point - line combos I initially move behave correctly. The error occurs usually after panning to work on another area of the data. I'll see if the data frame projection issue fixes things. Otherwise I may try a support ticket and see if that works. Thanks again for your suggestion! I'll post results here after I have a chance to check things out. Brad
... View more
05-28-2013
07:32 AM
|
0
|
0
|
368
|
POST
|
Hello - I am seeing strange problems with pretty simple topology edits in ArcGIS 10.1 in and ArcSDE GDB. The features are very simple: line feature class and a point feature class that has coincident points matching line vertices. INitially everything works fine in the topology. When I zoom in and start moving the points, they are correctly connected to the line and move properly. Panning down the line to the next point or points, however, shows that the next points that USED to be coincident with the line are now OFF the line. I have worked with the same data in a file GDB and did not experience this issue. Has this happened to anyone else, and is there a fix for it? ArcGIS 10.1 with SP 1 has been applied to the desktop environment. Oracle 11g DB for the SDE instance. Thanks in advance for any help! Brad
... View more
05-24-2013
08:44 AM
|
0
|
2
|
1028
|
POST
|
That pointed me in the right direction. I ended up with: lineName = "'Line" + line + "'"; Thanks! Brad
... View more
03-29-2013
05:42 PM
|
0
|
0
|
412
|
POST
|
I have a FC that I am working with in Python. I add a text field to it and want to calculate the field values based on a string variable. The string is read in and parsed to get the value. Example: Python reads in "1603-01_mp2.0", splits the string at the underscore, and uses the first item in the split: 1603-01. So, line = 1603-01. Then, to make it even MORE of a string, I do lineName = "Line"+line. This results in "Line1603-01". I know this to be good, because I have used print lineName to check. Fast forward to where I try to calculate the value of the text field in the FC. I use this python line: arcpy.CalculateField_management(TempPLCL_Point, "Route", lineName, "PYTHON", "") During this calculation, though, it appears that either ArcGIS or Python wants to treat the - as a minus sign and do math on the string. I get the following error: ExecuteError: ERROR 000539: Error running expression: Line1603-01 <type 'exceptions.NameError'>: name 'Line1603' is not defined Failed to execute (CalculateField). How can I get past this seemingly simple problem that shouldn't be a problem at all?
... View more
03-29-2013
12:40 PM
|
0
|
2
|
2191
|
POST
|
I have a task in which I have a table of addresses in a SQL Server 2008 table. I need to display these as referenced points in a map via JavaScript API. The addresses in the table are dynamic and change, so this won't work as a feature class. What is the best method to accomplish this? Thanks! B
... View more
03-07-2012
02:10 PM
|
0
|
1
|
966
|
POST
|
Thanks! I found a way in Model Builder to do what I was looking for, but your guidance likely will help in future needs as I will be porting my knowledge over to Python. I appreciate your input! Brad
... View more
01-13-2011
02:23 PM
|
0
|
0
|
664
|
POST
|
I am a Python newbie, though have other programming experience. I am looking to run through a set of features one at a time and process a union with another layer. There are better than 1000 features, so automating this is the only practical way. Can someone slip me some python code that would allow this, or point me to a better resource? Thanks!
... View more
01-10-2011
07:49 AM
|
0
|
3
|
1227
|
POST
|
Nevermind...that turns out to be the solution after all. There were TWO widgets with SWF files in the widgets folder, but I only removed the one I was concerned about working with. WHen I repeated the process on the other widget it solved the issue. Thanks, Robert! Brad
... View more
06-22-2010
10:26 AM
|
0
|
0
|
900
|
POST
|
I removed it, built the project, then readded it and built the project again. Still getting the spinning clock. Any other thoughts? Brad
... View more
06-22-2010
09:32 AM
|
0
|
0
|
900
|
POST
|
I've attached the code for the PDF print widget I'm trying to make work. Right now it will create a PDF with the map and title/subtitle. I also have a logo, disclaimer and copyright that SHOULD be making their way on to the PDF but aren't. If someone would like to take a quick look and tell me why, that would be great. I can't seem to figure out WHY they aren't being added to the PDF. Thanks in advance... Brad
... View more
06-21-2010
11:32 AM
|
0
|
0
|
2077
|
Online Status |
Offline
|
Date Last Visited |
07-14-2021
12:15 PM
|