private void SearchRes(IFeatureClass fc, string fieldName, string fieldValue) { IFdeCursor cursor = null; IRowBuffer row = null; try { int fidIndex = fc.GetFields().IndexOf(fc.FidFieldName); if (fidIndex == -1) { return; } int nameIndex = fc.GetFields().IndexOf(fieldName); if (nameIndex == -1) { return; } int geoIndex = fc.GetFields().IndexOf("Geometry"); if (geoIndex == -1) { return; } IQueryFilter filter = new QueryFilter(); filter.WhereClause = fieldName + " like '%" + fieldValue + "%'"; cursor = fc.Search(filter, false); while ((row = cursor.NextRow()) != null) { DataRow dr = this._dt.NewRow(); dr["geo"] = row.GetValue(geoIndex); dr["fid"] = row.GetValue(fidIndex); dr["Name"] = row.GetValue(nameIndex); dr["fcName"] = string.IsNullOrEmpty(fc.AliasName) ? fc.Name : fc.AliasName; this._dt.Rows.Add(dr); } } catch (Exception ex) { } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { IPickResult pr = PickResult; if (EventSender == gviMouseSelectMode.gviMouseSelectClick) { if (PickResult != null) { if (pr.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = pr as IFeatureLayerPickResult; int fid = flpr.FeatureId; IFeatureLayer fl = flpr.FeatureLayer; foreach (IFeatureClass fc in fcMap_POI.Keys) { if (fc.Guid.Equals(fl.FeatureClassId)) { IRowBuffer row = fc.GetRow(fid); int pos = row.FieldIndex("Geometry"); IPoint point = row.GetValue(pos) as IPoint; try { INetworkLocation location = new NetworkLocation(); location.Position = point; routeSolver.AddLocation(location); } catch (COMException ex) { MessageBox.Show("所选点距离网络太远,请调整LocationSearchTolerance大小"); return; } pos = row.FieldIndex("Name"); if (row.GetValue(pos) == null) { pos = 0; } if (txtLocationNames.Text == "") { txtLocationNames.Text = row.GetValue(pos).ToString(); } else { txtLocationNames.Text = txtLocationNames.Text + Environment.NewLine + row.GetValue(pos).ToString(); } this.axRenderControl1.FeatureManager.HighlightFeature(fc, fid, System.Drawing.Color.Yellow); } } } } } }
public int GetMaxOID(IFeatureClass fc) { int maxOID = -1; if (fc == null) { return(maxOID); } QueryFilter filter = new QueryFilter(); filter.AddSubField("max(oid) as MaxID"); IFdeCursor cur = fc.Search(filter, true); IRowBuffer row = cur.NextRow(); //Marshal.ReleaseComObject(cur); if (row == null) { return(maxOID); } if (row.IsNull(0)) { return(maxOID); } maxOID = int.Parse(row.GetValue(0).ToString()); return(maxOID); }
private byte[] GetLogicTreeContent(IFeatureDataSet dataset) { byte[] strContent = null; try { IQueryDef qd = dataset.DataSource.CreateQueryDef(); qd.AddSubField("content"); qd.Tables = new String[] { "cm_logictree", "cm_group" }; qd.WhereClause = String.Format("cm_group.groupuid = cm_logictree.groupid " + " and cm_group.DataSet = '{0}'", dataset.Name); IFdeCursor cursor = qd.Execute(false); IRowBuffer row = null; if ((row = cursor.NextRow()) != null) { //content int nPose = row.FieldIndex("content"); if (nPose != -1) { IBinaryBuffer bb = row.GetValue(nPose) as IBinaryBuffer; strContent = (byte[])bb.AsByteArray(); } } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return(null); } return(strContent); }
private void dataGridView1_MouseDoubleClick(object sender, MouseEventArgs e) { int featureId = int.Parse((sender as DataGridView).CurrentRow.Cells[0].Value.ToString()); IFeatureClass curFeatureClass = null; foreach (IFeatureClass fc in fcMap.Keys) { curFeatureClass = fc; IRowBuffer fdeRow = curFeatureClass.GetRow(featureId); if (fdeRow != null) { int nPos = fdeRow.FieldIndex("Geometry"); if (nPos != -1 && !fdeRow.IsNull(nPos)) { IPOI mp = fdeRow.GetValue(nPos) as IPOI; // 从库中读取值 IPoint pos = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ); pos.Position = mp.Position; pos.SpatialCRS = mp.SpatialCRS; IEulerAngle angle = new EulerAngle(); angle.Heading = 0; angle.Tilt = -60; angle.Roll = 0; this.axRenderControl1.Camera.LookAt2(pos, 3000, angle); this.axRenderControl1.FeatureManager.UnhighlightAll(); this.axRenderControl1.FeatureManager.HighlightFeature(curFeatureClass, int.Parse(fdeRow.GetValue(0).ToString()), System.Drawing.Color.Yellow); mp.ImageName = (strMediaPath + @"\png\lan.png"); IRenderPOI rpoi = this.axRenderControl1.ObjectManager.CreateRenderPOI(mp); rpoi.Highlight(System.Drawing.Color.Red); this.axRenderControl1.ObjectManager.DelayDelete(rpoi.Guid, 60000); } } } }
public static string GetString(IRowBuffer r, int nPos) { if (((r != null) && (nPos != -1)) && !r.IsNull(nPos)) { return(r.GetValue(nPos).ToString()); } return(""); }
public static IGeometry GetGeometry(IRowBuffer r, int nPos) { if (((r == null) || (nPos == -1)) || r.IsNull(nPos)) { return(null); } return(r.GetValue(nPos) as IGeometry); }
public static TopoClass GetTopoClassByFacClassCode(string facClassCode) { if (DF3DPipeCreateApp.App.TemplateLib == null) { return(null); } IFdeCursor o = null; IRowBuffer buffer = null; IQueryFilter filter = null; try { IFeatureDataSet fds = DF3DPipeCreateApp.App.TemplateLib.OpenFeatureDataset("DataSet_BIZ"); if (fds == null) { return(null); } IObjectClass oc = fds.OpenObjectClass("OC_Catalog"); if (oc == null) { return(null); } filter = new QueryFilterClass { WhereClause = string.Format("Code = '{0}'", facClassCode), SubFields = "TopoLayerId" }; o = oc.Search(filter, true); buffer = o.NextRow(); if (buffer != null) { if (buffer.IsNull(0)) { return(null); } return(FacilityInfoService.GetTopoClassByObjectId(buffer.GetValue(0).ToString())); } return(null); } catch (Exception ex) { return(null); } finally { if (o != null) { Marshal.ReleaseComObject(o); o = null; } if (buffer != null) { Marshal.ReleaseComObject(buffer); buffer = null; } } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { if (PickResult != null) { if (PickResult.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = PickResult as IFeatureLayerPickResult; int fid = flpr.FeatureId; IFeatureLayer fl = flpr.FeatureLayer; foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Guid.Equals(fl.FeatureClassId)) { IRowBuffer fdeRow = fc.GetRow(fid); int nPos = fdeRow.FieldIndex("Geometry"); switch (source) { case SOURCE.SELECT1: this.axRenderControl1.FeatureManager.HighlightFeature(fc, fid, System.Drawing.Color.Yellow); geo1.AddGeometry(fdeRow.GetValue(nPos) as IPolygon); drawLabel(IntersectPoint, "要素一", System.Drawing.Color.Yellow); break; case SOURCE.SELECT2: this.axRenderControl1.FeatureManager.HighlightFeature(fc, fid, System.Drawing.Color.Red); geo2.AddGeometry(fdeRow.GetValue(nPos) as IPolygon); drawLabel(IntersectPoint, "要素二", System.Drawing.Color.Yellow); break; } SelectObject obj = new SelectObject(); obj.FC = fc; obj.ID = fid; objToHide.Add(obj); } } // end foreach } } if (source == SOURCE.SELECT1 || source == SOURCE.SELECT2) { this.axRenderControl1.RcMouseClickSelect -= new _IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect); this.axRenderControl1.InteractMode = gviInteractMode.gviInteractNormal; } }
public static double GetDouble(IRowBuffer r, int nPos) { double result = 0.0; if (((r != null) && (nPos != -1)) && !r.IsNull(nPos)) { double.TryParse(r.GetValue(nPos).ToString(), out result); } return(result); }
public static int GetInt(IRowBuffer r, int nPos) { int result = 0; if (((r != null) && (nPos != -1)) && !r.IsNull(nPos)) { int.TryParse(r.GetValue(nPos).ToString(), out result); } return(result); }
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; } } }
public static void AddAndVisualizePipeData(IConnectionInfo ci, string geoColumnName, TreeList parentTree, Dictionary <string, string> pipeCatelog, Dictionary <string, IRowBuffer> pipeInfos, bool bNeedFly = false, bool bTempData = true) { try { if (ci == null || parentTree == null || pipeCatelog == null || pipeCatelog.Count == 0 || pipeInfos == null || pipeInfos.Count == 0) { return; } //获取要素类对照表:string:guid Dictionary <string, IFeatureClass> fcs = DataUtils.GetFeatureClass(ci); if (fcs == null || fcs.Count == 0) { return; } //获取要素类与设施类的关联:string:code,string:guid Dictionary <string, string> relation = DataUtils.GetRelation(ci, "DataSet_BIZ", "OC_FacilityClass"); if (relation == null || relation.Count == 0) { return; } foreach (KeyValuePair <string, string> kv in pipeCatelog) { string code = kv.Key.ToString(); string pcode = kv.Value.ToString(); if (!relation.ContainsKey(code) && pcode == "-1") { Dictionary <string, string> childRelation = FindChildRelationByPCode(code, pipeCatelog); if (childRelation == null || childRelation.Count == 0) { continue; } IRowBuffer row = pipeInfos[code]; string name = row.GetValue(row.FieldIndex("Name")).ToString(); Group g = new Group() { Name = name, CustomValue = row, Temp = bTempData }; g.OwnNode = parentTree.AppendNode(new object[] { g.Name }, (TreeListNode)null); g.Visible = true; VisualizePipeData(fcs, relation, geoColumnName, g, pipeCatelog, childRelation, pipeInfos, bNeedFly, bTempData); g.CollapseAll(); } } } catch (Exception ex) { } }
/// <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); } } }
private IModelPoint GetModel(IFeatureClass fc, string geoFieldName, int oid) { IModelPoint result = null; IRowBuffer row = fc.GetRow(oid); int num = row.FieldIndex(geoFieldName); if (num != -1) { result = (row.GetValue(num) as IModelPoint); } return(result); }
private void GetResultSet(IFeatureClass fc, IQueryFilter filter, DataTable dt) { if (fc != null) { IFdeCursor cursor = null; try { if (filter != null) { filter.PostfixClause = "order by oid asc"; } // 查找所有记录 cursor = fc.Search(filter, true); if (cursor != null) { dt.BeginLoadData(); IRowBuffer fdeRow = null; DataRow dr = null; while ((fdeRow = cursor.NextRow()) != null) { dr = dt.NewRow(); for (int i = 0; i < dt.Columns.Count; ++i) { string strColName = dt.Columns[i].ColumnName; int nPos = fdeRow.FieldIndex(strColName); if (nPos == -1 || fdeRow.IsNull(nPos)) { continue; } object v = fdeRow.GetValue(nPos); // 从库中读取值 dr[i] = v; } dt.Rows.Add(dr); } dt.EndLoadData(); } // 通过解析逻辑树获取GroupId对应的GroupName GroupId2LayerName(dt, fc.FeatureDataSet); } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } finally { if (cursor != null) { //Marshal.ReleaseComObject(cursor); cursor = null; } } } }
/// <summary> /// Returns the field value that at the specified <paramref name="index" /> for the <paramref name="source" />. /// </summary> /// <typeparam name="TValue">The type of the value.</typeparam> /// <param name="source">The row.</param> /// <param name="index">The field index.</param> /// <param name="fallbackValue">The default value.</param> /// <param name="value"> /// When this method returns, contains the value associat/ed with the specified /// index, if the index is found; otherwise, the default value for the type of the /// value parameter. This parameter is passed uninitialized. /// </param> /// <returns> /// Returns an <see cref="bool" /> representing <c>true</c> if the field index is valid; otherwise, false. /// </returns> public static bool TryGetValue <TValue>(this IRowBuffer source, int index, TValue fallbackValue, out TValue value) { try { value = source.GetValue(index, fallbackValue); return(true); } catch (Exception) { value = fallbackValue; return(false); } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { this.axRenderControl1.FeatureManager.UnhighlightAll(); // 置空 _buffer = null; _featureLayer = null; 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(); QueryFilter 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; } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } finally { } this.axRenderControl1.FeatureManager.HighlightFeature(_featureClass, fid, System.Drawing.Color.Yellow); EditGeometry(); } break; } } }
private void InitData() { try { this.cbxFacilityStyle.SelectedIndex = -1; this.listStyles.SelectedIndex = -1; DF3DFeatureClass dffc = CommonUtils.Instance().CurEditLayer; if (dffc == null) { return; } int count = SelectCollection.Instance().GetCount(false); if (count == 1) { HashMap hm = SelectCollection.Instance().GetSelectGeometrys(); if (hm != null && hm.Count == 1) { IRowBufferCollection rowBufferCollection = hm[dffc] as IRowBufferCollection; if (rowBufferCollection.Count == 1) { IRowBuffer rowBuffer = rowBufferCollection.Get(0); int index = rowBuffer.FieldIndex("StyleId"); if (index != -1 && !rowBuffer.IsNull(index)) { string styleId = rowBuffer.GetValue(index).ToString(); for (int i = 0; i < this.cbxFacilityStyle.Properties.Items.Count; i++) { FacStyleClass fsc = this.cbxFacilityStyle.Properties.Items[i] as FacStyleClass; if (fsc.ObjectId == styleId) { this.cbxFacilityStyle.SelectedIndex = i; this.listStyles.SelectedIndex = i; break; } } } } } } } catch (Exception ex) { } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { IPickResult pr = PickResult; if (pr == null) { return; } if (EventSender == gviMouseSelectMode.gviMouseSelectClick) { if (pr.Type == gviObjectType.gviObjectFeatureLayer) { // 高亮Polygon this.axRenderControl1.FeatureManager.UnhighlightAll(); IFeatureLayerPickResult flpr = pr as IFeatureLayerPickResult; fid = flpr.FeatureId; IFeatureLayer fl = flpr.FeatureLayer; foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Guid.Equals(fl.FeatureClassId)) { IRowBuffer fdeRow = fc.GetRow(fid); IFieldInfoCollection col = fdeRow.Fields; for (int i = 0; i < col.Count; ++i) { IFieldInfo info = col.Get(i); if (info.GeometryDef != null && info.GeometryDef.GeometryColumnType == gviGeometryColumnType.gviGeometryColumnPolyline) { int nPos = fdeRow.FieldIndex(info.Name); polyline = fdeRow.GetValue(nPos) as IPolyline; this.axRenderControl1.FeatureManager.HighlightFeature(fc, fid, System.Drawing.Color.Yellow); //获取路宽 nPos = fdeRow.FieldIndex("WIDTH"); //width = (double)fdeRow.GetValue(nPos); width = 10; } } } // end " if (fc.Guid.Equals(fl.FeatureClassId))" } // end "foreach (IFeatureClass fc in fcMap.Keys)" } } }
private void InitData() { try { foreach (DataRow dr in this._dt.Rows) { dr["FV"] = null; } DF3DFeatureClass dffc = CommonUtils.Instance().CurEditLayer; if (dffc == null) { return; } int count = SelectCollection.Instance().GetCount(false); if (count == 1) { HashMap hm = SelectCollection.Instance().GetSelectGeometrys(); if (hm != null && hm.Count == 1) { IRowBufferCollection rowBufferCollection = hm[dffc] as IRowBufferCollection; if (rowBufferCollection.Count == 1) { IRowBuffer rowBuffer = rowBufferCollection.Get(0); foreach (DataRow dr in this._dt.Rows) { IFieldInfo fi = dr["F"] as IFieldInfo; if (fi == null) { continue; } int index = rowBuffer.FieldIndex(fi.Name); if (index != -1) { dr["FV"] = rowBuffer.GetValue(index); } } } } } this.gridView1.RefreshData(); } catch (Exception ex) { } }
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; }
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; }
private void SpatialQuery() { DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } try { HashMap hashMap = new HashMap(); IRowBuffer buffer = null; IFdeCursor cursor = null; ISpatialFilter filter = null; IGeometry geo2D = this._drawTool.GetGeo(); if (geo2D != null && geo2D.GeometryType == gviGeometryType.gviGeometryPolygon) { IPolygon polygon = geo2D as IPolygon; if (polygon != null) { DF3DFeatureClass featureClassInfo = CommonUtils.Instance().CurEditLayer; if (featureClassInfo != null) { IFeatureClass featureClass = featureClassInfo.GetFeatureClass(); if (featureClass != null) { string typeName = featureClassInfo.GetFacilityClassName(); if (typeName == "PipeLine" || typeName == "PipeNode" || typeName == "PipeBuild" || typeName == "PipeBuild1") { filter = new SpatialFilterClass { GeometryField = "Shape", SpatialRel = gviSpatialRel.gviSpatialRelIntersects, Geometry = polygon.Clone2(gviVertexAttribute.gviVertexAttributeNone) }; } else { filter = new SpatialFilterClass { Geometry = polygon, GeometryField = "Geometry", SpatialRel = gviSpatialRel.gviSpatialRelEnvelope }; } filter.SubFields = featureClass.FidFieldName; cursor = featureClass.Search(filter, true); while ((buffer = cursor.NextRow()) != null) { int featureId = int.Parse(buffer.GetValue(0).ToString()); if (hashMap.Contains(featureClassInfo)) { System.Collections.Generic.List <int> list = hashMap[featureClassInfo] as System.Collections.Generic.List <int>; if (!list.Contains(featureId)) { list.Add(featureId); } } else { System.Collections.Generic.List <int> list2 = new System.Collections.Generic.List <int>(); if (!list2.Contains(featureId)) { list2.Add(featureId); } hashMap[featureClassInfo] = list2; } } } } } SelectCollection.Instance().UpdateSelection(hashMap); RenderControlEditServices.Instance().SetEditorPosition(SelectCollection.Instance().FcRowBuffersMap); this.Clear(); } if (buffer != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(buffer); } if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); } if (filter != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(filter); } } catch (Exception ex) { LoggingService.Error(ex.Message); } }
private void UpdateGeometry(EditParameters parameter) { try { DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } if (parameter != null) { System.Collections.Generic.Dictionary <DF3DFeatureClass, IRowBufferCollection> geometryMap = parameter.geometryMap; if (geometryMap != null) { CommandManagerServices.Instance().StartCommand(); FDECommand cmd = new FDECommand(false, true); foreach (DF3DFeatureClass current in geometryMap.Keys) { IRowBufferCollection rowBufferCollection = geometryMap[current]; IFeatureClass featureClass = current.GetFeatureClass(); if (featureClass.HasTemporal() && CommonUtils.Instance().EnableTemproalEdit) { int position = featureClass.GetFields().IndexOf(featureClass.FidFieldName); System.Collections.Generic.Dictionary <int, IRowBuffer> dictionary = new System.Collections.Generic.Dictionary <int, IRowBuffer>(); for (int i = 0; i < rowBufferCollection.Count; i++) { IRowBuffer rowBuffer = rowBufferCollection.Get(i); int key = (int)rowBuffer.GetValue(position); dictionary[key] = rowBuffer; } ITemporalManager temporalManager = featureClass.TemporalManager; ITemporalCursor temporalCursor = temporalManager.Search(new TemporalFilterClass { IdsFilter = dictionary.Keys.ToArray <int>() }); while (temporalCursor.MoveNext()) { bool flag = false; int currentId = temporalCursor.CurrentId; ITemporalInstanceCursor temporalInstances = temporalCursor.GetTemporalInstances(false); TemporalInstance temporalInstance; while ((temporalInstance = temporalInstances.NextInstance()) != null) { if (temporalInstance.StartDatetime == parameter.TemproalTime) { flag = true; temporalInstances.Update(dictionary[currentId]); break; } } System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalInstances); if (!flag) { temporalCursor.Insert(parameter.TemproalTime, dictionary[currentId]); } } app.Current3DMapControl.FeatureManager.RefreshFeatureClass(featureClass); System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalCursor); System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalManager); } else { CommonUtils.Instance().FdeUndoRedoManager.UpdateFeatures(featureClass, rowBufferCollection); } } CommandManagerServices.Instance().CallCommand(cmd); app.Workbench.UpdateMenu(); } } } catch (System.Runtime.InteropServices.COMException ex) { XtraMessageBox.Show(ex.Message); } catch (System.UnauthorizedAccessException) { XtraMessageBox.Show(StringParser.Parse("${res:Dataset_InsufficientPermission}")); } catch (System.Exception e) { LoggingService.Error(e.Message); } }
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); } } }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { try { if (PickResult != null) { if (PickResult.Type == gviObjectType.gviObjectFeatureLayer) { IFeatureLayerPickResult flpr = PickResult as IFeatureLayerPickResult; int fid = flpr.FeatureId; this.axRenderControl1.FeatureManager.HighlightFeature(_featureClass, fid, System.Drawing.Color.Yellow); ////////////////////////////////////////////////////////////////////////// // // GeometryConvert的代码添加在这里 // ////////////////////////////////////////////////////////////////////////// fidList.Clear(); fidList.Add(fid); IRowBuffer rowGC = _featureClass.GetRow(fidList[0]); int nPose = rowGC.FieldIndex("Geometry"); if (nPose == -1) { MessageBox.Show("不存在Geometry列"); return; } // 获取polygon IPolyline polylineGC = null; if (rowGC != null) { nPose = rowGC.FieldIndex("Geometry"); IGeometry geo = rowGC.GetValue(nPose) as IGeometry; if (geo.GeometryType == gviGeometryType.gviGeometryPolyline) { polylineGC = geo as IPolyline; } } if (polylineGC != null) { this.Text = "拾取成功"; } else { this.Text = "拾取失败"; } param = new PropertySet(); if (this.tabControl1.SelectedIndex == 0) { // 1.调接口构造模型 double innerRadius = double.Parse(this.numInnerRadius.Value.ToString()); param.SetProperty("InnerRadius", innerRadius); double outerRadius = double.Parse(this.numOuterRadius.Value.ToString()); param.SetProperty("OuterRadius", outerRadius); double deflection = double.Parse(this.numDeflection.Value.ToString()); param.SetProperty("Deflection", deflection); Color difColor = Color.FromArgb(Convert.ToInt32(DifColorBox.Text, 16)); param.SetProperty("DiffuseColor", difColor); Color speColor = Color.FromArgb(Convert.ToInt32(SpeColorBox.Text, 16)); param.SetProperty("SpecularColor", speColor); IModelPoint mp = null; IModel model = null; if (!paraModel.PolylineToPipeLine(polylineGC, param, out mp, out model)) { MessageBox.Show("拉管线出错!"); return; } //2、将模型及贴图写入osg文件 string modelName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".osg");//输出osg文件路径 model.WriteFile(modelName, null); //3、测试显示模型 mp.ModelName = modelName; IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, null, rootId); rmp.MouseSelectMask = gviViewportMask.gviViewNone; rmp.MaxVisibleDistance = 100000; this.axRenderControl1.Camera.LookAtEnvelope(mp.Envelope);//飞入 mpList.Add(rmp); } } } } catch (System.Exception ex) { if (ex.GetType().Name.Equals("UnauthorizedAccessException")) { MessageBox.Show("需要标准runtime授权"); } else { MessageBox.Show(ex.Message); } } }
/// <summary> /// 鼠标点击 拾取分析点 /// </summary> /// <param name="PickResult"></param> /// <param name="IntersectPoint"></param> /// <param name="Mask"></param> /// <param name="EventSender"></param> void g_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { if (IntersectPoint == null) { return; } if (EventSender.Equals(gviMouseSelectMode.gviMouseSelectClick)) { mouseClicks++; if (mouseClicks % 2 == 1) { this.label7.Text = "请鼠标点击选择目标点"; this.startX.Text = IntersectPoint.X.ToString(); this.startY.Text = IntersectPoint.Y.ToString(); this.startZ.Text = (IntersectPoint.Z + double.Parse(numZOffset.Value.ToString())).ToString(); axRenderControl1.MouseSelectMode = gviMouseSelectMode.gviMouseSelectClick | gviMouseSelectMode.gviMouseSelectMove; } else { this.label7.Text = "选择结束"; this.btnStartAnalyse.Enabled = true; axRenderControl1.InteractMode = gviInteractMode.gviInteractNormal; axRenderControl1.MouseSelectObjectMask = gviMouseSelectObjectMask.gviSelectNone; axRenderControl1.MouseSelectMode = gviMouseSelectMode.gviMouseSelectClick; axRenderControl1.RcMouseClickSelect -= new _IRenderControlEvents_RcMouseClickSelectEventHandler(g_RcMouseClickSelect); geoRegion = axRenderControl1.HighlightHelper.GetRegion(); //开始空间查询 try { this.label7.Text = "开始空间查询"; ISpatialFilter sfilter = new SpatialFilter(); sfilter.Geometry = geoRegion; sfilter.SpatialRel = gviSpatialRel.gviSpatialRelIntersects; sfilter.GeometryField = "footprint"; cursor = buildingFC.Search(sfilter, false); row = null; while ((row = cursor.NextRow()) != null) { int nfidpos = row.FieldIndex("Geometry"); if (nfidpos > -1) { geoInFC = row.GetValue(nfidpos) as IGeometry; } if (geoInFC != null) { //AddOcluder axRenderControl1.VisualAnalysis.AddOccluder(buildingFL, geoInFC); //highlight occluder int fidpos = row.FieldIndex("oid"); if (fidpos > -1) { axRenderControl1.FeatureManager.HighlightFeature(buildingFC, int.Parse(row.GetValue(fidpos).ToString()), System.Drawing.Color.Red); } } } } catch (System.Exception ex) { } finally { if (cursor != null) { //Marshal.ReleaseComObject(cursor); cursor = null; } } this.label7.Text = "正在视域分析中..."; //StartAnalyse axRenderControl1.VisualAnalysis.StartViewshedAnalyse(fde_point1, fde_point2, double.Parse(this.numHorizontalAngle.Value.ToString())); axRenderControl1.HighlightHelper.VisibleMask = 0; this.label7.Text = "分析结束"; } } else if (EventSender.Equals(gviMouseSelectMode.gviMouseSelectMove)) { this.endX.Text = IntersectPoint.X.ToString(); this.endY.Text = IntersectPoint.Y.ToString(); this.endZ.Text = IntersectPoint.Z.ToString(); fde_point1 = geoFactory.CreateGeometry(gviGeometryType.gviGeometryPoint, gviVertexAttribute.gviVertexAttributeZ) as IPoint; fde_point1.SetCoords(double.Parse(this.startX.Text), double.Parse(this.startY.Text), double.Parse(this.startZ.Text), 0, 0); fde_point2 = geoFactory.CreateGeometry(gviGeometryType.gviGeometryPoint, gviVertexAttribute.gviVertexAttributeZ) as IPoint; fde_point2.SetCoords(double.Parse(this.endX.Text), double.Parse(this.endY.Text), double.Parse(this.endZ.Text), 0, 0); axRenderControl1.HighlightHelper.SetSectorRegion(fde_point1, fde_point2, double.Parse(this.numHorizontalAngle.Value.ToString())); } }
private DataTable GetTextureInfo() { DataTable table = null; IFdeCursor cursor = null; IRowBuffer row = null; try { table = new DataTable("TextureInfo"); table.Columns.Add("Name", typeof(string)); table.Columns.Add("ObjectId", typeof(string)); table.Columns.Add("Thumbnail", typeof(object)); IFeatureDataSet fds = this._ds.OpenFeatureDataset("DataSet_BIZ"); if (fds == null) { return(null); } IObjectClass oc = fds.OpenObjectClass("OC_TextureInfo"); if (oc == null) { return(null); } IQueryFilter filter = new QueryFilterClass { WhereClause = "GroupId != '-1'", SubFields = "Name,ObjectId,Thumbnail", PostfixClause = "order by Name asc" }; cursor = oc.Search(filter, true); while ((row = cursor.NextRow()) != null) { DataRow dtRow = table.NewRow(); dtRow["Name"] = row.GetValue(0).ToString(); dtRow["ObjectId"] = row.GetValue(1).ToString(); if (!row.IsNull(2)) { try { IBinaryBuffer buffer2 = row.GetValue(2) as IBinaryBuffer; if (buffer2 != null) { MemoryStream stream = new MemoryStream(buffer2.AsByteArray()); dtRow["Thumbnail"] = Image.FromStream(stream); } } catch (Exception exception) { } } table.Rows.Add(dtRow); } return(table); } catch (Exception exception) { return(null); } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } } }
private void InitialView() { try { IRowBuffer myRow = fc.GetRow(fid); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { int iRowIndex = -1; IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } if (fieldinfo.FieldType == gviFieldType.gviFieldGeometry) { if (myRow.IsNull(i)) { iRowIndex = this.dgv_FieldValue.Rows.Add(new object[] { fieldinfo.Name, null }); continue; } IGeometry geo = myRow.GetValue(i) as IGeometry; string geoValue = null; if (geo != null) { switch (geo.GeometryType) { case gviGeometryType.gviGeometryModelPoint: geoValue = "ModelPoint"; break; case gviGeometryType.gviGeometryPoint: geoValue = "Point"; break; case gviGeometryType.gviGeometryMultiPoint: geoValue = "MultiPoint"; break; case gviGeometryType.gviGeometryPolyline: geoValue = "Polyline"; break; case gviGeometryType.gviGeometryMultiPolyline: geoValue = "MultiPolyline"; break; case gviGeometryType.gviGeometryPolygon: geoValue = "Polygon"; break; case gviGeometryType.gviGeometryMultiPolygon: geoValue = "MultiPolygon"; break; } } iRowIndex = this.dgv_FieldValue.Rows.Add(new object[] { fieldinfo.Name, geoValue }); } else if (fieldinfo.FieldType == gviFieldType.gviFieldFID) { iRowIndex = this.dgv_FieldValue.Rows.Add(new object[] { fieldinfo.Name, myRow.GetValue(i) }); } else { IDomain fieldDomain = fieldinfo.Domain; if (fieldDomain != null && fieldDomain.DomainType == gviDomainType.gviDomainCodedValue) { DataGridViewComboBoxCell comCell = new DataGridViewComboBoxCell(); comCell.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; comCell.Items.Clear(); comCell.Items.Add(""); Dictionary <object, string> codeValue = this.GetDomainCodeValuePair(fieldDomain); comCell.Items.AddRange(codeValue.Values.ToArray()); iRowIndex = this.dgv_FieldValue.Rows.Add(); DataGridViewRow myViewRow = this.dgv_FieldValue.Rows[iRowIndex]; myViewRow.Cells[1] = comCell; object oCodeValue = myRow.GetValue(i); if (codeValue.ContainsKey(oCodeValue)) { myViewRow.SetValues(new object[] { fieldinfo.Name, codeValue[oCodeValue] }); } else { myViewRow.SetValues(new object[] { fieldinfo.Name, oCodeValue }); } } else { iRowIndex = this.dgv_FieldValue.Rows.Add(new object[] { fieldinfo.Name, myRow.GetValue(i) }); } } this.dgv_FieldValue.Rows[iRowIndex].Tag = new EditField(fieldinfo, i); } this.dgv_FieldValue.Tag = myRow; } catch (COMException comEx) { MessageBox.Show(comEx.Message); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } finally { } }