arcpy.FeatureSet() From Feature Service

2849
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
1 Solution

Accepted Solutions
JamesCrandall
MVP Frequent Contributor

Moving latest testing results out as reply to OP:

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

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

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

 

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

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

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

View solution in original post

22 Replies
JoshuaBixby
MVP Esteemed Contributor

What version of server and client are you running?  I just tested your general steps using a feature service from ArcGIS Enterprise 10.5.1 and ArcGIS Pro 2.1 and the GlobalIDs are intact.

JamesCrandall
MVP Frequent Contributor

ArcGIS Server 10.4 (maybe 10.4.1)

ArcGIS Desktop 10.3.1

Good point -- I do have a 10.4 client I use to publish GP services but I didn't run this particular script on that box.  I only ran (with my issues) on the 10.3 install.

I'll check that out!

Thank you.

0 Kudos
JamesCrandall
MVP Frequent Contributor

Thanks again,

I ran the script from a client with ArcGIS Desktop10.4 installed but has the same issue with GlobalID -- it creates the feature class without error including all of the fields specified, but the globalId column is populated with {00000000-0000-0000-0000-000000000000}

Also: this is a hosted feature service on AGOL that I'm working with.

From the Feature Service end point:

  • globalid (type: esriFieldTypeGlobalID, alias: GlobalID, SQL Type: sqlTypeGUID, length: 38, nullable: false, editable: false)
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I only have access to an ArcMap 10.6 machine today, but I tested the same feature service I used to test with Pro 2.1, and the GlobalID field carries through fine.  So, it is either a hosted-feature service issue or client version issue.  I will test an older client and AGOL hosted feature service sometime soon.

JamesCrandall
MVP Frequent Contributor

Much appreciated. 

0 Kudos
RandyBurton
MVP Regular Contributor

I was experimenting with your script and was able to get a feature from AGOL with the global ID intact.  Since this is a URL request, I was wondering if the "where" clause might be part of the problem.  Normally the 1=1 would be encoded as 1%3D1 (%3D would be the equals sign).   Edit-- I did another try using where=1=1 (without escaping the equals sign) and was able to get the global IDs.

Have you examined the returned json before inserting it into your database to verify the global IDs?

JamesCrandall
MVP Frequent Contributor

Good call, Randy.  I did as you suggested and set a search cursor on the FeatureSet() after .load() to see what the GlobalID values are at that point (before converting to fgdb Feature Classes / tables).

You're test validates that they are {00000000-0000-0000-0000-000000000000}

When queried on the REST endpoint (WHERE 1=1, Fields = *) I see the globalid and parentglobalid values as expected.

with arcpy.da.SearchCursor(fs, ['objectid','globalid']) as fscur:
   for fsrow in fscur:
       print fsrow[1]

##result:
globalid
{00000000-0000-0000-0000-000000000000}
{00000000-0000-0000-0000-000000000000}
{00000000-0000-0000-0000-000000000000}‍‍‍‍‍‍‍‍‍
0 Kudos
JamesCrandall
MVP Frequent Contributor

Have you examined the returned json before inserting it into your database to verify the global IDs?

Response on the request from Dev Tools Response tab is:

"features" : [
    {
      "attributes" : {
        "objectid" : 2,
        "globalid" : "9667a224-a732-49f3-b3c2-3eafb17a482d",

0 Kudos
JamesCrandall
MVP Frequent Contributor

I have published a new feature service from a different feature class source (containing globalid's) and re-running the script produces the same {00000000-0000-0000-0000-000000000000} globald values.

0 Kudos