public static INetworkDataset GetNetworkDataset(IDatasetContainer2 datasetContainer, string ndName) { INetworkDataset networkDataset; try { networkDataset = datasetContainer.get_DatasetByName(esriDatasetType.esriDTNetworkDataset, ndName) as INetworkDataset; } catch (Exception e) { if (e.Message.Contains("0x80042603")) { throw new Exception("Unable to read network dataset. Ensure that the installed version of the TransitEvaluator.dll matches the installed version of ArcGIS. GDB Exception: " + e.Message); } else { throw e; } } if (networkDataset == null) { throw new Exception("NATestNetworkDataset: networkDataset should not be null"); } return(networkDataset); }
/// <summary> /// 打开网络数据集 /// </summary> /// <param name="GDBfileName"></param> /// <param name="featureDatasetName"></param> /// <param name="sNDSName"></param> /// <returns></returns> public static INetworkDataset OpenNetworkDataset(string GDBfileName, string featureDatasetName, string sNDSName) { try { IWorkspace pWorkspace = OpenWorkspace(GDBfileName); IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace; if (pFeatureWorkspace == null) { return(null); } IFeatureDatasetExtensionContainer pFeatureDatasetExtensionContainer = pFeatureWorkspace.OpenFeatureDataset(featureDatasetName) as IFeatureDatasetExtensionContainer; if (pFeatureDatasetExtensionContainer == null) { return(null); } IDatasetContainer2 pDatasetContainer2 = pFeatureDatasetExtensionContainer.FindExtension(esriDatasetType.esriDTNetworkDataset) as IDatasetContainer2; INetworkDataset pNetworkDataset = pDatasetContainer2.get_DatasetByName(esriDatasetType.esriDTAny, sNDSName) as INetworkDataset; return(pNetworkDataset); } catch (Exception ex) { Debug.Print(ex.Message); return(null); } }
private INetworkDataset ShapefileToNetwork(IWorkspace shpWS, string name) { IWorkspaceExtensionManager wsExtMgr = shpWS as IWorkspaceExtensionManager; UID myUID = new UIDClass(); myUID.Value = "esriGeoDatabase.NetworkDatasetWorkspaceExtension"; IWorkspaceExtension wsExt = wsExtMgr.FindExtension(myUID); IDatasetContainer2 dsCont = wsExt as IDatasetContainer2; IDataset dataset = dsCont.get_DatasetByName(esriDatasetType.esriDTNetworkDataset, name); INetworkDataset networkDataset = dataset as INetworkDataset; return(networkDataset); }
public bool ValidateSource(IDatasetContainer2 datasetContainer, INetworkSource networkSource, IEvaluatedNetworkAttribute attribute, ref int errorCode, ref string errorDescription, ref string errorAppendInfo) { if (SupportsSource(networkSource, attribute)) { errorCode = 0; errorDescription = errorAppendInfo = string.Empty; return(true); } else { errorCode = -1; errorDescription = errorAppendInfo = string.Empty; return(false); } }
private void SetMemberVariables() { IFeatureWorkspace pWorkspace = this.m_pWorkspace as IFeatureWorkspace; IWorkspaceExtensionManager manager = this.m_pWorkspace as IWorkspaceExtensionManager; UID gUID = new UIDClass { Value = "esriGeoDatabase.NetworkDatasetWorkspaceExtension" }; IDatasetContainer2 container = manager.FindExtension(gUID) as IDatasetContainer2; this.m_pNetworkDataset = container.get_DatasetByName(esriDatasetType.esriDTNetworkDataset, this.NETWORK_DATASET) as INetworkDataset; this.m_pInputStopsFClass = pWorkspace.OpenFeatureClass(this.INPUT_STOPS_FC); }
public INetworkDataset OpenNetworkDataset(IWorkspace pWorkspace, string sNDSName) { IWorkspaceExtensionManager manager = pWorkspace as IWorkspaceExtensionManager; int extensionCount = manager.ExtensionCount; for (int i = 0; i < extensionCount; i++) { IWorkspaceExtension extension = manager.get_Extension(i); if (extension.Name.Equals("Network Dataset")) { IDatasetContainer2 container = extension as IDatasetContainer2; return (container.get_DatasetByName(esriDatasetType.esriDTNetworkDataset, sNDSName) as INetworkDataset); } } return(null); }
public IDataset GetUNDataset2(IServerObject serverObject, string versionName = null) { IDataset unDataset = null; IMapServer mapService = (MapServer)serverObject; IMapServerDataAccess mapServerDataAccess = (IMapServerDataAccess)serverObject; // Get feature class from any layer IFeatureClass fc = (IFeatureClass)mapServerDataAccess.GetDataSource(mapService.DefaultMapName, 0); // Get the container feature dataset IFeatureDataset fd = fc.FeatureDataset; // Open feature dataset in specified version if (!String.IsNullOrEmpty(versionName)) { IWorkspace workspace = fd.Workspace; IVersionedWorkspace4 versionedWorkspace = (IVersionedWorkspace4)workspace; IVersion4 childVersion = (IVersion4)versionedWorkspace.FindVersion(versionName); IFeatureWorkspace childFWS = (IFeatureWorkspace)childVersion; fd = childFWS.OpenFeatureDataset(fd.Name); } // Get extension container IFeatureDatasetExtensionContainer fdce = (IFeatureDatasetExtensionContainer)fd; // Find UN dataset by type IFeatureDatasetExtension unFDSExt = fdce.FindExtension(esriDatasetType.esriDTUtilityNetwork); IDatasetContainer2 unDSContainer = (IDatasetContainer2)unFDSExt; IEnumDatasetName dsNames = unDSContainer.DatasetNames[esriDatasetType.esriDTUtilityNetwork]; IDatasetName dsName = dsNames.Next(); if (dsName != null) { unDataset = unDSContainer.DatasetByName[esriDatasetType.esriDTUtilityNetwork, dsName.Name]; } return(unDataset); }
private INetworkDataset OpenNetworkDataset(IWorkspace networkDatasetWorkspace, string networkDatasetName, string featureDatasetName) { if (networkDatasetWorkspace == null || networkDatasetName == "" || featureDatasetName == null) { return(null); } IDatasetContainer2 datasetContainer2 = null; IFeatureWorkspace featureWorkspace = networkDatasetWorkspace as IFeatureWorkspace; featureDataset = featureWorkspace.OpenFeatureDataset(featureDatasetName); IFeatureDatasetExtensionContainer featureDatasetExtensionContainer = featureDataset as IFeatureDatasetExtensionContainer; IFeatureDatasetExtension featureDatasetExtension = featureDatasetExtensionContainer.FindExtension(esriDatasetType.esriDTNetworkDataset); datasetContainer2 = featureDatasetExtension as IDatasetContainer3; if (datasetContainer2 == null) { return(null); } IDataset dataset = datasetContainer2.get_DatasetByName(esriDatasetType.esriDTNetworkDataset, networkDatasetName); return(dataset as INetworkDataset); }
public static INetworkDataset GetNetworkDataset(IDatasetContainer2 datasetContainer, string ndName) { INetworkDataset networkDataset; try { networkDataset = datasetContainer.get_DatasetByName(esriDatasetType.esriDTNetworkDataset, ndName) as INetworkDataset; } catch (Exception e) { if (e.Message.Contains("0x80042603")) { throw new Exception("Unable to read network dataset. Ensure that the installed version of the TransitEvaluator.dll matches the installed version of ArcGIS. GDB Exception: " + e.Message); } else { throw e; } } if (networkDataset == null) throw new Exception("NATestNetworkDataset: networkDataset should not be null"); return networkDataset; }
public static INetworkDataset GetNetworkDatasetFromPath(string ndPath) { // The last entry is the ND name, the penultimate entry is the FD name string[] splitPath = ndPath.Split('\\'); string ndName = splitPath[splitPath.Length - 1]; string fdName = splitPath[splitPath.Length - 2]; // trim off the nd and fd. string workspacePath = ndPath.Remove(ndPath.Length - fdName.Length - ndName.Length - 2); // Console.WriteLine("Opening feature workspace: " + workspacePath); IFeatureWorkspace featureWorkspace = GetFeatureWorkspace(workspacePath); //Console.WriteLine("Opening dataset container: " + fdName); IDatasetContainer2 datasetContainer = GetDatasetContainer(featureWorkspace, fdName); //Console.WriteLine("Opening network dataset: " + ndName); INetworkDataset networkDataset = GetNetworkDataset(datasetContainer, ndName); //Console.WriteLine("Opened"); return(networkDataset); }
public bool ValidateSource(IDatasetContainer2 datasetContainer, INetworkSource networkSource, IEvaluatedNetworkAttribute attribute, ref int errorCode, ref string errorDescription, ref string errorAppendInfo) { if (SupportsSource(networkSource, attribute)) { errorCode = 0; errorDescription = errorAppendInfo = string.Empty; return true; } else { errorCode = -1; errorDescription = errorAppendInfo = string.Empty; return false; } }
private INetworkDataset method_1(IFeatureDataset ifeatureDataset_1, string string_1) { int num; IGeoDataset dataset = (IGeoDataset)ifeatureDataset_1; ISpatialReference spatialReference = dataset.SpatialReference; IDENetworkDataset dataset2 = new DENetworkDatasetClass(); IDataElement element = (IDataElement)dataset2; IDEGeoDataset dataset3 = (IDEGeoDataset)dataset2; element.Name = string_1; dataset2.Buildable = true; dataset3.SpatialReference = spatialReference; IArray array = new ArrayClass(); for (num = 0; num < this.FeatureClassWraps.Count; num++) { if (this.FeatureClassWraps[num].IsUse) { INetworkSource source; IFeatureClass featureClass = this.FeatureClassWraps[num].FeatureClass; if (featureClass.ShapeType == esriGeometryType.esriGeometryPoint) { source = new JunctionFeatureSourceClass { Name = this.FeatureClassWraps[num].ToString() }; IJunctionFeatureSource source2 = (IJunctionFeatureSource)source; source2.ClassConnectivityPolicy = (esriNetworkJunctionConnectivityPolicy) this.FeatureClassWraps[num].NetworkConnectivityPolicy; if (this.ModifyConnectivity) { source2.ElevationFieldName = this.FeatureClassWraps[num].ElevationFieldName; } array.Add(source); } else if (featureClass.ShapeType == esriGeometryType.esriGeometryPolyline) { source = new EdgeFeatureSourceClass(); IEdgeFeatureSource source3 = (IEdgeFeatureSource)source; source.Name = this.FeatureClassWraps[num].ToString(); source3.ClassConnectivityGroup = 1; source3.ClassConnectivityPolicy = (esriNetworkEdgeConnectivityPolicy)this.FeatureClassWraps[num].NetworkConnectivityPolicy; if (this.ModifyConnectivity) { source3.FromElevationFieldName = this.FeatureClassWraps[num].FromElevationFieldName; source3.ToElevationFieldName = this.FeatureClassWraps[num].ToElevationFieldName; } array.Add(source); } } } dataset2.Sources = array; for (num = 0; num < this.iarray_0.Count; num++) { dataset2.Attributes.Add(this.iarray_0.get_Element(num)); } dataset2.SupportsTurns = this.bool_2; IFeatureDatasetExtensionContainer container = (IFeatureDatasetExtensionContainer)ifeatureDataset_1; IDatasetContainer2 container2 = (IDatasetContainer2)container.FindExtension(esriDatasetType.esriDTNetworkDataset); return((INetworkDataset)container2.CreateDataset((IDEDataset)dataset2)); }