问题描述
publicvoidSolveRoute(){IWorkspaceFactoryworkspaceFactory=System.Activator.CreateInstance(System.Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory"))asIWorkspaceFactory;IFeatureWorkspacefeatureWorkspace=workspaceFactory.OpenFromFile(FGDB_WORKSPACE,0)asIFeatureWorkspace;IFeatureClassinputStopsFClass=featureWorkspace.OpenFeatureClass(INPUT_STOPS_FC);IFeatureClassinputStopsToFClass=featureWorkspace.OpenFeatureClass(INPUT_STOPS_TO_FC);IFeatureClassinputStreetClass=featureWorkspace.OpenFeatureClass(INPUT_STREET_SHP);//ObtainthedatasetcontainerfromtheworkspaceESRI.ArcGIS.Geodatabase.IFeatureDatasetfeatureDataset=featureWorkspace.OpenFeatureDataset(FEATURE_DATASET);varfeatureDatasetExtensionContainer=featureDatasetasESRI.ArcGIS.Geodatabase.IFeatureDatasetExtensionContainer;ESRI.ArcGIS.Geodatabase.IFeatureDatasetExtensionfeatureDatasetExtension=featureDatasetExtensionContainer.FindExtension(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTNetworkDataset);vardatasetContainer3=featureDatasetExtensionasESRI.ArcGIS.Geodatabase.IDatasetContainer3;//Usethecontainertoopenthenetworkdataset.ESRI.ArcGIS.Geodatabase.IDatasetdataset=datasetContainer3.get_DatasetByName(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTNetworkDataset,NETWORK_DATASET);INetworkDatasetnetworkDataset=datasetasINetworkDataset;INALayernaLayerSA=CreateClosestFacilityLayer("ClosestFacility",networkDataset);INAContextnaSAContext=naLayerSA.Context;LoadNANetworkLocations("Incidents",inputStopsFClass,30000,naSAContext);LoadNANetworkLocations("Facilities",inputStopsToFClass,30000,naSAContext);INASolvernaSASolver=naSAContext.Solver;IGPMessagesnGPMessages=newGPMessagesClass();naSASolver.Solve(naSAContext,nGPMessages,newCancelTracker());//运行到此处提示未处理的OutOfMemoryExceptionINALayernaSAResultLayer=naSASolver.CreateLayer(naSAContext);SaveLayerToDisk(naSAResultLayerasILayer,System.Environment.CurrentDirectory+@"ClosestFacility.lyr");}privateINALayerCreateClosestFacilityLayer(StringlayerName,INetworkDatasetnetworkDataset){INAClosestFacilitySolvernaClosestFacilitySolver=newNAClosestFacilitySolverClass();INASolverSettingsnaSolverSettings=naClosestFacilitySolverasINASolverSettings;INASolvernaSolver=naClosestFacilitySolverasINASolver;//GettheNetworkDataset'sDataElementIDatasetComponentdatasetComponent=networkDatasetasIDatasetComponent;boolTestOldData=true;try{IDENetworkDatasetdeNetworkDataset=datasetComponent.DataElementasIDENetworkDataset;}catch(System.Exceptionex){TestOldData=false;}if(TestOldData){IDENetworkDatasetdeNetworkDataset2=datasetComponent.DataElementasIDENetworkDataset;INAContextnaContext;naContext=naSolver.CreateContext(deNetworkDataset2,layerName);INAContextEditnaContextEdit=naContextasINAContextEdit;IGPMessagespGPMessages=newGPMessagesClass();naContextEdit.Bind(networkDataset,pGPMessages);//IGPMessagespGPMessages//naContextEdit.Bind(networkDataset,newGPMessagesClass());//CreatetheNALayerINALayernaLayer;naLayer=naSolver.CreateLayer(naContext);(naLayerasILayer).Name=layerName;naClosestFacilitySolver.OutputLines=esriNAOutputLineType.esriNAOutputLineTrueShapeWithMeasure;naClosestFacilitySolver.TravelDirection=esriNATravelDirection.esriNATravelDirectionToFacility;//UpdatethecontextbasedonthechangesmadetothesolversettingsIGPMessagesmGPMessages=newGPMessagesClass();naSolver.UpdateContext(naContext,deNetworkDataset2,mGPMessages);//ReturnthelayerreturnnaLayer;}else{returnnull;}}publicvoidLoadNANetworkLocations(stringstrNAClassName,IFeatureClassinputFC,doublesnapTolerance,INAContextmm_NAContext){INAClassnaClass;INamedSetclasses;classes=mm_NAContext.NAClasses;naClass=classes.get_ItemByName(strNAClassName)asINAClass;//deleteexistingLocationsexceptifthatabarriersnaClass.DeleteAllRows();//CreateaNAClassLoaderandsetthesnaptolerance(metersunit)INAClassLoaderclassLoader=newNAClassLoader();classLoader.Locator=mm_NAContext.Locator;if(snapTolerance>0)classLoader.Locator.SnapTolerance=snapTolerance;classLoader.NAClass=naClass;//CreatefieldmaptoautomaticallymapfieldsfrominputclasstoNAClassINAClassFieldMapfieldMap;fieldMap=newNAClassFieldMap();fieldMap.CreateMapping(naClass.ClassDefinition,inputFC.Fields);classLoader.FieldMap=fieldMap;//Avoidloadingnetworklocationsontonon-traversableportionsofelementsINALocator3locator=mm_NAContext.LocatorasINALocator3;locator.ExcludeRestrictedElements=true;locator.CacheRestrictedElements(mm_NAContext);//LoadNetworkLocationsintrowsIn=0;introwsLocated=0;IFeatureCursorfeatureCursor=inputFC.Search(null,true);classLoader.Load(featureCursorasICursor,null,refrowsIn,refrowsLocated);//Messageallofthenetworkanalysisagentsthattheanalysiscontexthaschanged((INAContextEdit)mm_NAContext).ContextChanged();}
实在不清楚为什么Solve方法报了这样一个错误,加载的设施点与时间点均为10000点,在ArcgisDesktop中可以正常加载点位计算前往最近设施的路线···但是会提示有个别点不在路网上···想请各位大神帮我分析一下报错原因····拜谢各位了
解决方案
解决方案二:
看下是不是内存没有释放造成的。