This will not work with an ARC/INFO coverage as the feature dataset.
How to use
- Paste the function in your project.
- Call the function from your code.
HRESULT createDatasetFeatureClass(IFeatureDataset *pFDS, BSTR bstrName,
esriFeatureType featType, IFeatureClass **ppFeatureClass, esriGeometryType
geomType=esriGeometryPoint, IFields *pfields=0, IUID *pCLSID=0, IUID
*pCLSEXT=0, BSTR bstrConfigWord=L "")
{
//
// createDatasetFeatureClass: simple helper to create a featureclass in a geodatabase Dataset.
// NOTE: when creating a feature class in a dataset the spatial reference is inherited
// from the dataset object
//
if (!pFDS)
return E_POINTER;
CComBSTR bstrLocalName(bstrName);
if (bstrLocalName == L "")
return E_POINTER;
IUIDPtr ipCLSID(pCLSID);
if (0 == pCLSID)
{
ipCLSID.CreateInstance(CLSID_UID);
// determine the appropriate geometry type corresponding the the feature type
switch (featType)
{
case esriFTSimple:
ipCLSID->put_Value(CComVariant(L
"{d4803ef8-79f4-11d0-97fc-0080c7f79481}")); // IFeature's GUID
break;
case esriFTSimpleJunction:
geomType=esriGeometryPoint;
ipCLSID->put_Value(CComVariant(L
"{f366a3fa-5362-11d2-ab1b-000000000000}"));
// ISimpleJunctionFeature's GUID
break;
case esriFTComplexJunction:
ipCLSID->put_Value(CComVariant(L
"{66f783ae-ea1b-11d1-aa91-00c04fa37b81}"));
// IComplexJunctionFeature's GUID
break;
case esriFTSimpleEdge:
geomType=esriGeometryPolyline;
ipCLSID->put_Value(CComVariant(L
"{8ae6975e-ea99-11d1-aecc-0000f80372b4}"));
// ISimpleEdgeFeature's GUID
break;
case esriFTComplexEdge:
geomType=esriGeometryPolyline;
ipCLSID->put_Value(CComVariant(L
"{c87be760-da2a-11d1-aeba-0000f80372b4}"));
// IComplexEdgeFeature's GUID
break;
case esriFTAnnotation:
return E_FAIL;
default:
return E_FAIL;
}
}
// establish a fields collection
IFieldPtr ipField;
IFieldsPtr ipFields(pfields);
if (0 == ipFields)
{
ipFields.CreateInstance(CLSID_Fields);
IFieldsEditPtr ipFieldsEdit(ipFields);
// create the geometry field
IGeometryDefPtr ipGeomDef(CLSID_GeometryDef);
IGeometryDefEditPtr ipGeomDefEdit(ipGeomDef);
// assign the geometry definiton properties.
ipGeomDefEdit->put_GeometryType(geomType);
ipGeomDefEdit->put_GridCount(1);
ipGeomDefEdit->put_GridSize(0, 10);
ipGeomDefEdit->put_AvgNumPoints(2);
ipGeomDefEdit->put_HasM(VARIANT_FALSE);
ipGeomDefEdit->put_HasM(VARIANT_FALSE);
ipField.CreateInstance(CLSID_Field);
IFieldEditPtr ipFieldEdit(ipField);
ipFieldEdit->put_Name(CComBSTR(L "shape"));
ipFieldEdit->put_AliasName(CComBSTR(L "geometry"));
ipFieldEdit->put_Type(esriFieldTypeGeometry);
ipFieldEdit->putref_GeometryDef(ipGeomDef);
ipFieldsEdit->AddField(ipField);
// create the object id field
ipField.CreateInstance(CLSID_Field);
ipFieldEdit=ipField;
ipFieldEdit->put_Name(CComBSTR(L "OBJECTID"));
ipFieldEdit->put_AliasName(CComBSTR(L "object identifier"));
ipFieldEdit->put_Type(esriFieldTypeOID);
ipFieldsEdit->AddField(ipField);
}
// locate the shape field
CComBSTR bstrShapeFld;
esriFieldType fieldType;
long lNumFields;
ipFields->get_FieldCount(&lNumFields);
for (int i=0; i lt; lNumFields; ++i)
{
ipFields->get_Field(i, &ipField);
ipField->get_Type(&fieldType);
if (esriFieldTypeGeometry == fieldType)
{
ipField->get_Name(&bstrShapeFld);
}
}
HRESULT hr;
hr=pFDS->CreateFeatureClass(bstrName, ipFields, ipCLSID, pCLSEXT, featType,
bstrShapeFld, bstrConfigWord, ppFeatureClass);
return hr;
}
Development licensing | Deployment licensing |
---|---|
Engine Developer Kit | Engine |