arcpy.FeatureSet() From Feature Service

4693
22
Jump to solution
02-16-2018 01:25 PM
JamesCrandall
MVP Frequent Contributor

I'm not having luck with the GlobalID and ParentGlobalID columns when attempting to populate Feature Classes and Tables in a FGDB from a hosted feature service.  It's all fairly straight forward and seems to work just fine, except for when specifying these two fields.

Issues:

1. The GlobalId field does not seem to throw any error, however the feature classes get populated with the value: {00000000-0000-0000-0000-000000000000}

2. There's also related feature classes that contain a ParentGlobalID column as well, these throw an error when attempting to load the feature set "RuntimeError: RecordSetObject: Cannot open table for Load".  If I remove the "ParentGlobalID" column from my list of fields to download, then the process works fine without error (minus the ParentGlobalID column of course).

This is the important section:

fields = """objectid,globalid,SurveyStartTime,SurveyEndTime,CreationDate,Creator,EditDate,Editor"""
taburl =  <URLtoHostedFeatureService>/query/0
where = '1=1'
query = "?where={}&outFields={}&returnGeometry=true&f=json&token={}".format(where, '*', token)
queryfsURL = taburl + query
#try to convert the hosted service to a fgdb table
fs = arcpy.FeatureSet()
fs.load(queryfsURL)
fs.save(r'<pathToDirectory>\downloadTab.gdb\HostedFsNameHere)
#also attempted this
#arcpy.CopyRows_management(fs, r'<pathToDirectory>\downloadTab.gdb\HostedFsNameHere)
0 Kudos
22 Replies
JamesCrandall
MVP Frequent Contributor

As a separate test to possibly isolate if the issues is at the fs.load(url), I populated a json object and inspected the "features" attribute.  This actually shows the correct GlobalID values when printed in the python console.

fields = """objectid,globalid,SurveyStartTime,SurveyEndTime,CreationDate,Creator,EditDate,Editor"""
taburl =  <URLtoHostedFeatureService>/query/0
where = '1=1'
query = "?where={}&outFields={}&returnGeometry=true&f=json&token={}".format(where, '*', token)
queryfsURL = taburl + query

#this shows the globalid values when gfeats is printed in the python console
greq = urllib2.Request(queryfsURL)
gresp = urllib2.urlopen(greq)
gdata = json.load(gresp)
gfeats = gdata['features']
print gfeats
0 Kudos
RandyBurton
MVP Alum

For my previous test I was working in an IDE outside ArcMap (version 10.5).   I will do some experimenting with your last code sample later today.

JamesCrandall
MVP Frequent Contributor

fyi: I attempted in ArcGIS 10.3.1 and 10.4 client with pyScripter, IDLW and PythonWIn in combos of 32 & 64 bit all with the same result.

0 Kudos
JamesCrandall
MVP Frequent Contributor

Hi Randy,

Could you test my hosted feature service?

Please follow me back so that I can send you python code in a message!

0 Kudos
RandyBurton
MVP Alum

Following.  I did some additional testing last night and still couldn't duplicate the issue with the global ID.  I was going to suggest a test of your hosted feature service, and I would be willing to try that later today.

0 Kudos
JamesCrandall
MVP Frequent Contributor

Sending a note now!  Really do appreciate the assist.

0 Kudos
RandyBurton
MVP Alum

I was able to run the script you sent without issue.  I retrieved 41 global IDs:

ObjectID: 1 GlobalID: {3D7FD4DB-8FD4-4150-A6FA-7C8D9F490028}
....
ObjectID: 41 GlobalID: {58DC4684-2657-468D-AF0E-85277746984D}

I also pasted the URL into a web browser and was able to examine the json.  All global IDs were intact.

Since you are using a URL to access the feature, my only suggestion would be to use something like urllib.urlencode to make sure any characters in the URL string that need special encoding  are processed.  The characters include = < >.  But in these tests, it didn't seem to create a problem.

I did wonder about the field names and case sensitivity,  but again this did not seem to be an issue.

Again, my tests were done using 10.5 and Python's 32 bit IDE 2.7.12

JamesCrandall
MVP Frequent Contributor

Thank you!

0 Kudos
JamesCrandall
MVP Frequent Contributor

Run with the python window in ArcGIS Desktop 10.3.1 with both Background Processing checked and unchecked generates the 0's

Run as .bat pointing to C:\Python27\ArcGIS10.3\python.exe generates 0's

Run as .bat pointing to C:\Python27\ArcGISx6410.3\python.exe generates 0's

Run with the python window in ArcGIS Desktop 10.4.1 with both Background Processing checked and unchecked generates the expected GlobalID values.

Run as .bat pointing to C:\Python27\ArcGIS10.4\python.exe generates expected GlobalId values

Run as .bat pointing to C:\Python27\ArcGISx6410.4\python.exe generates 0's

0 Kudos
JamesCrandall
MVP Frequent Contributor

Another test/confirmation: GlobalID values come across fine after FeatureSet.load() when script is run on a feature service published to ArcGIS Server.

0 Kudos