Exemplo n.º 1
0
        private bool CreateLCRecordOfFDS(IDataSource ds, String fdsname)
        {
            ITable     table  = null;
            IFdeCursor cursor = null;

            try
            {
                String lcguid = System.Guid.NewGuid().ToString();
                byte[] lcbuf  = CreateLogicTree("LogicTree", lcguid);

                if (!GetQueryResults(String.Format("groupid='{0}'", lcguid), "cm_logictree", ds))
                {
                    table  = ds.OpenTable("cm_logictree");
                    cursor = table.Insert();
                    RowBufferFactory rbf = new RowBufferFactory();
                    IRowBuffer       rb  = rbf.CreateRowBuffer(table.GetFields());
                    rb.SetValue(1, lcguid);  //groupid
                    rb.SetValue(2, fdsname); //name
                    rb.SetValue(3, fdsname); //founder
                    IBinaryBuffer bb = new BinaryBuffer();
                    bb.FromByteArray(lcbuf);
                    rb.SetValue(4, bb);   //content
                    cursor.InsertRow(rb);
                }
                table  = ds.OpenTable("cm_group");
                cursor = table.Insert();
                RowBufferFactory rbf1 = new RowBufferFactory();
                IRowBuffer       rb1  = rbf1.CreateRowBuffer(table.GetFields());
                rb1.SetValue(1, lcguid);  //groupuid
                rb1.SetValue(2, fdsname); //DataSet
                cursor.InsertRow(rb1);
                return(true);
            }
            catch (COMException comEx)
            {
                System.Diagnostics.Trace.WriteLine(comEx.Message);
                return(false);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return(false);
            }
            finally
            {
                if (cursor != null)
                {
                    //Marshal.ReleaseComObject(cursor);
                    cursor = null;
                }
                if (table != null)
                {
                    //Marshal.ReleaseComObject(table);
                    table = null;
                }
            }
        }
Exemplo n.º 2
0
        private bool UpdateFacClassReg(FacClassReg reg)
        {
            IFdeCursor cursor = null;
            IRowBuffer row    = null;

            try
            {
                IFeatureDataSet fds = this._dsPipe.OpenFeatureDataset("DataSet_BIZ");
                if (fds == null)
                {
                    return(false);
                }
                IObjectClass oc = fds.OpenObjectClass("OC_FacilityClass");
                if (oc == null)
                {
                    return(false);
                }

                IQueryFilter filter = new QueryFilter()
                {
                    WhereClause = string.Format("FacClassCode = '{0}'", reg.FacClassCode),
                    SubFields   = "oid,LocationType,TurnerStyle,FacilityType,Comment"
                };
                cursor = oc.Update(filter);
                row    = cursor.NextRow();
                if (row != null)
                {
                    row.SetValue(1, reg.LocationType.ToString());
                    row.SetValue(2, reg.TurnerStyle.ToString());
                    row.SetValue(3, reg.FacilityType.Name);
                    row.SetValue(4, reg.Comment);
                    cursor.UpdateRow(row);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
                if (cursor != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                    cursor = null;
                }
                if (row != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(row);
                    row = null;
                }
            }
        }
Exemplo n.º 3
0
        public void InsertFeatures(IObjectClass oc, IRowBufferCollection rows)
        {
            if (oc == null || rows == null || rows.Count == 0)
            {
                return;
            }
            IFdeCursor cursor = null;

            try
            {
                oc.FeatureDataSet.DataSource.StartEditing();
                cursor = oc.Insert();
                for (int i = 0; i < rows.Count; ++i)
                {
                    IRowBuffer row = rows.Get(i);
                    cursor.InsertRow(row);
                    int oid = cursor.LastInsertId;
                    row.SetValue(0, oid);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                if (cursor != null)
                {
                    //Marshal.ReleaseComObject(cursor);
                    oc.FeatureDataSet.DataSource.StopEditing(true);
                }
                //Marshal.ReleaseComObject(cursor);
            }
        }
Exemplo n.º 4
0
 private void SetGeometry(IGeometry geo)
 {
     if (geo == null)
     {
         return;
     }
     if (this.beforeRowBufferMap != null)
     {
         foreach (DF3DFeatureClass featureClassInfo in this.beforeRowBufferMap.Keys)
         {
             string facName = featureClassInfo.GetFacilityClassName();
             IRowBufferCollection rowBufferCollection = this.beforeRowBufferMap[featureClassInfo] as IRowBufferCollection;
             object arg_51_0 = SelectCollection.Instance().FeatureClassInfoMap[featureClassInfo];
             for (int i = 0; i < rowBufferCollection.Count; i++)
             {
                 IRowBuffer rowBuffer = rowBufferCollection.Get(i);
                 if (rowBuffer != null)
                 {
                     #region 管线设施
                     if (facName == "PipeLine" || facName == "PipeBuild" || facName == "PipeBuild1")
                     {
                         int num3 = rowBuffer.FieldIndex("Shape");
                         if (num3 != -1)
                         {
                             rowBuffer.SetValue(num3, geo);
                         }
                         int num4 = rowBuffer.FieldIndex("FootPrint");
                         if (num4 != -1)
                         {
                             rowBuffer.SetValue(num4, geo.Clone2(gviVertexAttribute.gviVertexAttributeNone));
                         }
                     }
                     #endregion
                     else
                     {
                         int num2 = rowBuffer.FieldIndex(featureClassInfo.GetFeatureLayer().GeometryFieldName);
                         if (num2 != -1)
                         {
                             rowBuffer.SetValue(num2, geo);
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
 private void btn_Save_Click(object sender, EventArgs e)
 {
     try
     {
         IRowBuffer myRowBuffer = this.dgv_FieldValue.Tag as IRowBuffer;
         for (int i = 0; i < this.dgv_FieldValue.Rows.Count; i++)
         {
             DataGridViewRow myViewRow = this.dgv_FieldValue.Rows[i];
             if (myViewRow.Tag == null)
             {
                 continue;
             }
             EditField editfield = myViewRow.Tag as EditField;
             if (myViewRow.Cells["fieldvalue"].Value == null || string.IsNullOrEmpty(myViewRow.Cells["fieldvalue"].Value.ToString()))
             {
                 if (editfield.fieldInfo.Nullable)
                 {
                     myRowBuffer.SetNull(editfield.fieldIndex);
                 }
             }
             else
             {
                 IDomain dm = editfield.fieldInfo.Domain;
                 if (dm == null || dm.DomainType == gviDomainType.gviDomainRange)
                 {
                     myRowBuffer.SetValue(editfield.fieldIndex, myViewRow.Cells["fieldvalue"].Value);
                 }
                 else
                 {
                     myRowBuffer.SetValue(editfield.fieldIndex, this.GetDomainNameValuePair(dm)[myViewRow.Cells["fieldvalue"].Value.ToString()]);
                 }
             }
         }
         fc.Store(myRowBuffer);
         MessageBox.Show("保存编辑成功!");
         (this.Owner as MainForm).UnhighlightRcFeature(fc, fid);
         this.Close();
     }
     catch
     {
         MessageBox.Show("保存编辑失败!");
     }
 }
Exemplo n.º 6
0
        void axRenderControl1_RcMouseClickSelect_CreateFeature(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender)
        {
            _geoEditor.FinishEdit();   //用于当拾取到基准面时,或者没有正常右键结束连续调用Start时
            this.axRenderControl1.FeatureManager.UnhighlightAll();

            if (PickResult != null)
            {
                switch (PickResult.Type)
                {
                case gviObjectType.gviObjectFeatureLayer:
                {
                    IFeatureLayerPickResult flpr = PickResult as IFeatureLayerPickResult;
                    int fid = flpr.FeatureId;
                    //加载多FeatureClass时要每次重新获取
                    _featureClass = (IFeatureClass)fcGUIDMap[flpr.FeatureLayer.FeatureClassId];
                    _featureLayer = flpr.FeatureLayer;

                    IFdeCursor cursor = null;
                    try
                    {
                        _buffer = _featureClass.CreateRowBuffer();
                        IQueryFilter filter = new QueryFilter();
                        //filter.AddSubField("oid");  //注意:StartEditFeatureGeometry里必须传入一个完整的rowbuffer,所以这里不能限定字段
                        filter.WhereClause = "oid =" + fid;
                        cursor             = _featureClass.Search(filter, false);
                        IRowBuffer row = null;

                        if ((row = cursor.NextRow()) != null)
                        {
                            _buffer = row as IRowBuffer;
                            int pos = _buffer.FieldIndex("Geometry");
                            oldfdeGeometry = _buffer.GetValue(pos) as IGeometry;
                            _buffer.SetValue(0, _featureClass.GetCount(null));          //修改fid为不同值,否则不是创建而是编辑
                        }
                    }
                    catch (COMException ex)
                    {
                        System.Diagnostics.Trace.WriteLine(ex.Message);
                    }
                    finally
                    {
                    }

                    this.axRenderControl1.FeatureManager.HighlightFeature(_featureClass, fid, System.Drawing.Color.Yellow);

                    resultCode = _geoEditor.StartEditFeatureGeometry(_buffer, _featureLayer, gviGeoEditType.gviGeoEditCreator);
                    if (!resultCode)
                    {
                        MessageBox.Show(this.axRenderControl1.GetLastError().ToString());
                    }
                }
                break;
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// 传入Json设置属性值
 /// </summary>
 /// <param name="name"></param>
 /// <param name="value"></param>
 public static void SetValues(this IRowBuffer buffer, string json)
 {
     if (!string.IsNullOrWhiteSpace(json))
     {
         JObject attrs = JObject.Parse(json);
         foreach (var pair in attrs)
         {
             buffer.SetValue(pair.Key, pair.Value);
         }
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// 传入另一个对象设置属性值
 /// </summary>
 /// <param name="zRowBuffer"></param>
 public static void _SetValues(this IRowBuffer buffer, IRowBuffer otherBuffer)
 {
     for (int i = 0; i < buffer.Fields.FieldCount; i++)
     {
         if (buffer.Fields.Field[i].Editable)
         {
             string name = buffer.Fields.Field[i].Name;
             object obj  = otherBuffer.GetValue(name);
             buffer.SetValue(name, obj);
         }
     }
 }
Exemplo n.º 9
0
        public bool InsertRow(IDataSource ds, string tname, object[] values)
        {
            ITable           table            = ds.OpenTable(tname);
            IFdeCursor       fdeCursor        = table.Insert();
            RowBufferFactory rowBufferFactory = new RowBufferFactoryClass();
            IRowBuffer       rowBuffer        = rowBufferFactory.CreateRowBuffer(table.GetFields());

            for (int i = 1; i <= values.Length; i++)
            {
                rowBuffer.SetValue(i, values[i]);
            }
            fdeCursor.InsertRow(rowBuffer);
            return(true);
        }
Exemplo n.º 10
0
        private void tsb_Update_Click(object sender, EventArgs e)
        {
            this.cmdManager.StartCommand();

            //获取当前选中要素,将其放大一倍,作为新的行进行更新
            IRowBuffer row = curSelectFc.GetRow(curSelectFid);
            int geoPos = curSelectFc.GetFields().IndexOf("Geometry");
            if (geoPos != -1)
            {
                IModelPoint geo = row.GetValue(geoPos) as IModelPoint;
                geo.SelfScale(2, 2, 2);
                row.SetValue(geoPos, geo);
            }

            this.cmdManager.UpdateFeature(curSelectFc as IObjectClass, row);
            this.axRenderControl1.FeatureManager.EditFeature(curSelectFc, row);

            this.tsb_Redo.Enabled = this.cmdManager.CanRedo;
            this.tsb_Undo.Enabled = this.cmdManager.CanUndo;
            this.tsb_Update.Enabled = false;
        }
Exemplo n.º 11
0
        private void tsb_Insert_Click(object sender, EventArgs e)
        {
            this.cmdManager.StartCommand();

            //克隆当前选中要素,将z值提高10米,作为新的行进行插入
            IRowBuffer row = curSelectFc.GetRow(curSelectFid).Clone(false);
            int geoPos = curSelectFc.GetFields().IndexOf("Geometry");
            if (geoPos != -1)
            {
                IModelPoint geo = row.GetValue(geoPos) as IModelPoint;
                geo.Z = geo.Z + 10;
                row.SetValue(geoPos, geo);
            }
            row.SetNull(0);

            this.cmdManager.InsertFeature(curSelectFc as IObjectClass, row);
            this.axRenderControl1.FeatureManager.CreateFeature(curSelectFc, row);

            this.tsb_Redo.Enabled = this.cmdManager.CanRedo;
            this.tsb_Undo.Enabled = this.cmdManager.CanUndo;
            this.tsb_Insert.Enabled = false;
        }
Exemplo n.º 12
0
        /// <summary>
        /// 设置属性值
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        public static void SetValue(this IRowBuffer buffer, string name, object value)
        {
            int index = buffer.Fields.FindField(name);

            buffer.SetValue(index, value);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 通过json设置属性
        /// </summary>
        /// <param name="attributes"></param>
        public static void _SetAttrByJson(this IRowBuffer buffer, int index, JToken token)
        {
            object value = buffer.Fields.Field[index].Convert(token);

            buffer.SetValue(index, value);
        }
Exemplo n.º 14
0
        private void AddGeometry()
        {
            try
            {
                this.beforeRowBufferMap.Clear();
                SelectCollection.Instance().Clear();
                DF3DFeatureClass featureClassInfo = CommonUtils.Instance().CurEditLayer;
                if (featureClassInfo == null)
                {
                    return;
                }
                IFeatureClass fc = featureClassInfo.GetFeatureClass();
                if (fc == null)
                {
                    return;
                }
                IFieldInfoCollection fields = fc.GetFields();
                int indexGeo = fields.IndexOf(this._strGeometryFieldName);
                if (indexGeo == -1)
                {
                    return;
                }

                IGeometry geo    = this._drawTool.GetGeo();
                IGeometry geoOut = null;
                switch (geo.GeometryType)
                {
                case gviGeometryType.gviGeometryModelPoint:
                    geoOut = geo;
                    break;

                case gviGeometryType.gviGeometryPoint:
                    IPoint pt  = geo as IPoint;
                    IPoint pt1 = pt.Clone2(gviVertexAttribute.gviVertexAttributeZM) as IPoint;
                    pt1.SetCoords(pt.X, pt.Y, pt.Z, 0, 0);
                    geoOut = pt1;
                    break;

                case gviGeometryType.gviGeometryPolyline:
                    IPolyline line  = geo as IPolyline;
                    IPolyline line1 = this._geoFact.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZM) as IPolyline;
                    for (int i = 0; i < line.PointCount; i++)
                    {
                        IPoint ptGet  = line.GetPoint(i);
                        IPoint pttemp = ptGet.Clone2(gviVertexAttribute.gviVertexAttributeZM) as IPoint;
                        pttemp.SetCoords(ptGet.X, ptGet.Y, ptGet.Z, 0, 0);
                        line1.AppendPoint(pttemp);
                    }
                    geoOut = line1;
                    break;

                case gviGeometryType.gviGeometryPolygon:
                    IPolygon polygon  = geo as IPolygon;
                    IPolygon polygon1 = this._geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZM) as IPolygon;
                    for (int i = 0; i < polygon.ExteriorRing.PointCount; i++)
                    {
                        IPoint ptGet  = polygon.ExteriorRing.GetPoint(i);
                        IPoint pttemp = ptGet.Clone2(gviVertexAttribute.gviVertexAttributeZM) as IPoint;
                        pttemp.SetCoords(ptGet.X, ptGet.Y, ptGet.Z, 0, 0);
                        polygon1.ExteriorRing.AppendPoint(pttemp);
                    }
                    geoOut = polygon1;
                    break;
                }
                if (geoOut == null)
                {
                    return;
                }
                if (geo.GeometryType == gviGeometryType.gviGeometryModelPoint)
                {
                    //导入模型到数据库中
                    string      mn   = BitConverter.ToString(ObjectIdGenerator.Generate()).Replace("-", string.Empty).ToLowerInvariant();
                    IModelPoint mp   = geoOut as IModelPoint;
                    bool        bRes = this.ImportOsg(mn, mp.ModelName);
                    if (!bRes)
                    {
                        return;
                    }
                    mp.ModelName = mn;
                    geoOut       = mp;
                }
                IRowBufferCollection rowCol = new RowBufferCollection();
                IRowBufferFactory    fac    = new RowBufferFactory();
                IRowBuffer           row    = fac.CreateRowBuffer(fields);
                row.SetValue(indexGeo, geoOut);
                rowCol.Add(row);
                beforeRowBufferMap[featureClassInfo] = rowCol;
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 15
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;
                }
            }
        }
Exemplo n.º 16
0
        public override void Run(object sender, System.EventArgs e)
        {
            DF3DApplication app = DF3DApplication.Application;

            if (app == null || app.Current3DMapControl == null)
            {
                return;
            }
            try
            {
                Map3DCommandManager.Push(this);
                RenderControlEditServices.Instance().StopGeometryEdit(true);
                app.Current3DMapControl.PauseRendering(false);
                System.Collections.Generic.IList <System.Collections.Generic.KeyValuePair <int, string> > list = new System.Collections.Generic.List <System.Collections.Generic.KeyValuePair <int, string> >();
                HashMap          featureClassInfoMap              = SelectCollection.Instance().FeatureClassInfoMap;
                DF3DFeatureClass featureClassInfo                 = null;
                System.Collections.Generic.IList <int> list2      = new System.Collections.Generic.List <int>();
                System.Collections.IEnumerator         enumerator = featureClassInfoMap.Keys.GetEnumerator();
                try
                {
                    if (enumerator.MoveNext())
                    {
                        DF3DFeatureClass featureClassInfo2 = (DF3DFeatureClass)enumerator.Current;
                        featureClassInfo = featureClassInfo2;
                        ResultSetInfo resultSetInfo = featureClassInfoMap[featureClassInfo2] as ResultSetInfo;
                        foreach (DataRow dataRow in resultSetInfo.ResultSetTable.Rows)
                        {
                            int    num   = int.Parse(dataRow[featureClassInfo.GetFeatureClass().FidFieldName].ToString());
                            string value = num.ToString();
                            System.Collections.Generic.KeyValuePair <int, string> item = new System.Collections.Generic.KeyValuePair <int, string>(num, value);
                            list.Add(item);
                            list2.Add(num);
                        }
                    }
                }
                finally
                {
                    System.IDisposable disposable = enumerator as System.IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
                if (featureClassInfo != null)
                {
                    using (MergeDlg mergeDlg = new MergeDlg(list))
                    {
                        if (mergeDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            if (System.Windows.Forms.DialogResult.No != XtraMessageBox.Show("模型合并不支持撤销操作,是否继续?", "提示", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Exclamation))
                            {
                                int fid = mergeDlg.Fid;
                                using (new WaitDialogForm("", "正在进行模型合并,请稍后..."))
                                {
                                    IFeatureClass    featureClass      = featureClassInfo.GetFeatureClass();
                                    string           geometryFieldName = featureClassInfo.GetFeatureLayer().GeometryFieldName;
                                    IModelPoint      model             = this.GetModel(featureClass, geometryFieldName, fid);
                                    IResourceManager resourceManager   = CommonUtils.Instance().GetCurrentFeatureDataset() as IResourceManager;
                                    if (resourceManager != null)
                                    {
                                        if (!this.MergeModels(featureClass, geometryFieldName, list2.ToArray <int>(), resourceManager, ref model))
                                        {
                                            XtraMessageBox.Show("模型合并失败!");
                                        }
                                        else
                                        {
                                            if (list2.Remove(fid))
                                            {
                                                featureClass.Delete(new QueryFilterClass
                                                {
                                                    IdsFilter = list2.ToArray <int>()
                                                });
                                                CommonUtils.Instance().Delete(featureClassInfo, list2.ToArray <int>());
                                                app.Current3DMapControl.FeatureManager.DeleteFeatures(featureClass, list2.ToArray <int>());
                                            }
                                            app.Current3DMapControl.RefreshModel(CommonUtils.Instance().GetCurrentFeatureDataset(), model.ModelName);
                                            IFdeCursor fdeCursor = featureClass.Update(new QueryFilterClass
                                            {
                                                IdsFilter = new int[]
                                                {
                                                    fid
                                                }
                                            });
                                            IRowBuffer rowBuffer = fdeCursor.NextRow();
                                            if (rowBuffer != null)
                                            {
                                                int num2 = rowBuffer.FieldIndex(geometryFieldName);
                                                if (num2 != -1)
                                                {
                                                    rowBuffer.SetValue(num2, model);
                                                }
                                                fdeCursor.UpdateRow(rowBuffer);
                                                System.Runtime.InteropServices.Marshal.ReleaseComObject(fdeCursor);
                                                app.Current3DMapControl.FeatureManager.EditFeature(featureClass, rowBuffer);
                                            }
                                            //System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                XtraMessageBox.Show(ex.Message);
            }
            catch (System.UnauthorizedAccessException var_23_389)
            {
                XtraMessageBox.Show("拒绝访问");
            }
            catch (System.Exception ex2)
            {
                XtraMessageBox.Show(ex2.Message);
            }
            finally
            {
                app.Current3DMapControl.ResumeRendering();
            }
        }
Exemplo n.º 17
0
        private bool UpdateFacStyleClass(FacStyleClass style)
        {
            IFdeCursor cursor = null;
            IRowBuffer row    = null;

            try
            {
                IFeatureDataSet fds = this._ds.OpenFeatureDataset("DataSet_BIZ");
                if (fds == null)
                {
                    return(false);
                }
                IObjectClass oc = fds.OpenObjectClass("OC_FacilityStyle");
                if (oc == null)
                {
                    return(false);
                }

                IQueryFilter filter = new QueryFilter()
                {
                    WhereClause = string.Format("ObjectId = '{0}'", style.ObjectId)
                };
                cursor = oc.Update(filter);
                row    = cursor.NextRow();
                if (row != null)
                {
                    row.SetValue(row.FieldIndex("Name"), style.Name);
                    row.SetValue(row.FieldIndex("FacClassCode"), style.FacClassCode);
                    row.SetValue(row.FieldIndex("ObjectId"), style.ObjectId);
                    row.SetValue(row.FieldIndex("StyleType"), style.Type.ToString());
                    row.SetValue(row.FieldIndex("StyleInfo"), style.ObjectToJson());
                    if (style.Thumbnail != null)
                    {
                        try
                        {
                            IBinaryBuffer bb     = new BinaryBufferClass();
                            MemoryStream  stream = new MemoryStream();
                            style.Thumbnail.Save(stream, ImageFormat.Png);
                            bb.FromByteArray(stream.ToArray());
                            row.SetValue(row.FieldIndex("Thumbnail"), bb);
                        }
                        catch (Exception exception)
                        {
                        }
                    }
                    cursor.UpdateRow(row);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
                if (cursor != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                    cursor = null;
                }
                if (row != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(row);
                    row = null;
                }
            }
        }
Exemplo n.º 18
0
        private void AddRecord()
        {
            try
            {
                this.beforeRowBufferMap.Clear();
                SelectCollection.Instance().Clear();
                if (reg == null || tc == null)
                {
                    return;
                }
                FacStyleClass style = this.cmbStyle.EditValue as FacStyleClass;
                if (style == null)
                {
                    return;
                }
                SubClass sc = this.cmbClassify.EditValue as SubClass;

                DF3DFeatureClass featureClassInfo = CommonUtils.Instance().CurEditLayer;
                if (featureClassInfo == null)
                {
                    return;
                }
                IFeatureClass fc = featureClassInfo.GetFeatureClass();
                if (fc == null)
                {
                    return;
                }
                IResourceManager manager = fc.FeatureDataSet as IResourceManager;
                if (manager == null)
                {
                    return;
                }
                IFeatureLayer fl = featureClassInfo.GetFeatureLayer();
                if (fl == null)
                {
                    return;
                }
                IFieldInfoCollection fields = fc.GetFields();
                int indexOid = fields.IndexOf(fc.FidFieldName);
                if (indexOid == -1)
                {
                    return;
                }
                int mpindex = fields.IndexOf(fl.GeometryFieldName);
                if (mpindex == -1)
                {
                    return;
                }
                int indexShape = fields.IndexOf("Shape");
                if (indexShape == -1)
                {
                    return;
                }
                int indexFootPrint = fields.IndexOf("FootPrint");
                if (indexFootPrint == -1)
                {
                    return;
                }
                int indexStyleId = fields.IndexOf("StyleId");
                if (indexStyleId == -1)
                {
                    return;
                }
                int indexFacilityId = fields.IndexOf("FacilityId");
                if (indexFacilityId == -1)
                {
                    return;
                }

                IFieldInfo fiShape = fields.Get(indexShape);
                if (fiShape == null || fiShape.GeometryDef == null)
                {
                    return;
                }

                IGeometry geo = this._drawTool.GetGeo();
                if (geo.GeometryType != gviGeometryType.gviGeometryPoint)
                {
                    return;
                }
                IPoint pt     = geo as IPoint;
                IPoint geoOut = pt.Clone2(fiShape.GeometryDef.VertexAttribute) as IPoint;
                if (fiShape.GeometryDef.HasZ)
                {
                    geoOut.SetCoords(pt.X, pt.Y, pt.Z, 0, 0);
                }
                else
                {
                    geoOut.SetCoords(pt.X, pt.Y, 0, 0, 0);
                }

                IQueryFilter filter = new QueryFilter();
                filter.WhereClause      = "1=1";
                filter.ResultBeginIndex = 0;
                filter.ResultLimit      = 1;
                filter.PostfixClause    = "ORDER BY " + fc.FidFieldName + " desc";
                IFdeCursor cursor = null;
                cursor = fc.Search(filter, false);
                IRowBuffer rowtemp = cursor.NextRow();
                int        oid     = 0;
                if (rowtemp != null)
                {
                    oid = int.Parse(rowtemp.GetValue(indexOid).ToString());
                }
                if (cursor != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                    cursor = null;
                }

                IRowBufferFactory fac = new RowBufferFactory();
                IRowBuffer        row = fac.CreateRowBuffer(fields);
                row.SetValue(indexOid, oid + 1);
                row.SetValue(indexShape, geoOut);
                row.SetValue(indexFootPrint, geoOut.Clone2(gviVertexAttribute.gviVertexAttributeNone));
                row.SetValue(indexStyleId, style.ObjectId);
                row.SetValue(indexFacilityId, BitConverter.ToString(ObjectIdGenerator.Generate()).Replace("-", string.Empty).ToLowerInvariant());
                if (sc != null)
                {
                    int indexClassify = fields.IndexOf(this._classifyName);
                    int indexGroupId  = fields.IndexOf("GroupId");
                    if (indexClassify != -1 && indexGroupId != -1)
                    {
                        row.SetValue(indexClassify, sc.Name);
                        row.SetValue(indexGroupId, sc.GroupId);
                    }
                }
                foreach (DataRow dr in this._dt.Rows)
                {
                    IFieldInfo fi = dr["F"] as IFieldInfo;
                    if (fi == null)
                    {
                        continue;
                    }
                    string fn    = fi.Name;
                    int    index = fields.IndexOf(fn);
                    if (index != -1)
                    {
                        if (dr["FV"] == null)
                        {
                            row.SetNull(index);
                        }
                        else
                        {
                            string strobj = dr["FV"].ToString();
                            bool   bRes   = false;
                            switch (fi.FieldType)
                            {
                            case gviFieldType.gviFieldBlob:
                            case gviFieldType.gviFieldGeometry:
                            case gviFieldType.gviFieldUnknown:
                                break;

                            case gviFieldType.gviFieldFloat:
                                float f;
                                bRes = float.TryParse(strobj, out f);
                                if (bRes)
                                {
                                    row.SetValue(index, f);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            case gviFieldType.gviFieldDouble:
                                double d;
                                bRes = double.TryParse(strobj, out d);
                                if (bRes)
                                {
                                    row.SetValue(index, d);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            case gviFieldType.gviFieldFID:
                            case gviFieldType.gviFieldUUID:
                            case gviFieldType.gviFieldInt16:
                                Int16 i16;
                                bRes = Int16.TryParse(strobj, out i16);
                                if (bRes)
                                {
                                    row.SetValue(index, i16);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            case gviFieldType.gviFieldInt32:
                                Int32 i32;
                                bRes = Int32.TryParse(strobj, out i32);
                                if (bRes)
                                {
                                    row.SetValue(index, i32);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            case gviFieldType.gviFieldInt64:
                                Int64 i64;
                                bRes = Int64.TryParse(strobj, out i64);
                                if (bRes)
                                {
                                    row.SetValue(index, i64);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;;

                            case gviFieldType.gviFieldString:
                                row.SetValue(index, strobj);
                                break;

                            case gviFieldType.gviFieldDate:
                                DateTime dt;
                                bRes = DateTime.TryParse(strobj, out dt);
                                if (bRes)
                                {
                                    row.SetValue(index, dt);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
                Fac plf = new PipeNodeFac(reg, style, row, tc);

                IModelPoint mp          = null;
                IModel      finemodel   = null;
                IModel      simplemodel = null;
                string      name        = "";
                if (UCAuto3DCreate.RebuildModel(plf, style, out mp, out finemodel, out simplemodel, out name))
                {
                    if (finemodel == null || mp == null)
                    {
                        return;
                    }
                    mp.ModelEnvelope = finemodel.Envelope;
                    row.SetValue(mpindex, mp);
                    //if (mc != null)
                    //{
                    //    if (indexClassify != -1 && indexGroupid != -1)
                    //    {

                    //    }
                    //}
                    bool bRes = false;
                    if (!string.IsNullOrEmpty(mp.ModelName))
                    {
                        if (!manager.ModelExist(mp.ModelName))
                        {
                            if (manager.AddModel(mp.ModelName, finemodel, simplemodel))
                            {
                                bRes = true;
                            }
                        }
                        else
                        {
                            if (manager.UpdateModel(mp.ModelName, finemodel) && manager.UpdateSimplifiedModel(mp.ModelName, simplemodel))
                            {
                                bRes = true;
                            }
                        }
                    }
                    if (!bRes)
                    {
                        return;
                    }
                    IRowBufferCollection rowCol = new RowBufferCollection();
                    rowCol.Add(row);
                    beforeRowBufferMap[featureClassInfo] = rowCol;
                    UpdateDatabase();
                    app.Current3DMapControl.FeatureManager.RefreshFeatureClass(fc);
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 19
0
        public void ImportModelXml(IFeatureClass fc, string mdbFile, int groupId, int _nCount)
        {
            try
            {
                //2、获取基本信息
                FileInfo         fInfo       = new FileInfo(mdbFile);
                string           strFilePath = fInfo.DirectoryName;
                IResourceManager rm          = fc.FeatureDataSet as IResourceManager;
                Dictionary <string, IEnvelope> cacheModeInfos = new Dictionary <string, IEnvelope>();
                List <string> cacheImageNames = new List <string>();

                IGeometryFactory geoFactory = new GeometryFactory();
                IResourceFactory symbolFac  = new ResourceFactory();

                IRowBufferCollection fcRows = new RowBufferCollection();
                IRowBuffer           fcRow  = null;

                //4、解析xml
                string      strConn    = "" + mdbFile + "\'";
                int         index      = 0;
                int         totalCount = _nCount;
                IModelPoint modePoint  = null;
                for (int i = 0; i < _nCount; ++i)
                {
                    int    percent = ++index * 100 / totalCount;
                    string toolTip = string.Format("已完成{0}条/总共{1}条 {2}%", index, totalCount, percent);
                    CommonEntity.FormEntity.Text = toolTip;

                    //fc
                    fcRow = fc.CreateRowBuffer();
                    int nPose = fcRow.FieldIndex("name");
                    if (nPose == -1)
                    {
                        continue;
                    }
                    string modelName = _dataTable.Rows[i]["ModelName"].ToString();
                    fcRow.SetValue(nPose, modelName);

                    nPose = fcRow.FieldIndex("groupId");
                    if (nPose == -1)
                    {
                        continue;
                    }
                    fcRow.SetValue(nPose, groupId);

                    modePoint = (IModelPoint)geoFactory.CreateGeometry(
                        gviGeometryType.gviGeometryModelPoint,
                        gviVertexAttribute.gviVertexAttributeZ);
                    modePoint.ModelName = modelName;

                    double dModePointX = double.Parse(_dataTable.Rows[i]["LocationX"].ToString()) + 0;  // CoorX = 0
                    double dModePointY = double.Parse(_dataTable.Rows[i]["LocationY"].ToString()) + 0;  // CoorY = 0
                    double dModePointZ = double.Parse(_dataTable.Rows[i]["LocationZ"].ToString()) + 0;  // CoorZ = 0

                    string  strMatrix = _dataTable.Rows[i]["Matrix3"].ToString();
                    float[] Matrix    = null;
                    if (!string.IsNullOrEmpty(strMatrix))
                    {
                        string[] strArray = strMatrix.Split(',');
                        if (strArray.Length == 9)
                        {
                            Matrix    = new float[9];
                            Matrix[0] = float.Parse(strArray[0]);
                            Matrix[1] = float.Parse(strArray[1]);
                            Matrix[2] = float.Parse(strArray[2]);
                            Matrix[3] = float.Parse(strArray[3]);
                            Matrix[4] = float.Parse(strArray[4]);
                            Matrix[5] = float.Parse(strArray[5]);
                            Matrix[6] = float.Parse(strArray[6]);
                            Matrix[7] = float.Parse(strArray[7]);
                            Matrix[8] = float.Parse(strArray[8]);
                        }
                    }
                    modePoint.X        = dModePointX;
                    modePoint.Y        = dModePointY;
                    modePoint.Z        = dModePointZ;
                    modePoint.Matrix33 = Matrix;


                    //mc
                    IPropertySet Images = null;

                    //如果内存中不包含
                    if (!cacheModeInfos.Keys.Contains(modelName))
                    {
                        //数据库中包含
                        if (rm.ModelExist(modelName))
                        {
                            //重名即跳过
                            IEnvelope ev = rm.GetModel(modelName).Envelope;
                            modePoint.ModelEnvelope = ev;
                        }
                        else
                        {
                            IModel  simpleModel = null;
                            string  osgFilePath = strFilePath + "\\" + modelName + ".osg";
                            IModel  fineModel   = null;
                            IMatrix matrix      = null;
                            symbolFac.CreateModelAndImageFromFileEx(osgFilePath,
                                                                    out Images, out simpleModel, out fineModel, out matrix);
                            if (fineModel == null || fineModel.GroupCount == 0)
                            {
                                continue;
                            }

                            cacheModeInfos[modelName] = modePoint.ModelEnvelope = Clone(fineModel.Envelope);

                            rm.AddModel(modelName, fineModel, simpleModel);
                            //Marshal.ReleaseComObject(simpleModel);
                            //Marshal.ReleaseComObject(fineModel);
                        }
                    }
                    else
                    {
                        modePoint.ModelEnvelope = cacheModeInfos[modelName];
                    }

                    nPose = fcRow.FieldIndex("Geometry");
                    fcRow.SetValue(nPose, modePoint);
                    fcRows.Add(fcRow);

                    //tc
                    int nCount = Images.Count;
                    if (Images != null && nCount > 0)
                    {
                        Hashtable htImages = Images.AsHashtable();
                        foreach (DictionaryEntry item in htImages)
                        {
                            string imgName = item.Key.ToString();
                            IImage img     = item.Value as IImage;
                            if (img == null)
                            {
                                continue;
                            }
                            if (string.IsNullOrEmpty(imgName))
                            {
                                continue;
                            }

                            //如果内存中不包含
                            if (!cacheImageNames.Contains(imgName))
                            {
                                //数据库中包含
                                if (rm.ImageExist(imgName))
                                {
                                    //重名即跳过
                                }
                            }

                            //如果内存中不包含,数据库中也不包含
                            if (!rm.ImageExist(imgName) &&
                                !cacheImageNames.Contains(imgName))
                            {
                                cacheImageNames.Add(imgName);

                                rm.AddImage(imgName, img);
                            }
                        }
                    }
                    //end

                    if (fcRows.Count >= 10)
                    {
                        InsertFeatures(fc as IObjectClass, fcRows);
                        fcRows.Clear();
                    }
                }
                if (fcRows.Count > 0)
                {
                    InsertFeatures(fc as IObjectClass, fcRows);
                    fcRows.Clear();
                }
            }
            catch (System.Exception ex)
            {
                if (ex.GetType().Name.Equals("UnauthorizedAccessException"))
                {
                    MessageBox.Show("需要标准runtime授权");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Exemplo n.º 20
0
        private void btn_ok_Click(object sender, EventArgs e)
        {
            try
            {
                if (this._dt.Rows.Count == 0)
                {
                    return;
                }
                if (!this.ceConnectMajorClass.Checked && !this.ceConnectFacility.Checked)
                {
                    return;
                }
                WaitForm.Start("三维数据关联设置启动...", "请稍后", new Size(400, 50));
                CheckRowGroup();
                WaitForm.SetCaption("设施类关联设置进行中...");
                // 设置设施类
                HashSet <FacilityClass> listFac = _checkFacCList;
                if (listFac != null && this.ceConnectFacility.Checked)
                {
                    foreach (FacilityClass fac in listFac)
                    {
                        string strTemp = "";
                        foreach (DataRow dr in this._dt.Rows)
                        {
                            if (!(bool)dr["CheckState"])
                            {
                                continue;
                            }
                            IFeatureClass featureClass = dr["FeatureClass"] as IFeatureClass;
                            if (featureClass == null)
                            {
                                continue;
                            }
                            FacilityClass fcc = dr["FacilityClass"] as FacilityClass;
                            if (fcc == fac)
                            {
                                strTemp += featureClass.GuidString + ";";
                            }
                        }
                        if (this._facDoc != null)
                        {
                            XmlNode node = this._facDoc.SelectSingleNode(".//FacilityClass[@name=\"" + fac.Name + "\"]");
                            if (node != null)
                            {
                                if (node.Attributes["fc3D"] == null)
                                {
                                    XmlAttribute attr = this._facDoc.CreateAttribute("fc3D");
                                    node.Attributes.Append(attr);
                                }
                                node.Attributes["fc3D"].Value = strTemp;
                            }
                            this._facDoc.Save(this._xmlFacFilePath);
                        }
                    }
                }
                //设施大类所属
                WaitForm.SetCaption("所属大类关联设置进行中...");
                HashSet <MajorClass> listMC = _checkMCList;
                if (listMC != null && this.ceConnectMajorClass.Checked)
                {
                    foreach (MajorClass mc in listMC)
                    {
                        string strTemp = "";
                        List <IFeatureClass> listFc = new List <IFeatureClass>();
                        foreach (DataRow dr in this._dt.Rows)
                        {
                            if (!(bool)dr["CheckState"])
                            {
                                continue;
                            }
                            IFeatureClass featureClass = dr["FeatureClass"] as IFeatureClass;
                            if (featureClass == null)
                            {
                                continue;
                            }
                            MajorClass mcc = dr["MajorClass"] as MajorClass;
                            if (mcc == mc)
                            {
                                strTemp += featureClass.GuidString + ";";
                                listFc.Add(featureClass);
                            }
                        }
                        if (this._logicDoc != null)
                        {
                            XmlNode node = this._logicDoc.SelectSingleNode(".//MajorClass[@name=\"" + mc.Name + "\"]");
                            if (node != null)
                            {
                                if (node.Attributes["fc3D"] == null)
                                {
                                    XmlAttribute attr = this._logicDoc.CreateAttribute("fc3D");
                                    node.Attributes.Append(attr);
                                }
                                node.Attributes["fc3D"].Value = strTemp;
                            }
                            for (int i = node.ChildNodes.Count - 1; i >= 0; i--)
                            {
                                XmlNode childNode = node.ChildNodes[i];
                                node.RemoveChild(childNode);
                            }
                            //foreach (XmlNode childNode in node.ChildNodes)
                            //{
                            //    node.RemoveChild(childNode);
                            //}

                            // 二级分组
                            WaitForm.SetCaption("小类分组中...");
                            IQueryFilter     filter   = null;
                            IFdeCursor       cursor   = null;
                            IRowBuffer       row      = null;
                            HashSet <string> hsValues = new HashSet <string>();
                            try
                            {
                                foreach (IFeatureClass fc in listFc)
                                {
                                    WaitForm.SetCaption("要素类【" + (string.IsNullOrEmpty(fc.AliasName) ? fc.Name : fc.AliasName) + "】分组中...");
                                    if (fc.GetFields().IndexOf(mc.ClassifyField) == -1)
                                    {
                                        continue;
                                    }
                                    if (fc.GetFields().IndexOf("GroupId") == -1)
                                    {
                                        continue;
                                    }
                                    filter           = new QueryFilter();
                                    filter.SubFields = mc.ClassifyField;
                                    cursor           = fc.Search(filter, true);

                                    while ((row = cursor.NextRow()) != null)
                                    {
                                        if (!row.IsNull(0))
                                        {
                                            hsValues.Add(row.GetValue(0).ToString());
                                        }
                                    }
                                    if (cursor != null)
                                    {
                                        System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                                        cursor = null;
                                    }
                                    if (row != null)
                                    {
                                        System.Runtime.InteropServices.Marshal.ReleaseComObject(row);
                                        row = null;
                                    }
                                    fc.SubTypeFieldName = "";
                                    fc.SubTypeFieldName = "GroupId";
                                }
                                // 重设groupid
                                WaitForm.SetCaption("启动重置GroupId...");
                                foreach (IFeatureClass fc in listFc)
                                {
                                    string strfcname = (string.IsNullOrEmpty(fc.AliasName) ? fc.Name : fc.AliasName);
                                    WaitForm.SetCaption("要素类【" + strfcname + "】重置GroupId中...");
                                    if (fc.GetFields().IndexOf(mc.ClassifyField) == -1)
                                    {
                                        continue;
                                    }
                                    if (fc.GetFields().IndexOf("GroupId") == -1)
                                    {
                                        continue;
                                    }
                                    filter           = new QueryFilter();
                                    filter.SubFields = "GroupId,oid";
                                    int groupid = -1;
                                    foreach (string str in hsValues)
                                    {
                                        groupid++;
                                        filter.WhereClause = mc.ClassifyField + " = '" + str + "'";
                                        int fccount = fc.GetCount(filter);
                                        if (fccount == 0)
                                        {
                                            continue;
                                        }
                                        int counttemp = 0;
                                        cursor = fc.Update(filter);
                                        while ((row = cursor.NextRow()) != null)
                                        {
                                            row.SetValue(0, groupid);
                                            cursor.UpdateRow(row);
                                            counttemp++;
                                            WaitForm.SetCaption("要素类【" + strfcname + "】子类【" + str + "】(" + counttemp + "/" + fccount + ")重置GroupId中...");
                                        }
                                        if (cursor != null)
                                        {
                                            System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                                            cursor = null;
                                        }
                                        if (row != null)
                                        {
                                            System.Runtime.InteropServices.Marshal.ReleaseComObject(row);
                                            row = null;
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }
                            finally
                            {
                                if (cursor != null)
                                {
                                    System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                                    cursor = null;
                                }
                                if (row != null)
                                {
                                    System.Runtime.InteropServices.Marshal.ReleaseComObject(row);
                                    row = null;
                                }
                                if (filter != null)
                                {
                                    System.Runtime.InteropServices.Marshal.ReleaseComObject(filter);
                                    row = null;
                                }
                            }
                            WaitForm.SetCaption("分组信息写入配置文件中...");
                            int index = -1;
                            foreach (string str in hsValues)
                            {
                                index++;
                                XmlElement ele = this._logicDoc.CreateElement("SubClass");
                                ele.SetAttribute("name", str);
                                ele.SetAttribute("groupid", index.ToString());
                                node.AppendChild(ele);
                                foreach (IFeatureClass fc in listFc)
                                {
                                    if (fc.GetFields().IndexOf(mc.ClassifyField) == -1)
                                    {
                                        continue;
                                    }
                                    if (fc.GetFields().IndexOf("GroupId") == -1)
                                    {
                                        continue;
                                    }
                                    SubTypeInfo sti = new SubTypeInfo();
                                    sti.Code = index;
                                    sti.Name = str;
                                    fc.AddSubType(sti);
                                }
                            }
                            //XmlElement ele1 = this._logicDoc.CreateElement("SubClass");
                            //ele1.SetAttribute("name", "其他");
                            //ele1.SetAttribute("groupid", index.ToString());
                            //node.AppendChild(ele1);

                            this._logicDoc.Save(this._xmlLogicFilePath);
                        }
                    }
                }
                WaitForm.Stop();
                XtraMessageBox.Show("设置成功!", "提示");
            }
            catch (Exception ex)
            {
                WaitForm.Stop();
                XtraMessageBox.Show("设置失败!", "提示");
            }
        }
Exemplo n.º 21
0
        private bool InsertColor()
        {
            IFdeCursor cursor = null;
            IRowBuffer row    = null;

            try
            {
                IFeatureDataSet fds = this._ds.OpenFeatureDataset("DataSet_BIZ");
                if (fds == null)
                {
                    return(false);
                }
                IObjectClass oc = fds.OpenObjectClass("OC_ColorInfo");
                if (oc == null)
                {
                    return(false);
                }

                row    = oc.CreateRowBuffer();
                cursor = oc.Insert();
                row.SetValue(row.FieldIndex("Name"), this._color.Name);
                row.SetValue(row.FieldIndex("ObjectId"), this._color.ObjectId);
                row.SetValue(row.FieldIndex("GroupId"), this._color.Group);
                row.SetValue(row.FieldIndex("Code"), this._color.Code);
                row.SetValue(row.FieldIndex("Type"), this._color.Type);
                if (this._color.Thumbnail != null)
                {
                    try
                    {
                        IBinaryBuffer bb     = new BinaryBufferClass();
                        MemoryStream  stream = new MemoryStream();
                        this._color.Thumbnail.Save(stream, ImageFormat.Png);
                        bb.FromByteArray(stream.ToArray());
                        row.SetValue(row.FieldIndex("Thumbnail"), bb);
                    }
                    catch (Exception exception)
                    {
                    }
                }
                row.SetValue(row.FieldIndex("Comment"), this._color.Comment);
                cursor.InsertRow(row);
                this._color.Id = cursor.LastInsertId;
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
                if (cursor != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                    cursor = null;
                }
                if (row != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(row);
                    row = null;
                }
            }
        }
Exemplo n.º 22
0
        private bool UpdateColor()
        {
            IFdeCursor cursor = null;
            IRowBuffer row    = null;

            try
            {
                IFeatureDataSet fds = this._ds.OpenFeatureDataset("DataSet_BIZ");
                if (fds == null)
                {
                    return(false);
                }
                IObjectClass oc = fds.OpenObjectClass("OC_ColorInfo");
                if (oc == null)
                {
                    return(false);
                }

                IQueryFilter filter = new QueryFilter()
                {
                    WhereClause = string.Format("ObjectId = '{0}'", this._color.ObjectId)
                };
                cursor = oc.Update(filter);
                row    = cursor.NextRow();
                if (row != null)
                {
                    row.SetValue(row.FieldIndex("Name"), this._color.Name);
                    row.SetValue(row.FieldIndex("GroupId"), this._color.Group);
                    row.SetValue(row.FieldIndex("Code"), this._color.Code);
                    row.SetValue(row.FieldIndex("Type"), this._color.Type);
                    row.SetValue(row.FieldIndex("Comment"), this._color.Comment);
                    if (this._color.Thumbnail != null)
                    {
                        try
                        {
                            IBinaryBuffer newVal = new BinaryBufferClass();
                            MemoryStream  stream = new MemoryStream();
                            this._color.Thumbnail.Save(stream, ImageFormat.Png);
                            newVal.FromByteArray(stream.ToArray());
                            row.SetValue(2, newVal);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    cursor.UpdateRow(row);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
                if (cursor != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                    cursor = null;
                }
                if (row != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(row);
                    row = null;
                }
            }
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            //创建要素类要先定义属性字段
            IFieldInfoCollection fields = new FieldInfoCollection();
            {
                //名称列
                IFieldInfo field = new FieldInfo();
                field.Name      = "Name";
                field.FieldType = gviFieldType.gviFieldString;
                field.Length    = 255;
                fields.Add(field);

                //空间列
                field                  = new FieldInfo();
                field.Name             = "Geometry";
                field.FieldType        = gviFieldType.gviFieldGeometry;                              //列类型为空间类型
                field.GeometryDef      = new GeometryDef();                                          //需要实例化一个几何定义对象,里面有大量与空间有关的内容,比如:
                field.GeometryDef.HasZ = true;                                                       //是否在Z值,默认为false,只能存XY
                field.GeometryDef.GeometryColumnType = gviGeometryColumnType.gviGeometryColumnPoint; //空间列的几何类型
                field.RegisteredRenderIndex          = true;                                         //注册渲染索引,允许在renderControl中显示
                fields.Add(field);

                //多空间列
                field                  = new FieldInfo();
                field.Name             = "Model";
                field.FieldType        = gviFieldType.gviFieldGeometry;                                   //列类型为空间类型
                field.GeometryDef      = new GeometryDef();                                               //需要实例化一个几何定义对象,里面有大量与空间有关的内容,比如:
                field.GeometryDef.HasZ = true;                                                            //是否在Z值,默认为false,只能存XY
                field.GeometryDef.GeometryColumnType = gviGeometryColumnType.gviGeometryColumnModelPoint; //空间列的几何类型
                field.RegisteredRenderIndex          = true;                                              //注册渲染索引,允许在renderControl中显示
                fields.Add(field);
                //... 其它列
            }

            //创建要素类
            IFeatureClass FC = FDS.CreateFeatureClass("FC", fields);

            int nameID   = FC.GetFields().IndexOf("Name");      //获取对应列的索引,
            int geomID   = FC.GetFields().IndexOf("Geometry");
            int fidIndex = FC.GetFields().IndexOf(FC.FidFieldName);

            //增加单条数据,并同步到FeatureLayer
            IFdeCursor fcu = FC.Insert();                                                               //通过FC创建一个插入游标,用来操作rowBuffer
            IRowBuffer rb  = FC.CreateRowBuffer();                                                      //通过FC创建一条空要素实例,用来设置数据,设置完成后将其塞入FC
            IPoint     p   = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ); // 将要塞入空间列的几何对象,类型要对应 FC的field.GeometryDef.GeometryColumnType ,否则塞不进

            rb.SetValue(nameID, "testPointA");                                                          //塞名称
            rb.SetValue(geomID, p);                                                                     //塞几何
            fcu.InsertRow(rb);                                                                          //塞进FC
            int fid = fcu.LastInsertId;                                                                 //成功后反回这条buffer的主键ID

            rb.SetValue(fidIndex, fid);                                                                 //Cursor(FC)增加数据后会产生一个对应的FID,要把这个FID赋值给row才能在FLayer中显示
            ax.FeatureManager.CreateFeature(FC, rb);                                                    //同步到renderControl


            //增加很大量数据时,参考以下方法
            IFdeCursor           cu   = FC.Insert();
            IRowBufferCollection rows = new RowBufferCollection();

            for (int i = 0; i < 100000; i++)
            {
                IRowBuffer row = FC.CreateRowBuffer();
                // do something ...
                row.SetValue(geomID, p);
                cu.InsertRow(row);
                row.SetValue(fidIndex, cu.LastInsertId);
                rows.Add(row);
            }
            ax.FeatureManager.CreateFeatures(FC, rows);
            //或直接整体更新
            ax.FeatureManager.RefreshFeatureClass(FC);



            //查
            string       tagStr = "tagName";
            IQueryFilter qf     = new QueryFilter();        //过滤器

            qf.WhereClause = $"Name = '{tagStr}'";
            IFdeCursor res     = FC.Search(qf, true);       //条件查
            IRowBuffer aBuffer = res.NextRow();             //遍历查询结果

            //改
            IFdeCursor upCu     = FC.Update(qf);
            IRowBuffer upBuffer = upCu.NextRow();

            upCu.UpdateRow(upBuffer);

            //删
            FC.Delete(qf);
            FC.DeleteRow(0);
            FC.Truncate();          //保留表结构,清空表
        }
Exemplo n.º 24
0
        private void AddRecord()
        {
            try
            {
                this.beforeRowBufferMap.Clear();
                SelectCollection.Instance().Clear();
                DF3DFeatureClass featureClassInfo = CommonUtils.Instance().CurEditLayer;
                if (featureClassInfo == null)
                {
                    return;
                }
                IFeatureClass fc = featureClassInfo.GetFeatureClass();
                if (fc == null)
                {
                    return;
                }
                IFeatureLayer fl = featureClassInfo.GetFeatureLayer();
                if (fl == null)
                {
                    return;
                }
                IFieldInfoCollection fields = fc.GetFields();
                int indexGeo = fields.IndexOf(fl.GeometryFieldName);
                if (indexGeo == -1)
                {
                    return;
                }
                IFieldInfo fiGeo = fields.Get(indexGeo);
                if (fiGeo == null || fiGeo.GeometryDef == null)
                {
                    return;
                }

                IGeometry geo = this._drawTool.GetGeo();
                if (geo.GeometryType != gviGeometryType.gviGeometryPolygon)
                {
                    return;
                }
                IPolygon polygon = geo as IPolygon;
                IPolygon geoOut  = this._geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, fiGeo.GeometryDef.VertexAttribute) as IPolygon;
                for (int i = 0; i < polygon.ExteriorRing.PointCount; i++)
                {
                    IPoint ptGet  = polygon.ExteriorRing.GetPoint(i);
                    IPoint pttemp = ptGet.Clone2(fiGeo.GeometryDef.VertexAttribute) as IPoint;
                    if (fiGeo.GeometryDef.HasZ)
                    {
                        pttemp.SetCoords(ptGet.X, ptGet.Y, ptGet.Z, 0, 0);
                    }
                    else
                    {
                        pttemp.SetCoords(ptGet.X, ptGet.Y, 0, 0, 0);
                    }
                    geoOut.ExteriorRing.AppendPoint(pttemp);
                }

                IRowBufferCollection rowCol = new RowBufferCollection();
                IRowBufferFactory    fac    = new RowBufferFactory();
                IRowBuffer           row    = fac.CreateRowBuffer(fields);
                row.SetValue(indexGeo, geoOut);
                foreach (DataRow dr in this._dt.Rows)
                {
                    IFieldInfo fi = dr["F"] as IFieldInfo;
                    if (fi == null)
                    {
                        continue;
                    }
                    string fn    = fi.Name;
                    int    index = fields.IndexOf(fn);
                    if (index != -1)
                    {
                        if (dr["FV"] == null)
                        {
                            row.SetNull(index);
                        }
                        else
                        {
                            string strobj = dr["FV"].ToString();
                            bool   bRes   = false;
                            switch (fi.FieldType)
                            {
                            case gviFieldType.gviFieldBlob:
                            case gviFieldType.gviFieldGeometry:
                            case gviFieldType.gviFieldUnknown:
                                break;

                            case gviFieldType.gviFieldFloat:
                                float f;
                                bRes = float.TryParse(strobj, out f);
                                if (bRes)
                                {
                                    row.SetValue(index, f);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            case gviFieldType.gviFieldDouble:
                                double d;
                                bRes = double.TryParse(strobj, out d);
                                if (bRes)
                                {
                                    row.SetValue(index, d);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            case gviFieldType.gviFieldFID:
                            case gviFieldType.gviFieldUUID:
                            case gviFieldType.gviFieldInt16:
                                Int16 i16;
                                bRes = Int16.TryParse(strobj, out i16);
                                if (bRes)
                                {
                                    row.SetValue(index, i16);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            case gviFieldType.gviFieldInt32:
                                Int32 i32;
                                bRes = Int32.TryParse(strobj, out i32);
                                if (bRes)
                                {
                                    row.SetValue(index, i32);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            case gviFieldType.gviFieldInt64:
                                Int64 i64;
                                bRes = Int64.TryParse(strobj, out i64);
                                if (bRes)
                                {
                                    row.SetValue(index, i64);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;;

                            case gviFieldType.gviFieldString:
                                row.SetValue(index, strobj);
                                break;

                            case gviFieldType.gviFieldDate:
                                DateTime dt;
                                bRes = DateTime.TryParse(strobj, out dt);
                                if (bRes)
                                {
                                    row.SetValue(index, dt);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
                rowCol.Add(row);
                beforeRowBufferMap[featureClassInfo] = rowCol;
                UpdateDatabase();
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 25
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;
                }
            }
        }
Exemplo n.º 26
0
        private void CmdEditFacilityStyle_FacStyleClassChangedEvent(DF3DPipeCreateTool.Class.FacStyleClass style)
        {
            try
            {
                this.beforeRowBufferMap.Clear();
                if (style == null)
                {
                    return;
                }

                DF3DFeatureClass dffc = CommonUtils.Instance().CurEditLayer;
                if (dffc == null)
                {
                    return;
                }
                IFeatureClass fc = dffc.GetFeatureClass();
                if (fc == null)
                {
                    return;
                }
                FacClassReg reg = FacilityInfoService.GetFacClassRegByFeatureClassID(fc.GuidString);
                if (reg == null)
                {
                    return;
                }
                TopoClass tc = FacilityInfoService.GetTopoClassByFacClassCode(reg.FacClassCode);
                if (tc == null)
                {
                    return;
                }
                FacilityClass facc = reg.FacilityType;
                if (facc == null)
                {
                    return;
                }
                IResourceManager manager = fc.FeatureDataSet as IResourceManager;
                if (manager == null)
                {
                    return;
                }

                IFieldInfoCollection fields = fc.GetFields();
                //int indexGroupid = -1;
                //int indexClassify = -1;
                //SubClass sc = null;
                //MajorClass mc = LogicDataStructureManage3D.Instance.GetMajorClassByDFFeatureClassID(fc.GuidString);
                //if (mc != null)
                //{
                //    indexClassify = fields.IndexOf(mc.ClassifyField);
                //    indexGroupid = fields.IndexOf("GroupId");

                //}

                int index = fields.IndexOf("StyleId");
                if (index == -1)
                {
                    return;
                }
                int mnindex = fields.IndexOf("ModelName");
                int mpindex = fields.IndexOf("Geometry");
                if (mpindex == -1)
                {
                    return;
                }
                HashMap hm = SelectCollection.Instance().GetSelectGeometrys();
                if (hm != null && hm.Count == 1)
                {
                    IRowBufferCollection res = new RowBufferCollection();
                    IRowBufferCollection rowBufferCollection = hm[dffc] as IRowBufferCollection;
                    if (rowBufferCollection != null)
                    {
                        for (int i = 0; i < rowBufferCollection.Count; i++)
                        {
                            IRowBuffer  rowBuffer   = rowBufferCollection.Get(i);
                            Fac         fac         = null;
                            IModelPoint mp          = null;
                            IModel      finemodel   = null;
                            IModel      simplemodel = null;
                            string      name        = "";
                            switch (facc.Name)
                            {
                            case "PipeNode":
                                fac = new PipeNodeFac(reg, style, rowBuffer, tc);
                                break;

                            case "PipeLine":
                                fac = new PipeLineFac(reg, style, rowBuffer, tc, false, false);
                                break;

                            case "PipeBuild":
                            case "PipeBuild1":
                                fac = new PipeBuildFac(reg, style, rowBuffer);
                                break;
                            }
                            if (UCAuto3DCreate.RebuildModel(fac, style, out mp, out finemodel, out simplemodel, out name))
                            {
                                if (finemodel == null || mp == null)
                                {
                                    continue;
                                }
                                mp.ModelEnvelope = finemodel.Envelope;
                                rowBuffer.SetValue(mpindex, mp);
                                rowBuffer.SetValue(index, style.ObjectId);
                                //if (mc != null)
                                //{
                                //    if (indexClassify != -1 && indexGroupid != -1)
                                //    {

                                //    }
                                //}
                                bool bRes = false;
                                if (!string.IsNullOrEmpty(mp.ModelName))
                                {
                                    if (!manager.ModelExist(mp.ModelName))
                                    {
                                        if (manager.AddModel(mp.ModelName, finemodel, simplemodel))
                                        {
                                            bRes = true;
                                        }
                                    }
                                    else
                                    {
                                        if (manager.UpdateModel(mp.ModelName, finemodel) && manager.UpdateSimplifiedModel(mp.ModelName, simplemodel))
                                        {
                                            bRes = true;
                                        }
                                    }
                                }
                                if (bRes)
                                {
                                    res.Add(rowBuffer);
                                }
                            }
                        }
                    }
                    beforeRowBufferMap[dffc] = res;
                    //SelectCollection.Instance().Clear();
                    UpdateDatabase();
                    DF3DApplication app = DF3DApplication.Application;
                    if (app == null || app.Current3DMapControl == null)
                    {
                        return;
                    }
                    app.Current3DMapControl.FeatureManager.RefreshFeatureClass(fc);
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 27
0
        private void RotatingModel(double AxisX, double AxisY, double AxisZ, double Angle)
        {
            DF3DApplication app = DF3DApplication.Application;

            if (app == null || app.Current3DMapControl == null)
            {
                return;
            }
            this.bFinished          = false;
            this.modifyRowbufferMap = SelectCollection.Instance().Clone(this.beginRowbufferMap);
            if (this.modifyRowbufferMap != null)
            {
                foreach (DF3DFeatureClass featureClassInfo in this.modifyRowbufferMap.Keys)
                {
                    IFeatureClass        featureClass        = featureClassInfo.GetFeatureClass();
                    string               facName             = featureClassInfo.GetFacilityClassName();
                    IRowBufferCollection rowBufferCollection = this.modifyRowbufferMap[featureClassInfo] as IRowBufferCollection;
                    for (int i = 0; i < rowBufferCollection.Count; i++)
                    {
                        IRowBuffer rowBuffer = rowBufferCollection.Get(i);
                        if (rowBuffer != null)
                        {
                            int num = rowBuffer.FieldIndex(featureClassInfo.GetFeatureLayer().GeometryFieldName);
                            if (num != -1)
                            {
                                IGeometry geometry = rowBuffer.GetValue(num) as IGeometry;
                                if (geometry != null)
                                {
                                    ITransform transform = geometry as ITransform;
                                    if (geometry.HasZ())
                                    {
                                        transform.Rotate3D(AxisX, AxisY, AxisZ, this.centerX, this.centerY, this.centerZ, Angle);
                                    }
                                    else
                                    {
                                        if (!geometry.HasZ() && AxisZ > 0.0)
                                        {
                                            transform.Rotate2D(this.centerX, this.centerY, Angle);
                                        }
                                    }
                                    rowBuffer.SetValue(num, transform);
                                }
                            }
                            #region 管线设施
                            if (facName == "PipeLine" || facName == "PipeNode" || facName == "PipeBuild" || facName == "PipeBuild1")
                            {
                                int num3 = rowBuffer.FieldIndex("Shape");
                                if (num3 != -1)
                                {
                                    IGeometry geometry = rowBuffer.GetValue(num3) as IGeometry;
                                    if (geometry != null)
                                    {
                                        ITransform transform = geometry as ITransform;
                                        if (geometry != null && transform != null)
                                        {
                                            if (geometry.HasZ())
                                            {
                                                transform.Rotate3D(AxisX, AxisY, AxisZ, this.centerX, this.centerY, this.centerZ, Angle);
                                            }
                                            else
                                            {
                                                transform.Rotate2D(this.centerX, this.centerY, Angle);
                                            }
                                            rowBuffer.SetValue(num3, transform);
                                        }
                                    }
                                }
                                int num4 = rowBuffer.FieldIndex("FootPrint");
                                if (num4 != -1)
                                {
                                    IGeometry geometry = rowBuffer.GetValue(num4) as IGeometry;
                                    if (geometry != null)
                                    {
                                        ITransform transform = geometry as ITransform;
                                        if (geometry != null && transform != null)
                                        {
                                            if (geometry.HasZ())
                                            {
                                                transform.Rotate3D(AxisX, AxisY, AxisZ, this.centerX, this.centerY, this.centerZ, Angle);
                                            }
                                            else
                                            {
                                                transform.Rotate2D(this.centerX, this.centerY, Angle);
                                            }
                                            rowBuffer.SetValue(num4, transform);
                                        }
                                    }
                                }
                            }
                            #endregion
                        }
                    }
                    app.Current3DMapControl.FeatureManager.EditFeatures(featureClass, rowBufferCollection);
                    //System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
                }
            }
        }
Exemplo n.º 28
0
        void aaa(IFeatureClass fc, int index, IResourceManager resourceM)
        {
            //无条件查询,即全选
            IFdeCursor sourceCursor = fc.Update(null);
            IRowBuffer row          = null;

            //遍历feature
            while ((row = sourceCursor.NextRow()) != null)
            {
                //从feature中拿到几何属性
                IGeometry geom = (IGeometry)row.GetValue(index);
                //确定是模型
                if (geom.GeometryType == gviGeometryType.gviGeometryModelPoint)
                {
                    //转换为modelPoint
                    IModelPoint mp = (IModelPoint)geom;

                    //mp 的转换矩阵
                    IMatrix mx = mp.AsMatrix();

                    //获取模型实例
                    //注意:
                    //model可以被不同的modelPoint多次引用,需要修改模型时
                    //需要通过modelName判断一下,这个模型被修改过没有
                    IModel model = resourceM.GetModel(mp.ModelName);

                    //提取模型节点属性
                    if (model != null)
                    {
                        #region modelInside
                        //遍历DrawGroup
                        for (int dgrpi = 0; dgrpi < model.GroupCount; dgrpi++)
                        {
                            IDrawGroup dgrp = model.GetGroup(dgrpi);
                            if (dgrp != null)
                            {
                                //遍历DrawPrimitive
                                for (int dpri = 0; dpri < dgrp.PrimitiveCount; dpri++)
                                {
                                    IDrawPrimitive dpr = dgrp.GetPrimitive(dpri);
                                    if (dpr != null)
                                    {
                                        //获取顶点数组
                                        float[] verArray = dpr.VertexArray.Array;
                                        //创建新的顶点数组,替换原来的
                                        IFloatArray newArr = new FloatArray();

                                        //遍历数组,转为点,三个成员为一组,xyz
                                        for (int veri = 0; veri < verArray.Length; veri += 3)
                                        {
                                            Vector3 vec = new Vector3();
                                            vec.X = verArray[veri];
                                            vec.Y = verArray[veri + 1];
                                            vec.Z = verArray[veri + 2];

                                            //用矩阵转到决对坐标,并修改
                                            IVector3 refVec = mx.MultiplyVector(vec);

                                            //修改部份
                                            refVec.X = 3.3;
                                            refVec.Y = 4.4;
                                            refVec.Z = 5.5;

                                            //修改完,减掉mp中的位移,准备塞回modle
                                            newArr.Append((float)(refVec.X - mp.X));
                                            newArr.Append((float)(refVec.Y - mp.Y));
                                            newArr.Append((float)(refVec.Z - mp.Z));
                                        }
                                        //把新顶点数组塞入Primitive
                                        dpr.VertexArray = newArr;
                                        //再把Primitive更新到当前Group
                                        dgrp.SetPrimitive(dpri, dpr);
                                    }
                                }
                                //把组更新到当前model
                                model.SetGroup(dgrpi, dgrp);
                            }
                        }
                        //更新数据源
                        resourceM.UpdateModel(mp.ModelName, model);
                        resourceM.RebuildSimplifiedModel(mp.ModelName);//重建简模
                        //释放资源
                        model.Dispose();
                        model = null;
                        #endregion
                    }

                    //修改mp
                    mp.SetCoords(3.3, 4.4, 5.5, mp.M, mp.Id);
                    //塞回row
                    row.SetValue(index, mp);
                }
            }
        }
Exemplo n.º 29
0
        private bool CreateFacClassReg(FacClass fc)
        {
            if (fc == null || fc.FacilityType == null)
            {
                return(false);
            }
            IFdeCursor cursor = null;
            IRowBuffer row    = null;

            try
            {
                IFeatureDataSet fds = this._dsPipe.OpenFeatureDataset("DataSet_BIZ");
                if (fds == null)
                {
                    return(false);
                }
                IFeatureDataSet fdsActuality = this._dsPipe.OpenFeatureDataset("DataSet_GEO_Actuality");
                if (fdsActuality == null)
                {
                    return(false);
                }
                IObjectClass oc = fds.OpenObjectClass("OC_FacilityClass");
                if (oc == null)
                {
                    return(false);
                }

                row    = oc.CreateRowBuffer();
                cursor = oc.Insert();
                if (row != null)
                {
                    row.SetValue(row.FieldIndex("FacClassCode"), fc.Code);
                    row.SetValue(row.FieldIndex("Name"), fc.Name);
                    row.SetValue(row.FieldIndex("FacilityType"), fc.FacilityType.Name);
                    row.SetValue(row.FieldIndex("LocationType"), fc.LocationType.ToString());
                    row.SetValue(row.FieldIndex("TurnerStyle"), fc.TurnerStyle.ToString());
                    row.SetValue(row.FieldIndex("Comment"), fc.Comment);
                    string fcName = string.Format("FC_{0}_{1}", (int)DataLifeCyle.Actuality, fc.Code);
                    List <CMFieldConfig> fieldConfig  = GetFieldsConfig(fc.Code);
                    IFieldInfoCollection fielInfoCol  = CreateFieldInfoCollection(fieldConfig, fc.FacilityType.Name);
                    IFeatureClass        featureClass = fdsActuality.CreateFeatureClass(fcName, fielInfoCol);
                    if (featureClass == null)
                    {
                        return(false);
                    }
                    featureClass.AliasName = fc.Name;
                    featureClass.LockType  = gviLockType.gviLockExclusiveSchema;
                    IGridIndexInfo indexInfo = new GridIndexInfoClass
                    {
                        L1            = 500.0,
                        L2            = 2000.0,
                        L3            = 10000.0,
                        GeoColumnName = "Geometry"
                    };
                    featureClass.AddSpatialIndex(indexInfo);
                    indexInfo.GeoColumnName = "Shape";
                    featureClass.AddSpatialIndex(indexInfo);
                    indexInfo.GeoColumnName = "FootPrint";
                    featureClass.AddSpatialIndex(indexInfo);
                    IRenderIndexInfo info2 = new RenderIndexInfoClass
                    {
                        L1            = 500.0,
                        GeoColumnName = "Geometry"
                    };
                    featureClass.AddRenderIndex(info2);
                    info2.GeoColumnName = "Shape";
                    featureClass.AddRenderIndex(info2);
                    info2.GeoColumnName = "FootPrint";
                    featureClass.AddRenderIndex(info2);
                    featureClass.LockType = gviLockType.gviLockSharedSchema;
                    row.SetValue(row.FieldIndex("FeatureClassId"), featureClass.Guid.ToString());
                    row.SetValue(row.FieldIndex("DataSetName"), "DataSet_GEO_Actuality");
                    row.SetValue(row.FieldIndex("FcName"), featureClass.Name);
                    row.SetValue(row.FieldIndex("DataType"), DataLifeCyle.Actuality.ToString());
                    cursor.InsertRow(row);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                WaitForm.SetCaption("创建管线库中的设施要素类【" + fc.Name + "】失败!");
                return(false);
            }
            finally
            {
                if (cursor != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                    cursor = null;
                }
                if (row != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(row);
                    row = null;
                }
            }
        }
Exemplo n.º 30
0
        public void ImportModelMdb(IFeatureClass fc, string mdbFile, int groupId)
        {
            try
            {
                //2、获取基本信息
                FileInfo fInfo       = new FileInfo(mdbFile);
                string   strFilePath = fInfo.DirectoryName;

                Gvitech.CityMaker.Resource.IResourceFactory rf = new Gvitech.CityMaker.Resource.ResourceFactory();
                IResourceManager rm = fc.FeatureDataSet as IResourceManager;
                Dictionary <string, IEnvelope> cacheModeInfos = new Dictionary <string, IEnvelope>();
                List <string> cacheImageNames = new List <string>();

                IGeometryFactory geoFactory = new GeometryFactory();
                IResourceFactory symbolFac  = new ResourceFactory();

                IRowBufferCollection fcRows = new RowBufferCollection();
                IRowBuffer           fcRow  = null;

                //4、解析mdb
                string strConn    = _ConnStr + mdbFile + "\'";
                int    index      = 0;
                int    totalCount = 0;
                using (OleDbConnection oleConn = new OleDbConnection(strConn))
                {
                    oleConn.Open();
                    string          strSql      = "select count(*)  from Attribute_Table_CityManager";
                    OleDbCommand    countCmd    = new OleDbCommand(strSql, oleConn);
                    OleDbDataReader countReader = countCmd.ExecuteReader();
                    countReader.Read();
                    totalCount = countReader.GetInt32(0);
                    countReader.Close();

                    OleDbCommand    command   = new OleDbCommand(_QueryModelStr, oleConn);
                    OleDbDataReader reader    = command.ExecuteReader();
                    IModelPoint     modePoint = null;
                    while (reader.Read())
                    {
                        int    percent = ++index * 100 / totalCount;
                        string toolTip = string.Format("已完成{0}条/总共{1}条 {2}%", index, totalCount, percent);
                        CommonEntity.FormEntity.Text = toolTip;

                        double dScaleX = 0.0;
                        double dScaleY = 0.0;
                        double dScaleZ = 0.0;

                        double.TryParse(reader.GetString(9), out dScaleX);
                        double.TryParse(reader.GetString(10), out dScaleY);
                        double.TryParse(reader.GetString(11), out dScaleZ);

                        //if (dScaleX < 0 || dScaleY < 0 || dScaleZ < 0)
                        //    continue;

                        //fc
                        fcRow = fc.CreateRowBuffer();
                        int nPose = fcRow.FieldIndex("name");
                        if (nPose == -1)
                        {
                            continue;
                        }
                        string modelName = reader.GetString(0);
                        fcRow.SetValue(nPose, modelName);

                        nPose = fcRow.FieldIndex("groupId");
                        if (nPose == -1)
                        {
                            continue;
                        }
                        fcRow.SetValue(nPose, groupId);

                        modePoint = (IModelPoint)geoFactory.CreateGeometry(
                            gviGeometryType.gviGeometryModelPoint,
                            gviVertexAttribute.gviVertexAttributeZ);
                        modePoint.ModelName = modelName;

                        double dModePointX = double.Parse(reader.GetString(2)) + 0;  // CoorX = 0
                        double dModePointY = double.Parse(reader.GetString(3)) + 0;  // CoorY = 0
                        double dModePointZ = double.Parse(reader.GetString(4)) + 0;  // CoorZ = 0

                        double dRotationAngle = double.Parse(reader.GetString(5));
                        double dAxisX         = double.Parse(reader.GetString(6));
                        double dAxisY         = double.Parse(reader.GetString(7));
                        double dAxisZ         = double.Parse(reader.GetString(8));

                        double dUTransAngel = double.Parse(reader.GetString(12));
                        double dUTransX     = double.Parse(reader.GetString(13));
                        double dUTransY     = double.Parse(reader.GetString(14));
                        double dUTransZ     = double.Parse(reader.GetString(15));

                        modePoint.X = dModePointX;
                        modePoint.Y = dModePointY;
                        modePoint.Z = dModePointZ;

                        IMatrix matrix = new Matrix();

                        IVector3 pointVec = new Vector3();
                        pointVec.X = dModePointX;
                        pointVec.Y = dModePointY;
                        pointVec.Z = dModePointZ;

                        IVector3 Scale = new Vector3();
                        Scale.X = dScaleX;
                        Scale.Y = dScaleY;
                        Scale.Z = dScaleZ;

                        IVector3 Rotation = new Vector3();
                        Rotation.X = dAxisX;
                        Rotation.Y = dAxisY;
                        Rotation.Z = dAxisZ;

                        IVector3 Shear = new Vector3();
                        Shear.X = dUTransX;
                        Shear.Y = dUTransY;
                        Shear.Z = dUTransZ;

                        matrix.Compose2(pointVec, Scale, dRotationAngle, Rotation, dUTransAngel, Shear);
                        modePoint.FromMatrix(matrix);

                        //mc
                        IPropertySet Images = null;

                        //如果内存中不包含
                        if (!cacheModeInfos.Keys.Contains(modelName))
                        {
                            //数据库中包含
                            if (rm.ModelExist(modelName))
                            {
                                //重名即跳过
                                IEnvelope ev = rm.GetModel(modelName).Envelope;
                                modePoint.ModelEnvelope = ev;
                            }
                            else
                            {
                                IModel  simpleModel = null;
                                string  osgFilePath = strFilePath + "\\" + modelName + ".osg";
                                IModel  fineModel   = null;
                                IMatrix m           = null;
                                symbolFac.CreateModelAndImageFromFileEx(osgFilePath,
                                                                        out Images, out simpleModel, out fineModel, out m);
                                if (fineModel == null || fineModel.GroupCount == 0)
                                {
                                    continue;
                                }

                                cacheModeInfos[modelName] = modePoint.ModelEnvelope = Clone(fineModel.Envelope);

                                rm.AddModel(modelName, fineModel, simpleModel);
                            }
                        }
                        else
                        {
                            modePoint.ModelEnvelope = cacheModeInfos[modelName];
                        }

                        nPose = fcRow.FieldIndex("Geometry");
                        fcRow.SetValue(nPose, modePoint);
                        fcRows.Add(fcRow);

                        //tc
                        if (Images != null)
                        {
                            int nCount = Images.Count;
                            if (nCount > 0)
                            {
                                Hashtable htImages = Images.AsHashtable();
                                foreach (DictionaryEntry item in htImages)
                                {
                                    string imgName = item.Key.ToString();
                                    IImage img     = item.Value as IImage;
                                    if (img == null)
                                    {
                                        continue;
                                    }
                                    if (string.IsNullOrEmpty(imgName))
                                    {
                                        continue;
                                    }

                                    //如果内存中不包含
                                    if (!cacheImageNames.Contains(imgName))
                                    {
                                        //数据库中包含
                                        if (rm.ImageExist(imgName))
                                        {
                                            //重名即跳过
                                        }
                                    }

                                    //如果内存中不包含,数据库中也不包含
                                    if (!rm.ImageExist(imgName) &&
                                        !cacheImageNames.Contains(imgName))
                                    {
                                        cacheImageNames.Add(imgName);
                                        rm.AddImage(imgName, img);
                                    }
                                }
                            }
                        }
                        //end

                        if (fcRows.Count >= 10)
                        {
                            InsertFeatures(fc as IObjectClass, fcRows);
                            fcRows.Clear();
                        }
                    }
                    reader.Close();
                    oleConn.Close();
                }

                if (fcRows.Count > 0)
                {
                    InsertFeatures(fc as IObjectClass, fcRows);
                    fcRows.Clear();
                }
            }
            catch (System.Exception ex)
            {
                if (ex.GetType().Name.Equals("UnauthorizedAccessException"))
                {
                    MessageBox.Show("需要标准runtime授权");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }