AnsweredAssumed Answered

Create An IRouteLocator

Question asked by geonetadmin on May 22, 2014
Latest reply on May 23, 2014 by geonetadmin
Original User: jflorey

Greetings All,

I have written a tool that accesses the IRouteLocator to get the unit of measure. In order to test the tool, I need to attach an route
locator to my M-Value linear feature class. I have tried creating an event layer, and using the Make Route Event Layer
geoprocessing tool, and still when I query the workspace for locators, the collection does not have any valid locators in it. I have
attached the source code that queries for the locator for reference. It's C++. Any help would be greatly appreciated.

Regards,
Jay

IDatasetPtr pDataset(pFeatureClass);
if(NULL==pDataset) return NULL;
IWorkspacePtr pWorkspace;
if(!SUCCEEDED(pDataset->get_Workspace(&pWorkspace))) return NULL;
if(NULL==pWorkspace) return NULL;
ILocatorManagerPtr pLocManager(__uuidof(LocatorManager));
if(NULL==pLocManager) return NULL;
ILocatorWorkspacePtr pLocWorkspace;
if(!SUCCEEDED(pLocManager->GetLocatorWorkspace(pWorkspace, &pLocWorkspace))) return NULL;
if(NULL==pLocWorkspace) return NULL;
IEnumLocatorPtr pEnumLocators;
esriLocatorQuery queryType=esriLocator;
if(!SUCCEEDED(pLocWorkspace->get_Locators(queryType,CComBSTR(_T("")),&pEnumLocators))) return NULL;
if(NULL==pEnumLocators) return NULL;
ILocatorPtr pLocator;
pEnumLocators->Next(&pLocator);
// pLocator is always NULL
while(NULL!=pLocator)
{
  IRouteLocator2Ptr pRoute(pLocator);
  if(NULL!=pRoute)
  {
   IFeatureClassPtr pRouteClass;
   if(SUCCEEDED(pRoute->get_RouteFeatureClass(&pRouteClass)))
   {
    long lRouteClassId;
    long lFeatureClassId;
    if(SUCCEEDED(pFeatureClass->get_FeatureClassID(&lFeatureClassId)) &&
     SUCCEEDED(pRouteClass->get_FeatureClassID(&lRouteClassId)))
    {
     if(lRouteClassId==lFeatureClassId)
      return pRoute;
    }
   }
  }
  pEnumLocators->Next(&pLocator);
}
return NULL;

Attachments

Outcomes