Exemplo n.º 1
0
        private ISpatialReference GetSpatialReference(int xyCoordinateSystem)
        {
            const bool IsHighPrecision = true;

            ISpatialReference spatialReference;

            ISpatialReferenceFactory3 spatialReferenceFactory = new SpatialReferenceEnvironmentClass();

            spatialReference = spatialReferenceFactory.CreateSpatialReference(xyCoordinateSystem);

            IControlPrecision2 controlPrecision = spatialReference as IControlPrecision2;

            controlPrecision.IsHighPrecision = IsHighPrecision;

            ISpatialReferenceResolution spatialReferenceResolution = spatialReference as ISpatialReferenceResolution;

            spatialReferenceResolution.ConstructFromHorizon();
            spatialReferenceResolution.SetDefaultXYResolution();
            spatialReferenceResolution.SetDefaultZResolution();
            spatialReferenceResolution.SetDefaultMResolution();

            ISpatialReferenceTolerance spatialReferenceTolerance = spatialReference as ISpatialReferenceTolerance;

            spatialReferenceTolerance.SetDefaultXYTolerance();
            spatialReferenceTolerance.SetDefaultZTolerance();
            spatialReferenceTolerance.SetDefaultMTolerance();

            return(spatialReference);
        }
Exemplo n.º 2
0
        /// <summary>
        ///  创建要素集 20110919 xisheng
        /// </summary>
        /// <param name="feaworkspace">指定工作空间</param>
        /// <param name="datasetname">指定要素集名称</param>
        /// <param name="PrjPath">空间参考</param>
        /// <returns></returns>
        private static IFeatureDataset CreateFeatureDataset(IFeatureWorkspace feaworkspace, string datasetname, string PrjPath)
        {
            try
            {
                string spatialPath = PrjPath;
                ISpatialReferenceFactory pSpaReferenceFac  = new SpatialReferenceEnvironmentClass(); //空间参考工厂
                ISpatialReference        pSpatialReference = null;                                   //用来获得空间参考
                if (File.Exists(spatialPath))
                {
                    pSpatialReference = pSpaReferenceFac.CreateESRISpatialReferenceFromPRJFile(spatialPath);
                }
                if (pSpatialReference == null)
                {
                    pSpatialReference = new UnknownCoordinateSystemClass();
                }

                //设置默认的Resolution
                ISpatialReferenceResolution pSpatiaprefRes = pSpatialReference as ISpatialReferenceResolution;
                pSpatiaprefRes.ConstructFromHorizon();//Defines the XY resolution and domain extent of this spatial reference based on the extent of its horizon
                pSpatiaprefRes.SetDefaultXYResolution();
                pSpatiaprefRes.SetDefaultZResolution();
                pSpatiaprefRes.SetDefaultMResolution();
                //设置默认的Tolerence
                ISpatialReferenceTolerance pSpatialrefTole = pSpatiaprefRes as ISpatialReferenceTolerance;
                pSpatialrefTole.SetDefaultXYTolerance();
                pSpatialrefTole.SetDefaultZTolerance();
                pSpatialrefTole.SetDefaultMTolerance();

                //创建数据集

                IFeatureDataset pFeatureDataset = null;//定义数据集用来装载要素类
                pFeatureDataset = feaworkspace.CreateFeatureDataset(datasetname, pSpatialReference);


                return(pFeatureDataset);
            }
            catch (Exception e)
            {
                //*******************************************************************
                //guozheng added
                if (ModData.SysLog != null)
                {
                    ModData.SysLog.Write(e, null, DateTime.Now);
                }
                else
                {
                    ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                    ModData.SysLog.Write(e, null, DateTime.Now);
                }
                //********************************************************************
                return(null);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// shape图层入库
        /// </summary>
        /// <param name="sourceworkspace"></param>
        /// <param name="targetworkspace"></param>
        /// <param name="nameOfsourceFeatureClass"></param>
        /// <param name="nameOftargetFeatureClass"></param>
        /// <returns></returns>
        public IFeatureClass ShapeFileIntoGDB(IWorkspace sourceworkspace, IWorkspace targetworkspace,
                                              string nameOfsourceFeatureClass, string nameOftargetFeatureClass)
        {
            try
            {
                //创建源工作空间
                IDataset       sourceWorkspaceDataset = (IDataset)sourceworkspace;
                IWorkspaceName sourceWorkspaceName    = (IWorkspaceName)sourceWorkspaceDataset.FullName;

                //创建源数据集
                IFeatureClassName sourceFeatureClassName = new FeatureClassNameClass();
                IDatasetName      sourceDatasetName      = (IDatasetName)sourceFeatureClassName;
                sourceDatasetName.WorkspaceName = sourceWorkspaceName;
                sourceDatasetName.Name          = nameOfsourceFeatureClass;

                //创建目标工作空间
                IDataset       targetWorkspaceDataset = (IDataset)targetworkspace;
                IWorkspaceName targetWorkspaceName    = (IWorkspaceName)targetWorkspaceDataset.FullName;

                //创建目标数据集
                IFeatureClassName targetFeatureClassName = new FeatureClassNameClass();
                IDatasetName      targetDatasetName      = (IDatasetName)targetFeatureClassName;
                targetDatasetName.WorkspaceName = targetWorkspaceName;
                targetDatasetName.Name          = nameOftargetFeatureClass;

                //源数据集的字段集
                IName         sourceName         = (IName)sourceFeatureClassName;
                IFeatureClass sourceFeatureClass = (IFeatureClass)sourceName.Open();

                //验证字段
                IFieldChecker   fieldChecker = new FieldCheckerClass();
                IFields         targetFeatureClassFields;
                IFields         sourceFeatureClassFields = sourceFeatureClass.Fields;
                IEnumFieldError enumFieldError;

                //设置验证的对象
                fieldChecker.InputWorkspace    = sourceworkspace;
                fieldChecker.ValidateWorkspace = targetworkspace;
                fieldChecker.Validate(sourceFeatureClassFields, out enumFieldError, out targetFeatureClassFields);

                //找到空间对象字段
                IField geometryField;
                for (int i = 0; i < targetFeatureClassFields.FieldCount; i++)
                {
                    if (targetFeatureClassFields.get_Field(i).Type == esriFieldType.esriFieldTypeGeometry)
                    {
                        geometryField = targetFeatureClassFields.get_Field(i);

                        //得到空间字段的定义
                        IGeometryDef geometryDef = geometryField.GeometryDef;

                        //得到空间字段的索引
                        IGeometryDefEdit targetFCGeometryDefEdit = (IGeometryDefEdit)geometryDef;
                        targetFCGeometryDefEdit.GridCount_2 = 1;
                        targetFCGeometryDefEdit.set_GridSize(0, 0);
                        //targetFCGeometryDefEdit.SpatialReference_2 = geometryField.GeometryDef.SpatialReference;

                        ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
                        ISpatialReference        spatialReference        = DataEditCommon.g_pMap.SpatialReference;
                        //spatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_NAD1983UTM_20N);
                        ISpatialReferenceResolution spatialReferenceResolution = (ISpatialReferenceResolution)spatialReference;
                        spatialReferenceResolution.ConstructFromHorizon();
                        spatialReferenceResolution.SetDefaultXYResolution();
                        spatialReferenceResolution.SetDefaultZResolution();
                        ISpatialReferenceTolerance spatialReferenceTolerance = (ISpatialReferenceTolerance)spatialReference;
                        spatialReferenceTolerance.SetMinimumXYTolerance();
                        spatialReferenceTolerance.SetMinimumZTolerance();

                        double XMin, XMax, YMin, YMax, ZMin, ZMax, MinXYTolerance, MinZTolerance;
                        XMin = 4054.3603997438;
                        XMax = 78088.6926632544;
                        YMin = 14424.8510028409;
                        YMax = 59609.4812606697;
                        ZMin = 30330.1483519995;
                        ZMax = 38389.3283520005;
                        //spatialReference.SetDomain(XMin, XMax, YMin, YMax);
                        //spatialReference.SetZDomain(ZMin, ZMax);

                        MinXYTolerance = 0.000000000008219;
                        MinZTolerance  = 0.000000000007629;
                        //spatialReferenceTolerance.SetMinimumZTolerance( MinXYTolerance);

                        //spatialReference.GetDomain(out XMin, out XMax, out YMin, out YMax);
                        //spatialReference.GetZDomain(out ZMin, out ZMax);


                        targetFCGeometryDefEdit.SpatialReference_2 = spatialReference;


                        //开始导入
                        IQueryFilter queryFilter = new QueryFilterClass();
                        queryFilter.WhereClause = "";

                        //导入所有的输入对象
                        IFeatureDataConverter featureDataConverter = new FeatureDataConverterClass();
                        IEnumInvalidObject    enumInvalidObject    = featureDataConverter.ConvertFeatureClass(sourceFeatureClassName,
                                                                                                              queryFilter, null, targetFeatureClassName, geometryDef, targetFeatureClassFields, "", 1000, 0);
                        break;
                    }
                }

                //导入后数据集的字段集
                IName         targetName         = (IName)targetFeatureClassName;
                IFeatureClass targetFeatureClass = (IFeatureClass)targetName.Open();

                return(targetFeatureClass);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }