Wednesday 10 April 2019

arcpy - Is it possible to consume ArcGIS Hosted Table into local or ArcSDE geodatabase?


I would like to publish a table to our ArcGIS Online (AGOL) organization account.


Is it possible to consume hosted features in AGOL to a local db or ArcSDE database connection?


By consume I mean import a hosted ArcGIS Online table into a geodatabase with ArcPy.



By local db, I mean file geodatabase



Answer



Give a quick read of this blog. It lays the ground work for what you want to do. You just need to replace FeatureSet with RecordSet.


The following code uses a featureservice, and brings down the items as a table -- you keep saying table, so I assume you're talking items without geometry. If you actually mean features, change the returnGeo field to True, and then flip RecordSet to FeatureSet, and CopyRows to CopyFeatures


import arcpy

FSURL = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Military/FeatureServer/2/"

where = "1=1"
fields = "reinforced, speed, countrycode, staffcomment"

returnGeo = False
token = ''

query = "query?where={0}&outFields={1}&returnGeometry={2}&returnIdsOnly=false&returnCountOnly=false&f=json&token={3}".format(
where, fields, returnGeo, token)

url = FSURL + query
rs = arcpy.RecordSet()
rs.load(url)


arcpy.CopyRows_management(rs, r"c:\temp\f.gdb\fsTable")

Modify the query, where clause and fields to match what you want to copy local from your featureservice.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...