Skip to content

Instantly share code, notes, and snippets.

@mpayson
Created November 28, 2017 22:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mpayson/471516f8a103eba05287402226473bd1 to your computer and use it in GitHub Desktop.
Save mpayson/471516f8a103eba05287402226473bd1 to your computer and use it in GitHub Desktop.
[ArcGIS Python API] Add a field to a feature service
from arcgis.gis import *
from arcgis.features import FeatureLayer
gis = GIS("https://www.arcgis.com", "<UN>", "<PW>") #for AGOL, also can do Portal URL
fl_url = "<URL>"
fl = FeatureLayer(fl_url, gis)
# about field types http://pro.arcgis.com/en/pro-app/tool-reference/data-management/add-field.htm
# rest endpoint http://resources.arcgis.com/en/help/arcgis-rest-api/#/Add_to_Definition_Feature_Layer/02r300000228000000/
new_field = {
"name": "TEST_STR_FIELD",
"type": "esriFieldTypeString",
"alias": "TEST_STR_FIELD",
"length": 256,
"nullable": True,
"editable": True,
"visible": True,
"domain": None
}
update_dict = {"fields": [new_field]}
fl.manager.add_to_definition(update_dict)
@JosiahParry
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment