diff --git a/samples/05_content_publishers/DeleteFeatures_onebyone_Portal.ipynb b/samples/05_content_publishers/DeleteFeatures_onebyone_Portal.ipynb new file mode 100644 index 0000000000..8286f96008 --- /dev/null +++ b/samples/05_content_publishers/DeleteFeatures_onebyone_Portal.ipynb @@ -0,0 +1,182 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "from arcgis.gis import GIS\n", + "\n", + "# Iniciar sesión en ArcGIS Online\n", + "gis = GIS(\"https://www.arcgis.com\", \"YOURUSER\", \"YOURPASSWORD\")\n", + "\n", + "# Obtener el Feature Service por su ID\n", + "feature_service_id = \"YOURFEATURESERVICEID\" # Ejemplo: 1234567890abcdef1234567890abcdef\n", + "feature_service = gis.content.get(feature_service_id)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Feature Service: Servicios Técnicos\n" + ] + } + ], + "source": [ + "print(\"Feature Service: \" + feature_service.title)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "# Obtener la capa dentro del Feature Service, request the layer by index\n", + "layer = feature_service.layers[0] # Puedes ajustar el índice según tu cas de uso" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Feature Service: Servicios_Tecnicos\n" + ] + } + ], + "source": [ + "print(\"Feature Service: \" + layer.properties.name)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "# Consultar los elementos que deseas eliminar (por ejemplo, todos los elementos) , consult the features you want to delete (e.g. all features)\n", + "query_result = layer.query()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Número de elementos a eliminar: 64025\n" + ] + } + ], + "source": [ + "print(\"Número de elementos a eliminar: \" + str(len(query_result.features))) # Imprimir el número de elementos a eliminar , print the number of features to delete" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'objectid': 1,\n", + " 'globalid': '3929a7d7-8183-412a-94ec-df0bbb86d249',\n", + " 'zona': '1',\n", + " 'finca': 'Los Ángeles',\n", + " 'MuestreosST': 'Plagas fruta',\n", + " 'id_muestreador': 76,\n", + " 'lote': 21422,\n", + " 'seccion': 100,\n", + " 'grupo': 22,\n", + " 'cosecha': 2,\n", + " 'edad_plagas1': None,\n", + " 'block1': None,\n", + " 'camas_plagasblock': None,\n", + " 'camas_plagas1medio': None,\n", + " 'camas_plagas1medioATK': None,\n", + " 'camas_plagasblockATK': None,\n", + " 'edad_fruta1': '117',\n", + " 'block2': 'medio',\n", + " 'camas_fruta1': '1',\n", + " 'edad_larva1': None,\n", + " 'block3': None,\n", + " 'camas_larva1': None,\n", + " 'edad_pdt1': None,\n", + " 'evaluacion': None,\n", + " 'edad_prepa1': None,\n", + " 'blockprepa': None,\n", + " 'CreationDate': 1685038623651,\n", + " 'Creator': 'Admin_Pindeco',\n", + " 'EditDate': 1685120477962,\n", + " 'Editor': 'Admin_Pindeco'}" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "feature.attributes" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + " # Borrar cada elemento uno por uno , DeleteFeatures_onebyone\n", + "for feature in query_result.features:\n", + " layer.edit_features(deletes=str(feature.attributes[\"objectid\"]))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# borrar todos los elementos de una sola vez - Delete all features at once\n", + "layer.edit_features(deletes=str([feature.attributes['objectid'] for feature in query_result.features]))" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.16" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}