Create a new geodatabase dataset (C++)


This sample will demonstrate the steps needed to create a new geodatabase dataset. The function does not require that the spatial reference be supplied, however it is recommended that you always specify the appropriate spatial reference when modeling your data.

How to use:
  1. Paste the code into your C++ Application..
  2. Call the function from within your application.
// createDataset:  creates a dataset in a workspace
// ISpatialReference is optional but should generally be defined by the caller
HRESULT createDataset(BSTR name, IWorkspace* workspace, IFeatureDataset** ppOutFeatureDataset, 
         ISpatialReference* pSpatialReference)
	if (!workspace || !name)
		return E_POINTER;

	if (ppOutFeatureDataset == NULL)
		return E_POINTER;


	// establish the spatial reference if the caller took advantage of optional parameter
	CComPtr<ISpatialReference> ipSRef = pSpatialReference;
	if (!ipSRef)
		ipSRef->SetDomain(0, 21474.83645, 0, 21474.83645);
		ipSRef->SetMDomain(0, 21474.83645);
		ipSRef->SetZDomain(0, 21474.83645);
		ipSRef->SetZFalseOriginAndUnits(0, 100000);
	CComPtr<IFeatureWorkspace> ipFeatWksp;
	if (FAILED(hr = workspace->QueryInterface(&ipFeatWksp)))
		return hr;

	return ipFeatWksp->CreateFeatureDataset(name, ipSRef, ppOutFeatureDataset);