/// <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);
     }
 }
예제 #2
0
        //根据存放网络数据集的工作空间和网络数据集名称以及要素数据集名称打开网络数据集
        public static INetworkDataset OpenPathNetworkDataset(IWorkspace networkDatasetWorkspace,
                                                             string networkDatasetName, string featureDatasetName)
        {
            if (networkDatasetWorkspace == null || networkDatasetName == "" ||
                featureDatasetName == null)
            {
                return(null);
            }
            IDatasetContainer3 datasetContainer3 = null;//数据集容器。数据集的集合
            IFeatureWorkspace  featureWorkspace  = networkDatasetWorkspace as IFeatureWorkspace;
            IFeatureDataset    featureDataset;

            featureDataset = featureWorkspace.OpenFeatureDataset(featureDatasetName);//根据名字打开要素数据集
            IFeatureDatasetExtensionContainer featureDataExtensionContainer =
                featureDataset as IFeatureDatasetExtensionContainer;
            IFeatureDatasetExtension featureDatasetExtension = featureDataExtensionContainer.FindExtension(
                esriDatasetType.esriDTNetworkDataset);

            datasetContainer3 = featureDatasetExtension as IDatasetContainer3;
            if (datasetContainer3 == null)
            {
                return(null);
            }
            IDataset dataSet = datasetContainer3.get_DatasetByName(esriDatasetType.esriDTNetworkDataset,
                                                                   networkDatasetName);

            return(dataSet as INetworkDataset);
        }
예제 #3
0
        /// <summary>
        /// 打开网络数据集
        /// </summary>
        public INetworkDataset OpenNetworkDataset(IWorkspace networkDatasetWorkspace, System.String networkDatasetName, System.String featureDatasetName)
        {
            if (networkDatasetWorkspace == null || networkDatasetName == "" || featureDatasetName == null)
            {
                return(null);
            }
            IFeatureWorkspace featureWorkspace = networkDatasetWorkspace as IFeatureWorkspace;

            featureDataset = featureWorkspace.OpenFeatureDataset(featureDatasetName);
            IFeatureDatasetExtensionContainer featureDatasetExtensionContainer = featureDataset as IFeatureDatasetExtensionContainer;
            IFeatureDatasetExtension          featureDatasetExtension          = featureDatasetExtensionContainer.FindExtension(esriDatasetType.esriDTNetworkDataset);
            IDatasetContainer3 datasetContainer3 = (IDatasetContainer3)featureDatasetExtension;

            if (datasetContainer3 == null)
            {
                return(null);
            }
            IDataset dataset = datasetContainer3.get_DatasetByName(esriDatasetType.esriDTNetworkDataset, networkDatasetName);

            return(dataset as INetworkDataset);
        }
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        public static IDatasetContainer3 GetDatasetContainer(IFeatureWorkspace featureWorkspace, string fdName)
        {
            IDatasetContainer3 datasetContainer = null;

            if (featureWorkspace is IWorkspace2)
            {
                IWorkspace2 workspace = featureWorkspace as IWorkspace2;
                bool        fdExists  = workspace.get_NameExists(esriDatasetType.esriDTFeatureDataset, fdName);
                if (!fdExists)
                {
                    throw new Exception("Feature Dataset does not exist.");
                }
            }

            IFeatureDatasetExtensionContainer fdExtensionContainer = (IFeatureDatasetExtensionContainer)featureWorkspace.OpenFeatureDataset(fdName);

            datasetContainer = (IDatasetContainer3)fdExtensionContainer.FindExtension(esriDatasetType.esriDTNetworkDataset);
            if (datasetContainer == null)
            {
                throw new Exception("NATestNetworkDataset: dataset container should not be null");
            }

            return(datasetContainer);
        }
예제 #7
0
        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));
        }