Select to view content in your preferred language

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

05-11-2018 05:19 PM
New Contributor

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!

0 Kudos
1 Reply
New Contributor III

Does converting the SpatialDataFrame to a FeatureSet work?

subset_map.add_layer(output.to_featureset(), { "renderer":"ClassedColorRenderer", "field_name":"stress_likelihood" })
0 Kudos