The provided code connects to an ArcGIS account, retrieves content...

September 5, 2025 at 02:09 PM

from arcgis.gis import GIS import pandas as pd import inspect gis = GIS("home") all_items = gis.content.search(query="", max_items=-1) all_users = gis.users.search('*', max_users=300) details_list = [] for item in all_items: # Compile the additional details for each item sngl_list = [item.id, item.title, item.type, item.owner, item.access, item.lastViewed, item.numViews, item.numRatings, item.rating, item.created, item.modified, item.size] details_list.append(sngl_list) # Write the df to a file details_df = pd.DataFrame(details_list, columns =['id', 'title', 'type', 'owner_username', 'access', 'last_view', 'number_views', 'number_ratings', 'rating', 'created', 'modified', 'size'])

The provided code connects to an ArcGIS account, retrieves content (items) and users, and processes the metadata of all items into a pandas DataFrame for further analysis or storage. Here's a detailed breakdown of the code:

  1. Import Modules:

    • arcgis.gis is used to interact with the ArcGIS platform using the GIS module.
    • pandas is imported as pd for managing tabular data.
  2. Establishes GIS Connection:

    • gis = GIS("home") creates a connection to the ArcGIS account using an authenticated session ("home" refers to the user's currently logged-in account).
  3. Retrieve All Content Items from ArcGIS Content:

    • gis.content.search(query="", max_items=-1) retrieves all available content items in the GIS.
    • query="" effectively matches all items, and max_items=-1 ensures there is no upper limit to the number of returned items.
  4. Retrieve All Users:

    • gis.users.search('*', max_users=300) retrieves up to 300 users in the GIS organization. (Note that user details are retrieved but not used further in this code.)
  5. Extract Details for Each Item:

    • The code iterates through all retrieved content items (all_items).
    • For each item, several metadata properties are extracted: id, title, type, owner (username), access level, last viewed, number of views, number of ratings, average rating, created timestamp, modified timestamp, and size.
    • This information is stored as a list called sngl_list, which is then appended to a details_list.
  6. Create a DataFrame:

    • The list of all item details (details_list) is used to create a pandas DataFrame.
    • The DataFrame has proper column names: 'id', 'title', 'type', 'owner_username', 'access', 'last_view', 'number_views', 'number_ratings', 'rating', 'created', 'modified', 'size'.
  7. Output or Save the DataFrame (implicit):

    • Though not explicitly stated in the code, the DataFrame (details_df) can be further analyzed or written to a file, such as a CSV, for reporting, audit, or analysis purposes.

Summary:

This code connects to the user's ArcGIS account, fetches metadata for all content items in the account, and organizes the data into a pandas DataFrame. The resulting DataFrame includes attributes like titles, authors, types, and other usage-related properties of the items.

Generate your own explanations
Download our vscode extension
Read other generated explanations

Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node