Last active
April 26, 2019 20:20
-
-
Save nommuna2/15f33a5734db106957add566a83fb5fe to your computer and use it in GitHub Desktop.
(ArcGIS API for Python) Publish a feature layer from server to AGO idea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sample of how to copy a feature layer from a local ArcGIS server and publish it to AGOL. | |
import arcgis | |
from arcgis import features | |
from arcgis import GIS | |
from arcgis.gis import Item | |
import json | |
gis = GIS(username="username", password= "password") | |
#Turn Feature Layer to a Feature Set | |
feature_layer = features.FeatureLayer(url="https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0") | |
featureSet = feature_layer.query(where='1=1', out_fields= '*') | |
#Turn FeatureSet to JSON | |
FeatureSetAsjson = featureSet.to_json | |
#Write the JSON to a file on disk | |
with open(r'path to local\featureCollection.json', 'w') as f: | |
json.dump(FeatureSetAsjson, f) | |
#Add the file to AGO and publish | |
fcItem = gis.content.add({'type': 'Feature Collection', 'title': 'MyFeautrelayerFromFC'}, data= r'path to local\featureCollection.json') | |
fcItem.publish() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment