How to connect to a shapefile workspace


Making a connection to a workspace is the foundation to accessing data. This sample will show you how to connect to a a directory on disk to access shapefile data. The example code is a function that takes the path to the directory as a string and returns a workspace.
 

How to use

  1. Paste the function in your project.
  2. Call the function from your code.
[VCPP]
//
// openShapeFileWorkspace
// Note: location CANNOT be relative path ".\data\usa" it must be explicit pathname
//
HRESULT openShapeFileWorkspace(BSTR location, IWorkspace **outWorkspace)
{
  HRESULT hr;

  // open the workspace
  CComPtr < IWorkspaceFactory > ipWorkspaceFactory;
  ipWorkspaceFactory.CoCreateInstance(CLSID_ShapefileWorkspaceFactory);

  return ipWorkspaceFactory->OpenFromFile(location, NULL, outWorkspace);
}






Development licensing Deployment licensing
Engine Developer Kit Engine