<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How do I delete a feature from a ArcGIS for Server Feature server using arcpy? in Developers Questions</title>
    <link>https://community.esri.com/t5/developers-questions/how-do-i-delete-a-feature-from-a-arcgis-for-server/m-p/112798#M719</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a feature service created using ArcGIS for Server and using python i want to select feature(s) based on OBJECTID and delete them. The user will be selecting the features to delete in Arcmap. I know i am able to create a local copy, delete them manualy and sync back to the service but i want to do all the lifting via python. Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is what i have so far the section "Choose orginal features to delete" is what i can not get working, the rest of the code works fine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;import os&lt;BR /&gt;from arcpy import env&lt;BR /&gt;env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;# Variables...&lt;BR /&gt;in_datavarPOI = r'U:\Tools\SDE_Connection_Files\RedDeerNorthSaskRegion.GDB@genesis-sde.sde\RedDeerNorthSaskRegion.GDB.POI'&lt;BR /&gt;in_datavarTKS = r'U:\Tools\SDE_Connection_Files\RedDeerNorthSaskRegion.GDB@genesis-sde.sde\RedDeerNorthSaskRegion.GDB.Tracks'&lt;BR /&gt;inLyrPOI = 'AEP Field Data Collection/Points of Interest'&lt;BR /&gt;inLyrTKS = 'AEP Field Data Collection/Tracks'&lt;BR /&gt;sdeconnection = r'U:\Tools\SDE_Connection_Files\RedDeerNorthSaskRegion.GDB@genesis-sde.sde'&lt;BR /&gt;expChce = arcpy.GetParameterAsText(0)&lt;BR /&gt;out_location = arcpy.GetParameterAsText(1)&lt;BR /&gt;out_name = arcpy.GetParameterAsText(2)&lt;BR /&gt;delFeat = arcpy.GetParameterAsText(3)&lt;/P&gt;&lt;P&gt;# Create a FGDB to store copies data...&lt;BR /&gt;arcpy.AddMessage('\n... Creating new File Geodatabase')&lt;BR /&gt;arcpy.CreateFileGDB_management(out_location, out_name)&lt;/P&gt;&lt;P&gt;# Choice of data to export&lt;BR /&gt;if expChce == 'Points of Interest':&lt;BR /&gt; inData = in_datavarPOI&lt;BR /&gt; inLyr = inLyrPOI&lt;BR /&gt;else:&lt;BR /&gt; inData = in_datavarTKS&lt;BR /&gt; inLyr = inLyrTKS &lt;BR /&gt; &lt;BR /&gt;# Copy features and attachments to new GDB...&lt;BR /&gt;arcpy.AddMessage('\n... Coping features and attachments to the new File Geodatabase')&lt;BR /&gt;arcpy.Copy_management(in_data=inData,&lt;BR /&gt; out_data=os.path.join(out_location + os.sep + out_name +".gdb", out_name))&lt;/P&gt;&lt;P&gt;# Add New Featureclass to map and symbolize&lt;BR /&gt;arcpy.AddMessage('\n... Adding Copied features to the current map')&lt;BR /&gt;mxd = arcpy.mapping.MapDocument("CURRENT") &lt;BR /&gt;df = mxd.activeDataFrame &lt;BR /&gt;layer = arcpy.mapping.Layer(os.path.join(out_location + os.sep + out_name +".gdb", out_name)) &lt;BR /&gt;arcpy.mapping.AddLayer(df, layer, "TOP")&lt;/P&gt;&lt;P&gt;# List selected data...&lt;BR /&gt;selFeat = []&lt;BR /&gt;with arcpy.da.SearchCursor(inLyr, 'OBJECTID') as cursor:&lt;BR /&gt; for row in cursor:&lt;BR /&gt; selFeat.append(row[0])&lt;BR /&gt;del cursor&lt;/P&gt;&lt;P&gt;# Delete features that were not selected...&lt;BR /&gt;sql = ''&lt;BR /&gt;for sel in selFeat:&lt;BR /&gt; sql += 'OBJECTID = ' + str(sel) + ' OR '&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(out_name, selection_type='NEW_SELECTION', where_clause=sql[:-4])&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(out_name, selection_type='SWITCH_SELECTION')&lt;BR /&gt;arcpy.DeleteFeatures_management(out_name)&lt;/P&gt;&lt;P&gt;# Choose to delete orginal features&lt;BR /&gt;if delFeat == 'true': &lt;BR /&gt; #Start editing&lt;BR /&gt; print "Initiating editing"&lt;BR /&gt; edit = arcpy.da.Editor(sdeconnection)&lt;BR /&gt; edit.startEditing()&lt;BR /&gt; edit.startOperation()&lt;BR /&gt; &lt;BR /&gt; #Test Cursor&lt;BR /&gt; print "Testing cursor"&lt;BR /&gt; Cursor = arcpy.da.UpdateCursor (inData, ["ObjectID"], sql[:-4])&lt;BR /&gt; for row in Cursor:&lt;BR /&gt; print row[0]&lt;BR /&gt; del row&lt;BR /&gt; del Cursor&lt;BR /&gt; &lt;BR /&gt; #Stop/save edits&lt;BR /&gt; edit.stopOperation()&lt;BR /&gt; print "Stopping editing"&lt;BR /&gt; edit.stopEditing("True") &lt;BR /&gt;else:&lt;BR /&gt; arcpy.SelectLayerByAttribute_management(in_layer_or_view=inLyr, selection_type='CLEAR_SELECTION')&lt;BR /&gt; &lt;BR /&gt;arcpy.AddMessage('\n... Finished coping features :)\n')&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 18 May 2018 18:02:49 GMT</pubDate>
    <dc:creator>ShawnKeizer1</dc:creator>
    <dc:date>2018-05-18T18:02:49Z</dc:date>
    <item>
      <title>How do I delete a feature from a ArcGIS for Server Feature server using arcpy?</title>
      <link>https://community.esri.com/t5/developers-questions/how-do-i-delete-a-feature-from-a-arcgis-for-server/m-p/112798#M719</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a feature service created using ArcGIS for Server and using python i want to select feature(s) based on OBJECTID and delete them. The user will be selecting the features to delete in Arcmap. I know i am able to create a local copy, delete them manualy and sync back to the service but i want to do all the lifting via python. Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is what i have so far the section "Choose orginal features to delete" is what i can not get working, the rest of the code works fine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;import os&lt;BR /&gt;from arcpy import env&lt;BR /&gt;env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;# Variables...&lt;BR /&gt;in_datavarPOI = r'U:\Tools\SDE_Connection_Files\RedDeerNorthSaskRegion.GDB@genesis-sde.sde\RedDeerNorthSaskRegion.GDB.POI'&lt;BR /&gt;in_datavarTKS = r'U:\Tools\SDE_Connection_Files\RedDeerNorthSaskRegion.GDB@genesis-sde.sde\RedDeerNorthSaskRegion.GDB.Tracks'&lt;BR /&gt;inLyrPOI = 'AEP Field Data Collection/Points of Interest'&lt;BR /&gt;inLyrTKS = 'AEP Field Data Collection/Tracks'&lt;BR /&gt;sdeconnection = r'U:\Tools\SDE_Connection_Files\RedDeerNorthSaskRegion.GDB@genesis-sde.sde'&lt;BR /&gt;expChce = arcpy.GetParameterAsText(0)&lt;BR /&gt;out_location = arcpy.GetParameterAsText(1)&lt;BR /&gt;out_name = arcpy.GetParameterAsText(2)&lt;BR /&gt;delFeat = arcpy.GetParameterAsText(3)&lt;/P&gt;&lt;P&gt;# Create a FGDB to store copies data...&lt;BR /&gt;arcpy.AddMessage('\n... Creating new File Geodatabase')&lt;BR /&gt;arcpy.CreateFileGDB_management(out_location, out_name)&lt;/P&gt;&lt;P&gt;# Choice of data to export&lt;BR /&gt;if expChce == 'Points of Interest':&lt;BR /&gt; inData = in_datavarPOI&lt;BR /&gt; inLyr = inLyrPOI&lt;BR /&gt;else:&lt;BR /&gt; inData = in_datavarTKS&lt;BR /&gt; inLyr = inLyrTKS &lt;BR /&gt; &lt;BR /&gt;# Copy features and attachments to new GDB...&lt;BR /&gt;arcpy.AddMessage('\n... Coping features and attachments to the new File Geodatabase')&lt;BR /&gt;arcpy.Copy_management(in_data=inData,&lt;BR /&gt; out_data=os.path.join(out_location + os.sep + out_name +".gdb", out_name))&lt;/P&gt;&lt;P&gt;# Add New Featureclass to map and symbolize&lt;BR /&gt;arcpy.AddMessage('\n... Adding Copied features to the current map')&lt;BR /&gt;mxd = arcpy.mapping.MapDocument("CURRENT") &lt;BR /&gt;df = mxd.activeDataFrame &lt;BR /&gt;layer = arcpy.mapping.Layer(os.path.join(out_location + os.sep + out_name +".gdb", out_name)) &lt;BR /&gt;arcpy.mapping.AddLayer(df, layer, "TOP")&lt;/P&gt;&lt;P&gt;# List selected data...&lt;BR /&gt;selFeat = []&lt;BR /&gt;with arcpy.da.SearchCursor(inLyr, 'OBJECTID') as cursor:&lt;BR /&gt; for row in cursor:&lt;BR /&gt; selFeat.append(row[0])&lt;BR /&gt;del cursor&lt;/P&gt;&lt;P&gt;# Delete features that were not selected...&lt;BR /&gt;sql = ''&lt;BR /&gt;for sel in selFeat:&lt;BR /&gt; sql += 'OBJECTID = ' + str(sel) + ' OR '&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(out_name, selection_type='NEW_SELECTION', where_clause=sql[:-4])&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(out_name, selection_type='SWITCH_SELECTION')&lt;BR /&gt;arcpy.DeleteFeatures_management(out_name)&lt;/P&gt;&lt;P&gt;# Choose to delete orginal features&lt;BR /&gt;if delFeat == 'true': &lt;BR /&gt; #Start editing&lt;BR /&gt; print "Initiating editing"&lt;BR /&gt; edit = arcpy.da.Editor(sdeconnection)&lt;BR /&gt; edit.startEditing()&lt;BR /&gt; edit.startOperation()&lt;BR /&gt; &lt;BR /&gt; #Test Cursor&lt;BR /&gt; print "Testing cursor"&lt;BR /&gt; Cursor = arcpy.da.UpdateCursor (inData, ["ObjectID"], sql[:-4])&lt;BR /&gt; for row in Cursor:&lt;BR /&gt; print row[0]&lt;BR /&gt; del row&lt;BR /&gt; del Cursor&lt;BR /&gt; &lt;BR /&gt; #Stop/save edits&lt;BR /&gt; edit.stopOperation()&lt;BR /&gt; print "Stopping editing"&lt;BR /&gt; edit.stopEditing("True") &lt;BR /&gt;else:&lt;BR /&gt; arcpy.SelectLayerByAttribute_management(in_layer_or_view=inLyr, selection_type='CLEAR_SELECTION')&lt;BR /&gt; &lt;BR /&gt;arcpy.AddMessage('\n... Finished coping features :)\n')&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 May 2018 18:02:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/how-do-i-delete-a-feature-from-a-arcgis-for-server/m-p/112798#M719</guid>
      <dc:creator>ShawnKeizer1</dc:creator>
      <dc:date>2018-05-18T18:02:49Z</dc:date>
    </item>
  </channel>
</rss>

