Instrução
No ArcGIS Pro, as feições de ponto contendo campos de data são importantes para rastrear padrões ao longo do tempo. Às vezes, esses pontos contêm uma duração de data especificada e não são mais válidos para serem exibidos no mapa. Isso é importante para evitar confusão e melhorar a clareza dos dados, pois pontos inválidos podem criar confusão, levando a interpretações incorretas dos dados.
Este artigo descreve o fluxo de trabalho para remover pontos inválidos utilizando ArcPy no ArcGIS Pro.
Note: This workflow requires a full script to run in the ArcGIS Pro Python window. All the indents are to be kept as portrayed in the code block.
import arcpy
import datetime
arcpy.env.workspace = r"<pathToPointFc>"
feature_class = "<featureClassName>"
date_field = "<dateFieldName>"
#If using the Date field type
threshold_date = datetime.datetime(YYYY, MM, DD)
#If using the Date Only field type
threshold_date = datetime.date(YYYY, MM, DD)
try:
edit = arcpy.da.Editor(arcpy.env.workspace)
edit.startEditing(False, True)
edit.startOperation()
with arcpy.da.UpdateCursor(feature_class, ["OID@", date_field]) as cursor:
for row in cursor:
date_value = row[1]
# Check if date is not None and if it's expired
if date_value:
if date_value < threshold_date:
print(f"Deleting feature with OID {row[0]} and date {date_value}")
cursor.deleteRow()
else:
print(f"Skipping feature with OID {row[0]} because date field is None")
edit.stopOperation()
edit.stopEditing(True)
print("Points removed successfully.")
except Exception as e:
print(e)
edit.stopEditing(False)
O bloco de código abaixo demonstra o script completo.
import arcpy
import datetime
arcpy.env.workspace = r"C:\Users\Documents\ArcGIS\Projects\MyProject40\MyProject40.gdb"
feature_class = "Pointsss"
date_field = "Date"
threshold_date = datetime.datetime(2023, 1, 1)
try:
edit = arcpy.da.Editor(arcpy.env.workspace)
edit.startEditing(False, True)
edit.startOperation()
with arcpy.da.UpdateCursor(feature_class, ["OID@", date_field]) as cursor:
for row in cursor:
date_value = row[1]
if date_value:
if date_value < threshold_date:
print(f"Deleting feature with OID {row[0]} and date {date_value}")
cursor.deleteRow()
else:
print(f"Skipping feature with OID {row[0]} because date field is None")
edit.stopOperation()
edit.stopEditing(True)
print("Points removed successfully.")
except Exception as e:
print(e)
edit.stopEditing(False)
A imagem abaixo mostra os pontos expirados removidos usando o ArcPy. Atualize o mapa para aplicar as alterações.

ID do Artigo: 000032387
Obtenha ajuda de especialistas do ArcGIS
Comece a conversar agora