AnsweredAssumed Answered

Add a column to a layer object (inner join) then map amended layer 

Question asked by g_singh on May 11, 2018
Latest reply on Jun 9, 2018 by jrmatchett

I'm new to ArcGIS for Python and I've been trying to figure this out for 2 weeks. I am doing this in a ESRI python 3 jupyter notebook. editing feature layer spatial dataframe jupyter notebook


import pandas as pd
import arcgis
from arcgis.gis import GIS
my_gis = GIS()


#get feature layer
search_subset ="SA2_GEN_ID_2011", item_type = "Feature Layer")
subset_item = search_subset[0]
subset_feature_layer = subset_item.layers[0]


#query and create spatialdataframe
query_result = subset_feature_layer.query( where='SA2_MAIN>300000000 AND SA2_MAIN<400000000')
att_data_frame = query_result.df


#merge with suburb risk data (output is now a regular dataframe)
suburb_risk_data = pd.read_csv("")
suburb_risk_data['SA2_MAIN'] = suburb_risk_data['SA2_MAIN'].astype(str)
output = pd.merge(suburb_risk_data, att_data_frame, on='SA2_MAIN', how='inner')


Now i run into difficulty, I don't know how to convert the output dataframe into an object  that I can map using the .add_layer() method. The output dataframe has a 'SHAPE' column with the geographical information required for mapping (I think).


#map the merged data (this fails because output is a dataframe)

subset_map ="Queensland, Australia", zoomlevel=6)
subset_map.add_layer(output, { "renderer":"ClassedColorRenderer", "field_name":"stress_likelihood" })


I need to edit the layer here because I run a fairly complex python script above this to calculate the variables that I merge with the feature layer. I need to show how the variables change geographically based on the inputs the user provides. 


Any help much appreciated!