Ejemplo n.º 1
0
        private void buttonX_ok_Click(object sender, EventArgs e)
        {
            CGmpPoint xml    = new CGmpPoint();
            bool      result = xml.ReadGmpXML(XMLPath);
            Regex     regNum = new Regex("^[0-9]");

            if (regNum.IsMatch(textBoxX3.Text) == true)
            {
                MessageBox.Show("数据集名称不能以数字开头命名", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (result == true)
            {
                try
                {
                    IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();
                    gdbPath = textBoxX2.Text;
                    IFeatureWorkspace        pFeatureWorkspace        = workspaceFactory.OpenFromFile(gdbPath, 0) as IFeatureWorkspace;
                    ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironment();

                    //ISpatialReference pSpatialReference = new UnknownCoordinateSystemClass();
                    ISpatialReference pSpatialReference = ClsGDBDataCommon.CreateProjectedCoordinateSystem();
                    pSpatialReference.SetDomain(-8000000, 8000000, -800000, 8000000);
                    IFeatureDataset pFeatureDataset = pFeatureWorkspace.CreateFeatureDataset(textBoxX3.Text, pSpatialReference);
                    IFeatureClass   pFeatureclass   = CreatePointFeatureClass(pFeatureDataset, xml);
                    IFeatureClass   pFCLine         = CreatLineFC(pFeatureDataset, pFeatureclass);
                    if (pFeatureclass == null || pFCLine == null)
                    {
                        MessageBox.Show("数据生成失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    IFeatureLayer pFPointLayer = new FeatureLayerClass();
                    pFPointLayer.FeatureClass = pFeatureclass;
                    pFPointLayer.Name         = textBoxX3.Text + "_Gmppoint";

                    IFeatureLayer pFLintLayer = new FeatureLayerClass();
                    pFLintLayer.FeatureClass = pFCLine;
                    pFLintLayer.Name         = textBoxX3.Text + "_GmpLine";

                    m_pMapCtl.AddLayer(pFLintLayer as ILayer, 0);
                    m_pMapCtl.AddLayer(pFPointLayer as ILayer, 0);
                    m_pMapCtl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);

                    if (cmbImpSymbol.Text != null && symFilePath != null)
                    {
                        ImpSymbolFromFile(symFilePath, pFPointLayer, pFLintLayer);
                    }


                    //MessageBox.Show("数据已经生成", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        // 创建要素数据集
        /// </summary>
        /// <param name="workspace"></param>
        /// <param name="code"></param>
        /// <param name="datasetName"></param>
        /// <returns></returns>
        public IFeatureDataset CreateFeatureClass(IWorkspace workspace, int code, string datasetName)
        {
            IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
            //创建一个要素集创建一个投影
            ISpatialReferenceFactory spatialRefFactory = new SpatialReferenceEnvironmentClass();
            ISpatialReference        spatialReference  = spatialRefFactory.CreateProjectedCoordinateSystem(code);
            //确定是否支持高精度存储空间
            Boolean supportsHighPrecision            = false;
            IWorkspaceProperties workspaceProperties = (IWorkspaceProperties)workspace;
            IWorkspaceProperty   workspaceProperty   = workspaceProperties.get_Property
                                                           (esriWorkspacePropertyGroupType.esriWorkspacePropertyGroup,
                                                           (int)esriWorkspacePropertyType.esriWorkspacePropSupportsHighPrecisionStorage);

            if (workspaceProperty.IsSupported)
            {
                supportsHighPrecision = Convert.ToBoolean(workspaceProperty.PropertyValue);
            }
            //设置投影精度
            IControlPrecision2 controlPrecision = (IControlPrecision2)spatialReference;

            controlPrecision.IsHighPrecision = supportsHighPrecision;
            //设置容差
            ISpatialReferenceResolution spatialRefResolution = (ISpatialReferenceResolution)spatialReference;

            spatialRefResolution.ConstructFromHorizon();
            spatialRefResolution.SetDefaultXYResolution();
            ISpatialReferenceTolerance spatialRefTolerance = (ISpatialReferenceTolerance)spatialReference;

            spatialRefTolerance.SetDefaultXYTolerance();
            //创建要素集
            IFeatureDataset featureDataset = featureWorkspace.CreateFeatureDataset(datasetName, spatialReference);

            return(featureDataset);
        }
Ejemplo n.º 3
0
        //在文件数据库中新建要素数据集
        public IFeatureDataset CreateDatasetInGDB(IWorkspace pWorkspace, string name, ISpatialReference pSpatialReference)
        {
            IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
            IFeatureDataset   pFeatureDataset   = pFeatureWorkspace.CreateFeatureDataset(name, pSpatialReference);

            return(pFeatureDataset);
        }
Ejemplo n.º 4
0
        public static IDataset CreateFeatureDataSet(IWorkspace iworkspace_0, string string_0,
                                                    ISpatialReference ispatialReference_0)
        {
            if (iworkspace_0 == null)
            {
                return(null);
            }
            if (string_0 == null)
            {
                return(null);
            }
            if (string_0 == "")
            {
                return(null);
            }
            if (ispatialReference_0 == null)
            {
                return(null);
            }
            IWorkspace        workspace  = iworkspace_0;
            IFeatureWorkspace workspace2 = (IFeatureWorkspace)workspace;
            IDataset          dataset2   = null;

            try
            {
                dataset2 = workspace2.CreateFeatureDataset(string_0, ispatialReference_0);
            }
            catch (Exception)
            {
            }
            return(dataset2);
        }
Ejemplo n.º 5
0
 //创建一个新的地理数据集
 private void CreateFeatureDataset()
 {
     try
     {
         ISpatialReference pSpatialRef = pGeoDataset.SpatialReference;
         m_pFeatureWorkspace.CreateFeatureDataset("aa", pSpatialRef);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
0
        public void createFeatureDataset(IWorkspace workspace, IFeatureWorkspace featureworkspace, IFeatureDataset featuredataset, ISpatialReference spatialRef, string user, string featureDatasetName)
        {
            featureworkspace = workspace as IFeatureWorkspace;
            //定义空间参考
            // ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironment();
            ISpatialReference spatialReference = spatialRef;

            spatialReference.SetDomain(-1000, -1000, 1000, 1000);

            IEnumDatasetName enumDatasetName;
            IDatasetName     datasetName;
            string           dsName = "";

            enumDatasetName = workspace.get_DatasetNames(esriDatasetType.esriDTFeatureDataset);
            datasetName     = enumDatasetName.Next();
            bool isExist = false;

            //创建适量数据集
            // string featureDatasetName = "TEST";
            if (user == "")
            {
                dsName = featureDatasetName.ToUpper().ToString();
            }
            else
            {
                dsName = user.ToUpper().ToString() + "." + featureDatasetName.ToUpper().ToString();
            }
            while (datasetName != null)
            {
                if (datasetName.Name == dsName)
                {
                    isExist = true;
                    // MessageBox.Show("要素集已存在!");
                    Form form = new Form();
                    form.SetBounds(300, 300, 300, 300);
                    setMessage.MessageShow("", "要素集已存在!", form);
                    return;
                }
                datasetName = enumDatasetName.Next();
            }

            if (isExist == false)
            {
                featuredataset = featureworkspace.CreateFeatureDataset(featureDatasetName, spatialReference);
                //MessageBox.Show("要素集创建成功!");
                Form form = new Form();
                form.SetBounds(300, 300, 300, 300);
                setMessage.MessageShow("", "要素集创建成功!", form);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 创建要素集
        /// </summary>
        /// <param name="featureWorkspace"></param>
        /// <param name="featureDataName"></param>
        /// <returns></returns>
        public static IFeatureDataset CreateFeatureDataset(IFeatureWorkspace featureWorkspace, string featureDataName)
        {
            ISpatialReferenceFactory pSpatialReferebceFactory = new SpatialReferenceEnvironmentClass();
            ISpatialReference        pSpatialReference        = pSpatialReferebceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCS4Type.esriSRProjCS_Xian1980_3_Degree_GK_Zone_40);
            IFeatureDataset          featureDataset           = null;

            try
            {
                featureDataset = featureWorkspace.CreateFeatureDataset(featureDataName, pSpatialReference);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("创建要素集{0}失败,错误信息:{1}", featureDataName, ex.Message));
            }
            return(featureDataset);
        }
Ejemplo n.º 9
0
        public void CreateDataset(string dsName)
        {
            IWorkspace       pWs             = (IWorkspace)pAccessWorkSpace;
            IEnumDatasetName enumDatasetName = pWs.get_DatasetNames(esriDatasetType.esriDTFeatureDataset);

            IDatasetName datasetName = enumDatasetName.Next();  //如果datasetName存在则退出

            while (datasetName != null)
            {
                if (datasetName.Name == dsName)
                {
                    return;
                }
                datasetName = enumDatasetName.Next();
            }
            pAccessWorkSpace.CreateFeatureDataset(dsName, sPR);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 构建一个在要素集中的要素类
        /// </summary>
        /// <param name="targetWorkSpace">目标工作空间</param>
        /// <param name="DatasetName">要素集名</param>
        /// <param name="FcName">要素类名</param>
        /// <param name="FcAlias">要素类别名</param>
        /// <returns></returns>
        public bool CreateDatasetFeatureClass(IFeatureWorkspace targetWorkSpace, string DatasetName, string FcName, string FcAlias = "")
        {
            bool result = true;

            try
            {
                FieldsHelper = new FieldsHelper();
                OnAddField(FieldsHelper, FcName, FcAlias);

                IFeatureDataset targetDataset = null;
                if ((targetWorkSpace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureDataset, DatasetName) == false)
                {
                    targetDataset = targetWorkSpace.CreateFeatureDataset(DatasetName, FieldsHelper.GetSpatialRef());
                }
                else
                {
                    targetDataset = targetWorkSpace.OpenFeatureDataset(DatasetName);
                }


                if ((targetDataset as IFeatureClassContainer).get_ClassByName(FcName) != null)
                {
                    ErrorMessage = "当前要素类已经存在";
                    return(false);
                }

                UID CLSID = new UID();
                CLSID.Value = "esriGeoDatabase.Feature";

                ResultFeatureClass = targetDataset.CreateFeatureClass(FcName, FieldsHelper.Fields, CLSID, null, esriFeatureType.esriFTSimple, FieldsHelper.GetShapeFieldName(), null);

                if (string.IsNullOrEmpty(FcAlias) == false)
                {
                    IClassSchemaEdit pClassSchemaEdit = ResultFeatureClass as IClassSchemaEdit;
                    pClassSchemaEdit.AlterAliasName(FcAlias);
                }
            }
            catch (Exception ex)
            {
                result       = false;
                ErrorMessage = ex.Message;
            }
            return(result);
        }
Ejemplo n.º 11
0
        private IFeatureClass CreateFeatureClass(IFeatureWorkspace ws)
        {
            IFeatureClass     fc   = null;
            ISpatialReference ipSr = m_hookHelper.FocusMap.SpatialReference;

            IFeatureDataset ipFeatDs = ws.CreateFeatureDataset("newdataset", ipSr);

            IFields ipFields = new FieldsClass();

            ((IFieldsEdit)ipFields).FieldCount_2 = 3;

            IFieldEdit ipField = new FieldClass();

            ((IFieldEdit)ipField).Name_2      = "ObjectID";
            ((IFieldEdit)ipField).AliasName_2 = "FID";
            ((IFieldEdit)ipField).Type_2      = esriFieldType.esriFieldTypeOID;
            ((IFieldsEdit)ipFields).set_Field(0, ipField);
            //Add others miscellaneous text field
            IFieldEdit ipField2 = new FieldClass();

            ((IFieldEdit)ipField2).Name_2      = "SmallInteger";
            ((IFieldEdit)ipField2).AliasName_2 = "short";
            ((IFieldEdit)ipField2).Type_2      = esriFieldType.esriFieldTypeSmallInteger;
            ((IFieldsEdit)ipFields).set_Field(1, ipField2);
            //Make the shape field
            //it will need a geometry definition, with a spatial reference
            IGeometryDefEdit ipGeoDef = new GeometryDefClass();

            ipGeoDef.SpatialReference_2 = ipSr;
            ipGeoDef.GeometryType_2     = esriGeometryType.esriGeometryPolygon;
            IFieldEdit ipField3 = new FieldClass();

            ((IFieldEdit)ipField3).Name_2        = "Shape";
            ((IFieldEdit)ipField3).AliasName_2   = "shape";
            ((IFieldEdit)ipField3).Type_2        = esriFieldType.esriFieldTypeGeometry;
            ((IFieldEdit)ipField3).GeometryDef_2 = ipGeoDef;
            ((IFieldsEdit)ipFields).set_Field(2, ipField3);

            fc = ipFeatDs.CreateFeatureClass("polygon", ipFields, null, null,
                                             esriFeatureType.esriFTSimple, "Shape", "");

            return(fc);
        }
Ejemplo n.º 12
0
        private IFeatureClass CreateFeatureClass(IFeatureWorkspace ipWorkspace, ISpatialReference ipSr)
        {
            //添加函数CreateFeatureClass()
            IFieldsEdit ipFields = new FieldsClass();

            ipFields.FieldCount_2 = 3;
            IFieldEdit ipField = new FieldClass();

            ipField.Name_2      = "ObjectID";
            ipField.AliasName_2 = "FID";
            ipField.Type_2      = esriFieldType.esriFieldTypeOID;
            ipFields.set_Field(0, ipField);
            //Add others miscellaneous text field
            IFieldEdit ipField2 = new FieldClass();

            ipField2.Name_2      = "SmallInteger";
            ipField2.AliasName_2 = "short";
            ipField2.Type_2      = esriFieldType.esriFieldTypeSmallInteger;
            ipFields.set_Field(1, ipField2);
            //Make the shape field
            //it will need a geometry definition, with a spatial reference
            IGeometryDefEdit ipGeoDef = new GeometryDefClass();

            ipGeoDef.SpatialReference_2 = ipSr;
            ipGeoDef.GeometryType_2     =
                esriGeometryType.esriGeometryPolygon;
            IFieldEdit ipField3 = new FieldClass();

            ipField3.Name_2        = "Shape";
            ipField3.AliasName_2   = "shape";
            ipField3.Type_2        = esriFieldType.esriFieldTypeGeometry;
            ipField3.GeometryDef_2 = ipGeoDef;
            ipFields.set_Field(2, ipField3);
            ipSr.SetDomain(-60000000, 60000000, -60000000, 60000000);
            IFeatureDataset ipFeatDs =
                ipWorkspace.CreateFeatureDataset("sadf", ipSr);

            IFeatureClass ipFeatCls = ipFeatDs.CreateFeatureClass
                                          ("shiasszxx", ipFields, null, null, esriFeatureType.
                                          esriFTSimple, "Shape", "");

            return(ipFeatCls);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// vct转mdb的时候创建esri数据集
        /// </summary>
        /// <param name="pWorkspace"></param>
        /// <param name="sDatasetName"></param>
        /// <param name="pHeadnode"></param>
        /// <returns></returns>
        public bool CreateESRIDataset(string strDatasetName, HeadNode pHeadnode)
        {
            try
            {
                ISpatialReference pISpatialReference = CreateProjection(pHeadnode);
                if (pISpatialReference != null)
                {
                    IFeatureWorkspace pIFeatureWorkspace = this.m_pIWorkspace as IFeatureWorkspace;
                    this.m_pIDataset = pIFeatureWorkspace.CreateFeatureDataset(strDatasetName, pISpatialReference);
                    return true;
                }

            }
            catch (Exception ex)
            {
                LogAPI.WriteErrorLog(ex);
            }
            return false;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 创建数据集
        /// </summary>
        /// <param name="pWorkspace"></param>
        /// <param name="strDataName"></param>
        /// <param name="spatialReference"></param>
        /// <returns></returns>
        public IFeatureDataset CreateDataset(IWorkspace pWorkspace, string strDataName, ISpatialReference spatialReference)
        {
            try
            {
                if (pWorkspace == null)
                {
                    return(null);
                }
                IFeatureWorkspace aFeaWorkspace = pWorkspace as IFeatureWorkspace;
                if (aFeaWorkspace == null)
                {
                    return(null);
                }

                string            dsName = strDataName;
                ISpatialReference aSR    = spatialReference;
                IFeatureDataset   aDS    = aFeaWorkspace.CreateFeatureDataset(dsName, aSR);
                return(aDS);
            }
            catch (Exception ex) { }
            return(null);
        }
Ejemplo n.º 15
0
        public static IDataset CreateFeatureDataSet(IWorkspace iworkspace_0, string string_0,
                                                    ISpatialReference ispatialReference_0)
        {
            IDataset dataset;

            if (iworkspace_0 == null)
            {
                dataset = null;
            }
            else if (string_0 == null)
            {
                dataset = null;
            }
            else if (string_0 == "")
            {
                dataset = null;
            }
            else if (ispatialReference_0 != null)
            {
                IFeatureWorkspace iworkspace0 = (IFeatureWorkspace)iworkspace_0;
                IDataset          dataset1    = null;
                try
                {
                    dataset1 = iworkspace0.CreateFeatureDataset(string_0, ispatialReference_0);
                }
                catch (Exception exception)
                {
                }
                dataset = dataset1;
            }
            else
            {
                dataset = null;
            }
            return(dataset);
        }
Ejemplo n.º 16
0
            //创建要素数据集
            private void PRV_CreatFeatureDataset(string IN_FeatureDataSetName, string IN_ShapePath)
            {
                string            Temp_Direction         = System.IO.Path.GetDirectoryName(IN_ShapePath);            //Shp文件的目录
                string            Getname                = System.IO.Path.GetFileNameWithoutExtension(IN_ShapePath); //Shp文件的文件名
                IWorkspaceFactory Temp_MDBWorkFactory    = new AccessWorkspaceFactory();
                IFeatureWorkspace Temp_MDBWorkspace      = Temp_MDBWorkFactory.OpenFromFile(S_MDBFile, 0) as IFeatureWorkspace;
                IWorkspaceFactory Temp_ShapeWorkFactory  = new ShapefileWorkspaceFactory();
                IFeatureWorkspace Temp_ShapeWorkspace    = Temp_ShapeWorkFactory.OpenFromFile(Temp_Direction, 0) as IFeatureWorkspace;
                IFeatureClass     Temp_ShapeFeatureClass = Temp_ShapeWorkspace.OpenFeatureClass(Getname);            //获取shp文件
                ISpatialReference SP_SpatialRefer        = (Temp_ShapeFeatureClass as IGeoDataset).SpatialReference; //获取空间投影

                try
                {
                    FDS_Featuredataset = Temp_MDBWorkspace.OpenFeatureDataset(IN_FeatureDataSetName);
                }
                catch { }

                /*
                 * if (null != FDS_Featuredataset)
                 * {
                 *  FDS_Featuredataset.Delete();
                 * }
                 */
                /*
                 * if (null != FDS_Featuredataset)
                 * {
                 *
                 *  return;
                 * }
                 */
                try
                {
                    Temp_MDBWorkspace.CreateFeatureDataset(IN_FeatureDataSetName, SP_SpatialRefer);   //在MDB中创建要素数据集
                    FDS_Featuredataset = Temp_MDBWorkspace.OpenFeatureDataset(IN_FeatureDataSetName); //获取返回的要素数据集
                }catch {}
            }
Ejemplo n.º 17
0
        /// <summary>
        /// 以原工作空间为模板创建新的工作空间
        /// </summary>
        private void CreatWorkspaceFromOrig()
        {
            WaitForm.SetCaption("正在创建新的工作空间...请稍后");
            IFeatureClassContainer pFcContainer = null;
            IFeatureClass          pFcTemp      = null;
            IFeatureClass          pNewFc       = null;
            ISpatialReference      pSr          = null;
            ISpatialReference      pSrTemp      = null;
            IFields pflds = null;
            double  dblXmin, dblXmax, dblYmin, dblYmax;
            double  dblZmin, dblZmax, dblMmin, dblMmax;

            CreateWorkspaceDomains(m_pOrigWorkspace, m_pDestWorkspace);
            IFeatureWorkspace pFeaWorkspace = m_pDestWorkspace as IFeatureWorkspace;
            IEnumDataset      enumDs        = m_pOrigWorkspace.get_Datasets(esriDatasetType.esriDTAny);
            IDataset          pDs           = enumDs.Next();

            while (pDs != null)
            {
                if (pDs.Type == esriDatasetType.esriDTFeatureDataset)
                {
                    pSr     = new UnknownCoordinateSystemClass();
                    pSrTemp = (pDs as IGeoDataset).SpatialReference;
                    if (pSrTemp.HasXYPrecision())
                    {
                        pSrTemp.GetDomain(out dblXmin, out dblXmax, out dblYmin, out dblYmax);
                        pSr.SetDomain(dblXmin, dblXmax, dblYmin, dblYmax);
                    }
                    if (pSrTemp.HasZPrecision())
                    {
                        pSrTemp.GetZDomain(out dblZmin, out dblZmax);
                        pSr.SetZDomain(dblZmin, dblZmax);
                    }
                    if (pSrTemp.HasMPrecision())
                    {
                        pSrTemp.GetMDomain(out dblMmin, out dblMmax);
                        pSr.SetMDomain(dblMmin, dblMmax);
                    }
                    IFeatureDataset pFeaDs = pFeaWorkspace.CreateFeatureDataset(pDs.Name, pSr);
                    pFcContainer = (IFeatureClassContainer)pDs;
                    if (pFcContainer.ClassCount > 0)
                    {
                        for (int i = 0; i < pFcContainer.ClassCount; i++)
                        {
                            try
                            {
                                pFcTemp = pFcContainer.get_Class(i);
                                pflds   = CommonFunction.GetFieldsFormFeatureClass(pFcTemp);

                                //若为注记
                                if (pFcTemp.FeatureType == esriFeatureType.esriFTAnnotation)
                                {
                                    IFeatureWorkspaceAnno pFWSAno    = pFeaWorkspace as IFeatureWorkspaceAnno;
                                    IAnnoClass            pAnnoClass = pFcTemp.Extension as IAnnoClass;
                                    IGraphicsLayerScale   pGLS       = new GraphicsLayerScaleClass();
                                    pGLS.ReferenceScale = pAnnoClass.ReferenceScale;
                                    pGLS.Units          = pAnnoClass.ReferenceScaleUnits;


                                    pNewFc = pFWSAno.CreateAnnotationClass((pFcTemp as IDataset).Name,
                                                                           pflds, pFcTemp.CLSID, pFcTemp.EXTCLSID, pFcTemp.ShapeFieldName,
                                                                           "", pFeaDs, null, pAnnoClass.AnnoProperties, pGLS, pAnnoClass.SymbolCollection, true);
                                    (pNewFc as IClassSchemaEdit).AlterAliasName(pFcTemp.AliasName);
                                }
                                else//若为地理要素
                                {
                                    try
                                    {
                                        pNewFc = pFeaDs.CreateFeatureClass((pFcTemp as IDataset).Name,
                                                                           pflds, pFcTemp.CLSID, pFcTemp.EXTCLSID, pFcTemp.FeatureType, pFcTemp.ShapeFieldName, null);
                                        if (pFcTemp.AliasName == "图廓线")
                                        {
                                            int n = 0;
                                        }
                                        (pNewFc as IClassSchemaEdit).AlterAliasName(pFcTemp.AliasName);
                                    }
                                    catch (System.Exception ex)
                                    {
                                        System.Console.WriteLine(ex.Message);
                                    }
                                }
                            }
                            catch (System.Exception ex)
                            {
                                System.Console.WriteLine(ex.Message);
                            }
                        }
                    }
                }
                else if (pDs.Type == esriDatasetType.esriDTFeatureClass)
                {
                    pFcTemp = (IFeatureClass)pDs;
                    pflds   = CommonFunction.GetFieldsFormFeatureClass(pFcTemp, pSr);
                    try
                    {
                        pNewFc = pFeaWorkspace.CreateFeatureClass(pDs.Name,
                                                                  pflds,
                                                                  pFcTemp.CLSID,
                                                                  pFcTemp.EXTCLSID,
                                                                  pFcTemp.FeatureType,
                                                                  pFcTemp.ShapeFieldName,
                                                                  null);
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine(ex.Message);
                    }
                }
                else if (pDs.Type == esriDatasetType.esriDTTable)
                {
                    ITable pTable = (ITable)pDs;
                    try
                    {
                        ITable pNewTable = pFeaWorkspace.CreateTable(pDs.Name,
                                                                     pTable.Fields,
                                                                     pTable.CLSID,
                                                                     pTable.EXTCLSID,
                                                                     null);
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine(ex.Message);
                    }
                }
                pDs = enumDs.Next();
            }
        }
Ejemplo n.º 18
0
        public void CreateAnnoFeatureClass(IFeatureDataset featureDs, string strObjNum)
        {
            //更换注记字体 用两个重要的属性
            //IAnnotateLayerPropertiesCollection,ISymbolCollection
            IFeatureWorkspace pFeatureWs = pAccessWorkSpace;

            IFeatureWorkspaceAnno pFeatureWorkspaceAnno;

            pFeatureWorkspaceAnno = (IFeatureWorkspaceAnno)pFeatureWs;

            //说明:要控制图层中的字体必须在图层建立的时候定义好字体
            ITextSymbol pTextSymbol, tTextSymbol;

            pTextSymbol = PublicFun.makeTextSymbol("Arial", 16);
            tTextSymbol = PublicFun.makeTextSymbol("宋体", 50);
            /////textsymbol

            IGraphicsLayerScale pGLS;

            pGLS                = new GraphicsLayerScaleClass();
            pGLS.Units          = esriUnits.esriMeters;
            pGLS.ReferenceScale = 500;

            IAnnotateLayerProperties pAnnoProps = new LabelEngineLayerPropertiesClass();

            pAnnoProps.FeatureLinked = true;
            pAnnoProps.AddUnplacedToGraphicsContainer = false;
            pAnnoProps.CreateUnplacedElements         = false;
            pAnnoProps.DisplayAnnotation = true;
            pAnnoProps.UseOutput         = true;

            IAnnotationExpressionEngine aAnnoVBScriptEngine;

            aAnnoVBScriptEngine = new AnnotationVBScriptEngineClass();

            ILabelEngineLayerProperties pLELayerProps;

            pLELayerProps = (ILabelEngineLayerProperties)pAnnoProps;
            pLELayerProps.ExpressionParser = aAnnoVBScriptEngine;
            pLELayerProps.Expression       = "[DESCRIPTION]";

            pLELayerProps.IsExpressionSimple = true;
            pLELayerProps.Offset             = 0;
            pLELayerProps.SymbolID           = 0;
            pLELayerProps.Symbol             = pTextSymbol;

            IAnnotateLayerTransformationProperties pATP;

            pATP = (IAnnotateLayerTransformationProperties)pAnnoProps;
            pATP.ReferenceScale = pGLS.ReferenceScale;
            pATP.Units          = esriUnits.esriMeters;
            pATP.ScaleRatio     = 300;

            IAnnotateLayerPropertiesCollection pAnnoPropsColl;

            pAnnoPropsColl = new AnnotateLayerPropertiesCollectionClass();
            pAnnoPropsColl.Add(pAnnoProps);

            IObjectClassDescription pOCDesc;

            pOCDesc = new AnnotationFeatureClassDescriptionClass();

            IFeatureClassDescription pFDesc;

            pFDesc = (IFeatureClassDescription)pOCDesc;

            ISymbolCollection pSymbolColl;

            pSymbolColl = new SymbolCollectionClass();
            pSymbolColl.set_Symbol(0, (ISymbol)pTextSymbol);
            pSymbolColl.set_Symbol(2, (ISymbol)tTextSymbol);

            IFields pFields = pOCDesc.RequiredFields;

            //添加注记类的附加字段
            this.addAnnoField(ref pFields, strObjNum);

            string          featureName = TableName;                    //注记要素集的名字
            IFeatureDataset pFeatureDataset;

            if (featureDs == null)
            {
                pFeatureDataset = pFeatureWs.CreateFeatureDataset(featureName + "_Anno", sPR);
            }
            else
            {
                pFeatureDataset = featureDs;
            }

            pFeatureWorkspaceAnno.CreateAnnotationClass(featureName, pFields, pOCDesc.InstanceCLSID,
                                                        pOCDesc.ClassExtensionCLSID, pFDesc.ShapeFieldName, "",
                                                        pFeatureDataset, null, pAnnoPropsColl, pGLS, pSymbolColl, true);
        }
Ejemplo n.º 19
0
        public IFeatureDataset creatdataset(IWorkspace workspace, string fdsName, ISpatialReference fdsSR)
        {
            IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;

            return(featureWorkspace.CreateFeatureDataset(fdsName, fdsSR));
        }
Ejemplo n.º 20
0
        //转换要素类
        private void CoordConvertFeatureClass(IFeatureClass fc, ISpatialReference spatialReference, out IFeatureClass outfc)
        {
            WaitForm.SetCaption("正在转换" + fc.AliasName + ",请稍后...");
            outfc = null;
            IWorkspaceFactory pWsF    = new AccessWorkspaceFactoryClass();
            IFeatureWorkspace pFWs    = null;
            IFeatureClass     pTempFc = null;

            try
            {
                IFields pFields = new FieldsClass();
                pFields = GetFieldsFromFeatureClass(fc, spatialReference);

                pFWs = pWsF.OpenFromFile(m_Path + @"\" + m_Name, 0) as IFeatureWorkspace;

                IDataset pDataset  = fc as IDataset;
                string   strFCName = pDataset.Name;
                try
                {
                    pTempFc = pFWs.OpenFeatureClass(strFCName);
                }
                catch (System.Exception ex)
                {
                    IFeatureDataset pFeatureDataset    = fc.FeatureDataset;
                    IFeatureDataset pFeatureDatasetNew = null;
                    if (pFeatureDataset != null)
                    {
                        try
                        {
                            pFeatureDatasetNew = pFWs.OpenFeatureDataset(pFeatureDataset.Name);
                            pTempFc            = pFeatureDatasetNew.CreateFeatureClass(strFCName, pFields, fc.CLSID, fc.EXTCLSID, fc.FeatureType, fc.ShapeFieldName, null);
                            (pTempFc as IClassSchemaEdit).AlterAliasName(fc.AliasName);
                        }
                        catch
                        {
                            pFeatureDatasetNew = pFWs.CreateFeatureDataset(pFeatureDataset.Name, spatialReference);

                            //若为注记
                            if (fc.FeatureType == esriFeatureType.esriFTAnnotation)
                            {
                                IFeatureWorkspaceAnno pFWsAnno   = pFWs as IFeatureWorkspaceAnno;
                                IAnnoClass            pAnnoClass = fc.Extension as IAnnoClass;

                                IGraphicsLayerScale pGLS = new GraphicsLayerScaleClass();
                                pGLS.ReferenceScale = pAnnoClass.ReferenceScale;
                                pGLS.Units          = pAnnoClass.ReferenceScaleUnits;
                                try
                                {
                                    pTempFc = pFWsAnno.CreateAnnotationClass(strFCName,
                                                                             pFields, fc.CLSID, fc.EXTCLSID, fc.ShapeFieldName, "",
                                                                             pFeatureDatasetNew, null, pAnnoClass.AnnoProperties, pGLS,
                                                                             pAnnoClass.SymbolCollection, true);
                                    (pTempFc as IClassSchemaEdit).AlterAliasName(fc.AliasName);
                                }
                                catch
                                {
                                    WaitForm.Stop();
                                }
                            }
                            else//若为地理要素
                            {
                                try
                                {
                                    pTempFc = pFeatureDatasetNew.CreateFeatureClass(strFCName, pFields, null, null, fc.FeatureType, fc.ShapeFieldName, null);
                                    (pTempFc as IClassSchemaEdit).AlterAliasName(fc.AliasName);
                                }
                                catch
                                {
                                    WaitForm.Stop();
                                }
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            if (fc.FeatureType == esriFeatureType.esriFTAnnotation)//若为注记
                            {
                                IFeatureWorkspaceAnno pFWsAnno   = pFWs as IFeatureWorkspaceAnno;
                                IAnnoClass            pAnnoClass = fc.Extension as IAnnoClass;

                                IGraphicsLayerScale pGLS = new GraphicsLayerScaleClass();
                                pGLS.ReferenceScale = pAnnoClass.ReferenceScale;
                                pGLS.Units          = pAnnoClass.ReferenceScaleUnits;
                                try
                                {
                                    pTempFc = pFWsAnno.CreateAnnotationClass(strFCName,
                                                                             pFields, fc.CLSID, fc.EXTCLSID, fc.ShapeFieldName, "",
                                                                             pFeatureDatasetNew, null, pAnnoClass.AnnoProperties, pGLS,
                                                                             pAnnoClass.SymbolCollection, true);
                                    (pTempFc as IClassSchemaEdit).AlterAliasName(fc.AliasName);
                                }
                                catch
                                {
                                    WaitForm.Stop();
                                }
                            }
                            else
                            {
                                try
                                {
                                    pTempFc = pFeatureDatasetNew.CreateFeatureClass(strFCName, pFields, null, null, fc.FeatureType, fc.ShapeFieldName, null);
                                    (pTempFc as IClassSchemaEdit).AlterAliasName(fc.AliasName);
                                }
                                catch
                                {
                                    WaitForm.Stop();
                                }
                            }
                        }
                        catch
                        {
                            WaitForm.Stop();
                        }
                    }
                }
                if (fc.FeatureType == esriFeatureType.esriFTAnnotation)
                {
                    IFeature       outFeature;
                    IFeature       pFeature;
                    IFeatureCursor pFeatureCursor = GetSelectedFeatures(GetLayerByNameFromMap(m_Map, strFCName));
                    if (pFeatureCursor == null)
                    {
                        return;
                    }
                    while ((pFeature = pFeatureCursor.NextFeature()) != null)
                    {
                        try
                        {
                            outFeature = pTempFc.CreateFeature();
                            CoordConvertAnnotationFeature(pFeature, ref outFeature);
                            outFeature.Store();
                        }
                        catch (System.Exception ex)
                        {
                            WaitForm.Stop();
                        }
                    }
                    outfc = pTempFc;
                }
                else//若为几何要素
                {
                    IFeature       outFeature;
                    IFeature       pFeature;
                    IFeatureCursor pFeatureCursor = GetSelectedFeatures(GetLayerByNameFromMap(m_Map, strFCName));
                    if (pFeatureCursor == null)
                    {
                        return;
                    }
                    while ((pFeature = pFeatureCursor.NextFeature()) != null)
                    {
                        try
                        {
                            outFeature = pTempFc.CreateFeature();
                            CoordConvertFeature(pFeature, ref outFeature);
                            outFeature.Store();
                        }
                        catch
                        {
                            WaitForm.Stop();
                        }
                    }
                    outfc = pTempFc;
                }
            }
            catch (System.Exception ex)
            {
                WaitForm.Stop();
            }
        }
Ejemplo n.º 21
0
        //初始化数据库 创建数据集体
        private IDataset CreateDatasetByS(IDataset pDataset, IWorkspace pWks, string strTagDatasetName, ref string strError)
        {
            IGeoDataset       pGeoDataS   = pDataset as IGeoDataset;
            IWorkspace2       pWks2       = pWks as IWorkspace2;
            IFeatureWorkspace pFeaWks     = pWks as IFeatureWorkspace;
            IDataset          pTagDataset = null;

            if (!pWks2.get_NameExists(esriDatasetType.esriDTFeatureDataset, strTagDatasetName))
            {
                pTagDataset = pFeaWks.CreateFeatureDataset(strTagDatasetName, pGeoDataS.SpatialReference);
            }
            else
            {
                pTagDataset = pFeaWks.OpenFeatureDataset(strTagDatasetName);
            }
            if (pTagDataset == null)
            {
                return(null);
            }

            IEnumDataset pEnumSubFeaCls = pDataset.Subsets;
            IDataset     pSubDataset    = pEnumSubFeaCls.Next();

            while (pSubDataset != null)
            {
                IFeatureClass pSubFeaCls = pSubDataset as IFeatureClass;
                if (pSubFeaCls == null)
                {
                    pSubDataset = pEnumSubFeaCls.Next();
                    continue;
                }

                string[] strSubNames = pSubDataset.Name.Split('.');
                string   strSubName  = strSubNames[strSubNames.GetLength(0) - 1];
                if (pWks2.get_NameExists(esriDatasetType.esriDTFeatureClass, strSubName))
                {
                    IFeatureClass pTagCls = pFeaWks.OpenFeatureClass(strSubName);
                    if (pTagCls.FeatureDataset != null)
                    {
                        string[] strTagFeaClsNames = pTagCls.FeatureDataset.Name.Split('.');
                        string   strTagFeaClsName  = strTagFeaClsNames[strTagFeaClsNames.GetLength(0) - 1];
                        if (strTagFeaClsName.ToUpper() == strTagDatasetName.ToUpper())
                        {
                            pSubDataset = pEnumSubFeaCls.Next();
                            continue;//已经存在 继续
                        }
                        else
                        {
                            strError = strError + Environment.NewLine + strSubName + "  不在指定的数据集下";
                        }
                    }
                    else
                    {
                        strError = strError + Environment.NewLine + strSubName;
                    }
                }
                else
                {
                    //创建要素
                    IFeatureDataset pTagFeaDataset = pTagDataset as IFeatureDataset;
                    IFeatureClass   pTagsubCls     = CreateFeatureClass(strSubName, pSubFeaCls, pTagFeaDataset, pTagFeaDataset.Workspace as IFeatureWorkspace);
                    if (pTagsubCls == null)
                    {
                        strError    = strError + Environment.NewLine + strSubName + ":要素类创建失败";
                        pSubDataset = pEnumSubFeaCls.Next();//yjl20110815
                        continue;
                    }

                    //如果是注记
                    if (pTagsubCls.FeatureType == esriFeatureType.esriFTAnnotation)
                    {
                        CopyAnnoPropertyToFC(pSubFeaCls, pTagsubCls);
                    }
                }

                pSubDataset = pEnumSubFeaCls.Next();
            }

            return(pTagDataset);
        }
Ejemplo n.º 22
0
        //创建数据集(矢量数据集和影像数据集)
        private void button2_Click(object sender, EventArgs e)
        {
            featureWorkspace = workspace as IFeatureWorkspace;
            rasterWorkspace  = workspace as IRasterWorkspaceEx;
            //定义空间参考
            ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
            ISpatialReference        spatialReference        = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);

            spatialReference.SetDomain(-1000, -1000, 1000, 1000);

            IEnumDatasetName enumDatasetName;
            IDatasetName     datasetName;
            string           dsName = "";

            enumDatasetName = workspace.get_DatasetNames(esriDatasetType.esriDTFeatureDataset);
            datasetName     = enumDatasetName.Next();
            bool isExist = false;

            //创建矢量数据集
            dsName = "SDE." + this.textBox6.Text;
            while (datasetName != null)
            {
                if (datasetName.Name == dsName)
                {
                    isExist = true;
                }
                datasetName = enumDatasetName.Next();
            }
            if (isExist == false)
            {
                featureDataset = featureWorkspace.CreateFeatureDataset(this.textBox6.Text, spatialReference);
            }
            //创建影像数据集
            isExist         = false;
            enumDatasetName = workspace.get_DatasetNames(esriDatasetType.esriDTRasterDataset);
            datasetName     = enumDatasetName.Next();

            dsName = "SDE." + this.textBox6.Text;
            while (datasetName != null)
            {
                if (datasetName.Name == dsName)
                {
                    isExist = true;
                }
                datasetName = enumDatasetName.Next();
            }
            if (isExist == false)
            {
                //设置存储参数
                IRasterStorageDef rasterStorageDef = new RasterStorageDefClass();
                rasterStorageDef.CompressionType     = esriRasterCompressionType.esriRasterCompressionUncompressed;
                rasterStorageDef.PyramidLevel        = 1;
                rasterStorageDef.PyramidResampleType = rstResamplingTypes.RSP_BilinearInterpolation;
                rasterStorageDef.TileHeight          = 128;
                rasterStorageDef.TileWidth           = 128;
                //设置坐标系统
                IRasterDef        rasterDef             = new RasterDefClass();
                ISpatialReference rasterDpatialRefrence = new UnknownCoordinateSystemClass();
                rasterDef.SpatialReference = rasterDpatialRefrence;

                IGeometryDef     geometryDef     = new GeometryDefClass();
                IGeometryDefEdit geometryDefedit = (IGeometryDefEdit)geometryDef;
                geometryDefedit.AvgNumPoints_2 = 5;
                geometryDefedit.GridCount_2    = 1;
                geometryDefedit.set_GridSize(0, 1000);
                geometryDefedit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                ISpatialReference spatialReference2 = new UnknownCoordinateSystemClass();
                geometryDefedit.SpatialReference_2 = spatialReference2;
                rasterDataset = rasterWorkspace.CreateRasterDataset(this.textBox7.Text, 1, rstPixelType.PT_LONG, rasterStorageDef, "DEFAULTS", rasterDef, geometryDef);
            }
        }
Ejemplo n.º 23
0
        public void ConvertTable(IWorkspace sourceWorkspace, IDataset sourceDataset)
        {
            IWorkspace targetWorkspace = calcWorkspace;

            //Target dataset name
            string temporarySuffix     = MilSpace.DataAccess.Helper.GetTemporaryNameSuffix();
            string datasetName         = $"{visibilityCalcFeatureDataset}{temporarySuffix}";
            string nameOfTargetDataset = $"{visibilityCalcFeatureClass}{temporarySuffix}";

            try
            {
                //create source workspace name
                ITable        pSourceTab         = (ITable)sourceDataset;
                IFeatureClass sourceFeatureClass = (IFeatureClass)sourceDataset;

                IDataset       sourceWorkspaceDataset = (IDataset)sourceWorkspace;
                IWorkspaceName sourceWorkspaceName    = (IWorkspaceName)sourceWorkspaceDataset.FullName;

                IFeatureClassName sourceDatasetName = (IFeatureClassName)sourceDataset.FullName;

                //create target workspace name
                IDataset       targetWorkspaceDataset = (IDataset)targetWorkspace;
                IWorkspaceName targetWorkspaceName    = (IWorkspaceName)targetWorkspaceDataset.FullName;
                //create target dataset name
                IFeatureClassName targetFeatureClassName = new FeatureClassNameClass();


                IFeatureWorkspace featureworkspace = (IFeatureWorkspace)calcWorkspace;
                IFeatureDataset   targetDataset    = featureworkspace.CreateFeatureDataset(datasetName, EsriTools.Wgs84Spatialreference);

                IDatasetName targetDatasetName = (IDatasetName)targetFeatureClassName;
                targetDatasetName.WorkspaceName = targetWorkspaceName;
                targetDatasetName.Name          = nameOfTargetDataset;
                ////Open input Featureclass to get field definitions.
                //ESRI.ArcGIS.esriSystem.IName sourceName = (ESRI.ArcGIS.esriSystem.IName)sourceDatasetName;
                //ITable sourceTable = (ITable)sourceName.Open();

                // we want to convert all of the features
                IQueryFilter queryFilter = new QueryFilterClass();
                queryFilter.WhereClause = "";
                //Validate the field names because you are converting between different workspace types.
                IFieldChecker   fieldChecker = new FieldCheckerClass();
                IFields         targetFields;
                IFields         sourceFields = pSourceTab.Fields;
                IEnumFieldError enumFieldError;
                // Most importantly set the input and validate workspaces!
                fieldChecker.InputWorkspace    = sourceWorkspace;
                fieldChecker.ValidateWorkspace = targetWorkspace;
                fieldChecker.Validate(sourceFields, out enumFieldError, out targetFields);

                // Get the geometry definition from the shape field and clone it.
                string shapeFieldName  = sourceFeatureClass.ShapeFieldName;
                int    shapeFieldIndex = sourceFeatureClass.FindField(shapeFieldName);
                IField shapeField      = sourceFields.get_Field(shapeFieldIndex);

                IGeometryDef geometryDef            = shapeField.GeometryDef;
                IClone       geometryDefClone       = (IClone)geometryDef;
                IClone       targetGeometryDefClone = geometryDefClone.Clone();
                IGeometryDef targetGeometryDef      = (IGeometryDef)targetGeometryDefClone;


                if (enumFieldError == null)
                {
                    IFeatureDataConverter fctofc = new FeatureDataConverterClass();

                    IEnumInvalidObject enumErrors =
                        fctofc.ConvertFeatureClass(sourceDatasetName, queryFilter, (IFeatureDatasetName)targetDataset.FullName, targetFeatureClassName, targetGeometryDef,
                                                   pSourceTab.Fields, "", 1000, 0);
                }
            }
            catch (Exception exp)
            {
                logger.ErrorEx(exp.ToString());
                return;
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 创建一个要素集
        /// </summary>
        private void CreateFeatureClass()
        {
            string path    = txt_org.Text;
            string PRJFile = txt_prj.Text;
            AccessWorkspaceFactory pAccessFact = new AccessWorkspaceFactoryClass();

            IFeatureWorkspace         pFeatureWorkspace = pAccessFact.OpenFromFile(path, 0) as IFeatureWorkspace;
            ISpatialReferenceFactory2 Isp = new SpatialReferenceEnvironmentClass();                   //创建一个空间参照的接口空间

            ISpatialReference           spatial = Isp.CreateESRISpatialReferenceFromPRJFile(PRJFile); //利用要素类的PRJ文件参照
            ISpatialReferenceResolution pSRR    = (ISpatialReferenceResolution)spatial;               //设置分辨率

            pSRR.SetDefaultXYResolution();                                                            //设置默认XY值

            ISpatialReferenceTolerance pSRT = (ISpatialReferenceTolerance)spatial;

            pSRT.SetDefaultXYTolerance();//设置默认容差值
            IWorkspace space = pFeatureWorkspace as IWorkspace;

            IEnumDatasetName Dataset_name = space.get_DatasetNames(esriDatasetType.esriDTAny);//得到有多少个要素集合名字

            Dataset_name.Reset();
            IDatasetName Name_set = Dataset_name.Next();

            while (Name_set != null)
            {
                if (Name_set.Name == "Geo_Topo_ice")
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "数据集已存在,不用创建!");
                    this.Close();//如果要创建的数据集已存在,就返回,并关闭窗体
                    return;
                }
                Name_set = Dataset_name.Next();
            }
            IFeatureDataset pfd = pFeatureWorkspace.CreateFeatureDataset("Geo_Topo_ice", spatial); //创建一个要素集

            IEnumDataset dst = space.get_Datasets(esriDatasetType.esriDTAny);                      //得到所有的要素类的一个集合

            dst.Reset();
            IDataset det = dst.Next();

            _AppHk.OperatorTips = "开始创建对应的要素类...";
            while (det != null)
            {
                #region 给要素集创建空的要素类
                if (det.Type == esriDatasetType.esriDTFeatureClass)                       //判定是不是要素类
                {
                    string org_name = det.Name;                                           //原始的名字
                    _AppHk.OperatorTips = "开始创建" + org_name + "要素类...";
                    IFeatureClass f_class = pFeatureWorkspace.OpenFeatureClass(org_name); //打开源要素类
                    det.Rename(org_name + "_t");                                          //把源要素类进行重命名
                    IFields     Fieldset = new FieldsClass();                             //建立一个字段集
                    IFieldsEdit sField   = Fieldset as IFieldsEdit;                       //字段集
                    if (f_class.FeatureType != esriFeatureType.esriFTAnnotation)
                    {
                        //shape
                        IGeometryDefEdit d_edit;                       //定义一个用来接收要素类的SHAPE类型
                        d_edit = new GeometryDefClass();               //实例一个操作类
                        d_edit.GeometryType_2     = f_class.ShapeType; //将源要素类的SHAPE赋值给我们要创建的几何类型
                        d_edit.SpatialReference_2 = spatial;           //空间参考

                        string OID   = f_class.OIDFieldName;           //ODI名字
                        string SHAPE = f_class.ShapeFieldName;         //SHAPE名字

                        //IFields Fieldset = new FieldsClass();//建立一个字段集
                        //IFieldsEdit sField = Fieldset as IFieldsEdit;//字段集


                        //创建要素类里的字段
                        int count = f_class.Fields.FieldCount;//确定有多少个字段

                        #region 创建字段
                        for (int n = 0; n < count; n++)
                        {
                            IField f_ield = f_class.Fields.get_Field(n);

                            IFieldEdit fieldEdit = f_ield as IFieldEdit;
                            //Annotate
                            if (f_ield.Name == SHAPE)
                            {
                                //shape field
                                fieldEdit.Type_2        = esriFieldType.esriFieldTypeGeometry; //确定字段的类型
                                fieldEdit.GeometryDef_2 = d_edit;                              //把几何类型赋值给它
                                fieldEdit.Name_2        = SHAPE;                               //把几何类型SHPAE的名字赋值给它
                                f_ield = fieldEdit as IField;
                                sField.AddField(f_ield);                                       //加入要素集
                            }
                            else if (f_ield.Name == OID)
                            {
                                //oid
                                fieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; //OID标识字段
                                fieldEdit.Name_2 = OID;                            //OID的名字
                                f_ield           = fieldEdit as IField;
                                sField.AddField(f_ield);                           //加入OID
                            }
                            else
                            {
                                //一般字段
                                fieldEdit.Name_2 = f_ield.Name;
                                fieldEdit.Type_2 = f_ield.Type;//字段的类型

                                f_ield = fieldEdit as IField;
                                sField.AddField(f_ield);
                            }
                        }
                        #endregion

                        Fieldset = sField as IFields;                                                                             //将可编辑的字段集转成一般字段集
                        pfd.CreateFeatureClass(org_name, Fieldset, f_class.CLSID, null, esriFeatureType.esriFTSimple, SHAPE, ""); //给要素集中创建要素类
                    }
                    else
                    {
                        createAnnoFeatureClass(org_name, pfd, pfd.Workspace as IFeatureWorkspace, sField, 2000);
                    }

                    det = dst.Next();//重新遍历下一个
                }
                else
                {
                    det = dst.Next();//重新遍历下一个
                }
                #endregion
            }
            _AppHk.OperatorTips = "要素集合创建成功!";
            GetValue(pFeatureWorkspace);//当对应的要素类建立好后,就开始给空要素类赋值
            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "数据处理完成!");
            this.Close();
        }
Ejemplo n.º 25
0
        public bool CreateFeatureClassUnderDS(string FCName, string DSName, bool IncludeFeature, bool CreateDS, string TempDBID, bool AddFID)
        {
            IFeatureWorkspace pDesFeatureWorkspace = this._Workspace as IFeatureWorkspace;
            IFeatureClass     pDesFeatureClass     = null;

            if (pDesFeatureWorkspace == null)
            {
                return(false);
            }

            IFeatureWorkspace pSourFeatureWorkspace = this._TempleteWorkspace as IFeatureWorkspace;

            if (pSourFeatureWorkspace == null)
            {
                return(false);
            }

            IFeatureDataset pDesFeatureDataset = null;
            IFeatureDataset pSrcFeatureDataset = null;

            if (CreateDS)
            {
                //创建数据集

                pSrcFeatureDataset = pSourFeatureWorkspace.OpenFeatureDataset(DSName);
                IGeoDataset pGeoDataset = pSrcFeatureDataset as IGeoDataset;
                pDesFeatureDataset = pDesFeatureWorkspace.CreateFeatureDataset(DSName + TempDBID, pGeoDataset.SpatialReference);
            }
            else
            {
                pDesFeatureDataset = pDesFeatureWorkspace.OpenFeatureDataset(DSName + TempDBID);
            }

            #region 创建目标图层
            //获取源要素类
            IFeatureClass pSourFeatureClass = pSourFeatureWorkspace.OpenFeatureClass(FCName);
            if (pSourFeatureClass == null)
            {
                return(false);
            }

            //获取源要素类后判断要素类的类型

            if (pSourFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)   //如果是注记层
            {
                IFeatureWorkspaceAnno pFWSAnno   = pDesFeatureWorkspace as IFeatureWorkspaceAnno;
                IAnnoClass            pAnnoClass = pSourFeatureClass.Extension as IAnnoClass;
                IGraphicsLayerScale   pGLS       = new GraphicsLayerScaleClass();
                pGLS.ReferenceScale = pAnnoClass.ReferenceScale;
                pGLS.Units          = pAnnoClass.ReferenceScaleUnits;

                ///添加特殊字段
                ///
                IField     pField     = new FieldClass();
                IFieldEdit pFieldEdit = pField as IFieldEdit;

                pFieldEdit.Editable_2 = true;
                pFieldEdit.Name_2     = "GOFID";
                pFieldEdit.Type_2     = esriFieldType.esriFieldTypeInteger;



                IField     pField2     = new FieldClass();
                IFieldEdit pFieldEdit2 = pField2 as IFieldEdit;

                pFieldEdit2.Editable_2 = true;
                pFieldEdit2.Name_2     = "pro_id"; //项目ID
                pFieldEdit2.Type_2     = esriFieldType.esriFieldTypeInteger;

                IFields pFields = pSourFeatureClass.Fields;

                if (AddFID)
                {
                    IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
                    pFieldsEdit.AddField(pField);
                    pFieldsEdit.AddField(pField2);
                    pDesFeatureClass = pFWSAnno.CreateAnnotationClass(FCName + TempDBID, pFields, pSourFeatureClass.CLSID, pSourFeatureClass.EXTCLSID, pSourFeatureClass.ShapeFieldName, "", pDesFeatureDataset, null, pAnnoClass.AnnoProperties, pGLS, pAnnoClass.SymbolCollection, true);
                    pFieldsEdit.DeleteField(pField);
                    pFieldsEdit.DeleteField(pField2);
                }
                else
                {
                    pDesFeatureClass = pFWSAnno.CreateAnnotationClass(FCName + TempDBID, pFields, pSourFeatureClass.CLSID, pSourFeatureClass.EXTCLSID, pSourFeatureClass.ShapeFieldName, "", pDesFeatureDataset, null, pAnnoClass.AnnoProperties, pGLS, pAnnoClass.SymbolCollection, true);
                }
            }
            else    //如果是普通要素类
            {
                ///添加特殊字段
                ///
                IField     pField     = new FieldClass();
                IFieldEdit pFieldEdit = pField as IFieldEdit;

                pFieldEdit.Editable_2 = true;
                pFieldEdit.Name_2     = "GOFID";
                pFieldEdit.Type_2     = esriFieldType.esriFieldTypeInteger;


                IField     pField2     = new FieldClass();
                IFieldEdit pFieldEdit2 = pField2 as IFieldEdit;

                pFieldEdit2.Editable_2 = true;
                pFieldEdit2.Name_2     = "pro_id"; //项目ID
                pFieldEdit2.Type_2     = esriFieldType.esriFieldTypeInteger;

                IFields pFields = pSourFeatureClass.Fields;

                if (AddFID)
                {
                    IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
                    pFieldsEdit.AddField(pField);
                    pFieldsEdit.AddField(pField2);
                    pDesFeatureClass = pDesFeatureDataset.CreateFeatureClass(FCName + TempDBID, pFields, pSourFeatureClass.CLSID, pSourFeatureClass.EXTCLSID, pSourFeatureClass.FeatureType, pSourFeatureClass.ShapeFieldName, "");
                    pFieldsEdit.DeleteField(pField);
                    pFieldsEdit.DeleteField(pField2);
                }
                else
                {
                    pDesFeatureClass = pDesFeatureDataset.CreateFeatureClass(FCName + TempDBID, pFields, pSourFeatureClass.CLSID, pSourFeatureClass.EXTCLSID, pSourFeatureClass.FeatureType, pSourFeatureClass.ShapeFieldName, "");
                }
            }

            #endregion

            if (pDesFeatureClass == null)
            {
                return(false);
            }

            //导入要素
            if (IncludeFeature)  //如果需要复制要素
            {
                Exception eError = null;

                Dictionary <string, string> pDic = new Dictionary <string, string>();
                IFeatureCursor pFeatureCursor    = pSourFeatureClass.Search(null, false);

                IFields pFields = pSourFeatureClass.Fields;

                for (int i = 0; i < pFields.FieldCount; i++)
                {
                    IField pField = pFields.get_Field(i);
                    if (pField.Editable)
                    {
                        pDic.Add(pField.Name, pField.Name);
                    }
                }

                SysCommon.Gis.SysGisDataSet pSysGisDataSet = new SysCommon.Gis.SysGisDataSet();
                pSysGisDataSet.WorkSpace = this._Workspace;

                pSysGisDataSet.NewFeatures(FCName, pFeatureCursor, pDic, null, true, true, out eError);

                //释放cursor
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);
            }
            return(true);
        }