1

I would like to delete all rows which are joined to a layer from a csv table. Only the joined records which match (keep only matching records) should be deleted. After the records are deleted, the join should be removed again. I used the following script, but get the error: "cannot update join table".

arcpy.env.workspace = r"D:\skript\New File Geodatabase.gdb\test"

arcpy.MakeFeatureLayer_management("fc","featurelayer")

arcpy.AddJoin_management("featurelayer","OBJECTID",r"D:\skript\Errors.csv","id","KEEP_COMMON")

with arcpy.da.UpdateCursor("featurelayer", "OBJECTID") as cursor:
for row in cursor:
    if row[0] > 0:
        cursor.deleteRow()

arcpy.RemoveJoin_management ("featurelayer", "Errors")

arcpy.CopyFeatures_management("featurelayer","result")

Is this even possible?

  • Switch your join so that the rows you want to delete are the base and the features are the joined table. Use selection instead of a cursor. The selection persists after removing join, then call delete rows. – Ben S Nadler Jun 10 '16 at 20:12
  • 1
    I'm pretty sure that ArcGIS / Arcpy cannot modify a CSV file. I've just tried it using both an update cursor and Delete Rows (as mentioned by @BenSNadler above) and it gives me an error for both. You may need to convert your CSV into an ArcGIS editable table before you can do any edits to it. – Midavalo Jun 12 '16 at 8:17
  • You are correct. Missed that detail – Ben S Nadler Jun 12 '16 at 15:03
  • @Midavalo I think your comment would be fine as an answer. – PolyGeo Sep 24 '16 at 22:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.