创建要FeatureDataset素数据集

创建要素数据集代码


  /// <summary>
        /// 创建数据集
        /// </summary>
        /// <param name="Workspac">工作空间</param>
        /// <param name="featureDatasetName">要素数据集名称</param>
        /// <param name="spatialReference">空间参考,可以为空</param>
        /// <returns></returns>
        public static IFeatureDataset CreateOrOpenFeatureDataset(ref IWorkspace Workspac, string featureDatasetName, ISpatialReference spatialReference)
        {
            IFeatureWorkspace targetWorkspac = Workspac as IFeatureWorkspace;
            IFeatureClass pFeaClass = null;
            pFeaClass = ExitFeatureClass(Workspac, featureDatasetName, esriDatasetType.esriDTFeatureDataset);
            if (pFeaClass != null)
            {
                return targetWorkspac.OpenFeatureDataset(featureDatasetName);
            }

            if (spatialReference == null)
            {
                spatialReference = new UnknownCoordinateSystemClass();
            }
            IControlPrecision2 pCP = spatialReference as IControlPrecision2;
            IFeatureDataset newDataset = null;

            try
            {
                if (!pCP.IsHighPrecision)//判断是否为高精度
                {
                    pCP.IsHighPrecision = true;
                }
                newDataset = targetWorkspac.CreateFeatureDataset(featureDatasetName, spatialReference);
                return newDataset;
            }
            catch (Exception ex)//低精度创建
            {
                pCP.IsHighPrecision = false;
                IGeographicCoordinateSystem pGeo = spatialReference as IGeographicCoordinateSystem;
                bool bGeo = (pGeo == null) ? false : true;
                //要素分辨率
                ISpatialReferenceResolution spatialReferenceResolution = spatialReference as ISpatialReferenceResolution;
                if (bGeo)
                {
                    spatialReferenceResolution.ConstructFromHorizon();//定义XY的分辨率和范围根据空间参考的水平范围
                    spatialReferenceResolution.SetDefaultXYResolution();//设置默认分辨率容差
                }
                else
                {
                    spatialReferenceResolution.set_XYResolution(false, 0.04);
                }
                //要素数据集容差
                ISpatialReferenceTolerance spatialReferenceTolerance = spatialReference as ISpatialReferenceTolerance;
                if (bGeo)
                {
                    spatialReferenceTolerance.SetDefaultXYTolerance();
                }
                else
                {
                    spatialReferenceTolerance.SetMinimumXYTolerance();
                }
                try
                {
                    newDataset = targetWorkspac.CreateFeatureDataset(featureDatasetName, spatialReference);
                    return newDataset;
                }
                catch (Exception e)
                {

                }
                return null;
            }
        }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值