2

I am making an exact (empty) copy of an existing featureclass using the following code:

public static string createFCCopy(IFeatureClass pFromFC, IFeatureWorkspace pToFWS, string sNewFCName)
{
    IFeatureClass pNewFC;
    UID pUID;

    pUID = new UIDClass();
    pUID.Value = UID_FEATURECLASS; // UID_FEATURECLASS is a constant set to "esriGeodatabase.Feature"

    sShpFld = pFromFC.ShapeFieldName;
    pNewFC = pToFWS.CreateFeatureClass(sNewFC, pFromFC.Fields, pUID, null, pFromFC.FeatureType, sShpFld, "");
}

The problem is that the resulting copy does not have Measures and Z set like the original.

Is there a way of specifying the fields set that preserves the HasM and HasZ values in the Geometry Def?

2
  • I usually go through creating the IFields/IFieldsEdit from scratch, iterating the input fields and with the IGeometryDefEdit modify the HasM and HasZ as needed. I don't know why your HasM and HasZ properties aren't being copied but perhaps try starting from IFields OutFields = new FieldsClass(); and then for (int fIndx = 0;fIndx < pFromFC.Fields.FieldCount;fIndx++) add new fields created like the pFromFC. The only code that I have for copying a feature class is in VB.net, can you speak VB? Commented Jul 6, 2017 at 23:23
  • I don't remember where it is, but somewhere in the documentation it says not to directly use a feature class's Fields object to make another feature class. See if it works if you do this instead: (pFromFC.Fields as IClone).Clone() as IFields. If that doesn't work, you'll either have to alter the cloned fields object or make the whole thing from scratch.
    – danielm
    Commented Jul 7, 2017 at 14:46

1 Answer 1

1

Curious about this problem I wrote the following code in VBA and it transferred over the ZM properties without any problems.

Public Sub CreateFC()
     Dim pMxDoc As IMxDocument
     Set pMxDoc = ThisDocument
     Dim pFL As IFeatureLayer
     Dim pL As ILayer
     Dim pFC As IFeatureClass
     Set pL = pMxDoc.FocusMap.Layer(0)
     Set pFL = pL
     Set pFC = pFL.FeatureClass
     Dim pUID As UID
     Set pUID = New UID
     pUID.Value = "esriGeodatabase.Feature"
     Dim pFWs As IFeatureWorkspace
     Dim pWS As IWorkspace
     Dim pWSF As IWorkspaceFactory
     Set pWSF = New FileGDBWorkspaceFactory
     Set pWS = pWSF.OpenFromFile("c:\scratch\fGDB_Scratch.gdb", 0)
     Set pFWs = pWS
     Dim pNewFC As IFeatureClass
     Set pNewFC = pFWs.CreateFeatureClass("fcTest", pFC.Fields, pUID, Nothing, pFC.FeatureType, pFC.ShapeFieldName, "")
End Sub

Looking at your code it's possible to provide a different shape field name to the one that is in the FeatureClass you are copying from, may be you have introduced some sort of conflict and it is dropping ZM property?

Failing this you could call the Geo-processing tool Create FeatureClass using the IGeoProcessor?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.