Select to view content in your preferred language

How to count records in web map layers

237
2
04-04-2025 12:58 PM
Labels (1)
JoseSanchez
Frequent Contributor

Good afternoon

How can I  count records  in web map layers?

I want to count records in two layers from a web map. How can I do that?

# Open web map and layer
#
gis = GIS("Pro")
# Load the web map
webmap_item = gis.content.get("....")
# Load the web map
web_map = WebMap(webmap_item)

for layer in web_map.layers:
layer
print(layer.title)
# Query with return_count_only
# Get the layer as a FeatureLayer object
feature_layer =  ?????
# Count features

0 Kudos
2 Replies
RyanUthoff
MVP Regular Contributor

This should accomplish what you're asking. It's not necessary to bring in the web map. Just use the direct feature service URL from the layer you are needing from your web map.

from arcgis.gis import GIS
from arcgis.features import FeatureLayer

# Connect to ArcGIS Online
gis = GIS("https://arcgis.com", "username", "password")

# Feature Service URL and Table Layer Index
# "https://services.arcgis.com/abc123/arcgis/rest/services/MyService/FeatureServer/1"
table_url = "Your feature service URL"

# Connect to the table
table = FeatureLayer(table_url)

# Count the number of records
record_count = table.query(where="1=1", return_count_only=True)

print(f"Total records in the table: {record_count}")



0 Kudos
JonathanMcD
Frequent Contributor

Suppose it depends where you want to see the record count. If in online, and in a pop-up, you can do this quite easily in Arcade.

0 Kudos