Beispiel #1
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            // 加载FDB场景
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\community.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                dataset = ds.OpenFeatureDataset(setnames[0]);   //此处把dataset作为全局对象,以便后面调用
                string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            bool hasfly = false;

            layerList = new List <IFeatureLayer>();
            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    //****特别注意****
                    ISimpleGeometryRender geoRender = new SimpleGeometryRender();
                    geoRender.RenderGroupField = "Groupid";   // 逻辑组
                    //如果是IValueMapGeometryRender,默认被分到other组里,比如加上otherScheme,否则不显示
                    //IValueMapGeometryRender geoRender = new ValueMapGeometryRender();
                    //geoRender.RenderGroupField = "Groupid";   // 逻辑组
                    //IGeometryRenderScheme other = new GeometryRenderScheme();
                    //geoRender.AddScheme(other);
                    //****************
                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, null, geoRender, rootId);
                    layerList.Add(featureLayer);

                    // 设置featureLayer可见
                    SetGroupVisiable(dataset, featureLayer);

                    if (!hasfly)
                    {
                        IFieldInfoCollection fieldinfos  = fc.GetFields();
                        IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                        IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                        IEnvelope            env         = geometryDef.Envelope;
                        if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                            env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                        {
                            continue;
                        }
                        IEulerAngle angle = new EulerAngle();
                        angle.Set(0, -20, 0);
                        this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle);
                    }
                    hasfly = true;
                }
            }

            // 加载FeatureDataSet对应的LogicGroupTree到界面控件
            nodekeyMap = new Hashtable();
            byte[] bb = GetLogicTreeContent(dataset);
            if (bb != null)
            {
                string strContent = System.Text.Encoding.UTF8.GetString(bb).Trim();
                ShowCurDataSet(strContent);
            }
            // 删除回收站及其子节点
            foreach (TreeNode node in this.treeView1.Nodes[0].Nodes)
            {
                if (node.Text.Equals("回收站"))
                {
                    this.treeView1.Nodes.Remove(node);
                }
            }

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "LogicGroupTree.html";
            }
        }
Beispiel #2
0
        private void createFieldToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string          fc_name  = selectNode.Text;
            string          set_name = selectNode.Parent.Text;
            myTreeNode      node     = (myTreeNode)selectNode.Parent.Parent;
            IConnectionInfo ci       = node.con;

            IDataSource     ds   = null;
            IFeatureDataSet dset = null;
            IFeatureClass   fc   = null;

            try
            {
                ds   = dsFactory.OpenDataSource(ci);
                dset = ds.OpenFeatureDataset(set_name);
                fc   = dset.OpenFeatureClass(fc_name);

                OperateFieldInfoForm form = new OperateFieldInfoForm(null);
                if (form.ShowDialog() == DialogResult.OK)
                {
                    IFieldInfoCollection fieldinfos   = fc.GetFields();
                    IFieldInfo           newFieldInfo = form.newFieldInfo;

                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        if (newFieldInfo.Name == fieldinfo.Name)
                        {
                            MessageBox.Show("已有同名字段,添加失败");
                            return;
                        }
                    }

                    fc.LockType = gviLockType.gviLockExclusiveSchema;
                    fc.AddField(newFieldInfo);
                    fc.LockType = gviLockType.gviLockSharedSchema;

                    // 往树上挂节点
                    TreeNode fieldNode = new TreeNode(newFieldInfo.Name, 1, 1);
                    selectNode.Nodes.Add(fieldNode);
                    fieldNode.ContextMenuStrip = this.contextMenuStrip4;
                }
            }
            catch (COMException comEx)
            {
                System.Diagnostics.Trace.WriteLine(comEx.Message);
                MessageBox.Show("添加失败");
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                MessageBox.Show("添加失败");
            }
            finally
            {
                fc.LockType = gviLockType.gviLockSharedSchema;
                if (fc != null)
                {
                    //Marshal.ReleaseComObject(fc);
                    fc = null;
                }
                if (dset != null)
                {
                    //Marshal.ReleaseComObject(dset);
                    dset = null;
                }
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
            }
        }
Beispiel #3
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);
            this.axRenderControl1.Camera.FlyTime = 1;

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            // 加载FDB场景
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                string[]        fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            bool hasfly = false;

            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    if (!geoName.Equals("Geometry"))
                    {
                        continue;
                    }

                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                        fc, geoName, null, null, rootId);

                    if (!hasfly)
                    {
                        IFieldInfoCollection fieldinfos  = fc.GetFields();
                        IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                        IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                        IEnvelope            env         = geometryDef.Envelope;
                        if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                            env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                        {
                            continue;
                        }
                        IEulerAngle angle = new EulerAngle();
                        angle.Set(0, -20, 0);
                        this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle);
                    }
                    hasfly = true;
                }
            }

            // 注册控件拾取事件
            this.axRenderControl1.RcMouseClickSelect += new Gvitech.CityMaker.Controls._IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect);


            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "EmbedWatermark.html";
            }
        }
Beispiel #4
0
        private void toolStripMenuItemQuery_Click(object sender, EventArgs e)
        {
            string          fc_name  = selectNode.Text;
            string          set_name = selectNode.Parent.Text;
            myTreeNode      node     = (myTreeNode)selectNode.Parent.Parent;
            IConnectionInfo ci       = node.con;

            IDataSource     ds      = null;
            IFeatureDataSet dataset = null;
            IFeatureClass   fc      = null;

            try
            {
                ds      = dsFactory.OpenDataSource(ci);
                dataset = ds.OpenFeatureDataset(set_name);
                fc      = dataset.OpenFeatureClass(fc_name);

                QueryFilterDlg pQueryFilterDlg = new QueryFilterDlg();
                for (int index = 0; index < fc.GetFields().Count; index++)
                {
                    pQueryFilterDlg.FieldList_listBox.Items.Add(fc.GetFields().Get(index).Name);
                }
                if (DialogResult.OK == pQueryFilterDlg.ShowDialog())
                {
                    IQueryFilter filter = new QueryFilter();
                    filter.WhereClause = pQueryFilterDlg.QueryFilter_txt.Text;
                    int nCount = fc.GetCount(filter);
                    if (nCount == 0)
                    {
                        return;
                    }

                    // 初始化表格
                    DataTable dt = CreateDataTable(fc);
                    // 查找数据
                    GetResultSet(fc, filter, dt);
                    // 显示表格
                    FCConnectionInfo info = new FCConnectionInfo(ci, set_name, fc_name);
                    new AttributeFrm(dt, info, filter.WhereClause).Show();
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
                if (dataset != null)
                {
                    //Marshal.ReleaseComObject(dataset);
                    dataset = null;
                }
                if (fc != null)
                {
                    //Marshal.ReleaseComObject(fc);
                    fc = null;
                }
            }
        }
Beispiel #5
0
        private void modifyFieldToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string          fieldInfo_name = selectNode.Text;
            string          fc_name        = selectNode.Parent.Text;
            string          set_name       = selectNode.Parent.Parent.Text;
            myTreeNode      node           = (myTreeNode)selectNode.Parent.Parent.Parent;
            IConnectionInfo ci             = node.con;

            IDataSource     ds           = null;
            IFeatureDataSet dset         = null;
            IFeatureClass   fc           = null;
            IFieldInfo      newFieldInfo = null;

            try
            {
                ds   = dsFactory.OpenDataSource(ci);
                dset = ds.OpenFeatureDataset(set_name);
                fc   = dset.OpenFeatureClass(fc_name);

                // 获取fieldinfo对象
                IFieldInfoCollection fieldinfos = fc.GetFields();
                for (int i = 0; i < fieldinfos.Count; i++)
                {
                    IFieldInfo fieldinfo = fieldinfos.Get(i);
                    if (null == fieldinfo)
                    {
                        continue;
                    }
                    if (fieldInfo_name == fieldinfo.Name)
                    {
                        newFieldInfo = fieldinfo;
                        break;
                    }
                }

                OperateFieldInfoForm form = new OperateFieldInfoForm(newFieldInfo);
                if (form.ShowDialog() == DialogResult.OK)
                {
                    newFieldInfo = form.newFieldInfo;

                    fc.LockType = gviLockType.gviLockExclusiveSchema;
                    fc.ModifyField(newFieldInfo);
                    fc.LockType = gviLockType.gviLockSharedSchema;

                    // 修改树上的节点
                    selectNode.Text = newFieldInfo.Name;
                    MessageBox.Show("修改成功");
                }
            }
            catch (COMException comEx)
            {
                System.Diagnostics.Trace.WriteLine(comEx.Message);
                MessageBox.Show("修改失败");
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                MessageBox.Show("修改失败");
            }
            finally
            {
                fc.LockType = gviLockType.gviLockSharedSchema;
                if (newFieldInfo != null)
                {
                    //Marshal.ReleaseComObject(newFieldInfo);
                    newFieldInfo = null;
                }
                if (fc != null)
                {
                    //Marshal.ReleaseComObject(fc);
                    fc = null;
                }
                if (dset != null)
                {
                    //Marshal.ReleaseComObject(dset);
                    dset = null;
                }
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
            }
        }
Beispiel #6
0
 private void LoadData(IConnectionInfo connInfo)
 {
     try
     {
         IDataSourceFactory dsFactory = new DataSourceFactory();
         if (dsFactory.HasDataSource(connInfo))
         {
             IDataSource ds = dsFactory.OpenDataSource(connInfo);
             if (ds != null)
             {
                 string[] strfdss = ds.GetFeatureDatasetNames();
                 if (strfdss == null)
                 {
                     return;
                 }
                 foreach (string strfds in strfdss)
                 {
                     IFeatureDataSet fds = ds.OpenFeatureDataset(strfds);
                     if (fds == null)
                     {
                         continue;
                     }
                     string[] fcnames = fds.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                     if (fcnames == null)
                     {
                         continue;
                     }
                     foreach (string fcname in fcnames)
                     {
                         IFeatureClass fc = fds.OpenFeatureClass(fcname);
                         if (fc == null)
                         {
                             continue;
                         }
                         DataRow dr = this._dt.NewRow();
                         dr["FeatureClassAlias"] = fc.AliasName;
                         dr["FeatureClassName"]  = fc.Name;
                         dr["FeatureClass"]      = fc;
                         dr["CheckState"]        = true;
                         FacilityClass facC = DF3DData.Class.Dictionary3DTable.Instance.GetFacilityClassByDFFeatureClassID(fc.Guid.ToString());
                         if (facC != null)
                         {
                             dr["FacilityClass"] = facC;
                         }
                         else
                         {
                             foreach (FacilityClass facTemp in FacilityClassManager.Instance.GetAllFacilityClass())
                             {
                                 if (fc.AliasName.Contains(facTemp.Alias))
                                 {
                                     dr["FacilityClass"] = facTemp;
                                     break;
                                 }
                             }
                         }
                         MajorClass mc = LogicDataStructureManage3D.Instance.GetMajorClassByDFFeatureClassID(fc.Guid.ToString());
                         if (mc != null)
                         {
                             dr["MajorClass"] = mc;
                         }
                         else
                         {
                             foreach (MajorClass mcTemp in LogicDataStructureManage3D.Instance.GetAllMajorClass())
                             {
                                 if (fc.AliasName.Contains(mcTemp.Alias))
                                 {
                                     dr["MajorClass"] = mcTemp;
                                     break;
                                 }
                             }
                         }
                         this._dt.Rows.Add(dr);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
Beispiel #7
0
        private void toolStripButtonEditFeature_Click(object sender, EventArgs e)
        {
            this.dataGridView1.EndEdit();  //强制提交
            if (dsFactory == null)
            {
                dsFactory = new DataSourceFactory();
            }

            IDataSource     ds      = null;
            IFeatureDataSet dataset = null;
            IFeatureClass   fc      = null;
            IFdeCursor      cursor  = null;
            IFieldInfo      field   = null;

            try
            {
                if (dataGridView1.SelectedRows.Count == 1)
                {
                    ds      = dsFactory.OpenDataSource(Info.ci);
                    dataset = ds.OpenFeatureDataset(Info.datasetName);
                    fc      = dataset.OpenFeatureClass(Info.featureclassName);

                    // 比较是否修改了记录
                    int        oid    = int.Parse(dataGridView1.SelectedRows[0].Cells["oid"].Value.ToString());
                    IRowBuffer fdeRow = fc.GetRow(oid);

                    bool isChanged = false;
                    for (int i = 0; i < AttriTable.Columns.Count; ++i)
                    {
                        string strColName = AttriTable.Columns[i].ColumnName;
                        int    nPos       = fdeRow.FieldIndex(strColName);
                        if (nPos != -1)
                        {
                            field = fdeRow.Fields.Get(nPos);
                        }
                        if (nPos != -1 && strColName != "oid" && strColName != "GroupName" && field.FieldType != gviFieldType.gviFieldGeometry)
                        {
                            if (fdeRow.GetValue(nPos) == null || (!dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[i].EditedFormattedValue.Equals(fdeRow.GetValue(nPos).ToString())))
                            {
                                isChanged = true;
                                break;
                            }
                        }
                    }
                    if (!isChanged)
                    {
                        MessageBox.Show("该条记录无改动");
                        return;
                    }

                    for (int j = 0; j < AttriTable.Columns.Count; ++j)
                    {
                        string strColName = AttriTable.Columns[j].ColumnName;
                        int    nPos       = fdeRow.FieldIndex(strColName);
                        if (nPos != -1)
                        {
                            field = fdeRow.Fields.Get(nPos);
                        }
                        if (nPos != -1 && strColName != "oid" && strColName != "GroupName" && field.FieldType != gviFieldType.gviFieldGeometry)
                        {
                            fdeRow.SetValue(nPos, dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[j].EditedFormattedValue);   //插入字段值
                        }
                    }

                    // 修改数据库中记录
                    IRowBufferCollection col = new RowBufferCollection();
                    col.Add(fdeRow);
                    fc.UpdateRows(col, false);
                    MessageBox.Show("修改成功");
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
                if (dataset != null)
                {
                    //Marshal.ReleaseComObject(dataset);
                    dataset = null;
                }
                if (fc != null)
                {
                    //Marshal.ReleaseComObject(fc);
                    fc = null;
                }
                if (cursor != null)
                {
                    //Marshal.ReleaseComObject(cursor);
                    cursor = null;
                }
            }
        }
Beispiel #8
0
        private void UpdateAttribute(object param)
        {
            DF3DApplication app = DF3DApplication.Application;

            if (app == null || app.Current3DMapControl == null)
            {
                return;
            }
            EditParameters editParameters = (EditParameters)param;

            if (editParameters == null)
            {
                return;
            }
            string           featureClassGuid = editParameters.featureClassGuid;
            DF3DFeatureClass featureClassInfo = DF3DFeatureClassManager.Instance.GetFeatureClassByID(featureClassGuid);

            if (featureClassInfo == null)
            {
                return;
            }
            CommandManagerServices.Instance().StartCommand();
            FDECommand cmd         = new FDECommand(false, true);
            int        nTotalCount = editParameters.nTotalCount;
            int        num         = 0;

            if (featureClassInfo.GetFeatureClass().HasTemporal() && CommonUtils.Instance().EnableTemproalEdit)
            {
                IConnectionInfo connectionInfo = new ConnectionInfoClass();
                connectionInfo.FromConnectionString(featureClassInfo.GetFeatureClass().DataSource.ConnectionInfo.ToConnectionString());
                IDataSource      dataSource      = ((IDataSourceFactory) new DataSourceFactoryClass()).OpenDataSource(connectionInfo);
                IFeatureDataSet  featureDataSet  = dataSource.OpenFeatureDataset(CommonUtils.Instance().GetCurrentFeatureDataset().Name);
                IFeatureClass    featureClass    = featureDataSet.OpenFeatureClass(featureClassInfo.GetFeatureClass().Name);
                ITemporalManager temporalManager = featureClass.TemporalManager;
                ITemporalCursor  temporalCursor  = temporalManager.Search(new TemporalFilterClass
                {
                    IdsFilter = editParameters.fidList
                });
                while (temporalCursor.MoveNext())
                {
                    this._manualResult.WaitOne();
                    num++;
                    string userState       = string.Format(StringParser.Parse("${res:feature_progress_finished}"), num, nTotalCount);
                    int    percentProgress = num * 100 / nTotalCount;
                    this._bgWorker.ReportProgress(percentProgress, userState);
                    bool       flag      = false;
                    int        currentId = temporalCursor.CurrentId;
                    IRowBuffer row       = featureClass.GetRow(currentId);
                    base.UpdateRowBuffer(ref row, editParameters.colName, editParameters.regexDataList);
                    ITemporalInstanceCursor temporalInstances = temporalCursor.GetTemporalInstances(false);
                    TemporalInstance        temporalInstance;
                    while ((temporalInstance = temporalInstances.NextInstance()) != null)
                    {
                        if (temporalInstance.StartDatetime == editParameters.TemproalTime)
                        {
                            flag = true;
                            temporalInstances.Update(row);
                            break;
                        }
                    }
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalInstances);
                    if (!flag)
                    {
                        temporalCursor.Insert(editParameters.TemproalTime, row);
                    }
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalCursor);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalManager);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(featureDataSet);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(dataSource);
            }
            else
            {
                IFeatureClass featureClass2 = featureClassInfo.GetFeatureClass();
                System.Collections.Generic.Dictionary <int, string> dictionary = new System.Collections.Generic.Dictionary <int, string>();
                IRowBufferCollection rowBufferCollection  = new RowBufferCollectionClass();
                IRowBufferCollection rowBufferCollection2 = new RowBufferCollectionClass();
                for (int i = 0; i < editParameters.fidList.Length; i++)
                {
                    if (this._bgWorker.CancellationPending)
                    {
                        CommonUtils.Instance().FdeUndoRedoManager.UpdateFeatures(featureClass2, rowBufferCollection2);
                        break;
                    }
                    this._manualResult.WaitOne();
                    System.Threading.Thread.Sleep(1);
                    int        num2 = editParameters.fidList[i];
                    IRowBuffer row2 = featureClass2.GetRow(num2);
                    if (row2 != null)
                    {
                        string value = base.UpdateRowBuffer(ref row2, editParameters.colName, editParameters.regexDataList);
                        rowBufferCollection.Add(row2);
                        rowBufferCollection2.Add(row2);
                        dictionary[num2] = value;
                        num++;
                        string userState2       = string.Format(StringParser.Parse("${res:feature_progress_finished}"), num, nTotalCount);
                        int    percentProgress2 = num * 100 / nTotalCount;
                        this._bgWorker.ReportProgress(percentProgress2, userState2);
                    }
                }
                if (dictionary.Count > 0)
                {
                    CommonUtils.Instance().FdeUndoRedoManager.UpdateFeatures(featureClass2, rowBufferCollection2);
                    object[] args = new object[]
                    {
                        featureClassInfo,
                        editParameters.colName,
                        dictionary
                    };
                    //System.IAsyncResult asyncResult = MainFrmService.ResultSetPanel.BeginInvoke(this._updateSelection, args);
                    //MainFrmService.ResultSetPanel.EndInvoke(asyncResult);
                }
            }
            CommandManagerServices.Instance().CallCommand(cmd);
            app.Workbench.UpdateMenu();
        }
Beispiel #9
0
 private void UpdateGeometry(object param)
 {
     try
     {
         DF3DApplication app = DF3DApplication.Application;
         if (app == null || app.Current3DMapControl == null)
         {
             return;
         }
         EditParameters editParameters = (EditParameters)param;
         if (editParameters != null)
         {
             System.Collections.Generic.Dictionary <DF3DFeatureClass, IRowBufferCollection> geometryMap = editParameters.geometryMap;
             if (geometryMap != null)
             {
                 CommandManagerServices.Instance().StartCommand();
                 FDECommand cmd         = new FDECommand(false, true);
                 int        nTotalCount = editParameters.nTotalCount;
                 int        num         = 0;
                 foreach (DF3DFeatureClass current in geometryMap.Keys)
                 {
                     if (this._bgWorker.CancellationPending)
                     {
                         break;
                     }
                     IRowBufferCollection rowBufferCollection = geometryMap[current];
                     if (current.GetFeatureClass().HasTemporal() && CommonUtils.Instance().EnableTemproalEdit)
                     {
                         IConnectionInfo connectionInfo = new ConnectionInfoClass();
                         connectionInfo.FromConnectionString(current.GetFeatureClass().DataSource.ConnectionInfo.ToConnectionString());
                         IDataSource     dataSource     = ((IDataSourceFactory) new DataSourceFactoryClass()).OpenDataSource(connectionInfo);
                         IFeatureDataSet featureDataSet = dataSource.OpenFeatureDataset(CommonUtils.Instance().GetCurrentFeatureDataset().Name);
                         IFeatureClass   featureClass   = featureDataSet.OpenFeatureClass(current.GetFeatureClass().Name);
                         int             position       = featureClass.GetFields().IndexOf(featureClass.FidFieldName);
                         System.Collections.Generic.Dictionary <int, IRowBuffer> dictionary = new System.Collections.Generic.Dictionary <int, IRowBuffer>();
                         for (int i = 0; i < rowBufferCollection.Count; i++)
                         {
                             IRowBuffer rowBuffer = rowBufferCollection.Get(i);
                             int        key       = (int)rowBuffer.GetValue(position);
                             dictionary[key] = rowBuffer;
                         }
                         ITemporalManager temporalManager = featureClass.TemporalManager;
                         ITemporalCursor  temporalCursor  = temporalManager.Search(new TemporalFilterClass
                         {
                             IdsFilter = dictionary.Keys.ToArray <int>()
                         });
                         while (temporalCursor.MoveNext() && !this._bgWorker.CancellationPending)
                         {
                             this._manualResult.WaitOne();
                             System.Threading.Thread.Sleep(1);
                             num++;
                             string userState       = string.Format(StringParser.Parse("${res:feature_progress_finished}"), num, nTotalCount);
                             int    percentProgress = num * 100 / nTotalCount;
                             this._bgWorker.ReportProgress(percentProgress, userState);
                             bool flag      = false;
                             int  currentId = temporalCursor.CurrentId;
                             ITemporalInstanceCursor temporalInstances = temporalCursor.GetTemporalInstances(false);
                             TemporalInstance        temporalInstance;
                             while ((temporalInstance = temporalInstances.NextInstance()) != null)
                             {
                                 if (temporalInstance.StartDatetime == editParameters.TemproalTime)
                                 {
                                     flag = true;
                                     temporalInstances.Update(dictionary[currentId]);
                                     break;
                                 }
                             }
                             System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalInstances);
                             if (!flag)
                             {
                                 temporalCursor.Insert(editParameters.TemproalTime, dictionary[currentId]);
                             }
                         }
                         System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalCursor);
                         System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalManager);
                         System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
                         System.Runtime.InteropServices.Marshal.ReleaseComObject(featureDataSet);
                         System.Runtime.InteropServices.Marshal.ReleaseComObject(dataSource);
                     }
                     else
                     {
                         IFeatureClass featureClass2 = current.GetFeatureClass();
                         int           num2          = 0;
                         while (num2 < rowBufferCollection.Count && !this._bgWorker.CancellationPending)
                         {
                             this._manualResult.WaitOne();
                             System.Threading.Thread.Sleep(1);
                             num++;
                             string userState2       = string.Format(StringParser.Parse("${res:feature_progress_finished}"), num, nTotalCount);
                             int    percentProgress2 = num * 100 / nTotalCount;
                             this._bgWorker.ReportProgress(percentProgress2, userState2);
                             num2++;
                         }
                         CommonUtils.Instance().FdeUndoRedoManager.UpdateFeatures(featureClass2, rowBufferCollection);
                     }
                 }
                 CommandManagerServices.Instance().CallCommand(cmd);
                 app.Workbench.UpdateMenu();
             }
         }
     }
     catch (System.Runtime.InteropServices.COMException ex)
     {
         XtraMessageBox.Show(ex.Message);
     }
     catch (System.UnauthorizedAccessException)
     {
         XtraMessageBox.Show(StringParser.Parse("${res:Dataset_InsufficientPermission}"));
     }
     catch (System.Exception e)
     {
         LoggingService.Error(e.Message);
     }
 }
Beispiel #10
0
        private void DeleteSelection(object param)
        {
            DF3DApplication app = DF3DApplication.Application;

            if (app == null || app.Current3DMapControl == null)
            {
                return;
            }
            EditParameters editParameters = (EditParameters)param;

            if (editParameters == null)
            {
                return;
            }
            CommandManagerServices.Instance().StartCommand();
            FDECommand cmd   = new FDECommand(false, true);
            int        count = SelectCollection.Instance().GetCount(false);
            int        num   = 0;

            foreach (DF3DFeatureClass featureClassInfo in SelectCollection.Instance().FeatureClassInfoMap.Keys)
            {
                if (this._bgWorker.CancellationPending)
                {
                    break;
                }
                ResultSetInfo resultSetInfo = SelectCollection.Instance().FeatureClassInfoMap[featureClassInfo] as ResultSetInfo;
                if (resultSetInfo != null)
                {
                    System.Collections.Generic.List <int> list = new System.Collections.Generic.List <int>();
                    if (featureClassInfo.GetFeatureClass().HasTemporal() && CommonUtils.Instance().EnableTemproalEdit)
                    {
                        IConnectionInfo connectionInfo = new ConnectionInfoClass();
                        connectionInfo.FromConnectionString(featureClassInfo.GetFeatureClass().DataSource.ConnectionInfo.ToConnectionString());
                        IDataSource     dataSource     = ((IDataSourceFactory) new DataSourceFactoryClass()).OpenDataSource(connectionInfo);
                        IFeatureDataSet featureDataSet = dataSource.OpenFeatureDataset(CommonUtils.Instance().GetCurrentFeatureDataset().Name);
                        IFeatureClass   featureClass   = featureDataSet.OpenFeatureClass(featureClassInfo.GetFeatureClass().Name);
                        foreach (DataRow dataRow in resultSetInfo.ResultSetTable.Rows)
                        {
                            int item = int.Parse(dataRow[featureClass.FidFieldName].ToString());
                            list.Add(item);
                        }
                        TemporalFilter temporalFilter = new TemporalFilterClass();
                        temporalFilter.AddSubField(featureClass.FidFieldName);
                        temporalFilter.IdsFilter = list.ToArray();
                        ITemporalManager temporalManager = featureClass.TemporalManager;
                        ITemporalCursor  temporalCursor  = temporalManager.Search(temporalFilter);
                        while (temporalCursor.MoveNext())
                        {
                            this._manualResult.WaitOne();
                            System.Threading.Thread.Sleep(1);
                            temporalCursor.Dead(editParameters.TemproalTime);
                            num++;
                            string userState       = string.Format(StringParser.Parse("${res:feature_progress_delete}"), num, count);
                            int    percentProgress = num * 100 / count;
                            this._bgWorker.ReportProgress(percentProgress, userState);
                        }
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalCursor);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalManager);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(featureDataSet);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(dataSource);
                    }
                    else
                    {
                        IFeatureClass featureClass2 = featureClassInfo.GetFeatureClass();
                        foreach (DataRow dataRow2 in resultSetInfo.ResultSetTable.Rows)
                        {
                            if (this._bgWorker.CancellationPending)
                            {
                                break;
                            }
                            this._manualResult.WaitOne();
                            System.Threading.Thread.Sleep(1);
                            int item2 = int.Parse(dataRow2[featureClass2.FidFieldName].ToString());
                            list.Add(item2);
                            num++;
                            string userState2       = string.Format(StringParser.Parse("${res:feature_progress_delete}"), num, count);
                            int    percentProgress2 = num * 100 / count;
                            this._bgWorker.ReportProgress(percentProgress2, userState2);
                        }
                        if (list.Count > 0)
                        {
                            CommonUtils.Instance().FdeUndoRedoManager.DeleteFeatures(featureClass2, list.ToArray());
                            list.Clear();
                        }
                    }
                }
            }
            CommandManagerServices.Instance().CallCommand(cmd);
            app.Workbench.UpdateMenu();
            //System.IAsyncResult asyncResult = MainFrmService.ResultSetPanel.BeginInvoke(this._clearSelection);
            //MainFrmService.ResultSetPanel.EndInvoke(asyncResult);
        }
Beispiel #11
0
        private void DeleteFeatures(object param)
        {
            DF3DApplication app = DF3DApplication.Application;

            if (app == null || app.Current3DMapControl == null)
            {
                return;
            }
            EditParameters   editParameters   = (EditParameters)param;
            string           featureClassGuid = editParameters.featureClassGuid;
            DF3DFeatureClass featureClassInfo = DF3DFeatureClassManager.Instance.GetFeatureClassByID(featureClassGuid);
            string           fcName           = editParameters.fcName;

            if (string.IsNullOrEmpty(fcName) || featureClassInfo == null)
            {
                return;
            }
            int nTotalCount = editParameters.nTotalCount;
            int num         = 0;

            CommandManagerServices.Instance().StartCommand();
            object[] args = null;
            if (featureClassInfo.GetFeatureClass().HasTemporal() && CommonUtils.Instance().EnableTemproalEdit)
            {
                IConnectionInfo connectionInfo = new ConnectionInfoClass();
                connectionInfo.FromConnectionString(featureClassInfo.GetFeatureClass().DataSource.ConnectionInfo.ToConnectionString());
                IDataSource     dataSource     = ((IDataSourceFactory) new DataSourceFactoryClass()).OpenDataSource(connectionInfo);
                IFeatureDataSet featureDataSet = dataSource.OpenFeatureDataset(CommonUtils.Instance().GetCurrentFeatureDataset().Name);
                IFeatureClass   featureClass   = featureDataSet.OpenFeatureClass(featureClassInfo.GetFeatureClass().Name);
                System.DateTime temproalTime   = editParameters.TemproalTime;
                TemporalFilter  temporalFilter = new TemporalFilterClass();
                temporalFilter.AddSubField(featureClass.FidFieldName);
                temporalFilter.IdsFilter = editParameters.fidList;
                ITemporalManager temporalManager = featureClass.TemporalManager;
                ITemporalCursor  temporalCursor  = temporalManager.Search(temporalFilter);
                while (temporalCursor.MoveNext())
                {
                    this._manualResult.WaitOne();
                    System.Threading.Thread.Sleep(1);
                    num++;
                    string userState       = string.Format(StringParser.Parse("${res:feature_progress_delete}"), num, nTotalCount);
                    int    percentProgress = num * 100 / nTotalCount;
                    this._bgWorker.ReportProgress(percentProgress, userState);
                    temporalCursor.Dead(temproalTime);
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalCursor);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalManager);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(featureDataSet);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(dataSource);
                args = new object[]
                {
                    featureClassInfo,
                    editParameters.fidList
                };
            }
            else
            {
                IFeatureClass featureClass2 = featureClassInfo.GetFeatureClass();
                FDECommand    cmd           = new FDECommand(false, true);
                System.Collections.Generic.List <int> list  = new System.Collections.Generic.List <int>();
                System.Collections.Generic.List <int> list2 = new System.Collections.Generic.List <int>();
                int[] fidList = editParameters.fidList;
                int   i       = 0;
                while (i < fidList.Length)
                {
                    int item = fidList[i];
                    if (this._bgWorker.CancellationPending)
                    {
                        if (list.Count > 0)
                        {
                            CommonUtils.Instance().Delete(featureClassInfo, list.ToArray());
                            list.Clear();
                            break;
                        }
                        break;
                    }
                    else
                    {
                        this._manualResult.WaitOne();
                        System.Threading.Thread.Sleep(1);
                        num++;
                        string userState2       = string.Format(StringParser.Parse("${res:feature_progress_delete}"), num, nTotalCount);
                        int    percentProgress2 = num * 100 / nTotalCount;
                        this._bgWorker.ReportProgress(percentProgress2, userState2);
                        list2.Add(item);
                        list.Add(item);
                        i++;
                    }
                }
                if (list.Count > 0)
                {
                    CommonUtils.Instance().FdeUndoRedoManager.DeleteFeatures(featureClass2, list.ToArray());
                    list.Clear();
                    CommandManagerServices.Instance().CallCommand(cmd);
                    app.Workbench.UpdateMenu();
                }
                args = new object[]
                {
                    featureClassInfo,
                    list2.ToArray()
                };
            }
            //System.IAsyncResult asyncResult = MainFrmService.ResultSetPanel.BeginInvoke(this._deleteSelection, args);
            //MainFrmService.ResultSetPanel.EndInvoke(asyncResult);
        }
Beispiel #12
0
        private void init()
        {
            // 设置RenderControl控件为球

            string tmpTedPath = (strMediaPath + @"\terrain\SingaporeGlobeTerrain.ted");

            wkt = this.axRenderControl1.GetTerrainCrsWKT(tmpTedPath, "");
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", "OpenGL");
            this.axRenderControl1.Initialize2(wkt, ps);
            this.axRenderControl1.Camera.FlyTime = 1;

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 注册地形
            this.axRenderControl1.Terrain.RegisterTerrain(tmpTedPath, "");
            this.axRenderControl1.Terrain.FlyTo(gviTerrainActionCode.gviFlyToTerrain);

            this.axRenderControl1.RcFrame += new Gvitech.CityMaker.Controls._IRenderControlEvents_RcFrameEventHandler(axRenderControl1_RcFrame);
            this.OnFrame = new _IRenderControlEvents_RcFrameEventHandler(OnFrameUpdateUI);

            #region 加载FDB场景
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                string[]        fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            //bool hasfly = false;
            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    if (!geoName.Equals("Geometry"))
                    {
                        continue;
                    }

                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                        fc, geoName, null, null, rootId);

                    //if (!hasfly)
                    //{
                    //    IFieldInfoCollection fieldinfos = fc.GetFields();
                    //    IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                    //    IGeometryDef geometryDef = fieldinfo.GeometryDef;
                    //    IEnvelope env = geometryDef.Envelope;
                    //    if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                    //        env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                    //        continue;
                    //    angle.Set(0, -20, 0);
                    //    point = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                    //    point.SpatialCRS = fc.FeatureDataSet.SpatialReference;
                    //    point.SetCoords(env.Center.X, env.Center.Y, env.Center.Z, 0, 0);
                    //    this.axRenderControl1.Camera.LookAt2(point, 500, angle);
                    //}
                    //hasfly = true;
                }
            }
            #endregion
        }
Beispiel #13
0
        private Dictionary <string, string> GetQueryResult(IFeatureClassInfo fcInfo, int featureId)
        {
            if (fcInfo == null || featureId < 0)
            {
                return(null);
            }
            IFdeCursor cursor = null;
            IRowBuffer row    = null;

            try
            {
                IDataSourceFactory dsf = new DataSourceFactory();
                if (!dsf.HasDataSourceByString(fcInfo.DataSourceConnectionString))
                {
                    return(null);
                }
                IDataSource ds = dsf.OpenDataSourceByString(fcInfo.DataSourceConnectionString);
                if (ds == null)
                {
                    return(null);
                }
                IFeatureDataSet fds = ds.OpenFeatureDataset(fcInfo.DataSetName);
                if (fds == null)
                {
                    return(null);
                }
                IFeatureClass fc = fds.OpenFeatureClass(fcInfo.FeatureClassName);
                if (fc == null)
                {
                    return(null);
                }
                IQueryFilter filter = new QueryFilter();
                filter.WhereClause = fc.FidFieldName + "=" + featureId;
                if (fc.GetCount(filter) == 0)
                {
                    return(null);
                }
                cursor = fc.Search(filter, false);
                if (cursor == null)
                {
                    return(null);
                }
                row = cursor.NextRow();
                if (row == null)
                {
                    return(null);
                }
                IFieldInfoCollection        fiCol = row.Fields;
                Dictionary <string, string> dict  = new Dictionary <string, string>();
                for (int i = 0; i < fiCol.Count; i++)
                {
                    IFieldInfo fi  = row.Fields.Get(i);
                    object     obj = row.GetValue(fiCol.IndexOf(fi.Name));
                    if (obj == null)
                    {
                        continue;
                    }
                    string str = "";
                    switch (fi.FieldType)
                    {
                    case gviFieldType.gviFieldBlob:
                    case gviFieldType.gviFieldUnknown:
                    case gviFieldType.gviFieldGeometry:
                        break;

                    case gviFieldType.gviFieldFloat:
                    case gviFieldType.gviFieldDouble:
                        double d;
                        if (double.TryParse(obj.ToString(), out d))
                        {
                            str = d.ToString("0.00");
                        }
                        break;

                    default:
                        str = obj.ToString();
                        break;
                    }
                    if (!string.IsNullOrEmpty(str.Trim()))
                    {
                        string temp = (string.IsNullOrEmpty(fi.Alias)) ? fi.Name : fi.Alias;
                        dict[temp] = str;
                    }
                }
                return(dict);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Beispiel #14
0
        private static List <Project> SelectProjects(IDataSource ds, string WhereClause)
        {
            List <Project> list   = new List <Project>();
            IFdeCursor     cursor = null;
            IRowBuffer     row    = null;

            try
            {
                if (ds == null)
                {
                    return(list);
                }
                IFeatureDataSet fds = ds.OpenFeatureDataset("UP_PlanLibDs_Indication");
                if (fds == null)
                {
                    return(list);
                }
                IFeatureClass class2 = fds.OpenFeatureClass("UP_Project");
                if (class2 != null)
                {
                    IQueryFilter filter = new QueryFilter
                    {
                        WhereClause = WhereClause
                    };
                    IFieldInfoCollection fiCol = class2.GetFields();
                    cursor = class2.Search(filter, true);
                    while ((row = cursor.NextRow()) != null)
                    {
                        Project item = new Project
                        {
                            ProjectID        = (row.IsNull(fiCol.IndexOf("oid"))) ? -1 : Convert.ToInt32(row.GetValue(fiCol.IndexOf("oid"))),
                            ProjectName      = (row.IsNull(fiCol.IndexOf("projectName"))) ? "" : row.GetValue(fiCol.IndexOf("projectName")).ToString(),
                            ProjectCode      = (row.IsNull(fiCol.IndexOf("projectCode"))) ? "" : row.GetValue(fiCol.IndexOf("projectCode")).ToString(),
                            ProjectType      = (row.IsNull(fiCol.IndexOf("projectType"))) ? ProjectType.None : (ProjectType)row.GetValue(fiCol.IndexOf("projectType")),
                            ChangeState      = (row.IsNull(fiCol.IndexOf("changeState"))) ? ProjectChangeState.None : (ProjectChangeState)Convert.ToInt32(row.GetValue(fiCol.IndexOf("changeState"))),
                            ProjectTime      = (row.IsNull(fiCol.IndexOf("projectTime"))) ? DateTime.MinValue : (DateTime)row.GetValue(fiCol.IndexOf("projectTime")),
                            ProjectOwner     = (row.IsNull(fiCol.IndexOf("projectOwner"))) ? "" : row.GetValue(fiCol.IndexOf("projectOwner")).ToString(),
                            Description      = (row.IsNull(fiCol.IndexOf("description"))) ? "" : row.GetValue(fiCol.IndexOf("description")).ToString(),
                            ProjectBound     = (row.IsNull(fiCol.IndexOf("projectBound"))) ? "" : row.GetValue(fiCol.IndexOf("projectBound")).ToString(),
                            ProjectLandUse   = (row.IsNull(fiCol.IndexOf("projectLandUse"))) ? null : (row.GetValue(fiCol.IndexOf("projectLandUse")) as IGeometry),
                            ProjectElevation = (row.IsNull(fiCol.IndexOf("projectElevation"))) ? double.NaN : Convert.ToDouble(row.GetValue(fiCol.IndexOf("projectElevation"))),
                            ProjectRemark1   = (row.IsNull(fiCol.IndexOf("projectRemark1"))) ? "" : row.GetValue(fiCol.IndexOf("projectRemark1")).ToString(),
                            ProjectLocation  = (row.IsNull(fiCol.IndexOf("projectRemark2"))) ? "" : row.GetValue(fiCol.IndexOf("projectRemark2")).ToString(),
                            ProjectQuo       = (row.IsNull(fiCol.IndexOf("projectQuo"))) ? null : (row.GetValue(fiCol.IndexOf("projectQuo")) as IBinaryBuffer)
                        };
                        list.Add(item);
                    }
                }
                return(list);
            }
            catch (Exception exception)
            {
            }
            finally
            {
                if (cursor != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                    cursor = null;
                }
                if (row != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(row);
                    row = null;
                }
            }
            return(list);
        }
Beispiel #15
0
        /// <summary>
        /// 在要素类里删除要素
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButtonDeleteFeature_Click(object sender, EventArgs e)
        {
            if (dsFactory == null)
            {
                dsFactory = new DataSourceFactory();
            }

            IDataSource     ds      = null;
            IFeatureDataSet dataset = null;
            IFeatureClass   fc      = null;

            try
            {
                if (dataGridView1.SelectedRows.Count > 0)
                {
                    if (MessageBox.Show("该操作无法恢复,请确定是否删除所选择的要素?", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                    {
                        ds      = dsFactory.OpenDataSource(Info.ci);
                        dataset = ds.OpenFeatureDataset(Info.datasetName);
                        fc      = dataset.OpenFeatureClass(Info.featureclassName);

                        int oid = int.Parse(dataGridView1.SelectedRows[0].Cells["oid"].Value.ToString());

                        // 从数据库中删除
                        IQueryFilter filter = new QueryFilter();
                        filter.WhereClause = "oid = " + oid;
                        int nRet = fc.Delete(filter);
                        MessageBox.Show("成功删除" + nRet + "条记录");

                        // 从界面DataTable中删除
                        int index = dataGridView1.SelectedRows[0].Index;
                        AttriTable.Rows.RemoveAt(index);
                        this.dataGridView1.Refresh();
                        if (index < dataGridView1.RowCount)
                        {
                            this.dataGridView1.Rows[index].Selected            = true;
                            this.dataGridView1.FirstDisplayedScrollingRowIndex = index;
                        }
                        else
                        {
                            this.dataGridView1.Rows[dataGridView1.RowCount - 1].Selected = true;
                            this.dataGridView1.FirstDisplayedScrollingRowIndex           = dataGridView1.RowCount - 1;
                        }


                        // 更新表头文字
                        if (FilterWhereClause.Equals(""))
                        {
                            this.Text = "Attributes of " + Info.featureclassName + "  [Total records: " + fc.GetCount(null).ToString() + "]";
                        }
                        else
                        {
                            this.Text = "Attributes of " + Info.featureclassName + "  [Total records: " + AttriTable.Rows.Count.ToString() + "]" + "  Filter: " + FilterWhereClause;
                        }
                    }
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
                if (dataset != null)
                {
                    //Marshal.ReleaseComObject(dataset);
                    dataset = null;
                }
                if (fc != null)
                {
                    //Marshal.ReleaseComObject(fc);
                    fc = null;
                }
            }
        }
Beispiel #16
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);
            this.axRenderControl1.Camera.FlyTime = 1;

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            // 加载FDB场景
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\TemporalOldSummerPalace.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                string[]        fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);

                bool hasSetTime = false;
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);

                    if (!fc.Name.Equals("水系"))
                    {
                        ///* 准备数据时打开,执行完后注释掉
                        // 开启时态
                        //if (!fc.HasTemporal())
                        //{
                        //    fc.LockType = gviLockType.gviLockExclusiveSchema;
                        //    DateTime defaultBirthDatetime = new DateTime(2010, 1, 1);
                        //    fc.EnableTemporal(defaultBirthDatetime, "StartDate", "EndDate");
                        //    fc.LockType = gviLockType.gviLockSharedSchema;
                        //}

                        if (!hasSetTime)
                        {
                            ITemporalManager tm    = fc.TemporalManager;
                            DateTime[]       times = tm.GetKeyDatetimes();
                            for (int tt = 0; tt < times.Length; tt++)
                            {
                                double keytime = times[tt].ToOADate();
                                timelist.Add(keytime);
                            }

                            if (timelist.Count > 3)
                            {
                                this.trackBarTime.Minimum = (int)((double)timelist[0]);
                                this.trackBarTime.Maximum = (int)((double)timelist[timelist.Count - 1] - 1);
                            }
                            // 设置时间轴
                            this.trackBarTime.Value = this.trackBarTime.Minimum;

                            // 创建OverlayLabel
                            label      = this.axRenderControl1.ObjectManager.CreateOverlayLabel(rootId);
                            label.Text = "乾隆初期";
                            label.SetX(0, 0.5f, 0);
                            label.SetY(0, 0, 0.5f);
                            label.SetWidth(0, 1, 0);
                            label.SetHeight(0, 0, 1);
                            label.Alignment = gviPivotAlignment.gviPivotAlignTopLeft;
                            TextAttribute att = new TextAttribute();
                            att.Font        = "幼圆";
                            att.TextColor   = System.Drawing.Color.Red;
                            att.TextSize    = 25;
                            label.TextStyle = att;

                            hasSetTime = true;
                        }
                    }
                } //end of fc
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            bool hasfly = false;

            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                        fc, geoName, null, null, rootId);

                    if (!fc.Name.Equals("水系") && geoName.Equals("Geometry"))
                    {
                        featureLayer.EnableTemporal = true;
                        layers.Add(featureLayer);

                        //设置curLayer的时刻
                        if (featureLayer != null)
                        {
                            DateTime d = DateTime.FromOADate((double)this.trackBarTime.Value);
                            featureLayer.Time = d;
                        }
                    }

                    if (!hasfly)
                    {
                        IFieldInfoCollection fieldinfos  = fc.GetFields();
                        IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                        IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                        IEnvelope            env         = geometryDef.Envelope;
                        if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                            env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                        {
                            continue;
                        }
                        angle.Set(0, -40, 0);
                        this.axRenderControl1.Camera.LookAt(env.Center, 100, angle);
                    }
                    hasfly = true;
                }
            }

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "TemporalOldSummerPalace.html";
            }
        }
Beispiel #17
0
        private void cbGlobe_CheckedChanged(object sender, EventArgs e)
        {
            if (cbGlobe.Checked)
            {
                // 重置RenderControl控件置为球
                string tmpTedPath = (strMediaPath + @"\terrain\SingaporeGlobeTerrain.ted");
                string wkt        = this.axRenderControl1.GetTerrainCrsWKT(tmpTedPath, "");
                this.axRenderControl1.Reset2(wkt);

                // 注册地形
                this.axRenderControl1.Terrain.RegisterTerrain(tmpTedPath, "");
                //this.axRenderControl1.Terrain.FlyTo();

                cbUseEarthOrbitManipulator.Enabled = true;
            }
            else
            {
                // 重置RenderControl控件置为平面
                string tmpTedPath = (strMediaPath + @"\terrain\SingaporePlanarTerrain.ted");
                string wkt        = this.axRenderControl1.GetTerrainCrsWKT(tmpTedPath, "");
                this.axRenderControl1.Reset2(wkt);

                // 设置天空盒

                if (System.IO.Directory.Exists(strMediaPath))
                {
                    string  tmpSkyboxPath = strMediaPath + @"\skybox";
                    ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                    skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                    skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                    skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                    skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                    skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                    skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
                }
                else
                {
                    MessageBox.Show("请不要随意更改SDK目录名");
                    return;
                }

                // 注册地形
                this.axRenderControl1.Terrain.RegisterTerrain(tmpTedPath, "");
                //this.axRenderControl1.Terrain.FlyTo();

                cbUseEarthOrbitManipulator.Enabled = false;
            }

            #region 加载FDB场景
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                string[]        fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            bool hasfly = false;
            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    if (!geoName.Equals("Geometry"))
                    {
                        continue;
                    }

                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                        fc, geoName, null, null, rootId);

                    if (!hasfly)
                    {
                        IFieldInfoCollection fieldinfos  = fc.GetFields();
                        IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                        IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                        IEnvelope            env         = geometryDef.Envelope;
                        if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                            env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                        {
                            continue;
                        }
                        angle.Set(0, -20, 0);
                        point            = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                        point.SpatialCRS = fc.FeatureDataSet.SpatialReference;
                        point.SetCoords(env.Center.X, env.Center.Y, env.Center.Z, 0, 0);
                        this.axRenderControl1.Camera.LookAt2(point, 500, angle);
                    }
                    hasfly = true;
                }
            }
            #endregion
        }
Beispiel #18
0
        private IMultiPolygon GetMultiPolygonFromFile(string sFilePath)
        {
            IDataSource     dataSource     = null;
            IFeatureDataSet featureDataSet = null;
            IFeatureClass   featureClass   = null;
            IFdeCursor      fdeCursor      = null;
            IMultiPolygon   result;

            try
            {
                IConnectionInfo connectionInfo = new ConnectionInfoClass();
                connectionInfo.ConnectionType = gviConnectionType.gviConnectionShapeFile;
                connectionInfo.Database       = sFilePath;
                dataSource = ((IDataSourceFactory) new DataSourceFactoryClass()).OpenDataSource(connectionInfo);
                string[] featureDatasetNames = dataSource.GetFeatureDatasetNames();
                if (featureDatasetNames != null && featureDatasetNames.Length > 0)
                {
                    featureDataSet = dataSource.OpenFeatureDataset(featureDatasetNames[0]);
                    string[] namesByType = featureDataSet.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                    if (namesByType != null && namesByType.Length > 0)
                    {
                        featureClass = featureDataSet.OpenFeatureClass(namesByType[0]);
                        IFieldInfoCollection fields = featureClass.GetFields();
                        int num = -1;
                        gviGeometryColumnType gviGeometryColumnType = gviGeometryColumnType.gviGeometryColumnUnknown;
                        gviVertexAttribute    vertexAttribute       = gviVertexAttribute.gviVertexAttributeNone;
                        for (int i = 0; i < fields.Count; i++)
                        {
                            IFieldInfo fieldInfo = fields.Get(i);
                            if (fieldInfo.FieldType == gviFieldType.gviFieldGeometry && fieldInfo.GeometryDef != null)
                            {
                                num = i;
                                gviGeometryColumnType = fieldInfo.GeometryDef.GeometryColumnType;
                                vertexAttribute       = fieldInfo.GeometryDef.VertexAttribute;
                                break;
                            }
                        }
                        if (num == -1 || gviGeometryColumnType != gviGeometryColumnType.gviGeometryColumnPolygon)
                        {
                            XtraMessageBox.Show("应选择面状矢量数据!");
                            result = null;
                        }
                        else
                        {
                            IGeometryFactory geometryFactory = new GeometryFactoryClass();
                            IMultiPolygon    multiPolygon    = geometryFactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, vertexAttribute) as IMultiPolygon;
                            multiPolygon.SpatialCRS = featureDataSet.SpatialReference;
                            fdeCursor = featureClass.Search(null, true);
                            IRowBuffer rowBuffer;
                            while ((rowBuffer = fdeCursor.NextRow()) != null)
                            {
                                object value = rowBuffer.GetValue(num);
                                if (value != null && value is IGeometry)
                                {
                                    IGeometry geometry = value as IGeometry;
                                    if (geometry.GeometryType == gviGeometryType.gviGeometryPolygon)
                                    {
                                        multiPolygon.AddPolygon(geometry as IPolygon);
                                    }
                                    else
                                    {
                                        if (geometry.GeometryType == gviGeometryType.gviGeometryMultiPolygon)
                                        {
                                            IMultiPolygon multiPolygon2 = geometry as IMultiPolygon;
                                            for (int j = 0; j < multiPolygon2.GeometryCount; j++)
                                            {
                                                IPolygon polygon = multiPolygon2.GetPolygon(j);
                                                if (polygon != null)
                                                {
                                                    multiPolygon.AddPolygon(polygon);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (multiPolygon.GeometryCount < 1)
                            {
                                XtraMessageBox.Show("无可用范围数据!");
                                result = null;
                            }
                            else
                            {
                                result = multiPolygon;
                            }
                        }
                    }
                    else
                    {
                        XtraMessageBox.Show("打开shp文件失败!");
                        result = null;
                    }
                }
                else
                {
                    XtraMessageBox.Show("名称为空");
                    result = null;
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                XtraMessageBox.Show(ex.Message);
                result = null;
            }
            finally
            {
                if (dataSource != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(dataSource);
                    dataSource = null;
                }
                if (featureDataSet != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(featureDataSet);
                    featureDataSet = null;
                }
                if (featureClass != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
                    featureClass = null;
                }
                if (fdeCursor != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(fdeCursor);
                    fdeCursor = null;
                }
            }
            return(result);
        }
Beispiel #19
0
        // 公共方法
        void FeatureLayerVisualize(IConnectionInfo ci, bool needfly, string sourceName)
        {
            try
            {
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                string[]        fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    _featureClass = fc;
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            bool hasfly = !needfly;

            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                        fc, geoName, null, null, rootId);

                    IFieldInfoCollection fieldinfos  = fc.GetFields();
                    IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                    IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                    IEnvelope            env         = geometryDef.Envelope;
                    if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                        env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                    {
                        continue;
                    }

                    // 相机飞入
                    if (!hasfly)
                    {
                        IEulerAngle angle = new EulerAngle();
                        angle.Set(0, -20, 0);
                        this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle);
                    }
                    hasfly = true;
                }
            }
        }
Beispiel #20
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);
            this.axRenderControl1.Camera.FlyTime = 1;

            ICRSFactory crsfac = new CRSFactory();

            _currentCRS = (crsfac.CreateFromWKT(this.axRenderControl1.GetCurrentCrsWKT())) as ISpatialCRS;

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            this.axRenderControl1.Camera.FlyTime = 0;

            // 加载瓦片图层
            string       tilelayerString = (strMediaPath + @"\sdk.tdb");
            I3DTileLayer layer           = this.axRenderControl1.ObjectManager.Create3DTileLayer(tilelayerString, "", rootId);

            this.axRenderControl1.Camera.FlyToObject(layer.Guid, gviActionCode.gviActionFlyTo);
            // 添加节点到界面控件上
            myListNode item = new myListNode("tilelayer", TreeNodeType.NT_TiltedLAYER, layer);

            item.Checked = true;
            listView1.Items.Add(item);

            #region 加载FDB
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                _datasetCRS = dataset.SpatialReference;

                //遍历FeatureClass
                string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap    = new Hashtable(fcnames.Length);
                fcuidMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        if (geometryDef.GeometryColumnType == gviGeometryColumnType.gviGeometryColumnPolygon)
                        {
                            geoNames.Add(fieldinfo.Name);
                        }
                    }
                    fcMap.Add(fc, geoNames);
                    fcuidMap.Add(fc.Guid, fc);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }
            #endregion

            //CreateFeautureLayer for 矢量贴地
            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                if (geoNames.Count == 0)
                {
                    continue;
                }

                #region 定义几何物体渲染风格
                ICurveSymbol cs = new CurveSymbol();
                cs.Color = System.Drawing.Color.Empty;  //防止贴瓦片时出现绿色竖边
                IValueMapGeometryRender geoRender = new ValueMapGeometryRender();
                {
                    IRangeRenderRule rangeRule = new RangeRenderRule();
                    rangeRule.LookUpField = "oid";
                    rangeRule.MaxValue    = 1100;
                    rangeRule.MinValue    = 1000;
                    rangeRule.IncludeMin  = false;

                    ISurfaceSymbol geoSymbol = new SurfaceSymbol();
                    geoSymbol.Color          = System.Drawing.Color.Yellow;
                    geoSymbol.BoundarySymbol = cs;

                    IGeometryRenderScheme grs = new GeometryRenderScheme();
                    grs.AddRule(rangeRule);
                    grs.Symbol = geoSymbol;
                    geoRender.AddScheme(grs);
                }
                {
                    IRangeRenderRule rangeRule = new RangeRenderRule();
                    rangeRule.LookUpField = "oid";
                    rangeRule.MaxValue    = 1200;
                    rangeRule.MinValue    = 1100;
                    rangeRule.IncludeMin  = false;

                    ISurfaceSymbol geoSymbol = new SurfaceSymbol();
                    geoSymbol.Color          = System.Drawing.Color.Blue;
                    geoSymbol.BoundarySymbol = cs;

                    IGeometryRenderScheme grs = new GeometryRenderScheme();
                    grs.AddRule(rangeRule);
                    grs.Symbol = geoSymbol;
                    geoRender.AddScheme(grs);
                }
                {
                    IRangeRenderRule rangeRule = new RangeRenderRule();
                    rangeRule.LookUpField = "oid";
                    rangeRule.MaxValue    = 1300;
                    rangeRule.MinValue    = 1200;
                    rangeRule.IncludeMin  = false;

                    ISurfaceSymbol geoSymbol = new SurfaceSymbol();
                    geoSymbol.Color          = System.Drawing.Color.Green;
                    geoSymbol.BoundarySymbol = cs;

                    IGeometryRenderScheme grs = new GeometryRenderScheme();
                    grs.AddRule(rangeRule);
                    grs.Symbol = geoSymbol;
                    geoRender.AddScheme(grs);
                }
                {
                    IRangeRenderRule rangeRule = new RangeRenderRule();
                    rangeRule.LookUpField = "oid";
                    rangeRule.MaxValue    = 1400;
                    rangeRule.MinValue    = 1300;
                    rangeRule.IncludeMin  = false;

                    ISurfaceSymbol geoSymbol = new SurfaceSymbol();
                    geoSymbol.Color          = System.Drawing.Color.Goldenrod;
                    geoSymbol.BoundarySymbol = cs;

                    IGeometryRenderScheme grs = new GeometryRenderScheme();
                    grs.AddRule(rangeRule);
                    grs.Symbol = geoSymbol;
                    geoRender.AddScheme(grs);
                }
                {
                    ISurfaceSymbol geoSymbol = new SurfaceSymbol();
                    geoSymbol.Color          = System.Drawing.Color.Fuchsia;
                    geoSymbol.BoundarySymbol = cs;

                    IGeometryRenderScheme geoSchemeOther = new GeometryRenderScheme();
                    geoSchemeOther.Symbol = geoSymbol;
                    geoRender.AddScheme(geoSchemeOther);
                }
                #endregion
                geoRender.HeightStyle = gviHeightStyle.gviHeightOnEverything;

                IFeatureLayer fcLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoNames[0], null, geoRender, rootId);
                if (fcLayer != null)
                {
                    fcLayer.VisibleMask = gviViewportMask.gviViewNone;

                    // 添加节点到界面控件上
                    myListNode item2 = new myListNode(fc.Name + "_" + geoNames[0], TreeNodeType.NT_FeatureLayer, fcLayer);
                    item.Checked = false;
                    listView1.Items.Add(item2);
                }
                else
                {
                    MessageBox.Show("Create FeatureLayer Failed! " + this.axRenderControl1.GetLastError().ToString());
                }
            }

            // 注册事件
            this.axRenderControl1.RcMouseClickSelect += new Gvitech.CityMaker.Controls._IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect);


            //设置highlight可用
            this.axRenderControl1.HighlightHelper.VisibleMask = 1;



            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "TileHole.html";
            }
        }
Beispiel #21
0
        private void toolStripMenuItemFieldInfo_Click(object sender, EventArgs e)
        {
            string          fieldinfo_name = selectNode.Text;
            string          fc_name        = selectNode.Parent.Text;
            string          set_name       = selectNode.Parent.Parent.Text;
            myTreeNode      node           = (myTreeNode)selectNode.Parent.Parent.Parent;
            IConnectionInfo ci             = node.con;

            IDataSource          ds         = null;
            IFeatureDataSet      dataset    = null;
            IFeatureClass        fc         = null;
            IFieldInfoCollection fieldinfos = null;

            try
            {
                ds         = dsFactory.OpenDataSource(ci);
                dataset    = ds.OpenFeatureDataset(set_name);
                fc         = dataset.OpenFeatureClass(fc_name);
                fieldinfos = fc.GetFields();
                for (int i = 0; i < fieldinfos.Count; i++)
                {
                    IFieldInfo fieldinfo = fieldinfos.Get(i);
                    if (null == fieldinfo)
                    {
                        continue;
                    }
                    if (fieldinfo_name == fieldinfo.Name)
                    {
                        FieldInfoForm form = new FieldInfoForm(fieldinfo);
                        form.Show();
                    }
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
                if (dataset != null)
                {
                    //Marshal.ReleaseComObject(dataset);
                    dataset = null;
                }
                if (fc != null)
                {
                    //Marshal.ReleaseComObject(fc);
                    fc = null;
                }
                if (fieldinfos != null)
                {
                    //Marshal.ReleaseComObject(fieldinfos);
                    fieldinfos = null;
                }
            }
        }
Beispiel #22
0
        // 公共方法
        void FeatureLayerVisualize(IConnectionInfo ci, bool needfly, string sourceName,
                                   ITextRender textRender, IGeometryRender geoRender)
        {
            IDataSourceFactory dsFactory = null;
            IDataSource        ds        = null;
            IFeatureDataSet    dataset   = null;

            try
            {
                dsFactory = new DataSourceFactory();
                ds        = dsFactory.OpenDataSource(ci);
                string[] setnames = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                dataset = ds.OpenFeatureDataset(setnames[0]);
                crs     = dataset.SpatialReference;
                string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }

                // CreateFeautureLayer
                bool hasfly = !needfly;
                foreach (IFeatureClass fcInMap in fcMap.Keys)
                {
                    List <string> geoNames = (List <string>)fcMap[fcInMap];
                    foreach (string geoName in geoNames)
                    {
                        IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                            fcInMap, geoName, textRender, geoRender, rootId);

                        // 添加节点到界面控件上
                        object[]   registeredFields = GetRegisteredRenderIndexFields(fcInMap);
                        myListNode item             = new myListNode(string.Format("{0}_{1}_{2}", sourceName, fcInMap.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer, registeredFields);
                        item.Checked = true;
                        listView1.Items.Add(item);
                        layerFcMap.Add(featureLayer, fcInMap);

                        IFieldInfoCollection fieldinfos  = fcInMap.GetFields();
                        IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                        IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                        IEnvelope            env         = geometryDef.Envelope;
                        layerEnvelopeMap.Add(featureLayer, env);
                        if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                            env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                        {
                            continue;
                        }

                        // 相机飞入
                        if (!hasfly)
                        {
                            angle.Set(0, -20, 0);
                            IPoint pos = (new GeometryFactory()).CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                            pos.SpatialCRS = crs;
                            pos.Position   = env.Center;
                            this.axRenderControl1.Camera.LookAt2(pos, 1000, angle);
                        }
                        hasfly = true;
                    }
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }
            catch (System.Exception e)
            {
                System.Diagnostics.Trace.WriteLine(e.Message);
                return;
            }
            finally
            {
                if (ds != null)
                {
                    ds.Dispose();
                    ds = null;
                }
                if (dataset != null)
                {
                    dataset.Dispose();
                    dataset = null;
                }
                //if (fc != null)
                //{
                //    fc.Dispose();
                //    fc = null;
                //}
            }
        }
Beispiel #23
0
        // 公共方法
        private void bindDataToCatalogTree(IConnectionInfo ci)
        {
            try
            {
                if (dsFactory == null)
                {
                    dsFactory = new DataSourceFactory();
                }
                IDataSource ds = dsFactory.OpenDataSource(ci);

                myTreeNode sourceNode = null;
                if (ci.ConnectionType == gviConnectionType.gviConnectionMySql5x)
                {
                    sourceNode = new myTreeNode(ci.Database + "@" + ci.Server, ci);
                }
                else
                {
                    sourceNode = new myTreeNode(ci.Database, ci);
                }
                this.treeView1.Nodes.Add(sourceNode);

                // 获取dataset
                string[] setnames = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                foreach (string setname in setnames)
                {
                    IFeatureDataSet dataset = ds.OpenFeatureDataset(setname);

                    TreeNode setNode = new TreeNode(setname, 1, 1);
                    sourceNode.Nodes.Add(setNode);

                    // 获取featureclass
                    string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                    if (fcnames == null || fcnames.Length == 0)
                    {
                        continue;
                    }
                    foreach (string fcname in fcnames)
                    {
                        IFeatureClass fc = dataset.OpenFeatureClass(fcname);

                        TreeNode fcNode = new TreeNode(fcname, 2, 2);
                        fcNode.ContextMenuStrip = this.contextMenuStrip2;
                        setNode.Nodes.Add(fcNode);

                        // 获取属性字段
                        IFieldInfoCollection fieldinfos = fc.GetFields();
                        for (int i = 0; i < fieldinfos.Count; i++)
                        {
                            IFieldInfo fieldinfo = fieldinfos.Get(i);
                            if (null == fieldinfo)
                            {
                                continue;
                            }

                            TreeNode fieldinfoNode = new TreeNode(fieldinfo.Name);
                            fieldinfoNode.ContextMenuStrip = this.contextMenuStrip1;  // 绑定右键菜单
                            fcNode.Nodes.Add(fieldinfoNode);
                        }
                    }
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }
        }
Beispiel #24
0
        // 公共方法
        void FeatureLayerVisualize(IConnectionInfo ci, bool needfly, string sourceName,
                                   ITextRender textRender, IGeometryRender geoRender, LayerType type)
        {
            try
            {
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                string[]        fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcGeoMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    fcGuidMap.Add(fc.Guid, fc);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcGeoMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            bool hasfly = !needfly;

            foreach (IFeatureClass fc in fcGeoMap.Keys)
            {
                List <string> geoNames = (List <string>)fcGeoMap[fc];
                foreach (string geoName in geoNames)
                {
                    if (!geoName.Equals("Geometry"))
                    {
                        continue;
                    }

                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                        fc, geoName, textRender, geoRender, rootId);

                    // 添加节点到界面控件上
                    myListNode item = new myListNode(string.Format("{0}_{1}_{2}", sourceName, fc.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer, type);
                    item.Checked = true;
                    listView1.Items.Add(item);

                    IFieldInfoCollection fieldinfos  = fc.GetFields();
                    IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                    IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                    IEnvelope            env         = geometryDef.Envelope;
                    layerEnvelopeMap.Add(featureLayer, env);
                    if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                        env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                    {
                        continue;
                    }

                    // 相机飞入
                    if (!hasfly)
                    {
                        angle.Set(0, -20, 0);
                        this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle);
                    }
                    hasfly = true;
                }
            }
        }
Beispiel #25
0
        /// <summary>
        /// 添加数据源
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addDatasourceToolStripButton_Click(object sender, EventArgs e)
        {
            OpenDataSourceForm dsForm = new OpenDataSourceForm(false);

            if (dsForm.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            IConnectionInfo ci = new ConnectionInfo();

            switch (dsForm.ConnectionType)
            {
            case "gviConnectionMySql5x":
                ci.ConnectionType = gviConnectionType.gviConnectionMySql5x;
                break;

            case "gviConnectionFireBird2x":
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                break;

            case "gviConnectionSQLite3":
                ci.ConnectionType = gviConnectionType.gviConnectionSQLite3;
                break;
            }
            ci.Server   = dsForm.Server;
            ci.Port     = dsForm.Port;
            ci.Database = dsForm.Database;
            ci.UserName = dsForm.UserName;
            ci.Password = dsForm.Password;

            IDataSource     ds      = null;
            IFeatureDataSet dataset = null;
            IFeatureClass   fc      = null;

            try
            {
                if (dsFactory == null)
                {
                    dsFactory = new DataSourceFactory();
                }
                ds = dsFactory.OpenDataSource(ci);

                myTreeNode sourceNode = null;
                if (ci.ConnectionType == gviConnectionType.gviConnectionMySql5x)
                {
                    sourceNode = new myTreeNode(ci.Database + "@" + ci.Server, ci);
                }
                else
                {
                    sourceNode = new myTreeNode(ci.Database, ci);
                }
                sourceNode.ContextMenuStrip = this.contextMenuStrip1;
                this.treeView1.Nodes.Add(sourceNode);

                // 获取dataset
                string[] setnames = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                foreach (string setname in setnames)
                {
                    dataset = ds.OpenFeatureDataset(setname);

                    TreeNode setNode = new TreeNode(setname, 1, 1);
                    setNode.ContextMenuStrip = this.contextMenuStrip2;
                    sourceNode.Nodes.Add(setNode);

                    // 获取featureclass
                    string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                    if (fcnames == null || fcnames.Length == 0)
                    {
                        continue;
                    }
                    foreach (string fcname in fcnames)
                    {
                        fc = dataset.OpenFeatureClass(fcname);

                        TreeNode fcNode = new TreeNode(fcname, 2, 2);
                        fcNode.ContextMenuStrip = this.contextMenuStrip3;
                        setNode.Nodes.Add(fcNode);

                        // 获取属性字段
                        IFieldInfoCollection fieldinfos = fc.GetFields();
                        for (int i = 0; i < fieldinfos.Count; i++)
                        {
                            IFieldInfo fieldinfo = fieldinfos.Get(i);
                            if (null == fieldinfo)
                            {
                                continue;
                            }

                            TreeNode fieldinfoNode = new TreeNode(fieldinfo.Name);
                            fieldinfoNode.ContextMenuStrip = this.contextMenuStrip4;  // 绑定右键菜单
                            fcNode.Nodes.Add(fieldinfoNode);
                        }
                    }
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
                if (dataset != null)
                {
                    //Marshal.ReleaseComObject(dataset);
                    dataset = null;
                }
                if (fc != null)
                {
                    //Marshal.ReleaseComObject(fc);
                    fc = null;
                }
            }
        }
Beispiel #26
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);
            this.axRenderControl1.Camera.FlyTime = 1;

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            this.axRenderControl1.Camera.NearClipPlane = 0.1f;
            this.axRenderControl1.Camera.AutoClipPlane = false;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            // 加载FDB场景
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                dataset = ds.OpenFeatureDataset(setnames[0]);
                string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            //bool hasfly = false;
            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    if (!geoName.Equals("Geometry"))
                    {
                        continue;
                    }

                    this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, null, null, rootId);

                    //if (!hasfly)
                    //{
                    //    IFieldInfoCollection fieldinfos = fc.GetFields();
                    //    IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                    //    IGeometryDef geometryDef = fieldinfo.GeometryDef;
                    //    IEnvelope env = geometryDef.Envelope;
                    //    if (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                    //        env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)
                    //        continue;
                    //    IEulerAngle angle = new EulerAngle();
                    //    angle.Set(0, -20, 0);
                    //    this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle);
                    //}
                    //hasfly = true;
                }
            }

            geoFactory               = new GeometryFactory();
            positionPoint            = geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
            positionPoint.SpatialCRS = dataset.SpatialReference;

            // 加载仪表盘
            string modelNameBiaoPan = (strMediaPath + @"\osg\Dashboard\yibiaopan.osg");

            fdepoint_biaopan           = (IModelPoint)geoFactory.CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ);
            fdepoint_biaopan.ModelName = modelNameBiaoPan;
            fdepoint_biaopan.SetCoords(biaoPanX, biaoPanY, biaoPanZ, 0, 0);
            fdepoint_biaopan.SpatialCRS = dataset.SpatialReference;
            render_biaopan = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(fdepoint_biaopan, null, rootId);
            // 加载指针
            string modelNameZhiZhen = (strMediaPath + @"\osg\Dashboard\zhizhen.osg");

            fdepoint_ZhiZhen           = (IModelPoint)geoFactory.CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ);
            fdepoint_ZhiZhen.ModelName = modelNameZhiZhen;
            fdepoint_ZhiZhen.SetCoords(biaoPanX, biaoPanY, biaoPanZ + 0.01, 0, 0);
            fdepoint_ZhiZhen.SpatialCRS = dataset.SpatialReference;
            render_ZhiZhen = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(fdepoint_ZhiZhen, null, rootId);
            // 加载文字标签
            IVector3 positionLabel = new Vector3();

            positionLabel.Set(biaoPanX, biaoPanY, biaoPanZ + 0.1);
            positionPoint.Position = positionLabel;
            label          = this.axRenderControl1.ObjectManager.CreateLabel(rootId);
            label.Text     = "当前的压力值是:" + zhiZhenValue.ToString();
            label.Position = positionPoint;
            ITextSymbol   textSymbol    = new TextSymbol();
            TextAttribute textAttribute = new TextAttribute();

            textAttribute.TextColor      = System.Drawing.Color.Black;
            textAttribute.TextSize       = 30;
            textAttribute.Font           = "宋体";
            textSymbol.TextAttribute     = textAttribute;
            textSymbol.MaxVisualDistance = 3;
            label.TextSymbol             = textSymbol;
            // 飞入表盘
            IEulerAngle angle_camera = new EulerAngle();

            angle_camera.Set(0, -45, 0);
            this.axRenderControl1.Camera.LookAt2(positionPoint, 2, angle_camera);

            // 注册鼠标单击事件
            this.axRenderControl1.RcMouseClickSelect += new _IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect);


            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "DynamicBoard.html";
            }
        }
Beispiel #27
0
        private void deleteFieldToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string          fieldInfo_name = selectNode.Text;
            string          fc_name        = selectNode.Parent.Text;
            string          set_name       = selectNode.Parent.Parent.Text;
            myTreeNode      node           = (myTreeNode)selectNode.Parent.Parent.Parent;
            IConnectionInfo ci             = node.con;

            IDataSource     ds   = null;
            IFeatureDataSet dset = null;
            IFeatureClass   fc   = null;

            try
            {
                ds   = dsFactory.OpenDataSource(ci);
                dset = ds.OpenFeatureDataset(set_name);
                fc   = dset.OpenFeatureClass(fc_name);

                if (fieldInfo_name == "oid")
                {
                    MessageBox.Show("此字段不支持删除");
                    return;
                }

                if (MessageBox.Show("该操作无法恢复,请确定是否删除字段?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    fc.LockType = gviLockType.gviLockExclusiveSchema;
                    fc.DeleteField(fieldInfo_name);
                    fc.LockType = gviLockType.gviLockSharedSchema;

                    // 从树上删除节点
                    selectNode.Parent.Nodes.Remove(selectNode);
                    MessageBox.Show("删除成功");
                }
            }
            catch (COMException comEx)
            {
                System.Diagnostics.Trace.WriteLine(comEx.Message);
                MessageBox.Show("删除失败");
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                MessageBox.Show("删除失败");
            }
            finally
            {
                fc.LockType = gviLockType.gviLockSharedSchema;
                if (fc != null)
                {
                    //Marshal.ReleaseComObject(fc);
                    fc = null;
                }
                if (dset != null)
                {
                    //Marshal.ReleaseComObject(dset);
                    dset = null;
                }
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
            }
        }
Beispiel #28
0
        /// <summary>
        /// 在要素类里创建要素
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButtonInsertFeature_Click(object sender, EventArgs e)
        {
            if (dsFactory == null)
            {
                dsFactory = new DataSourceFactory();
            }

            IDataSource     ds      = null;
            IFeatureDataSet dataset = null;
            IFeatureClass   fc      = null;
            IFdeCursor      cursor  = null;

            try
            {
                ds      = dsFactory.OpenDataSource(Info.ci);
                dataset = ds.OpenFeatureDataset(Info.datasetName);
                fc      = dataset.OpenFeatureClass(Info.featureclassName);

                DataRow          dr  = AttriTable.NewRow();;
                RowBufferFactory rbf = new RowBufferFactory();
                IRowBuffer       rb  = rbf.CreateRowBuffer(fc.GetFields());

                // 构造待插入的数据:暂时用最后一行的数据进行插入
                int        lastOid = int.Parse(dataGridView1.Rows[AttriTable.Rows.Count - 1].Cells["oid"].Value.ToString());
                IRowBuffer lastRow = fc.GetRow(lastOid);
                for (int i = 0; i < fc.GetFields().Count; ++i)
                {
                    string strColName = fc.GetFields().Get(i).Name;
                    int    nPos       = rb.FieldIndex(strColName);
                    if (fc.GetFields().Get(i).Name != "oid")
                    {
                        rb.SetValue(nPos, lastRow.GetValue(nPos));   //插入字段值
                    }
                }
                // 构造界面显示数据
                for (int j = 0; j < AttriTable.Columns.Count; ++j)
                {
                    string strColName = AttriTable.Columns[j].ColumnName;
                    int    nPos       = rb.FieldIndex(strColName);
                    if (nPos != -1 && strColName != "oid")
                    {
                        if (lastRow.GetValue(nPos) != null)
                        {
                            dr[j] = lastRow.GetValue(nPos).ToString();
                        }
                    }

                    if ("GroupName" == strColName)
                    {
                        dr[j] = this.dataGridView1.Rows[AttriTable.Rows.Count - 1].Cells["GroupName"].Value.ToString();
                    }
                }

                // 往数据库中增加
                cursor = fc.Insert();
                cursor.InsertRow(rb);

                // 往界面DataTable上增加
                dr["oid"] = cursor.LastInsertId;  //获取插入后oid值在界面显示
                AttriTable.Rows.Add(dr);
                this.dataGridView1.Refresh();
                this.dataGridView1.Rows[AttriTable.Rows.Count - 1].Selected = true;
                this.dataGridView1.FirstDisplayedScrollingRowIndex          = AttriTable.Rows.Count - 1;
                MessageBox.Show("增加记录成功");

                // 更新表头文字
                if (FilterWhereClause.Equals(""))
                {
                    this.Text = "Attributes of " + Info.featureclassName + "  [Total records: " + fc.GetCount(null).ToString() + "]";
                }
                else
                {
                    this.Text = "Attributes of " + Info.featureclassName + "  [Total records: " + AttriTable.Rows.Count.ToString() + "]" + "  Filter: " + FilterWhereClause;
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
                if (dataset != null)
                {
                    //Marshal.ReleaseComObject(dataset);
                    dataset = null;
                }
                if (fc != null)
                {
                    //Marshal.ReleaseComObject(fc);
                    fc = null;
                }
                if (cursor != null)
                {
                    //Marshal.ReleaseComObject(cursor);
                    cursor = null;
                }
            }
        }
Beispiel #29
0
        /// <summary>
        /// 初始化
        /// </summary>
        private void init()
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(false, ps);

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;
            this.axRenderControl1.Camera.FlyTime = 1;

            currentEnvCRS = (new CRSFactory()).CreateFromWKT(this.axRenderControl1.GetCurrentCrsWKT()) as ISpatialCRS;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            #region 加载FDB场景
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\polyline.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                datasetCRS = dataset.SpatialReference;
                string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            bool hasfly = false;
            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    if (!geoName.Equals("Geometry"))
                    {
                        continue;
                    }

                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                        fc, geoName, null, null, rootId);

                    if (!hasfly)
                    {
                        IFieldInfoCollection fieldinfos  = fc.GetFields();
                        IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                        IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                        IEnvelope            env         = geometryDef.Envelope;
                        if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                            env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                        {
                            continue;
                        }
                        IEulerAngle angle = new EulerAngle();
                        angle.Set(0, -90, 0);
                        if (geoFactory == null)
                        {
                            geoFactory = new GeometryFactory();
                        }
                        IPoint pos = geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                        pos.SpatialCRS = datasetCRS;
                        pos.Position   = env.Center;
                        this.axRenderControl1.Camera.LookAt2(pos, 1000, angle);
                    }
                    hasfly = true;
                }
            }
            #endregion 加载FDB场景

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "SpatialQuery2.html";
            }

            this.btnFlyToSourcePoint.Enabled = false;
            this.btnFlyToTargetPoint.Enabled = false;
        }
Beispiel #30
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            this.axRenderControl1.Camera.FlyTime = 0;
            this.cbOrderPolicy.SelectedIndex     = 0;

            if (geoFac == null)
            {
                geoFac = new GeometryFactory();
            }

            #region 加载road FDB
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\Network.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                dataset_Road = ds.OpenFeatureDataset(setnames[0]);
                string[] fcnames = (string[])dataset_Road.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap_Road = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset_Road.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap_Road.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            bool hasfly = false;
            foreach (IFeatureClass fc in fcMap_Road.Keys)
            {
                List <string> geoNames = (List <string>)fcMap_Road[fc];
                foreach (string geoName in geoNames)
                {
                    if (!geoName.Equals("Geometry"))
                    {
                        continue;
                    }

                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                        fc, geoName, null, null, rootId);

                    if (!hasfly)
                    {
                        IFieldInfoCollection fieldinfos  = fc.GetFields();
                        IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                        IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                        IEnvelope            env         = geometryDef.Envelope;
                        if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                            env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                        {
                            continue;
                        }
                        IEulerAngle angle = new EulerAngle();
                        angle.Set(0, -20, 0);
                        this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle);
                    }
                    hasfly = true;
                }
            }

            Thread.Sleep(2000);

            // 加载网络
            try
            {
                dsManager = dataset_Road.GetNetworkManager();
                string[] networkDatasetNames = dsManager.GetNetworkNames();
                bool     hasNetworkDataset   = false;
                for (int i = 0; i < networkDatasetNames.Length; i++)
                {
                    if (networkDatasetNames[i] == "newNetworkDataset")
                    {
                        hasNetworkDataset = true;
                    }
                }

                if (!hasNetworkDataset)
                {
                    dsLoader             = dsManager.CreateNetworkLoader();
                    dsLoader.Name        = "newNetworkDataset";
                    dsLoader.XYTolerance = double.Parse(txtLoaderTolerance.Text);
                    edgeNS                        = new EdgeNetworkSource();
                    edgeNS.SourceName             = "road";
                    edgeNS.ConnectivityPolicy     = gviNetworkEdgeConnectivityPolicy.gviEndVertex;
                    edgeNS.GeoColumnName          = "Geometry";
                    edgeNS.ClassConnectivityGroup = 1;
                    dsLoader.AddSource(edgeNS);
                    INetworkAttribute attr = new NetworkAttribute();
                    attr.FieldType = gviFieldType.gviFieldDouble;
                    attr.Name      = "Length";
                    attr.UsageType = gviNetworkAttributeUsageType.gviUseAsCost;
                    INetworkFieldEvaluator fieldEvaluator = new NetworkFieldEvaluator();
                    fieldEvaluator.FieldName = "Geometry";
                    attr.SetEvaluator(edgeNS, gviEdgeDirection.gviAlongDigitized, fieldEvaluator);
                    attr.SetEvaluator(edgeNS, gviEdgeDirection.gviAgainstDigitized, fieldEvaluator);
                    dsLoader.AddNetworkAttribute(attr);
                    dsLoader.LoadNetwork();
                }
                network = dsManager.GetNetwork("newNetworkDataset");

                routeSolver = network.CreateRouteSolver();
                routeSolver.ImpedanceAttributeName  = "Length";
                routeSolver.LocationSearchTolerance = double.Parse(txtSearchTolerance.Text);
                ////Marshal.ReleaseComObject(dsManager);
                ////Marshal.ReleaseComObject(dsLoader);
                ////Marshal.ReleaseComObject(attr);
                ////Marshal.ReleaseComObject(edgeNS);
                ////Marshal.ReleaseComObject(fieldEvaluator);
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            #endregion

            #region 加载POI FDB
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\POI-1.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                string[]        fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap_POI = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap_POI.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            //解析配置文件
            string featurelayerName = "";
            IValueMapGeometryRender render_JingDian = new ValueMapGeometryRender();
            IValueMapGeometryRender render_MeiShi   = new ValueMapGeometryRender();
            IValueMapGeometryRender render_ZhuSu    = new ValueMapGeometryRender();
            IValueMapGeometryRender render_HuoDong  = new ValueMapGeometryRender();
            IValueMapGeometryRender render_GouWu    = new ValueMapGeometryRender();
            IValueMapGeometryRender render_ATM      = new ValueMapGeometryRender();
            IValueMapGeometryRender render_WC       = new ValueMapGeometryRender();

            string[] fn = Directory.GetFiles((strMediaPath + @"\xml\xml"));
            foreach (string str in fn)
            {
                IValueMapGeometryRender render = new ValueMapGeometryRender();
                try
                {
                    XmlDocument docReader = new XmlDocument();
                    docReader.Load(str);
                    if (docReader.SelectSingleNode("FeatureLayer") != null)
                    {
                        featurelayerName = docReader.SelectSingleNode("FeatureLayer").Attributes["Name"].Value;

                        XmlNode GeometryRenderNode = docReader.SelectSingleNode("FeatureLayer").ChildNodes[0];
                        switch (GeometryRenderNode.Attributes["HeightStyle"].Value)
                        {
                        case "gviHeightAbsolute":
                            render.HeightStyle = gviHeightStyle.gviHeightAbsolute;
                            break;

                        case "gviHeightOnTerrain":
                            render.HeightStyle = gviHeightStyle.gviHeightOnTerrain;
                            break;

                        case "gviHeightRelative":
                            render.HeightStyle = gviHeightStyle.gviHeightRelative;
                            break;
                        }
                        render.RenderGroupField = GeometryRenderNode.Attributes["GroupField"].Value;

                        XmlNodeList xnl = docReader.SelectSingleNode("FeatureLayer").ChildNodes[0].ChildNodes[0].ChildNodes;
                        if (xnl.Count > 0)
                        {
                            foreach (XmlNode RenderSchemeNode in xnl)
                            {
                                IGeometryRenderScheme renderScheme = new GeometryRenderScheme();

                                IUniqueValuesRenderRule uniqueRenderRule   = new UniqueValuesRenderRule();
                                IImagePointSymbol       imagePointSym      = new ImagePointSymbol();
                                XmlNodeList             renderSchemeChilds = RenderSchemeNode.ChildNodes;
                                if (renderSchemeChilds.Count > 0)
                                {
                                    XmlNode renderRuleNode = renderSchemeChilds.Item(0);
                                    uniqueRenderRule.LookUpField = renderRuleNode.Attributes["LookUpField"].Value;
                                    uniqueRenderRule.AddValue(renderRuleNode.Attributes["UniqueValue"].Value);

                                    XmlNode geometrySymbolNode = renderSchemeChilds.Item(1);
                                    imagePointSym.ImageName = geometrySymbolNode.Attributes["ImageName"].Value;
                                    //imagePointSym.Size = int.Parse(geometrySymbolNode.Attributes["Size"].Value);
                                    imagePointSym.Size      = 60;
                                    imagePointSym.Alignment = gviPivotAlignment.gviPivotAlignBottomCenter;
                                }
                                renderScheme.AddRule(uniqueRenderRule);
                                renderScheme.Symbol = imagePointSym;
                                render.AddScheme(renderScheme);
                            }
                        }

                        switch (featurelayerName)
                        {
                        case "景点347":
                            render_JingDian = render;
                            break;

                        case "ATM611":
                            render_ATM = render;
                            break;

                        case "购物67":
                            render_GouWu = render;
                            break;

                        case "活动927":
                            render_HuoDong = render;
                            break;

                        case "WC968":
                            render_WC = render;
                            break;

                        case "美食563":
                            render_MeiShi = render;
                            break;

                        case "住宿513":
                            render_ZhuSu = render;
                            break;
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(str + " 解析失败");
                    return;
                }
            }

            ISimpleTextRender textRender = new SimpleTextRender();
            textRender.Expression       = "$(Name)";
            textRender.DynamicPlacement = true;
            textRender.MinimizeOverlap  = true;
            ITextSymbol   textSymbol    = new TextSymbol();
            TextAttribute textAttribute = new TextAttribute();
            textAttribute.TextColor   = System.Drawing.Color.Blue;
            textAttribute.Font        = "微软雅黑";
            textSymbol.TextAttribute  = textAttribute;
            textSymbol.PivotAlignment = gviPivotAlignment.gviPivotAlignBottomCenter;
            textSymbol.VerticalOffset = 10;
            textRender.Symbol         = textSymbol;

            // CreateFeautureLayer
            foreach (IFeatureClass fc in fcMap_POI.Keys)
            {
                List <string> geoNames = (List <string>)fcMap_POI[fc];
                foreach (string geoName in geoNames)
                {
                    if (!geoName.Equals("Geometry"))
                    {
                        continue;
                    }

                    switch (fc.Name)
                    {
                    case "景点347":
                        this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, textRender, render_JingDian, rootId);
                        break;

                    case "ATM611":
                        this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, textRender, render_ATM, rootId);
                        break;

                    case "购物67":
                        this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, textRender, render_GouWu, rootId);
                        break;

                    case "活动927":
                        this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, textRender, render_HuoDong, rootId);
                        break;

                    case "WC968":
                        this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, textRender, render_WC, rootId);
                        break;

                    case "美食563":
                        this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, textRender, render_MeiShi, rootId);
                        break;

                    case "住宿513":
                        this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, textRender, render_ZhuSu, rootId);
                        break;
                    }
                }
            }
            #endregion

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "Network.html";
            }
        }