Skip to content

Instantly share code, notes, and snippets.

@maptastik
Last active December 11, 2017 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maptastik/7df70cf854c8f009cdae5eb69e4c3406 to your computer and use it in GitHub Desktop.
Save maptastik/7df70cf854c8f009cdae5eb69e4c3406 to your computer and use it in GitHub Desktop.
Search, select, and generate a pandas DataFrame from a Feature Layer Collection on ArcGIS Online.
import pandas as pd
from arcgis.gis import GIS
# Login to AGOL
gis = GIS()
# For other login methods see: https://developers.arcgis.com/python/guide/working-with-different-authentication-schemes/
# use for logging in within active ArcGIS Pro session
# gis = GIS('pro')
# Create a function that returns a list of feature layer collections for a search
def agolSearch(term):
item_list = []
items = gis.content.search(term, item_type="Feature Layer Collection")
for item in items:
item_list.append(item)
return item_list
results = agolSearch('search terms')
results_select = results[0] # select the index postions at which the item you want is positione. This example selects the first result.
# Create dataframe from selected dataset
results_select_df = results_select.layers[0].query().df
# Check out the first 5 records of the new DataFrame
results_select_df.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment