ArcGIS API for Python not plotting Spatially Enabled Dataframe

987
2
01-07-2020 02:08 PM
Miguel-Fernandez
Occasional Contributor

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

Miguel Fernandez
0 Kudos
2 Replies
Miguel-Fernandez
Occasional Contributor

One year and a few months later, and I still can't get the data to plot. Can anyone offer any insights?

Miguel Fernandez
0 Kudos
ConradSchaefer__DOIT_
New Contributor III

Miguel-Fernandez

I am in a Jupyter Notebook using the same basic code as you, except that I ingest a csv of records. The records contain an x field and y field, both type float. I create a dataframe (which has no geometry typed SHAPE field), then convert it to a spatially enabled dataframe using from_xy(). I can see the new SHAPE field typed geometry. I can then call the following after creating a map widget first.

centroids_sdf.spatial.plot(map_widget=map_widget) # WORKS

Could it be that your latitude and longitude values are not numeric? You didn't paste your df.info() so it's not possible to see your fields and types. 

Just an idea.

Thanks

0 Kudos