Create An IRouteLocator

1909
2
05-22-2014 04:17 PM
by Anonymous User
Not applicable
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;
Reply
0 Kudos
2 Replies
by Anonymous User
Not applicable
Original User: jflorey

Hi All,

An update to my original post. This morning I added an Address Locator to the geodatabase and was able to verify that the code up to the point where it queries the IEnumLocator for the next Locator is working and does correctly return the Address Locator. I also tried creating an IRouteLocator on the fly using sample code, but the locator is not stored in the geodatabase, even though I made sure that the locator was still in scope when I ran my code. Is there any way to store an IRouteLocator created on the fly in the geodatabase so that it can be retrieved later for reuse?

Regards,
Jay
Reply
0 Kudos
by Anonymous User
Not applicable
Original User: jflorey

Hi All,

Second update. I tried to add the locator created in code to the locator workspace using the ILocatorWorkspace AddLocator function, but it failed with an InvalidCastException. I tried it with both the IRouteLocator2 interface and an ILocator interface.

Cheers,
Jay
Reply
0 Kudos