CopyFeatures_management doens't include globalid

1922
9
08-24-2018 01:13 PM
danbecker
Regular Contributor

fields = "*"

where = "objectid > 0"

gdbfc = os.path.join(localgdb,"intercept_" + layerName +"_"+ str(dtstr))

query = "/query?where={}&outFields={}&returnGeometry=true&f=json&token={}".format(where, fields, token)
fsURL = baseURL + layerID + query

fs = arcpy.FeatureSet()

fs.load(fsURL)

arcpy.CopyFeatures_management(fs, gdbfc)

the resulting feature class doesn't contain any globalid values, (doesnt' even contain the field) but I can see them in the featureSet. Any pointers on how to include the original globalid values? They are used for relationships and are important.

0 Kudos
9 Replies
DanPatterson_Retired
MVP Esteemed Contributor

Copy features and Feature Class to Feature Class—Conversion toolbox | ArcGIS Desktop are your options.

It must have something with your use of a featureset.

The environment setting

Preserve Global IDs (Environment setting)—Geoprocessing | ArcGIS Desktop is supported by the FeatureClassToFeatureClass tool, but doesn't appear to be by Copy Features.

Check that environment setting for other options that might be useful if you need copy features

danbecker
Regular Contributor

Can a featureSet be input to the feature class to feature class tool?

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

From the link... The feature class or feature layer that will be converted.

which might be your problem since I can't find any other 'copy-like' tools that supports it... and I presume a 'clone' of the globalid won't cut it.

0 Kudos
danbecker
Regular Contributor

Am I missing something here? Is there a way to dump a feature service layer using the REST API where all fields are copied verbatim?

Do I have to decode the JSON string from the returned featureSet  and manually build a feature class?

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

With no mention of globalid's, there are a number of links on geonet.

How to copy all records from a Map/Feature Service 

And this one from Jake Skinner‌ on GitHub looks promising

GitHub - pmacMaps/copy-features-from-map-service: Python module for copying records from a map/featu... 

could be Python‌ isn't the best place to post... maybe one of those web places ArcGIS REST API i‌f those don't pan out or Jake doesn't see this post

0 Kudos
JoeBorgione
MVP Esteemed Contributor

Uggh.. Gobal IDs:  I love 'em and I hate 'em equally.  The copy features tool is generally used to 'move' a feature class from one gbd to another, right?  As a personal rule I avoid shapefiles, so I won't go down that rabbit hole.

At any rate, let's back up a click or two; when you add a Global ID to a featureclass, the resulting values are auto generated.  I look at Global ID values as a property/function of the gdb, and have no control over them.  Which is great with respect to adding new records to that fc within that gdb and keeping track between replication parents and children.  The downfall is the values won't transfer if/when you move, copy, append,  or load a feature class from one gdb to another.  That's just the rule of the game.

If you add a GUID field to a feature class within a gbd, you will need to populate the values.  Upon entering a new record, you would need to populate the GUID_field value as well. (google 'python uuid' for more info.)  But a GUID value will transfer to another gdb.  

Personally, I have only used GlobalIDs in database replication.  Recently I've been exposed to their use in Survey 123 where GobalIDs are deployed as a relationship key to related tables.  The thing is, Survey 123 adds a GUID field to the related table that holds the 'parent global id'.  All is good if you don't want to move the data and related tables from AGOL to your own portal or hub, or vice-versa.

That should just about do it....
0 Kudos
danbecker
Regular Contributor

The hosted feature service I'm attempting to dump was generated from survey123 connect. After wasting hours last Friday dealing with globalid values not being properly dumped via REST API and CopyFeatures_Management tool, I just decided to do this the quick way today. Simply login to portal, Export the entire database to FGDB.

And, like magic, the local FGDB contains all globalid and parentglobalid values. Now, I can just loop over the various tables and build my exported Excel file like I want.

Sure, it would be nice to just dump via REST API so one doesn't have to continually login/dump to FGDB/extract, ect... but the process only takes 2 minutes vs. hours trying to figure out how to do it via the REST API. Our fixed price contracts don't support learning curves very well

thanks everyone.

0 Kudos
JoeBorgione
MVP Esteemed Contributor

Awesome!

The issue I dealt with with survey 123 is once I got the data into a file gdb, I had to then get the data into an Enterprise GDB...

That should just about do it....
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

GlobalID| Definition - Esri Support GIS Dictionary :

[ESRI software] A field of type UUID (Universal Unique Identifier) in which values are automatically assigned by the geodatabase when a row is created. The GlobalID field is necessary for maintaining object uniqueness across replicas. All feature classes and tables participating in one-way or two-way replication must contain the GlobalID field. This field is not editable and is automatically populated when it is added for existing data.

Since GlobalIDs were primarily created for geodatabase replication, what about using Create Replica—ArcGIS REST API: Services Directory | ArcGIS for Developers ?