<?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 Help with - Parameters not valid for delete_features &amp;amp; Deleted 2 Features in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/help-with-parameters-not-valid-for-delete-features/m-p/1400180#M10612</link>
    <description>&lt;P&gt;Hello, I am trying to run a delete features function for any expired feature/point layer. After running the code in Esri Notebook I am receiving "parameters not valid for delete_features" and "Deleted 2 features". There are only two features in the map I am testing the code on (neither should be deleted, expecting a return of "No Features to Delete"). When I revisit the map the feature points are still there. Code below:&lt;BR /&gt;&lt;BR /&gt;# Function to determine if the feature's desired_time_frame has expired&lt;BR /&gt;def is_time_frame_expired(creation_date, desired_time_frame):&lt;BR /&gt;current_date = datetime.datetime.now()&lt;BR /&gt;difference = current_date - creation_date&lt;BR /&gt;&lt;BR /&gt;# Define the maximum age for each time frame&lt;BR /&gt;max_ages = {&lt;BR /&gt;"0-3 months": 90,&lt;BR /&gt;"3-6 months": 180,&lt;BR /&gt;"6-9 months": 270,&lt;BR /&gt;"9-12+ months": 365 # Adjust as necessary for "12+ months"&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;# Calculate the age of the feature in days&lt;BR /&gt;age_in_days = difference.days&lt;BR /&gt;&lt;BR /&gt;# Get the maximum age for the feature's desired_time_frame&lt;BR /&gt;max_age = max_ages.get(desired_time_frame, 0)&lt;BR /&gt;&lt;BR /&gt;# Check if the feature's age exceeds the maximum age for its time frame&lt;BR /&gt;return age_in_days &amp;gt; max_age&lt;/P&gt;&lt;P&gt;# Query all features (adjust as needed for performance)&lt;BR /&gt;features = survey.query(where="1=1").features&lt;/P&gt;&lt;P&gt;# List to hold Object IDs of features to delete&lt;BR /&gt;object_ids_to_delete = []&lt;/P&gt;&lt;P&gt;# Process each feature&lt;BR /&gt;for feature in features:&lt;BR /&gt;creation_date = feature.attributes['CreationDate']&lt;BR /&gt;creation_date = datetime.datetime.fromtimestamp(creation_date / 1000) # Assuming the date is in UNIX timestamp format&lt;BR /&gt;&lt;BR /&gt;# Correct the attribute name to match the one in your feature layer&lt;BR /&gt;desired_time_frame = feature.attributes['desired_time_frame'] # Adjust the attribute name as necessary&lt;BR /&gt;&lt;BR /&gt;# Check if the feature's desired_time_frame has expired&lt;BR /&gt;if is_time_frame_expired(creation_date, desired_time_frame):&lt;BR /&gt;# Find the correct unique identifier field name and use it&lt;BR /&gt;object_id_field_name = survey.properties.objectIdField&lt;BR /&gt;object_ids_to_delete.append(feature.attributes[object_id_field_name])&lt;/P&gt;&lt;P&gt;# Delete features if any are to be deleted&lt;BR /&gt;if object_ids_to_delete:&lt;BR /&gt;delete_result = survey.delete_features(deletes=object_ids_to_delete)&lt;BR /&gt;print(f"Deleted {len(object_ids_to_delete)} features.")&lt;BR /&gt;else:&lt;BR /&gt;print("No features to delete.")&lt;/P&gt;</description>
    <pubDate>Mon, 25 Mar 2024 01:46:09 GMT</pubDate>
    <dc:creator>CedricCorbett</dc:creator>
    <dc:date>2024-03-25T01:46:09Z</dc:date>
    <item>
      <title>Help with - Parameters not valid for delete_features &amp; Deleted 2 Features</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/help-with-parameters-not-valid-for-delete-features/m-p/1400180#M10612</link>
      <description>&lt;P&gt;Hello, I am trying to run a delete features function for any expired feature/point layer. After running the code in Esri Notebook I am receiving "parameters not valid for delete_features" and "Deleted 2 features". There are only two features in the map I am testing the code on (neither should be deleted, expecting a return of "No Features to Delete"). When I revisit the map the feature points are still there. Code below:&lt;BR /&gt;&lt;BR /&gt;# Function to determine if the feature's desired_time_frame has expired&lt;BR /&gt;def is_time_frame_expired(creation_date, desired_time_frame):&lt;BR /&gt;current_date = datetime.datetime.now()&lt;BR /&gt;difference = current_date - creation_date&lt;BR /&gt;&lt;BR /&gt;# Define the maximum age for each time frame&lt;BR /&gt;max_ages = {&lt;BR /&gt;"0-3 months": 90,&lt;BR /&gt;"3-6 months": 180,&lt;BR /&gt;"6-9 months": 270,&lt;BR /&gt;"9-12+ months": 365 # Adjust as necessary for "12+ months"&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;# Calculate the age of the feature in days&lt;BR /&gt;age_in_days = difference.days&lt;BR /&gt;&lt;BR /&gt;# Get the maximum age for the feature's desired_time_frame&lt;BR /&gt;max_age = max_ages.get(desired_time_frame, 0)&lt;BR /&gt;&lt;BR /&gt;# Check if the feature's age exceeds the maximum age for its time frame&lt;BR /&gt;return age_in_days &amp;gt; max_age&lt;/P&gt;&lt;P&gt;# Query all features (adjust as needed for performance)&lt;BR /&gt;features = survey.query(where="1=1").features&lt;/P&gt;&lt;P&gt;# List to hold Object IDs of features to delete&lt;BR /&gt;object_ids_to_delete = []&lt;/P&gt;&lt;P&gt;# Process each feature&lt;BR /&gt;for feature in features:&lt;BR /&gt;creation_date = feature.attributes['CreationDate']&lt;BR /&gt;creation_date = datetime.datetime.fromtimestamp(creation_date / 1000) # Assuming the date is in UNIX timestamp format&lt;BR /&gt;&lt;BR /&gt;# Correct the attribute name to match the one in your feature layer&lt;BR /&gt;desired_time_frame = feature.attributes['desired_time_frame'] # Adjust the attribute name as necessary&lt;BR /&gt;&lt;BR /&gt;# Check if the feature's desired_time_frame has expired&lt;BR /&gt;if is_time_frame_expired(creation_date, desired_time_frame):&lt;BR /&gt;# Find the correct unique identifier field name and use it&lt;BR /&gt;object_id_field_name = survey.properties.objectIdField&lt;BR /&gt;object_ids_to_delete.append(feature.attributes[object_id_field_name])&lt;/P&gt;&lt;P&gt;# Delete features if any are to be deleted&lt;BR /&gt;if object_ids_to_delete:&lt;BR /&gt;delete_result = survey.delete_features(deletes=object_ids_to_delete)&lt;BR /&gt;print(f"Deleted {len(object_ids_to_delete)} features.")&lt;BR /&gt;else:&lt;BR /&gt;print("No features to delete.")&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2024 01:46:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/help-with-parameters-not-valid-for-delete-features/m-p/1400180#M10612</guid>
      <dc:creator>CedricCorbett</dc:creator>
      <dc:date>2024-03-25T01:46:09Z</dc:date>
    </item>
    <item>
      <title>Re: Help with - Parameters not valid for delete_features &amp; Deleted 2 Features</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/help-with-parameters-not-valid-for-delete-features/m-p/1543743#M10721</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/745922"&gt;@CedricCorbett&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The delete_features() deletes parameter is expecting a string of comma-separated values representing the OIDs to delete not a list of integers&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;object_ids_to_delete = ",".join(str(oid) for oid in object_ids_to_delete)
# eg. "12,44,67,98"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The delete_features() will not fail if supplied the wrong format it will run successfully and allow you to access information about any failed deletions, check out the &lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayer.delete_features" target="_blank" rel="noopener"&gt;documentation&lt;/A&gt;. This is why you are getting your print statement executed that "Deleted 2 features", even though they are not deleted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2024 09:41:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/help-with-parameters-not-valid-for-delete-features/m-p/1543743#M10721</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2024-09-30T09:41:55Z</dc:date>
    </item>
  </channel>
</rss>

