AnsweredAssumed Answered

ArcGIS API for Python not plotting Spatially Enabled Dataframe

Question asked by miguelf88 on Jan 7, 2020

I'm pulling data from an API and viewing it in a pandas dataframe using a Jupyter Notebook. The data has several attributes including latitude and longitude. I can successfully convert the pandas dataframe to a spatially enabled dataframe, call the .head() method and see the new SHAPE column. I can create a map object but when I try to plot my dataframe on the map object, the map does not update and display the points. I've included my code below:

# Define parameters for API call
headers = {
    'accept': 'application/json',
    'Api-Token': 'Key',
    'Agency-ID': 'ID'
}

# Call API and save to a varialbe
response = requests.get('URL', headers=headers).json()

# Convert json to dataframe
df = pd.DataFrame(response)

# Convert dataframe to spatially enabled dataframe
df = pd.DataFrame.spatial.from_xy(df, x_column = 'longitude', y_column = 'latitude')

# Create map object and display map
gis = GIS()
m = GIS().map()
m.center = [36.081179, -79.556955]
m.zoom = 9
m

# Plot dataframe
df.spatial.plot(map_widget= m)

Line 22 returns a map and Line 25 returns 'True' but no updates to the map are made. I've also tried using the renderer and symbol_type and symbol_style attributes.

df.spatial.plot(map_widget=m,
            symbol_type='simple',
            symbol_style='d', # d - for diamonds
            colors='Reds_r',
            cstep=10,
            outline_color='Blues',
            marker_size=10)

This block of code replaced Line 25 in the first section but did not display in the map either.

 

I've been through the documentation and the guide on GitHub but cannot find anything to make it work. Please advise.

 

Thanks,

Miguel Fernandez

Outcomes