Select to view content in your preferred language

Saving a featureSet to a feature class

3079
4
08-04-2011 01:32 PM
HemingZhu
Frequent Contributor
I create a gp service on ArcGIS server. Within this GP service there is a sub model which basically is Feature Class to Feature Class system tool except that Input Features parameter is a featureSet instead of featue class. The purpose of that is I want to save a featureSet from a query result to a feature class in %scratchworkspace%\scratch.gdb. It successfully save the featureset except for one thing: it only saved OBJECTID and Shape fields. all the other fields are lost in the process! Do someone have any ideas or Do i missing something? I have tried Copy Features, Table to Table and Copy Rows. They all have the same results. If i used the gp service on a mxd. It worked perfectly. That lead me to suspect it might have something to do with the FeatureSet. I wish someone can enlighten me on this.
Tags (2)
0 Kudos
4 Replies
BenjaminZank1
Deactivated User
Heming,
I have a script that does something similar, but rather than creating a feature class in the scratch.gdb, my script creates a new file geodatabase in the the scratch folder and uses feature class to feature class to populate features while applying a query. The geodatabase is then zipped so it can be downloaded by a user.

You could try creating a new file GDB in the scratch folder and populate the feature class using Feature Class to Feature Class in the new GDB rather than using the sratch.gdb.

Alternately, rather than populating with Feature Class to Feature Class. You could create a new empty feature class in the sratch.gdb using Create Feature Class, setting your input or feature set as the template feature class (so the schemas match) . You could then use the Append to add the feature set (or a feature layer to which you apply your query) to the newly created feature class.

Not sure why what you are trying wouldn't work, but it my be worth trying a work around. 

Best of luck,
BZ
0 Kudos
HemingZhu
Frequent Contributor
Heming,
I have a script that does something similar, but rather than creating a feature class in the scratch.gdb, my script creates a new file geodatabase in the the scratch folder and uses feature class to feature class to populate features while applying a query. The geodatabase is then zipped so it can be downloaded by a user.

You could try creating a new file GDB in the scratch folder and populate the feature class using Feature Class to Feature Class in the new GDB rather than using the sratch.gdb.

Alternately, rather than populating with Feature Class to Feature Class. You could create a new empty feature class in the sratch.gdb using Create Feature Class, setting your input or feature set as the template feature class (so the schemas match) . You could then use the Append to add the feature set (or a feature layer to which you apply your query) to the newly created feature class.

Not sure why what you are trying wouldn't work, but it my be worth trying a work around. 

Best of luck,
BZ


Thanks for reply. I have tried all the things you mentioned. I got the same results. I think the problem is not on those arcpy functions other than arcpy does not treat a featureset, which is a queryTask result from Web API, as a feature class or feature layer as ESRI doc claim. I do find a work around by changing the type from FeaturSet to FeatureLayer. Thanks for your suggestion anyway!
0 Kudos
ChristopherFricke1
Deactivated User
What is the schema for your featureset input?  It sounds like something might be wonky with that since you are getting data out the other end, just missing fields.

1) Check schema of featureset input for tool.
2) If this is correct, you might want to do some error checking in your tool itself before you output to feature class.  Make sure all the fields are going into your featureclass->featureclass
featureset = your featureset
fields = arcpy.ListFields(featureset)
for field in fields:
    arcpy.AddMessage(field.name)
arcpy.CopyFeatures_management(featureset, outputFeatureclass)
0 Kudos
HemingZhu
Frequent Contributor
What is the schema for your featureset input?  It sounds like something might be wonky with that since you are getting data out the other end, just missing fields.

1) Check schema of featureset input for tool.
2) If this is correct, you might want to do some error checking in your tool itself before you output to feature class.  Make sure all the fields are going into your featureclass->featureclass
featureset = your featureset
fields = arcpy.ListFields(featureset)
for field in fields:
    arcpy.AddMessage(field.name)
arcpy.CopyFeatures_management(featureset, outputFeatureclass)


First of all, I cann't use predefined schema because the featureset is based on user's choice of layer in .mxd, it is dynamic. Since featureset is the lightweight of featureclass, I thought the arcpy.ListFields(featureset) would give me a list of fields. Actually it is not the case. Featureset is a common result of interacting with map, unfortunately there is no easy ways to get its field names through arcpy.  Thanks for your suggestion.
0 Kudos