ArcGIS API for Python

repository·master·Indexed 24 days ago

https://github.com/esri/arcgis-python-api

A specialized library for geospatial data science and GIS management. It enables users to automate tasks, perform advanced spatial analysis (including deep learning, vector, and raster analysis), and manage web GIS content. The API integrates with the scientific Python ecosystem, including Pandas, Scikit-Learn, Fast.ai, and Jupyter notebooks. It supports deployment via AWS Lambda using a dedicated Docker image and provides utilities for cloning Portal users, groups, and content.

Tokens
15.2K
Snippets
30
Records
91
Agent score
80%

What's inside ArcGIS API for Python

  1. Overview of ArcGIS API for Python

    master

    ArcGIS API for Python is a library designed for working with maps and geospatial data via web GIS. It provides tools for:

    • Analysis: Deep learning, vector and raster analysis, geocoding, routing, and directions.
    • GIS Management: Organizing and managing users, groups, and information items.
    • Map Making: Creating and working with maps and curated geographic data from Esri and other sources.
    • Scientific Integration: Seamless integration with the scientific Python ecosystem, including support for Pandas, Scikit-Learn, Fast.ai, and Jupyter notebooks.
  2. Use the ArcGIS API for Python Lambda base image

    master

    You can use the ghcr.io/esri/arcgis-python-api-lambda:latest Docker image to deploy ArcGIS API for Python workflows to AWS Lambda.

    To use this image:

    1. Set up your Dockerfile using the image as the base and copying your application code to the ${LAMBDA_TASK_ROOT}.
    2. Ensure your application (e.g., app.py) contains a standard AWS Lambda handler method.
    3. Push the resulting image to a private AWS ECR instance. Note that public AWS ECR instances are not supported for Lambda.
    4. Configure your AWS Lambda function to run from this container image.
    FROM ghcr.io/esri/arcgis-python-api-lambda:latest
    COPY app.py ${LAMBDA_TASK_ROOT}
    import arcgis
    
    def handler(event, context):
        """
        AWS Lambda Handler
        """
        print(f"Hello from AWS Lambda using ArcGIS API for Python {arcgis.__version__}!")
  3. Azure Functions deployment guidance

    master
    The AzureFunctionsBaseImage has been deprecated. For Azure Functions development, use the standard Azure Functions runtime instead. Refer to the samples/devops_azure_functions directory in this repository for a sample implementation using the standard runtime deployment.
  4. Ways to execute ArcGIS API for Python notebooks

    master

    You can run the provided sample notebooks and guide chapters using several different environments:

    • Local Installation: Install the API on your computer using a package manager like Anaconda.
    • ArcGIS Pro: Execute notebooks directly within the ArcGIS Pro application.
    • ArcGIS Notebooks: Use the hosted notebook service available on ArcGIS Online.
    • Docker: Run the API within a Dockerised environment.
    • Binder: Execute notebooks in a web-based interactive environment via Binder.
  5. Explore ArcGIS API for Python samples by user role

    master

    The ArcGIS API for Python repository provides a structured collection of Jupyter notebooks organized by user persona. You can follow these sample paths to learn specific workflows:

    • Get Started: For a high-level overview and initial setup.
    • Power Users / Developers: Focuses on core API usage, including the GIS object, the Map widget, Basemaps, Geoprocessing tools, Geometry services, and Smart Mapping.
    • Org Administrators: Covers administrative tasks such as batch creation of Groups and cloning Portal Users, Groups, and Content.
    • GIS Analysts and Data Scientists: Demonstrates spatial analysis, Big Data analytics (GeoAnalytics), and raster analytics using real-world datasets (e.g., floods, forest fires, hurricane tracks).
    • Content Publishers: Focuses on data ingestion and publishing, such as converting HTML tables to Pandas DataFrames, publishing Shapefiles/CSVs, and managing web maps and web scenes.
  6. Populate a fresh portal with users, groups, and content

    master

    This sample provides scripts to automate the population of a fresh ArcGIS Portal with users, groups, and content. The configuration for users and groups is defined in users.csv and groups.csv files within the directory.

    Automated Setup via Batch Files

    You can use the provided batch files to automate the environment setup and script execution:

    1. cloud_formation_a.bat: Downloads and installs Miniconda, then installs the arcgis package into a dedicated environment named cloud_formation.
    2. cloud_formation_b.bat: Executes the Python scripts in sequence to create users, groups, and content. This script requires the Portal URL, administrator username, administrator password, and a log file path as arguments.
    3. clean_up.bat (Optional): Erases all users, groups, and content created by the scripts.
    >> cloud_formation_a.bat
    0
    
    >> cloud_formation_b.bat https://ESRIwebgis.webgistesting.net/portal -u admin -p xxxxxx -l python_log.log
  7. Clone Portal users, groups, and content using clone_portal.py

    master

    The clone_portal.py script is a stand-alone Python utility designed to clone an entire ArcGIS Portal environment from a source portal to a target portal. This includes:

    1. Users: Recreating user accounts in the target portal.
    2. Groups: Recreating groups in the target portal.
    3. Items: Copying content items (e.g., Web Maps, Feature Services, CSVs, etc.) from the source to the target.
    4. Relationships: Re-establishing relationships between items (such as Service2Data relationships) in the target portal to ensure content remains functional.

    To use the script, run it in a Python environment with the ArcGIS API for Python installed. The script will prompt you for the passwords of both the source and target portals during execution.

  8. Understand Conda and its distributions

    master

    Conda is a platform-independent package manager used to install, update, and remove Python packages. It uses channels (repositories) to find software. Esri maintains a specific channel named esri which contains the arcgis package.

    There are two main ways to install Conda:

    • Full Anaconda Distribution: Installs Conda along with hundreds of pre-installed Python packages.
    • Miniconda: A lightweight version that installs only Python, Conda, and the essential libraries required to run Conda.
  9. Anatomy of a Custom Python NLP Function

    master

    To integrate third-party language models (like LLMs or open-source models) into ArcGIS, you must author a custom Python NLP function. This function is packaged as an Esri deep learning package (.dlpk) and must implement several specific methods to handle the model lifecycle and data processing:

    • __init__: The constructor. Initializes instance variables like name and description.
    • initialize: Called at the start. Receives kwargs['model'] (the path to the .emd file). Use this to load model weights and store a reference to the model instance.
    • getParameterInfo: Defines the input parameters the function accepts. Returns a list of dictionaries describing each parameter (name, dataType, required, displayName, description, and value).
    • getConfiguration: Manages parameter updates from the user. It is called after getParameterInfo but before predict. It should return a dictionary containing updated parameter values, including batch_size to inform the tool how to split input data.
    • predict: Performs the actual inference. It receives a FeatureSet containing input text and kwargs containing the input field name. It must return the results as a FeatureSet object.