Ejemplo n.º 1
0
        /// <summary>
        /// 查询数据,将查询到的结果放到新建的 temp 类中
        /// </summary>
        /// <param name="className">要查询的类的名字</param>
        /// <param name="search">查询语句</param>
        /// <param name="tempClass">要创建的临时类</param>
        /// <returns></returns>
        public static bool SearchData(string className, string search, string tempClass)
        {
            //定义变量
            IVectorCls VectorCls = new SFeatureCls();
            //打开简单要素类
            bool rtn = VectorCls.Open("GDBP://MapGisLocal/Templates/sfcls/" + className);

            if (!rtn)
            {
                PUMessageBox.ShowDialog("简单要素类 " + className + " 打开失败", "失败");
                return(false);
            }

            QueryDef def = new QueryDef();

            //设置属性查询条件
            def.Filter = search;
            //查询要素
            RecordSet recordSet = VectorCls.Select(def);

            if (recordSet != null)
            {
                int num = recordSet.Count;
            }
            else
            {
                return(false);
            }

            Server svr = new Server();

            //连接数据源
            svr.Connect("MapGISLocal", "", "");
            DataBase    GDB      = svr.OpenGDB("templates");
            SFeatureCls tmpSFCls = new SFeatureCls(GDB);
            int         id       = tmpSFCls.Create(tempClass, GeomType.Pnt, 0, 0, null);

            if (id == 0)
            {
                bool temp = SFeatureCls.Remove(GDB, tempClass);
                id = tmpSFCls.Create(tempClass, GeomType.Pnt, 0, 0, null);
                if (id == 0)
                {
                    PUMessageBox.ShowDialog("无法操作简单要素类,请检查是否有其他进程正在使用 " + tempClass, "失败");
                    return(false);
                }
            }

            rtn = tmpSFCls.CopySet(recordSet);
            if (rtn == false)
            {
                tmpSFCls.Close();
                SFeatureCls.Remove(GDB, id);
            }
            //关闭类
            VectorCls.Close();
            return(true);
        }
Ejemplo n.º 2
0
        void test()
        {
            //设置转换源数据url,67数据为区简单要素类
            string SrcUrl = @"D:\武汉地质调查中心---矿产资源潜力评价项目\广西壮族自治区\铝土矿种潜力评价图库\DZ_成矿地质背景\CJGZ_预测工作区沉积建造构造图\JWMAP_经纬坐标图件\MDZCJGZDFSPX_扶绥-凭祥预测工作区沉积建造构造图\LDLYAAB002.WT";
            //目的数据的名称
            string DesSFname = "convertsfcls";

            SFeatureCls decsfc = null;

            Server   Svr = null;
            DataBase GDB = null;

            Svr = new Server();

            Svr.Connect("MapGISLocal", "", "");
            GDB = Svr.OpenGDB("test");

            decsfc = new SFeatureCls(GDB);

            //创建区简单要素类目的数据
            decsfc.Create(DesSFname, GeomType.Pnt, 0, 0, null);

            //设置转换类型
            DataConvert dataConvert = new DataConvert();

            dataConvert.SetOption(ConvertOptionType.OPT_6TO7, 0);

            //打开源数据和目的数据
            if (dataConvert.OpenSource(SrcUrl) > 0 && dataConvert.OpenDestination(decsfc) > 0)
            {
                //转换数据
                bool rtn = dataConvert.Convert() > 0;
                if (rtn)
                {
                    MessageBox.Show("数据迁移成功");
                }
                else
                {
                    MessageBox.Show("数据转换失败");
                }
                dataConvert.Close();
                decsfc.Close();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建简单要素类
        /// </summary>
        /// <param name="layerName">要素类名</param>
        /// <param name="geomType">几何类型,枚举</param>
        /// <param name="gdbName">打开的地理数据库名</param>
        public static bool CreateXClass(string layerName, GeomType geomType, string gdbName, string[] fields)
        {
            //方法:指定类型、数据集ID,空间参考系,创建类
            Server      svr   = new Server();
            SFeatureCls sfcls = null;
            //连接数据源,打开数据库
            bool rtn = svr.Connect("MapGISLocal", "", "");

            if (rtn == true)
            {
                DataBase gdb = svr.OpenGDB(gdbName);
                //打开简单要素类
                sfcls = gdb.GetXClass(XClsType.SFCls) as SFeatureCls;
                //创建区类型的简单要素类
                int id = sfcls.Create(layerName, geomType, 0, 0, null);
                if (id <= 0)
                {
                    //关闭类、数据库、断开数据源
                    sfcls.Close();
                    gdb.Close();
                    svr.DisConnect();
                    return(false);
                }

                sfcls.Open(layerName, 0);
                Fields temp = sfcls.Fields;
                if (temp == null)
                {
                    temp = new Fields();
                }
                //Field adding = null;

                #region 添加属性

                //1: successful  0: failed
                int result = temp.AppendField(new Field
                {
                    FieldName   = "DataID",
                    FieldLength = 255,
                    FieldType   = FieldType.FldString,
                    Editable    = 1,
                    MskLength   = 15
                });

                result = temp.AppendField(new Field
                {
                    FieldName   = "BikeID",
                    FieldLength = 255,
                    FieldType   = FieldType.FldString,
                    Editable    = 1,
                    MskLength   = 15
                });

                result = temp.AppendField(new Field
                {
                    FieldName   = "ParkTime",
                    FieldType   = FieldType.FldTime,
                    Editable    = 1,
                    FieldLength = 10,
                    MskLength   = 10
                });

                result = temp.AppendField(new Field
                {
                    FieldName   = "Date",
                    FieldType   = FieldType.FldTime,
                    Editable    = 1,
                    FieldLength = 10,
                    MskLength   = 10
                });

                result = temp.AppendField(new Field
                {
                    FieldName   = "xAsis",
                    FieldLength = 255,
                    FieldType   = FieldType.FldDouble,
                    Editable    = 1,
                    MskLength   = 15
                });

                result = temp.AppendField(new Field
                {
                    FieldName   = "yAsis",
                    FieldLength = 255,
                    FieldType   = FieldType.FldDouble,
                    Editable    = 1,
                    MskLength   = 15
                });

                #endregion

                //foreach (var item in fields)
                //{
                //    adding = new Field
                //    {
                //        FieldName = item,
                //        FieldLength = 255,
                //        FieldType = FieldType.FldString,
                //        Editable = 1,
                //        MskLength = 15
                //    };
                //    int result = temp.AppendField(adding);  //1: successful  0: failed
                //}
                sfcls.Fields = temp;

                //关闭类、数据库、断开数据源
                sfcls.Close();
                gdb.Close();
                svr.DisConnect();

                if (id > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }