private DataTable DoStats() { DataTable dtResult = new DataTable(); dtResult.TableName = "DataStats"; dtResult.Columns.AddRange(new DataColumn[] { new DataColumn("PIPELINETYPE"), new DataColumn("FIELDNAME"), new DataColumn("PVALUE"), new DataColumn("LENGTH", typeof(double)), new DataColumn("TOTALLENGTH", typeof(double)) }); string localDataPath = SystemInfo.Instance.LocalDataPath; string tmpPath = ""; tmpPath = Path.Combine(localDataPath, "Stats"); if (!Directory.Exists(tmpPath)) { Directory.CreateDirectory(tmpPath); } string filePath = tmpPath + "\\全库3D管线统计.xml"; bool bHaveXml = false; if (File.Exists(filePath)) { dtResult.ReadXml(filePath); if (dtResult != null && dtResult.Rows.Count != 0) { bHaveXml = true; return(dtResult); } else { bHaveXml = false; } } List <MajorClass> list = LogicDataStructureManage3D.Instance.GetAllMajorClass(); foreach (MajorClass mc in list) { string[] arrFc3DId = mc.Fc3D.Split(';'); if (arrFc3DId == null) { continue; } double majorclasslength = 0.0; int indexStart = dtResult.Rows.Count; foreach (SubClass sc in mc.SubClasses) { double subclasslength = 0.0; bool bHave = false; foreach (string fc3DId in arrFc3DId) { DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(fc3DId); if (dffc == null) { continue; } FacilityClass facc = dffc.GetFacilityClass(); IFeatureClass fc = dffc.GetFeatureClass(); if (fc == null || facc == null || facc.Name != "PipeLine") { continue; } DFDataConfig.Class.FieldInfo fiPipeLength = facc.GetFieldInfoBySystemName("PipeLength"); if (fiPipeLength == null) { continue; } int indexPipeLength = fc.GetFields().IndexOf(fiPipeLength.Name); if (indexPipeLength == -1) { continue; } IQueryFilter filter = new QueryFilter(); filter.SubFields = fiPipeLength.Name; filter.WhereClause = "GroupId = " + sc.GroupId; int count = fc.GetCount(filter); if (count == 0) { continue; } int loop = (int)Math.Ceiling(count / 800.0); for (int k = 1; k <= loop; k++) { if (k == 1) { filter.ResultBeginIndex = 0; } else { filter.ResultBeginIndex = (k - 1) * 800; } filter.ResultLimit = 800; IFdeCursor cur = null; IRowBuffer rowBuf = null; try { cur = fc.Search(filter, true); while ((rowBuf = cur.NextRow()) != null) { if (!rowBuf.IsNull(0)) { object tempobj = rowBuf.GetValue(0); double dtemp = 0.0; if (tempobj != null && double.TryParse(tempobj.ToString(), out dtemp)) { subclasslength += dtemp; bHave = true; } } } } catch { } finally { if (cur != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cur); cur = null; } if (rowBuf != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(rowBuf); rowBuf = null; } } } } if (bHave) { DataRow dr = dtResult.NewRow(); dr["PIPELINETYPE"] = mc; dr["FIELDNAME"] = ""; dr["PVALUE"] = sc; dr["LENGTH"] = subclasslength.ToString("0.00"); majorclasslength += subclasslength; dtResult.Rows.Add(dr); } } int indexEnd = dtResult.Rows.Count; for (int i = indexStart; i < indexEnd; i++) { DataRow dr = dtResult.Rows[i]; dr["TOTALLENGTH"] = majorclasslength.ToString("0.00"); } } if (!bHaveXml) { dtResult.WriteXml(filePath); } return(dtResult); }
private void LineQuery() { IFdeCursor cursor = null; IRowBuffer row = null; try { IGeometry geo = this._drawTool.GetGeo(); if (geo == null || geo.GeometryType != gviGeometryType.gviGeometryPolyline) { return; } IPolyline line = geo as IPolyline; IPolyline l = line.Clone2(gviVertexAttribute.gviVertexAttributeNone) as IPolyline; if (l.Length > 500) { XtraMessageBox.Show("横断面线超过500米,分析效率很低,请重新绘制", "提示"); return; } WaitForm.Start("正在进行横断面分析...", "请稍后"); DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } List <MajorClass> list = LogicDataStructureManage3D.Instance.GetAllMajorClass(); if (list == null) { return; } string road1 = ""; string road2 = ""; bool bAlert = false; double hmax = double.MinValue; double hmin = double.MaxValue; List <PPLine> pplines = new List <PPLine>(); foreach (MajorClass mc in list) { foreach (SubClass sc in mc.SubClasses) { if (!sc.Visible3D) { continue; } string[] arrFc3DId = mc.Fc3D.Split(';'); if (arrFc3DId == null) { continue; } foreach (string fc3DId in arrFc3DId) { DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(fc3DId); if (dffc == null) { continue; } IFeatureClass fc = dffc.GetFeatureClass(); FacilityClass fac = dffc.GetFacilityClass(); if (fc == null || fac == null || fac.Name != "PipeLine") { continue; } IFieldInfoCollection fields = fc.GetFields(); int indexShape = fields.IndexOf("Shape"); if (indexShape == -1) { continue; } int indexFootPrint = fields.IndexOf("FootPrint"); if (indexFootPrint == -1) { continue; } DFDataConfig.Class.FieldInfo fiDiameter = fac.GetFieldInfoBySystemName("Diameter"); if (fiDiameter == null) { continue; } int indexDiameter = fields.IndexOf(fiDiameter.Name); if (indexDiameter == -1) { continue; } DFDataConfig.Class.FieldInfo fiRoad = fac.GetFieldInfoBySystemName("Road"); int indexRoad = -1; if (fiRoad != null) { indexRoad = fields.IndexOf(fiRoad.Name); } DFDataConfig.Class.FieldInfo fiHLB = fac.GetFieldInfoBySystemName("HLB"); int indexHLB = -1; if (fiHLB != null) { indexHLB = fields.IndexOf(fiHLB.Name); } int indexClassify = fields.IndexOf(mc.ClassifyField); ISpatialFilter pSpatialFilter = new SpatialFilter(); pSpatialFilter.Geometry = l; pSpatialFilter.GeometryField = "FootPrint"; pSpatialFilter.SpatialRel = gviSpatialRel.gviSpatialRelIntersects; pSpatialFilter.WhereClause = mc.ClassifyField + " = '" + sc.Name + "'"; cursor = fc.Search(pSpatialFilter, false); while ((row = cursor.NextRow()) != null) { if (indexRoad != -1 && !row.IsNull(indexRoad)) { if (road2 == "") { road1 = row.GetValue(indexRoad).ToString(); road2 = row.GetValue(indexRoad).ToString(); } else { road1 = row.GetValue(indexRoad).ToString(); if (road1 != road2) { if (!bAlert) { XtraMessageBox.Show("横断面线跨越多条道路,当前只绘制在【" + road2 + "】上的管线横断面图。", "提示"); bAlert = true; } continue; } } } double startSurfHeight = double.MaxValue; double endSurfHeight = double.MaxValue; if (!app.Current3DMapControl.Terrain.IsRegistered) { DFDataConfig.Class.FieldInfo fiStartSurfHeight = fac.GetFieldInfoBySystemName("StartSurfHeight"); if (fiStartSurfHeight == null) { continue; } int indexStartSurfHeight = fields.IndexOf(fiStartSurfHeight.Name); if (indexStartSurfHeight == -1) { continue; } DFDataConfig.Class.FieldInfo fiEndSurfHeight = fac.GetFieldInfoBySystemName("EndSurfHeight"); if (fiEndSurfHeight == null) { continue; } int indexEndSurfHeight = fields.IndexOf(fiEndSurfHeight.Name); if (indexEndSurfHeight == -1) { continue; } if (!row.IsNull(indexStartSurfHeight)) { startSurfHeight = double.Parse(row.GetValue(indexStartSurfHeight).ToString()); } if (!row.IsNull(indexEndSurfHeight)) { endSurfHeight = double.Parse(row.GetValue(indexEndSurfHeight).ToString()); } } if (!row.IsNull(indexShape) && !row.IsNull(indexFootPrint)) { object objFootPrint = row.GetValue(indexFootPrint); object objShape = row.GetValue(indexShape); if (objFootPrint is IPolyline && objShape is IPolyline) { IPolyline polylineFootPrint = objFootPrint as IPolyline; IPolyline polylineShape = objShape as IPolyline; IGeometry geoIntersect = (geo as ITopologicalOperator2D).Intersection2D(polylineFootPrint); if (geoIntersect == null) { continue; } PPLine ppline = new PPLine(); if (indexClassify == -1 || row.IsNull(indexClassify)) { ppline.facType = mc.Name; } else { ppline.facType = row.GetValue(indexClassify).ToString(); } if (!row.IsNull(indexDiameter)) { string diameter = row.GetValue(indexDiameter).ToString(); if (diameter.Trim() == "") { continue; } ppline.dia = diameter; int indexDia = diameter.IndexOf('*'); if (indexDia != -1) { ppline.isrect = true; int iDia1; bool bDia1 = int.TryParse(diameter.Substring(0, indexDia), out iDia1); if (!bDia1) { continue; } int iDia2; bool bDia2 = int.TryParse(diameter.Substring(indexDia + 1, diameter.Length - indexDia - 1), out iDia2); if (!bDia2) { continue; } ppline.gj.Add(iDia1); ppline.gj.Add(iDia2); } else { ppline.isrect = false; int iDia; bool bDia = int.TryParse(diameter, out iDia); if (!bDia) { continue; } ppline.gj.Add(iDia); ppline.gj.Add(iDia); } } int hlb = 0; if (indexHLB != -1 && !row.IsNull(indexHLB)) { string strhlb = row.GetValue(indexHLB).ToString(); if (strhlb.Contains("内")) { hlb = 1; } else if (strhlb.Contains("外")) { hlb = -1; } else { hlb = 0; } ppline.hlb = hlb; } #region 交点为一个 if (geoIntersect.GeometryType == gviGeometryType.gviGeometryPoint) //交点为1个 { IPoint ptIntersect = geoIntersect as IPoint; ppline.interPoint = new PPPoint(ptIntersect.X, ptIntersect.Y, ptIntersect.Z); ppline.clh = GetInterPointHeight(ptIntersect, polylineShape, polylineFootPrint); if (ppline.clh > hmax) { hmax = ppline.clh; } if (ppline.clh < hmin) { hmin = ppline.clh; } if (app.Current3DMapControl.Terrain.IsRegistered) { ppline.cgh = app.Current3DMapControl.Terrain.GetElevation(ptIntersect.X, ptIntersect.Y, Gvitech.CityMaker.RenderControl.gviGetElevationType.gviGetElevationFromDatabase); } else { ppline.cgh = startSurfHeight + (endSurfHeight - startSurfHeight) * Math.Sqrt((polylineFootPrint.StartPoint.X - ptIntersect.X) * (polylineFootPrint.StartPoint.X - ptIntersect.X) + (polylineFootPrint.StartPoint.Y - ptIntersect.Y) * (polylineFootPrint.StartPoint.Y - ptIntersect.Y)) / polylineFootPrint.Length; } if (ppline.cgh > hmax) { hmax = ppline.cgh; } if (ppline.cgh < hmin) { hmin = ppline.cgh; } // 辅助画图 ppline.startPt = new PPPoint(l.StartPoint.X, l.StartPoint.Y, l.StartPoint.Z); pplines.Add(ppline); } #endregion #region 交点为多个 else if (geoIntersect.GeometryType == gviGeometryType.gviGeometryMultiPoint) //交点为多个 { IMultiPoint multiPts = geoIntersect as IMultiPoint; for (int m = 0; m < multiPts.GeometryCount; m++) { IPoint ptIntersect = multiPts.GetPoint(m); ppline.interPoint = new PPPoint(ptIntersect.X, ptIntersect.Y, ptIntersect.Z); ppline.clh = GetInterPointHeight(ptIntersect, polylineShape, polylineFootPrint); if (ppline.clh > hmax) { hmax = ppline.clh; } if (ppline.clh < hmin) { hmin = ppline.clh; } if (app.Current3DMapControl.Terrain.IsRegistered) { ppline.cgh = app.Current3DMapControl.Terrain.GetElevation(ptIntersect.X, ptIntersect.Y, Gvitech.CityMaker.RenderControl.gviGetElevationType.gviGetElevationFromDatabase); } else { ppline.cgh = startSurfHeight + (endSurfHeight - startSurfHeight) * Math.Sqrt((polylineFootPrint.StartPoint.X - ptIntersect.X) * (polylineFootPrint.StartPoint.X - ptIntersect.X) + (polylineFootPrint.StartPoint.Y - ptIntersect.Y) * (polylineFootPrint.StartPoint.Y - ptIntersect.Y)) / polylineFootPrint.Length; } if (ppline.cgh > hmax) { hmax = ppline.cgh; } if (ppline.cgh < hmin) { hmin = ppline.cgh; } // 辅助画图 ppline.startPt = new PPPoint(l.StartPoint.X, l.StartPoint.Y, l.StartPoint.Z); pplines.Add(ppline); } } #endregion else { continue; } } } } } } } WaitForm.Stop(); if (pplines.Count < 2) { XtraMessageBox.Show("相交管线少于2个", "提示"); return; } pplines.Sort(new PPLineCompare()); double spacesum = 0.0; for (int i = 1; i < pplines.Count; i++) { PPLine line1 = pplines[i - 1]; PPLine line2 = pplines[i]; line2.space = Math.Sqrt((line1.interPoint.X - line2.interPoint.X) * (line1.interPoint.X - line2.interPoint.X) + (line1.interPoint.Y - line2.interPoint.Y) * (line1.interPoint.Y - line2.interPoint.Y)); spacesum += line2.space; } ; var str1 = (pplines[0].interPoint.X / 1000).ToString("0.00"); var str2 = (pplines[0].interPoint.Y / 1000).ToString("0.00"); string mapNum = str2 + "-" + str1; string mapName = SystemInfo.Instance.SystemFullName + "横断面图"; FrmSectionAnalysis dialog = new FrmSectionAnalysis("横断面分析结果", 0); dialog.SetInfo(mapName, mapNum, pplines, hmax, hmin, spacesum, road2); dialog.Show(); } catch (Exception ex) { WaitForm.Stop(); } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } } }
private ITableLabel DrawTableLabel(IRowBuffer row, IPoint point) { // 创建一个有3行2列的TableLabel ITableLabel tableLabel = this.axRenderControl1.ObjectManager.CreateTableLabel(row.FieldCount, 2, rootId); // 设定表头文字 tableLabel.TitleText = "瓦片信息展示"; IFieldInfoCollection fieldCols = row.Fields; for (int k = 0; k < row.FieldCount; k++) { tableLabel.SetRecord(k, 0, fieldCols.Get(k).Name); tableLabel.SetRecord(k, 1, row.GetValue(k).ToString()); } //标牌的位置 tableLabel.Position = point; // 列宽度 tableLabel.SetColumnWidth(0, 100); tableLabel.SetColumnWidth(1, 100); // 表的边框颜色 tableLabel.BorderColor = System.Drawing.Color.White; // 表的边框的宽度 tableLabel.BorderWidth = 2; // 表的背景色 tableLabel.TableBackgroundColor = System.Drawing.Color.Gray; // 标题背景色 tableLabel.TitleBackgroundColor = System.Drawing.Color.Red; // 第一列文本样式 TextAttribute headerTextAttribute = new TextAttribute(); headerTextAttribute.TextColor = System.Drawing.Color.White; headerTextAttribute.OutlineColor = System.Drawing.Color.Red; headerTextAttribute.Font = "黑体"; headerTextAttribute.Bold = true; headerTextAttribute.MultilineJustification = gviMultilineJustification.gviMultilineLeft; tableLabel.SetColumnTextAttribute(0, headerTextAttribute); // 第二列文本样式 TextAttribute contentTextAttribute = new TextAttribute(); contentTextAttribute.TextColor = System.Drawing.Color.Black; contentTextAttribute.OutlineColor = System.Drawing.Color.Red; contentTextAttribute.Font = "黑体"; contentTextAttribute.Bold = false; contentTextAttribute.MultilineJustification = gviMultilineJustification.gviMultilineLeft; tableLabel.SetColumnTextAttribute(1, contentTextAttribute); // 标题文本样式 TextAttribute capitalTextAttribute = new TextAttribute(); capitalTextAttribute.TextColor = System.Drawing.Color.White; capitalTextAttribute.OutlineColor = System.Drawing.Color.Gray; capitalTextAttribute.Font = "华文新魏"; capitalTextAttribute.TextSize = 14; capitalTextAttribute.MultilineJustification = gviMultilineJustification.gviMultilineCenter; capitalTextAttribute.Bold = true; tableLabel.TitleTextAttribute = capitalTextAttribute; return(tableLabel); }
protected override void OnClick() { // // TODO: Sample code showing how to access button host // #region Get Shapefile // Ask user to browse to a shapefile IGxObject openedFile = commonFunctions.OpenShapefile("Select your Fissure Waypoint Shapefile"); if (openedFile == null) { return; } // Open the file as an IFeatureClass IWorkspaceFactory wsFact = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace ws = wsFact.OpenFromFile(openedFile.Parent.FullName, 0) as IFeatureWorkspace; string path = @"C:\tmp\config.txt"; if (!File.Exists(path)) { MessageBox.Show("Missing the config File !"); return; } IFeatureClass fissureWaypoints = ws.OpenFeatureClass(openedFile.Name); // Make sure user selected a point featureclass if (fissureWaypoints.ShapeType != esriGeometryType.esriGeometryPoint) { MessageBox.Show("The shapefile you selected does not contain points. Try again."); return; } // Make sure that the Coordinate System is set IGeoDataset gDs = fissureWaypoints as IGeoDataset; IGeoDatasetSchemaEdit schemaEditor = gDs as IGeoDatasetSchemaEdit; ISpatialReferenceFactory2 spaRefFact = new SpatialReferenceEnvironmentClass(); IProjectedCoordinateSystem projCs = spaRefFact.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_NAD1983UTM_12N); schemaEditor.AlterSpatialReference(projCs); // Put all the points into a cursor IFeatureCursor sourcePoints = fissureWaypoints.Search(null, false); #endregion #region Prepare for Loop // Get a reference to the Stations featureclass in EarthFissure SDE database IWorkspace sdeWs = commonFunctions.OpenFissureWorkspace(); if (sdeWs == null) { return; } IFeatureClass stations = commonFunctions.OpenFeatureClass(sdeWs, "Stations"); // Get a reference to the Fissure Info table in the SDE database ITable fissInfoTable = commonFunctions.OpenTable(sdeWs, "FissureStationDescription"); // Get a reference to the SysInfo table for spinning up IDs sysInfo fissDbInfo = new sysInfo(sdeWs); // Get field indexes Dictionary <string, int> stationIndexes = GetFieldIndexes(stations as ITable); Dictionary <string, int> infoIndexes = GetFieldIndexes(fissInfoTable); Dictionary <string, int> sourceIndexes = GetFieldIndexes(fissureWaypoints as ITable); // Need a geographic coordinate system in the loop IGeographicCoordinateSystem geoCs = spaRefFact.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_NAD1983); // Setup the ProgressBar //setupProgressBar(fissureWaypoints.FeatureCount(null)); #endregion #region Perform Loop // Start an edit session IWorkspaceEdit wsEditor = sdeWs as IWorkspaceEdit; wsEditor.StartEditing(false); wsEditor.StartEditOperation(); try { // Get Insert Cursors IFeatureCursor stationInsert = stations.Insert(true); ICursor stationInfoInsert = fissInfoTable.Insert(true); // Loop through the source points, appending appropriately to both tables. IFeature sourcePoint = sourcePoints.NextFeature(); while (sourcePoint != null) { // Get the new station's identifier string stationID = "FIS.StationPoints." + fissDbInfo.GetNextIdValue("StationPoints"); // Get the new station description entry's identifier string descriptionID = "FIS.FissureStationDescription." + fissDbInfo.GetNextIdValue("FissureStationDescription"); // Get the Lat/Long values for the new point IGeometry locGeom = sourcePoint.ShapeCopy as IGeometry; locGeom.Project(geoCs); IPoint locPoint = locGeom as IPoint; // Make the new StationPoint IFeatureBuffer newStation = stations.CreateFeatureBuffer(); newStation.set_Value(stationIndexes["Stations_ID"], stationID); newStation.set_Value(stationIndexes["FieldID"], ""); newStation.set_Value(stationIndexes["Label"], ""); newStation.set_Value(stationIndexes["Symbol"], sourcePoint.get_Value(sourceIndexes["Waypoint_T"])); newStation.set_Value(stationIndexes["PlotAtScale"], 24000); newStation.set_Value(stationIndexes["LocationConfidenceMeters"], sourcePoint.get_Value(sourceIndexes["Horz_Prec"])); newStation.set_Value(stationIndexes["MapY"], locPoint.Y); newStation.set_Value(stationIndexes["MapX"], locPoint.X); newStation.set_Value(stationIndexes["DataSourceID"], ""); newStation.Shape = sourcePoint.ShapeCopy; stationInsert.InsertFeature(newStation); // Make the new FissureDescription IRowBuffer newDescription = fissInfoTable.CreateRowBuffer(); newDescription.set_Value(infoIndexes["stationid"], stationID); newDescription.set_Value(infoIndexes["dateofobservation"], sourcePoint.get_Value(sourceIndexes["Date_of_th"])); newDescription.set_Value(infoIndexes["timeofobservation"], sourcePoint.get_Value(sourceIndexes["Time_of_th"])); newDescription.set_Value(infoIndexes["surfaceexpression"], sourcePoint.get_Value(sourceIndexes["Surface_Ex"])); newDescription.set_Value(infoIndexes["displacement"], sourcePoint.get_Value(sourceIndexes["Displaceme"])); newDescription.set_Value(infoIndexes["surfacewidth"], sourcePoint.get_Value(sourceIndexes["Surface_Wi"])); newDescription.set_Value(infoIndexes["fissuredepth"], sourcePoint.get_Value(sourceIndexes["Fissure_De"])); newDescription.set_Value(infoIndexes["vegetation"], sourcePoint.get_Value(sourceIndexes["Vegetation"])); newDescription.set_Value(infoIndexes["fissureshape"], sourcePoint.get_Value(sourceIndexes["Fissure_Sh"])); newDescription.set_Value(infoIndexes["linecontinuity"], string.IsNullOrEmpty(sourcePoint.get_Value(sourceIndexes["Line_Conti"]).ToString().Trim()) ? DBNull.Value : sourcePoint.get_Value(sourceIndexes["Line_Conti"])); newDescription.set_Value(infoIndexes["datafile"], sourcePoint.get_Value(sourceIndexes["Datafile"])); newDescription.set_Value(infoIndexes["locationwrtfissure"], sourcePoint.get_Value(sourceIndexes["Location_w"])); newDescription.set_Value(infoIndexes["vegetationtype"], sourcePoint.get_Value(sourceIndexes["Vegetatio2"])); newDescription.set_Value(infoIndexes["fissdescription_id"], descriptionID); stationInfoInsert.InsertRow(newDescription); // Iterate sourcePoint = sourcePoints.NextFeature(); // progress.PerformStep(); } // Done. Save edits. wsEditor.StopEditOperation(); wsEditor.StopEditing(true); } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); wsEditor.StopEditOperation(); wsEditor.StopEditing(false); } finally { // progress.Visible = false; } #endregion ArcMap.Application.CurrentTool = null; }
public void SetCamera(IFeatureClass fc, int beginOid) { // 获取外包框进行定位 double[] extent = new double[7]; int i = 0; int endOid = GetMaxOID(fc); QueryFilter filter = new QueryFilter(); filter.WhereClause = string.Format("oid > {0} and oid <= {1}", beginOid, endOid); IRowBuffer fdeRow = null; IFdeCursor cursor = fc.Search(filter, true); while ((fdeRow = cursor.NextRow()) != null) { int nPos = fdeRow.FieldIndex("Geometry"); if (nPos == -1 || fdeRow.IsNull(nPos)) { continue; } IGeometry geo = fdeRow.GetValue(nPos) as IGeometry; if (geo != null) { double[] ev = new double[7]; ev[0] = geo.Envelope.MinX; ev[1] = geo.Envelope.MaxX; ev[2] = geo.Envelope.MinY; ev[3] = geo.Envelope.MaxY; ev[4] = geo.Envelope.MinZ; ev[5] = geo.Envelope.MaxZ; double dis = (geo.Envelope.Width > geo.Envelope.Height) ? geo.Envelope.Width : geo.Envelope.Height; dis = (dis > geo.Envelope.Depth) ? dis : geo.Envelope.Depth; ev[6] = dis * 2; if (i == 0) { extent[0] = ev[0]; extent[1] = ev[1]; extent[2] = ev[2]; extent[3] = ev[3]; extent[4] = ev[4]; extent[5] = ev[5]; extent[6] = ev[6]; } else { extent[0] = (ev[0] < extent[0]) ? ev[0] : extent[0]; extent[1] = (ev[1] > extent[1]) ? ev[1] : extent[1]; extent[2] = (ev[2] < extent[2]) ? ev[2] : extent[2]; extent[3] = (ev[3] > extent[3]) ? ev[3] : extent[3]; extent[4] = (ev[4] < extent[4]) ? ev[4] : extent[4]; extent[5] = (ev[5] > extent[5]) ? ev[5] : extent[5]; extent[6] = (ev[6] > extent[6]) ? ev[6] : extent[6]; } ++i; } nPos = fdeRow.FieldIndex("oid"); if (nPos == -1 || fdeRow.IsNull(nPos)) { continue; } int nFid = int.Parse(fdeRow.GetValue(0).ToString()); CommonEntity.RenderEntity.FeatureManager.HighlightFeature(fc, nFid, System.Drawing.Color.Yellow); } //Marshal.ReleaseComObject(cursor); if (extent != null) { double x = (extent[0] + extent[1]) / 2.0; double y = (extent[2] + extent[3]) / 2.0; double z = (extent[4] + extent[5]) / 2.0; double distance = 300; if (extent.Length == 7) { distance = extent[6]; } IVector3 center = new Vector3(); center.Set(x, y, z); IEulerAngle angle = new EulerAngle(); angle.Set(0, -50, 0); CommonEntity.RenderEntity.Camera.LookAt(center, distance, angle); } }
public int QueryValues(IRowBuffer Row) { try { if (m_sbuffer == null) return -1; for (int i = 0; i < m_fieldMap.GetLength(0); i++) { //HIGHLIGHT: 2.2 QueryValues - field map interpretation if (m_fieldMap.GetValue(i).Equals(-1)) continue; IField valField = m_fields.get_Field(i); char parse = m_sbuffer[m_sbuffer.Length - 1]; switch (valField.Type) { case esriFieldType.esriFieldTypeInteger: case esriFieldType.esriFieldTypeDouble: case esriFieldType.esriFieldTypeSmallInteger: case esriFieldType.esriFieldTypeSingle: Row.set_Value(i, Convert.ToInt32(parse)); //get ascii code # for the character break; case esriFieldType.esriFieldTypeString: Row.set_Value(i, parse.ToString()); break; } } return m_iInterate; //HIGHLIGHT: 2.3 QueryValues - return OID } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); return -1; } }
private void InsertFeatures(object param) { DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } EditParameters editParameters = (EditParameters)param; if (editParameters == null) { return; } System.Collections.Generic.Dictionary <DF3DFeatureClass, IRowBufferCollection> geometryMap = editParameters.geometryMap; if (geometryMap != null) { CommandManagerServices.Instance().StartCommand(); FDECommand fDECommand = new FDECommand(true, true); int nTotalCount = editParameters.nTotalCount; int num = 0; //System.IAsyncResult asyncResult = MainFrmService.ResultSetPanel.BeginInvoke(this._clearSelection); //MainFrmService.ResultSetPanel.EndInvoke(asyncResult); foreach (DF3DFeatureClass current in geometryMap.Keys) { if (this._bgWorker.CancellationPending) { break; } IFeatureClass featureClass = current.GetFeatureClass(); IRowBufferCollection rowBufferCollection = new RowBufferCollectionClass(); IRowBufferCollection rowBufferCollection2 = geometryMap[current]; int num2 = 0; while (num2 < rowBufferCollection2.Count && !this._bgWorker.CancellationPending) { this._manualResult.WaitOne(); System.Threading.Thread.Sleep(1); IRowBuffer value = rowBufferCollection2.Get(num2); rowBufferCollection.Add(value); num++; string userState = string.Format(StringParser.Parse("${res:feature_progress_finished}"), num, nTotalCount); int percentProgress = num * 100 / nTotalCount; this._bgWorker.ReportProgress(percentProgress, userState); num2++; } if (rowBufferCollection.Count > 0) { CommonUtils.Instance().FdeUndoRedoManager.InsertFeatures(featureClass, rowBufferCollection); //object[] args = new object[] //{ // current, // rowBufferCollection2, // true, // false //}; //asyncResult = MainFrmService.ResultSetPanel.BeginInvoke(this._InsertSelection, args); //MainFrmService.ResultSetPanel.EndInvoke(asyncResult); rowBufferCollection.Clear(); } } fDECommand.SetSelectionMap(); CommandManagerServices.Instance().CallCommand(fDECommand); app.Workbench.UpdateMenu(); } }
/// <summary> /// Allows writing additional project-specific attributes such as /// - operator /// - correction status /// - work unit / release cycle / model id /// </summary> /// <param name="issueWriter"></param> /// <param name="rowBuffer"></param> /// <param name="qualityCondition"></param> /// <param name="qaError"></param> protected abstract void WriteAttributesCore( [NotNull] IssueDatasetWriter issueWriter, [NotNull] IRowBuffer rowBuffer, [NotNull] QualityCondition qualityCondition, [NotNull] QaError qaError);
private void MovingModel(double X, double Y, double Z) { 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) { int num = rowBuffer.FieldIndex(featureClassInfo.GetFeatureClass().FidFieldName); if (num != -1) { int arg_87_0 = (int)rowBuffer.GetValue(num); } int num2 = rowBuffer.FieldIndex(featureClassInfo.GetFeatureLayer().GeometryFieldName); if (num2 != -1) { IGeometry geometry = rowBuffer.GetValue(num2) as IGeometry; if (geometry != null) { ITransform transform = geometry as ITransform; if (geometry != null && transform != null) { if (geometry.HasZ()) { transform.Move3D(X, Y, Z); } else { transform.Move2D(X, Y); } rowBuffer.SetValue(num2, 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.Move3D(X, Y, Z); } else { transform.Move2D(X, Y); } 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.Move3D(X, Y, Z); } else { transform.Move2D(X, Y); } rowBuffer.SetValue(num4, transform); } } } } #endregion } } } } }
private static List <Plan> SelectPlans(IDataSource ds, string WhereClause) { List <Plan> list = new List <Plan>(); IFdeCursor cursor = null; IRowBuffer row = null; try { if (ds == null) { return(list); } IFeatureDataSet fds = ds.OpenFeatureDataset("UP_PlanLibDs_Indication"); if (fds == null) { return(list); } IObjectClass class2 = fds.OpenObjectClass("UP_Plan"); if (class2 != null) { IQueryFilter filter = new QueryFilter { WhereClause = WhereClause }; IFieldInfoCollection fiCol = class2.GetFields(); cursor = class2.Search(filter, true); while ((row = cursor.NextRow()) != null) { Plan plan = new Plan { PlanID = (row.IsNull(fiCol.IndexOf("oid"))) ? -1 : Convert.ToInt32(row.GetValue(fiCol.IndexOf("oid"))), PlanGuid = (row.IsNull(fiCol.IndexOf("planGuid"))) ? "" : row.GetValue(fiCol.IndexOf("planGuid")).ToString(), PlanName = (row.IsNull(fiCol.IndexOf("planName"))) ? "" : row.GetValue(fiCol.IndexOf("planName")).ToString(), PlanCode = (row.IsNull(fiCol.IndexOf("planCode"))) ? "" : row.GetValue(fiCol.IndexOf("planCode")).ToString(), PlanDesigner = (row.IsNull(fiCol.IndexOf("planDesigner"))) ? "" : row.GetValue(fiCol.IndexOf("planDesigner")).ToString(), PlanState = (row.IsNull(fiCol.IndexOf("planState"))) ? PlanState.None : (PlanState)row.GetValue(fiCol.IndexOf("planState")), ProjectID = (row.IsNull(fiCol.IndexOf("projectID"))) ? -1 : Convert.ToInt32(row.GetValue(fiCol.IndexOf("projectID"))), XOffset = (row.IsNull(fiCol.IndexOf("xOffset"))) ? double.NaN : Convert.ToDouble(row.GetValue(fiCol.IndexOf("xOffset"))), YOffset = (row.IsNull(fiCol.IndexOf("yOffset"))) ? double.NaN : Convert.ToDouble(row.GetValue(fiCol.IndexOf("yOffset"))), Creator = (row.IsNull(fiCol.IndexOf("creator"))) ? "" : row.GetValue(fiCol.IndexOf("creator")).ToString(), CreateTime = (row.IsNull(fiCol.IndexOf("createTime"))) ? DateTime.MinValue : (DateTime)row.GetValue(fiCol.IndexOf("createTime")), AbandonReason = (row.IsNull(fiCol.IndexOf("abandonReason"))) ? "" : row.GetValue(fiCol.IndexOf("abandonReason")).ToString(), Description = (row.IsNull(fiCol.IndexOf("description"))) ? "" : row.GetValue(fiCol.IndexOf("description")).ToString(), Bound = (row.IsNull(fiCol.IndexOf("Bound"))) ? "" : row.GetValue(fiCol.IndexOf("Bound")).ToString(), ConnType = (row.IsNull(fiCol.IndexOf("ConnType"))) ? PlanType.None : (PlanType)row.GetValue(fiCol.IndexOf("ConnType")) }; if (plan.ConnType == PlanType.Network) { list.Add(new NetWorkPlan(plan)); } else { list.Add(new LocalPlan(plan)); } } } return(list); } catch (Exception exception) { } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } } return(list); }
private void Scalling(double X, double Y, double Z) { 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(); if (featureClass == null) { continue; } 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.Scale3D(X, Y, Z, this.centerX, this.centerY, this.centerZ); } else { transform.Scale2D(X, Y, this.centerX, this.centerY); } 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.Scale3D(X, Y, Z, this.centerX, this.centerY, this.centerZ); } else { transform.Scale2D(X, Y, this.centerX, this.centerY); } 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.Scale3D(X, Y, Z, this.centerX, this.centerY, this.centerZ); } else { transform.Scale2D(X, Y, this.centerX, this.centerY); } rowBuffer.SetValue(num4, transform); } } } } #endregion } } app.Current3DMapControl.FeatureManager.EditFeatures(featureClass, rowBufferCollection); //System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass); } } }
private static List <Project> SelectProjects(IDataSource ds, string WhereClause) { List <Project> list = new List <Project>(); IFdeCursor cursor = null; IRowBuffer row = null; try { if (ds == null) { return(list); } IFeatureDataSet fds = ds.OpenFeatureDataset("UP_PlanLibDs_Indication"); if (fds == null) { return(list); } IFeatureClass class2 = fds.OpenFeatureClass("UP_Project"); if (class2 != null) { IQueryFilter filter = new QueryFilter { WhereClause = WhereClause }; IFieldInfoCollection fiCol = class2.GetFields(); cursor = class2.Search(filter, true); while ((row = cursor.NextRow()) != null) { Project item = new Project { ProjectID = (row.IsNull(fiCol.IndexOf("oid"))) ? -1 : Convert.ToInt32(row.GetValue(fiCol.IndexOf("oid"))), ProjectName = (row.IsNull(fiCol.IndexOf("projectName"))) ? "" : row.GetValue(fiCol.IndexOf("projectName")).ToString(), ProjectCode = (row.IsNull(fiCol.IndexOf("projectCode"))) ? "" : row.GetValue(fiCol.IndexOf("projectCode")).ToString(), ProjectType = (row.IsNull(fiCol.IndexOf("projectType"))) ? ProjectType.None : (ProjectType)row.GetValue(fiCol.IndexOf("projectType")), ChangeState = (row.IsNull(fiCol.IndexOf("changeState"))) ? ProjectChangeState.None : (ProjectChangeState)Convert.ToInt32(row.GetValue(fiCol.IndexOf("changeState"))), ProjectTime = (row.IsNull(fiCol.IndexOf("projectTime"))) ? DateTime.MinValue : (DateTime)row.GetValue(fiCol.IndexOf("projectTime")), ProjectOwner = (row.IsNull(fiCol.IndexOf("projectOwner"))) ? "" : row.GetValue(fiCol.IndexOf("projectOwner")).ToString(), Description = (row.IsNull(fiCol.IndexOf("description"))) ? "" : row.GetValue(fiCol.IndexOf("description")).ToString(), ProjectBound = (row.IsNull(fiCol.IndexOf("projectBound"))) ? "" : row.GetValue(fiCol.IndexOf("projectBound")).ToString(), ProjectLandUse = (row.IsNull(fiCol.IndexOf("projectLandUse"))) ? null : (row.GetValue(fiCol.IndexOf("projectLandUse")) as IGeometry), ProjectElevation = (row.IsNull(fiCol.IndexOf("projectElevation"))) ? double.NaN : Convert.ToDouble(row.GetValue(fiCol.IndexOf("projectElevation"))), ProjectRemark1 = (row.IsNull(fiCol.IndexOf("projectRemark1"))) ? "" : row.GetValue(fiCol.IndexOf("projectRemark1")).ToString(), ProjectLocation = (row.IsNull(fiCol.IndexOf("projectRemark2"))) ? "" : row.GetValue(fiCol.IndexOf("projectRemark2")).ToString(), ProjectQuo = (row.IsNull(fiCol.IndexOf("projectQuo"))) ? null : (row.GetValue(fiCol.IndexOf("projectQuo")) as IBinaryBuffer) }; list.Add(item); } } return(list); } catch (Exception exception) { } finally { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } } return(list); }
public int QueryValues(IRowBuffer row) { try { if (m_currentOGRFeature == null) return -1; // loop and only set values in the rowbuffer // that were requested from the fieldMap int count = m_esriQueryFieldMap.GetLength(0); for (int i = 0; i < count; i++) { int esriFieldIndex = (int)m_esriQueryFieldMap.GetValue(i); // have to skip 1) objectid and 2) geometry field or we will get an ESRI // exception. Also have to skip anything that the query map is asking to ignore if (esriFieldIndex == -1 || esriFieldIndex == m_pDataset.get_OIDFieldIndex(0) || esriFieldIndex == m_pDataset.get_ShapeFieldIndex(0)) continue; try { IField valField = m_pDataset.get_Fields(0).get_Field(i); object val = m_pDataset.get_mapped_value(m_currentOGRFeature, i); row.set_Value(i, val); } catch (Exception ex) { // skip values that fail to be set but continue doing it anyway System.Diagnostics.Debug.WriteLine(ex.Message); } } return m_currentOGRFeature.GetFID(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); return -1; } }
// 唯一值符号化 public static void UniqueValueRenderer(IFeatureLayer featureLayer, string fieldName, IMapControl2 mapControl, AxTOCControl tocControl) { ITable pTable = featureLayer as ITable; IUniqueValueRenderer pRenderer = new UniqueValueRendererClass(); pRenderer.FieldCount = 1; // 设置唯一值符号化的关键字段为一个 pRenderer.set_Field(0, fieldName); // 设置唯一值符号化的第一个关键字段 IRandomColorRamp pColorRamp = new RandomColorRampClass() { StartHue = 0, MinValue = 0, MinSaturation = 0, EndHue = 360, MaxValue = 100, MaxSaturation = 100 }; // 根据渲染字段的值的个数,设置一组随机颜色 pColorRamp.Size = featureLayer.FeatureClass.FeatureCount(new QueryFilterClass()); bool bSuccess = false; pColorRamp.CreateRamp(out bSuccess); IEnumColors pEnumColors = pColorRamp.Colors; IColor pNextUniqueColor = null; // 查询字段的值 IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField(fieldName); int fieldNumber = pTable.FindField(fieldName); // 获取渲染字段索引 ICursor pCursor = pTable.Search(pQueryFilter, true); IRow pNextRow = pCursor.NextRow(); object codeValue = null; IRowBuffer pNextRowBuffer = null; while (pNextRow != null) { pNextRowBuffer = pNextRow as IRowBuffer; // 获取渲染字段的每一个值 codeValue = pNextRowBuffer.get_Value(fieldNumber); pNextUniqueColor = pEnumColors.Next(); if (pNextUniqueColor == null) { pEnumColors.Reset(); pNextUniqueColor = pEnumColors.Next(); } ISymbol pSymbol = null; switch (featureLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPolygon: pSymbol = new SimpleFillSymbolClass() { Color = pNextUniqueColor }; break; case esriGeometryType.esriGeometryPolyline: pSymbol = new SimpleLineSymbolClass() { Color = pNextUniqueColor }; break; case esriGeometryType.esriGeometryPoint: pSymbol = new SimpleMarkerSymbolClass() { Color = pNextUniqueColor }; break; } pRenderer.AddValue(codeValue.ToString(), "", pSymbol); pNextRow = pCursor.NextRow(); } (featureLayer as IGeoFeatureLayer).Renderer = pRenderer as IFeatureRenderer; mapControl.Refresh(); tocControl.Update(); }
public void SaveExtendedAttributes() { int idFld = m_ExtendedAttributesTable.FindField("ExtendedAttributes_ID"); int ownerTableFld = m_ExtendedAttributesTable.FindField("OwnerTable"); int ownerFld = m_ExtendedAttributesTable.FindField("OwnerID"); int propertyFld = m_ExtendedAttributesTable.FindField("Property"); int propertyValueFld = m_ExtendedAttributesTable.FindField("PropertyValue"); int valueLinkFld = m_ExtendedAttributesTable.FindField("ValueLinkID"); int qualifierFld = m_ExtendedAttributesTable.FindField("Qualifier"); int dataSrcFld = m_ExtendedAttributesTable.FindField("DataSourceID"); int notesFld = m_ExtendedAttributesTable.FindField("Notes"); IEditor theEditor = ArcMap.Editor; if (theEditor.EditState == esriEditState.esriStateNotEditing) { theEditor.StartEditing(m_theWorkspace); } theEditor.StartOperation(); try { string updateWhereClause = "ExtendedAttributes_ID = '"; ICursor insertCursor = m_ExtendedAttributesTable.Insert(true); foreach (KeyValuePair <string, ExtendedAttributes> aDictionaryEntry in m_ExtendedAttributesDictionary) { ExtendedAttributes thisExtendedAttributes = (ExtendedAttributes)aDictionaryEntry.Value; switch (thisExtendedAttributes.RequiresUpdate) { case true: updateWhereClause += thisExtendedAttributes.ExtendedAttributes_ID + "' OR ExtendedAttributes_ID = '"; break; case false: IRowBuffer theRowBuffer = m_ExtendedAttributesTable.CreateRowBuffer(); theRowBuffer.set_Value(idFld, thisExtendedAttributes.ExtendedAttributes_ID); theRowBuffer.set_Value(ownerFld, thisExtendedAttributes.OwnerID); theRowBuffer.set_Value(propertyFld, thisExtendedAttributes.Property); theRowBuffer.set_Value(propertyValueFld, thisExtendedAttributes.PropertyValue); theRowBuffer.set_Value(valueLinkFld, thisExtendedAttributes.ValueLinkID); theRowBuffer.set_Value(qualifierFld, thisExtendedAttributes.Qualifier); theRowBuffer.set_Value(dataSrcFld, thisExtendedAttributes.DataSourceID); theRowBuffer.set_Value(notesFld, thisExtendedAttributes.Notes); insertCursor.InsertRow(theRowBuffer); break; } } System.Runtime.InteropServices.Marshal.ReleaseComObject(insertCursor); theEditor.StopOperation("Insert ExtendedAttributes"); if (updateWhereClause == "ExtendedAttributes_ID = '") { return; } theEditor.StartOperation(); updateWhereClause = updateWhereClause.Remove(updateWhereClause.Length - 29); IQueryFilter QF = new QueryFilterClass(); QF.WhereClause = updateWhereClause; ICursor updateCursor = m_ExtendedAttributesTable.Update(QF, false); IRow theRow = updateCursor.NextRow(); while (theRow != null) { string theID = theRow.get_Value(idFld).ToString(); ExtendedAttributes thisExtendedAttributes = m_ExtendedAttributesDictionary[theID]; theRow.set_Value(ownerFld, thisExtendedAttributes.OwnerID); theRow.set_Value(propertyFld, thisExtendedAttributes.Property); theRow.set_Value(propertyValueFld, thisExtendedAttributes.PropertyValue); theRow.set_Value(valueLinkFld, thisExtendedAttributes.ValueLinkID); theRow.set_Value(qualifierFld, thisExtendedAttributes.Qualifier); theRow.set_Value(dataSrcFld, thisExtendedAttributes.DataSourceID); theRow.set_Value(notesFld, thisExtendedAttributes.Notes); updateCursor.UpdateRow(theRow); theRow = updateCursor.NextRow(); } theEditor.StopOperation("Update ExtendedAttributes"); } catch { theEditor.StopOperation("ExtendedAttributes Management Failure"); } }
void ITable.UpdateSearchedRows(IQueryFilter QueryFilter, IRowBuffer buffer) { throw new NotImplementedException(); }
void ITable.UpdateSearchedRows(IQueryFilter QueryFilter, IRowBuffer Buffer) { ((ITable)featureLayer).UpdateSearchedRows(QueryFilter, Buffer); }
private Dictionary <string, string> GetQueryResult(IFeatureClassInfo fcInfo, int featureId) { if (fcInfo == null || featureId < 0) { return(null); } IFdeCursor cursor = null; IRowBuffer row = null; try { IDataSourceFactory dsf = new DataSourceFactory(); if (!dsf.HasDataSourceByString(fcInfo.DataSourceConnectionString)) { return(null); } IDataSource ds = dsf.OpenDataSourceByString(fcInfo.DataSourceConnectionString); if (ds == null) { return(null); } IFeatureDataSet fds = ds.OpenFeatureDataset(fcInfo.DataSetName); if (fds == null) { return(null); } IFeatureClass fc = fds.OpenFeatureClass(fcInfo.FeatureClassName); if (fc == null) { return(null); } IQueryFilter filter = new QueryFilter(); filter.WhereClause = fc.FidFieldName + "=" + featureId; if (fc.GetCount(filter) == 0) { return(null); } cursor = fc.Search(filter, false); if (cursor == null) { return(null); } row = cursor.NextRow(); if (row == null) { return(null); } IFieldInfoCollection fiCol = row.Fields; Dictionary <string, string> dict = new Dictionary <string, string>(); for (int i = 0; i < fiCol.Count; i++) { IFieldInfo fi = row.Fields.Get(i); object obj = row.GetValue(fiCol.IndexOf(fi.Name)); if (obj == null) { continue; } string str = ""; switch (fi.FieldType) { case gviFieldType.gviFieldBlob: case gviFieldType.gviFieldUnknown: case gviFieldType.gviFieldGeometry: break; case gviFieldType.gviFieldFloat: case gviFieldType.gviFieldDouble: double d; if (double.TryParse(obj.ToString(), out d)) { str = d.ToString("0.00"); } break; default: str = obj.ToString(); break; } if (!string.IsNullOrEmpty(str.Trim())) { string temp = (string.IsNullOrEmpty(fi.Alias)) ? fi.Name : fi.Alias; dict[temp] = str; } } return(dict); } catch (Exception ex) { return(null); } }
private void btnFindWC_Click(object sender, EventArgs e) { clear(); clearDeep(); IFdeCursor cursor = null; try { if (closestFacilitySolver == null) { closestFacilitySolver = network.CreateClosestFacilitySolver(); closestFacilitySolver.ImpedanceAttributeName = "Length"; } closestFacilitySolver.LocationSearchTolerance = double.Parse(txtSearchTolerance.Text); closestFacilitySolver.ClearFacilityLocations(); closestFacilitySolver.ClearEventLocations(); // 添加WC设施点 foreach (IFeatureClass fc in fcMap_POI.Keys) { if (fc.Name.Contains("WC")) { cursor = fc.Search(null, true); IRowBuffer row = null; while ((row = cursor.NextRow()) != null) { try { INetworkLocation facility = new NetworkLocation(); int pos = row.FieldIndex("Geometry"); IPoint point = row.GetValue(pos) as IPoint; facility.Position = point; facility.Name = fc.Guid.ToString() + "_" + row.GetValue(0).ToString(); //设定名字"fcGUID_oid" closestFacilitySolver.AddFacilityLocation(facility); } catch (COMException ex) { } } break; } } if (closestFacilitySolver.FacilityLocationCount == 0) { MessageBox.Show("添加的厕所数为0,请调整LocationSearchTolerance大小"); return; } // 添加人所在的位置 INetworkEventLocation location = new NetworkEventLocation(); this.axRenderControl1.Camera.GetCamera2(out fdepoint, out ang); location.Position = fdepoint; location.Name = "I'mHere"; location.TargetFacilityCount = int.Parse(txtMaxNum.Text); location.SetCutoff("Length", double.Parse(txtCutoff.Text)); closestFacilitySolver.AddEventLocation(location); // 可视化人的位置 IImagePointSymbol ips = new ImagePointSymbol(); ips.ImageName = "#(i)"; ips.Size = 50; renderPoint = this.axRenderControl1.ObjectManager.CreateRenderPoint(fdepoint, ips, rootId); if (closestFacilitySolver.Solve()) { int routeCount = closestFacilitySolver.RouteCount; if (routeCount == 0) { MessageBox.Show("没有厕所在指定范围内"); return; } for (int i = 0; i < routeCount; i++) { INetworkRoute route = closestFacilitySolver.GetRoute(i); if (route != null) { // 可视化线路 ICurveSymbol lineSym = new CurveSymbol(); lineSym.Color = System.Drawing.Color.Yellow; lineSym.Width = -2; IGeometry geo = route.GetRouteGeometry(); if (geo.GeometryType == gviGeometryType.gviGeometryPolyline) { IPolyline line = geo as IPolyline; renderLine = this.axRenderControl1.ObjectManager.CreateRenderPolyline(line, lineSym, rootId); renderLine.MaxVisibleDistance = 10000; renderLineArray.Add(renderLine); } else if (geo.GeometryType == gviGeometryType.gviGeometryMultiPolyline) { IMultiPolyline line = geo as IMultiPolyline; multiRenderLine = this.axRenderControl1.ObjectManager.CreateRenderMultiPolyline(line, lineSym, rootId); multiRenderLine.MaxVisibleDistance = 10000; multiRenderLineArray.Add(multiRenderLine); } drawTempLine(route); // 高亮厕所 int segmentCount = route.SegmentCount; for (int j = 0; j < segmentCount; j++) { INetworkLocation endLocation = route.GetSegment(j).EndLocation; string[] strs = endLocation.Name.Split('_'); foreach (IFeatureClass fc in fcMap_POI.Keys) { if (fc.Guid.ToString() == strs[0]) { this.axRenderControl1.FeatureManager.HighlightFeature(fc, int.Parse(strs[1]), System.Drawing.Color.Yellow); break; } } //////////////////////测试NetworkElement相关////////////////////////////////// INetworkElementCollection elementCols = route.GetSegment(j).GetNetworkElements(); for (int c = 0; c < elementCols.Count; c++) { INetworkElement element = elementCols.Get(c); if (element.Type == gviNetworkElementType.gviEdge) { INetworkEdge edge = element as INetworkEdge; int subId = edge.SubID; } else { INetworkJunction junction = element as INetworkJunction; INetworkEdgeCollection edgeCol = junction.IncomingEdges; for (int ee = 0; ee < edgeCol.Count; ee++) { INetworkEdge edge = edgeCol.Get(ee); int subId = edge.SubID; } } } ////////////////////////////////////////////////////////////////////////// } } } } else { MessageBox.Show("查找失败"); } } catch (COMException ex) { MessageBox.Show(ex.Message); } finally { if (cursor != null) { //Marshal.ReleaseComObject(cursor); cursor = null; } } }
private Dictionary <string, string> GetQueryResult(DF3DFeatureClass dffc, int featureId) { if (dffc == null) { return(null); } IFeatureClass fc = dffc.GetFeatureClass(); if (fc == null) { return(null); } IFdeCursor cursor = null; IRowBuffer row = null; try { IQueryFilter filter = new QueryFilter(); filter.WhereClause = fc.FidFieldName + "=" + featureId; if (fc.GetCount(filter) == 0) { return(null); } cursor = fc.Search(filter, false); if (cursor == null) { return(null); } row = cursor.NextRow(); if (row == null) { return(null); } FacilityClass facClass = dffc.GetFacilityClass(); IFieldInfoCollection fiCol = row.Fields; Dictionary <string, string> dict = new Dictionary <string, string>(); if (facClass == null) { for (int i = 0; i < fiCol.Count; i++) { IFieldInfo fi = row.Fields.Get(i); object obj = row.GetValue(i); if (obj == null) { continue; } string str = ""; switch (fi.FieldType) { case gviFieldType.gviFieldBlob: case gviFieldType.gviFieldUnknown: case gviFieldType.gviFieldGeometry: break; case gviFieldType.gviFieldFloat: case gviFieldType.gviFieldDouble: double d; if (double.TryParse(obj.ToString(), out d)) { str = d.ToString("0.00"); } break; default: str = obj.ToString(); break; } if (!string.IsNullOrEmpty(str.Trim())) { string temp = (string.IsNullOrEmpty(fi.Alias)) ? fi.Name : fi.Alias; dict[temp] = str; } } } else { foreach (DFDataConfig.Class.FieldInfo fi in facClass.FieldInfoCollection) { if (!fi.CanQuery) { continue; } int index = row.Fields.IndexOf(fi.Name); if (index == -1) { continue; } object obj = row.GetValue(index); if (obj == null) { continue; } IFieldInfo fiFC = row.Fields.Get(index); string str = ""; switch (fiFC.FieldType) { case gviFieldType.gviFieldBlob: case gviFieldType.gviFieldUnknown: case gviFieldType.gviFieldGeometry: break; case gviFieldType.gviFieldFloat: case gviFieldType.gviFieldDouble: double d; if (double.TryParse(obj.ToString(), out d)) { str = d.ToString("0.00"); } break; default: str = obj.ToString(); break; } if (!string.IsNullOrEmpty(str.Trim())) { string temp = (string.IsNullOrEmpty(fi.Alias)) ? fi.Name : fi.Alias; dict[temp] = str; } } } return(dict); } catch (Exception ex) { if (cursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor); cursor = null; } if (row != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(row); row = null; } return(null); } }
private void AddRecord(IGeometry geo) { try { if (geo.GeometryType != gviGeometryType.gviGeometryModelPoint) { return; } this.beforeRowBufferMap.Clear(); SelectCollection.Instance().Clear(); DF3DFeatureClass featureClassInfo = CommonUtils.Instance().CurEditLayer; if (featureClassInfo == null) { return; } IFeatureClass fc = featureClassInfo.GetFeatureClass(); if (fc == null) { return; } IFeatureDataSet fds = fc.FeatureDataSet; if (fds == 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; } IModelPoint pt = geo as IModelPoint; string mname = Path.GetFileNameWithoutExtension(pt.ModelName); IEnvelope envelope = ImportOsg(fc, pt.ModelName); if (envelope == null) { return; } IModelPoint geoOut = pt.Clone2(fiGeo.GeometryDef.VertexAttribute) as IModelPoint; if (fiGeo.GeometryDef.HasZ) { geoOut.SetCoords(pt.X, pt.Y, pt.Z, 0, 0); } else { geoOut.SetCoords(pt.X, pt.Y, 0, 0, 0); } geoOut.ModelName = mname; geoOut.ModelEnvelope = new EnvelopeClass { MinX = envelope.MinX, MaxX = envelope.MaxX, MinY = envelope.MinY, MaxY = envelope.MaxY, MinZ = envelope.MinZ, MaxZ = envelope.MaxZ }; 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(); Clear(); (this._drawTool as Draw3DModel).Set3DModelFilePath(this.beFilePath.Text); } catch (Exception ex) { } }
private TextureClass GetTextureClass(string objectId) { IFdeCursor cursor = null; IRowBuffer row = null; try { IDataSource ds = DF3DPipeCreateApp.App.TemplateLib; if (ds == null) { return(null); } IFeatureDataSet fds = 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 = "ObjectId = '" + objectId + "'" }; cursor = oc.Search(filter, true); if ((row = cursor.NextRow()) != null) { int id = -1; string name = "", objectid = "", groupid = "", code = "", comment = ""; Image thumbnail = null; int index = row.FieldIndex("oid"); if (index != -1 && !row.IsNull(index)) { id = Convert.ToInt32(row.GetValue(index).ToString()); } index = row.FieldIndex("Name"); if (index != -1 && !row.IsNull(index)) { name = row.GetValue(index).ToString(); } index = row.FieldIndex("ObjectId"); if (index != -1 && !row.IsNull(index)) { objectid = row.GetValue(index).ToString(); } index = row.FieldIndex("GroupId"); if (index != -1 && !row.IsNull(index)) { groupid = row.GetValue(index).ToString(); } index = row.FieldIndex("Code"); if (index != -1 && !row.IsNull(index)) { code = row.GetValue(index).ToString(); } index = row.FieldIndex("Comment"); if (index != -1 && !row.IsNull(index)) { comment = row.GetValue(index).ToString(); } index = row.FieldIndex("Thumbnail"); if (index != -1 && !row.IsNull(index)) { IBinaryBuffer b = row.GetValue(index) as IBinaryBuffer; if (row != null) { MemoryStream stream = new MemoryStream(b.AsByteArray()); thumbnail = Image.FromStream(stream); } } if (id != -1 && thumbnail != null) { TextureClass cc = new TextureClass(); cc.Id = id; cc.Name = name; cc.Group = groupid; cc.ObjectId = objectid; cc.Code = code; cc.Comment = comment; cc.Thumbnail = thumbnail; return(cc); } } return(null); } 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; } } }
public static void Symbology_UniqueValue(IFeatureLayer featureLayer, string fieldName, IMapControl2 mapControl, AxTOCControl tocControl) { IUniqueValueRenderer pRenderer = new UniqueValueRendererClass() { FieldCount = 1 }; pRenderer.set_Field(0, fieldName); // 设置符号化色带 IRandomColorRamp pColorRamp = new RandomColorRampClass() { StartHue = 0, MinValue = 0, MinSaturation = 0, EndHue = 360, MaxValue = 100, MaxSaturation = 100, Size = featureLayer.FeatureClass.FeatureCount(new QueryFilterClass()) }; bool bOk = false; pColorRamp.CreateRamp(out bOk); IEnumColors pColors = pColorRamp.Colors; // 获取渲染字段索引 ITable pTable = featureLayer as ITable; int fieldIndex = pTable.FindField(fieldName); // 遍历唯一值要素 IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField(fieldName); ICursor pCursor = pTable.Search(pQueryFilter, true); IRow pRow = pCursor.NextRow(); while (pRow != null) { IRowBuffer pRowBuffer = pRow as IRowBuffer; string value = pRowBuffer.get_Value(fieldIndex).ToString(); IColor pColor = pColors.Next(); ISymbol pSymbol = null; switch (featureLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: pSymbol = new SimpleMarkerSymbolClass() { Color = pColor }; break; case esriGeometryType.esriGeometryPolyline: pSymbol = new SimpleLineSymbolClass() { Color = pColor }; break; case esriGeometryType.esriGeometryPolygon: pSymbol = new SimpleFillSymbolClass() { Color = pColor }; break; } pRenderer.AddValue(value, "", pSymbol); pRow = pCursor.NextRow(); } (featureLayer as IGeoFeatureLayer).Renderer = pRenderer as IFeatureRenderer; mapControl.Refresh(); tocControl.Update(); }
public void SaveGlossary() { int idFld = m_GlossaryTable.FindField("Glossary_ID"); int trmFld = m_GlossaryTable.FindField("Term"); int defFld = m_GlossaryTable.FindField("Definition"); int dsFld = m_GlossaryTable.FindField("DefinitionSourceID"); IEditor theEditor = ArcMap.Editor; if (theEditor.EditState == esriEditState.esriStateNotEditing) { theEditor.StartEditing(m_theWorkspace); } theEditor.StartOperation(); try { string updateWhereClause = "Glossary_ID = '"; ICursor insertCursor = m_GlossaryTable.Insert(true); foreach (KeyValuePair <string, Glossary> aDictionaryEntry in m_GlossaryDictionary) { Glossary thisGlossary = (Glossary)aDictionaryEntry.Value; switch (thisGlossary.RequiresUpdate) { case true: updateWhereClause += thisGlossary.Glossary_ID + "' OR Glossary_ID = '"; break; case false: IRowBuffer theRowBuffer = m_GlossaryTable.CreateRowBuffer(); theRowBuffer.set_Value(idFld, thisGlossary.Glossary_ID); theRowBuffer.set_Value(trmFld, thisGlossary.Term); theRowBuffer.set_Value(defFld, thisGlossary.Definition); theRowBuffer.set_Value(dsFld, thisGlossary.DefinitionSourceID); insertCursor.InsertRow(theRowBuffer); break; } } System.Runtime.InteropServices.Marshal.ReleaseComObject(insertCursor); theEditor.StopOperation("Insert Glossary"); theEditor.StartOperation(); updateWhereClause = updateWhereClause.Remove(updateWhereClause.Length - 32); IQueryFilter QF = new QueryFilterClass(); QF.WhereClause = updateWhereClause; ICursor updateCursor = m_GlossaryTable.Update(QF, false); IRow theRow = updateCursor.NextRow(); while (theRow != null) { string theID = theRow.get_Value(idFld).ToString(); Glossary thisGlossary = m_GlossaryDictionary[theID]; theRow.set_Value(trmFld, thisGlossary.Term); theRow.set_Value(defFld, thisGlossary.Definition); theRow.set_Value(dsFld, thisGlossary.DefinitionSourceID); updateCursor.UpdateRow(theRow); theRow = updateCursor.NextRow(); } theEditor.StopOperation("Update Glossary"); } catch { theEditor.StopOperation("Glossary Management Failure"); } }
private void sbtn_Split_Click(object sender, System.EventArgs e) { DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } if (System.Windows.Forms.DialogResult.No != XtraMessageBox.Show("模型拆分不支持撤销操作,是否继续?", "询问", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Exclamation)) { IFeatureClass featureClass = null; IFdeCursor fdeCursor = null; app.Current3DMapControl.PauseRendering(false); WaitDialogForm waitDialogForm = null; try { int count = SelectCollection.Instance().GetCount(true); if (count <= 0) { XtraMessageBox.Show("未选中要拆分的模型!"); } else { if (this._renderGeo == null || this._renderGeo.GetFdeGeometry() == null) { XtraMessageBox.Show("请先绘制或选择拆分多边形!"); } else { IMultiPolygon multiPolygon = null; if (this.radioGroup1.SelectedIndex == 1) { IGeometryFactory geometryFactory = new GeometryFactoryClass(); multiPolygon = (geometryFactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon); multiPolygon.AddPolygon(this._renderGeo.GetFdeGeometry() as IPolygon); } else { if (this.radioGroup1.SelectedIndex == 0) { multiPolygon = (this._renderGeo.GetFdeGeometry() as IMultiPolygon); } } if (multiPolygon == null) { XtraMessageBox.Show("获取裁剪多边形失败!"); } else { waitDialogForm = new WaitDialogForm(string.Empty, "正在拆分模型,请稍后..."); HashMap featureClassInfoMap = SelectCollection.Instance().FeatureClassInfoMap; System.Collections.Hashtable hashtable = new System.Collections.Hashtable(); foreach (DF3DFeatureClass featureClassInfo in featureClassInfoMap.Keys) { if (featureClassInfo.GetFeatureLayer().GeometryType == gviGeometryColumnType.gviGeometryColumnModelPoint) { System.Collections.Generic.List <int> list = new System.Collections.Generic.List <int>(); System.Collections.Generic.List <int> list2 = new System.Collections.Generic.List <int>(); IRowBufferCollection rowBufferCollection = new RowBufferCollectionClass(); IRowBufferCollection rowBufferCollection2 = new RowBufferCollectionClass(); ResultSetInfo resultSetInfo = featureClassInfoMap[featureClassInfo] as ResultSetInfo; DataTable resultSetTable = resultSetInfo.ResultSetTable; if (resultSetTable.Rows.Count >= 1) { featureClass = featureClassInfo.GetFeatureClass(); IResourceManager resourceManager = featureClass.FeatureDataSet as IResourceManager; string fidFieldName = featureClass.FidFieldName; int num = featureClass.GetFields().IndexOf(fidFieldName); foreach (DataRow dataRow in resultSetTable.Rows) { int num2 = int.Parse(dataRow[fidFieldName].ToString()); IRowBuffer row = featureClass.GetRow(num2); int position = row.FieldIndex(featureClassInfo.GetFeatureLayer().GeometryFieldName); IModelPoint modelPoint = row.GetValue(position) as IModelPoint; if (modelPoint != null) { Gvitech.CityMaker.Resource.IModel model = resourceManager.GetModel(modelPoint.ModelName); IGeometryConvertor geometryConvertor = new GeometryConvertorClass(); Gvitech.CityMaker.Resource.IModel model2 = null; Gvitech.CityMaker.Resource.IModel model3 = null; IModelPoint modelPoint2 = null; IModelPoint modelPoint3 = null; bool flag = geometryConvertor.SplitModelPointByPolygon2D(multiPolygon, model, modelPoint, out model2, out modelPoint2, out model3, out modelPoint3); if (flag && model2 != null && !model2.IsEmpty && modelPoint2 != null && model3 != null && !model3.IsEmpty && modelPoint3 != null) { System.Guid guid = System.Guid.NewGuid(); string text = guid.ToString(); resourceManager.AddModel(text, model2, null); resourceManager.RebuildSimplifiedModel(text); guid = System.Guid.NewGuid(); string text2 = guid.ToString(); resourceManager.AddModel(text2, model3, null); resourceManager.RebuildSimplifiedModel(text2); modelPoint3.ModelName = text2; row.SetValue(position, modelPoint3); rowBufferCollection.Add(row); list.Add(num2); modelPoint2.ModelName = text; IRowBuffer rowBuffer = row.Clone(false); rowBuffer.SetNull(num); rowBuffer.SetValue(position, modelPoint2); fdeCursor = featureClass.Insert(); fdeCursor.InsertRow(rowBuffer); int lastInsertId = fdeCursor.LastInsertId; rowBuffer.SetValue(num, lastInsertId); rowBufferCollection2.Add(rowBuffer); list2.Add(lastInsertId); System.Runtime.InteropServices.Marshal.ReleaseComObject(fdeCursor); fdeCursor = null; } } } featureClass.UpdateRows(rowBufferCollection, false); app.Current3DMapControl.FeatureManager.EditFeatures(featureClass, rowBufferCollection); app.Current3DMapControl.FeatureManager.CreateFeatures(featureClass, rowBufferCollection2); hashtable[featureClassInfo] = list2; //System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass); featureClass = null; System.Runtime.InteropServices.Marshal.ReleaseComObject(resourceManager); resourceManager = null; } } } SelectCollection.Instance().UpdateSelection(hashtable); base.Close(); base.DialogResult = System.Windows.Forms.DialogResult.OK; } } } } catch (System.Runtime.InteropServices.COMException ex) { XtraMessageBox.Show(ex.Message); } catch (System.UnauthorizedAccessException var_35_4EC) { XtraMessageBox.Show("拒绝访问"); } catch (System.Exception ex2) { XtraMessageBox.Show(ex2.Message); } finally { if (waitDialogForm != null) { waitDialogForm.Close(); } if (fdeCursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(fdeCursor); fdeCursor = null; } //if (featureClass != null && System.Runtime.InteropServices.Marshal.IsComObject(featureClass)) //{ // System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass); // featureClass = null; //} app.Current3DMapControl.ResumeRendering(); } } }
public void UpdateSearchedRows(IQueryFilter QueryFilter, IRowBuffer Buffer) { log.enterFunc("UpdateSearchedRows"); }
void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender) { //删除包围框 for (int i = 0; i < rPolylinelist.Count; i++) { this.axRenderControl1.ObjectManager.DeleteObject((rPolylinelist[i] as IRenderPolyline).Guid); } rPolylinelist.Clear(); for (int i = 0; i < rPolylinelistWhole.Count; i++) { this.axRenderControl1.ObjectManager.DeleteObject((rPolylinelistWhole[i] as IRenderPolyline).Guid); } rPolylinelistWhole.Clear(); for (int i = 0; i < tableLabelList.Count; i++) { this.axRenderControl1.ObjectManager.DeleteObject((tableLabelList[i] as ITableLabel).Guid); } tableLabelList.Clear(); for (int i = 0; i < modelpointList.Count; i++) { this.axRenderControl1.ObjectManager.DeleteObject((modelpointList[i] as IRenderModelPoint).Guid); } modelpointList.Clear(); if (rpl1 != null) { this.axRenderControl1.ObjectManager.DeleteObject(rpl1.Guid); } if (rpl2 != null) { this.axRenderControl1.ObjectManager.DeleteObject(rpl2.Guid); } this.axRenderControl1.HighlightHelper.SetRegion(null); if (EventSender == gviMouseSelectMode.gviMouseSelectClick) { IPickResult pr = PickResult; if (pr == null) { return; } if (pr.Type == gviObjectType.gviObject3DTileLayer) { if (Mode == 1) { IPoint intersectPoint = IntersectPoint; IRelationalOperator2D relation = intersectPoint as IRelationalOperator2D; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = fcMap[fc] as List <string>; if (geoNames.Count == 0) { continue; } IFdeCursor cursor = null; IRowBuffer row = null; List <IRowBuffer> list = new List <IRowBuffer>(); try { ISpatialFilter filter = new SpatialFilter(); filter.Geometry = intersectPoint; filter.SpatialRel = gviSpatialRel.gviSpatialRelEnvelope; filter.GeometryField = "Geometry"; cursor = fc.Search(filter, false); while ((row = cursor.NextRow()) != null) { list.Add(row); } //开始遍历 foreach (IRowBuffer r in list) { int geometryIndex = -1; geometryIndex = r.FieldIndex(geoNames[0].ToString()); if (geometryIndex != -1) { IGeometry polygon = r.GetValue(geometryIndex) as IGeometry; if (relation.Within2D(polygon)) { this.axRenderControl1.HighlightHelper.SetRegion(polygon); } } } } catch (System.Exception ex) { if (ex.GetType().Name.Equals("UnauthorizedAccessException")) { MessageBox.Show("需要标准runtime授权"); } else { MessageBox.Show(ex.Message); } } finally { if (cursor != null) { //System.Runtime.InteropServices.//Marshal.ReleaseComObject(cursor); cursor = null; } } if (Mask != gviModKeyMask.gviModKeyCtrl && Mask != gviModKeyMask.gviModKeyShift) { if (list.Count > 0) { break; } } } } else if (Mode == 2) { this.axRenderControl1.Camera.GetCamera2(out cameraPoint, out cameraAngle); IProximityOperator disOperator = cameraPoint as IProximityOperator; double length = disOperator.Distance3D(IntersectPoint); //向相机方向延伸n米:n跟眼睛到交点距离有关,当距离远时n大,当距离近时n小。 factor = length * 0.001; IPoint aimingPoint = this.axRenderControl1.Camera.GetAimingPoint2(IntersectPoint, cameraAngle, factor); IPoint sourcePoint = this.axRenderControl1.Camera.GetAimingPoint2(IntersectPoint, cameraAngle, -factor); IPolyline intersetPolyline = geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline; intersetPolyline.SpatialCRS = _currentCRS; intersetPolyline.AppendPoint(sourcePoint); //瓦片焦点可能在ModelPoint内部,导致拾取不上。因此要向intersectPoint内外各拉一定距离。 //intersetPolyline.AppendPoint(IntersectPoint); intersetPolyline.AppendPoint(aimingPoint); ICurveSymbol cs = new CurveSymbol(); cs.Color = System.Drawing.Color.Yellow; cs.Width = -5; rpl1 = this.axRenderControl1.ObjectManager.CreateRenderPolyline(intersetPolyline, cs, rootId); rpl1.Glow(-1); //IPolyline intersetPolyline2 = geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline; //intersetPolyline2.AppendPoint(cameraPoint); //intersetPolyline2.AppendPoint(IntersectPoint); //cs.Color = System.Drawing.Color.Yellow; //rpl2 = this.axRenderControl1.ObjectManager.CreateRenderPolyline(intersetPolyline2, cs, rootId); //rpl2.Glow(-1); foreach (IFeatureClass fc in fcMap.Keys) { ISpatialFilter sp = new SpatialFilter(); sp.Geometry = intersetPolyline; sp.SpatialRel = gviSpatialRel.gviSpatialRelIntersects; sp.GeometryField = "Geometry"; IFdeCursor cursor = null; try { cursor = fc.Search(sp, false); IRowBuffer row = null; while ((row = cursor.NextRow()) != null) { int index = row.FieldIndex("Geometry"); IModelPoint mp = row.GetValue(index) as IModelPoint; //DrawEnvelope(mp.Envelope, mp.SpatialCRS, out rPolylinelist); //rPolylinelistWhole.AddRange(rPolylinelist); //创建RenderModelPoint,显示轮廓线 //IModelPointSymbol mps = new ModelPointSymbol(); //mps.Color = 0; //防止与瓦片同时显示时打架 //mps.EnableColor = true; //mps.SetResourceDataSet(fc.FeatureDataSet); //IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, mps, rootId); //rmp.ShowOutline = true; //modelpointList.Add(rmp); //创建RenderModelPoint,禁止深度检测 IModelPointSymbol mps = new ModelPointSymbol(); mps.Color = System.Drawing.Color.Red; mps.EnableColor = true; mps.EnableTexture = false; mps.SetResourceDataSet(fc.FeatureDataSet); IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, mps, rootId); rmp.DepthTestMode = gviDepthTestMode.gviDepthTestDisable; //防止与瓦片同时显示时打架 modelpointList.Add(rmp); //创建TableLabel if (fde_point == null) { fde_point = (new GeometryFactory()).CreatePoint(gviVertexAttribute.gviVertexAttributeZ); } fde_point.Position = mp.Position; fde_point.SpatialCRS = mp.SpatialCRS; tableLabelList.Add(DrawTableLabel(row, fde_point)); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } finally { if (cursor != null) { //System.Runtime.InteropServices.//Marshal.ReleaseComObject(cursor); cursor = null; } } } } } } }
/// <summary> /// Converts the row buffer to a <see cref="DynamicRowBuffer" /> /// </summary> /// <param name="source">The dictionary.</param> /// <returns> /// Returns a <see cref="DynamicRowBuffer" /> representing the row. /// </returns> public static dynamic ToDynamic(this IRowBuffer source) { return(new DynamicRowBuffer(source)); }
/// <summary> /// 定位和闪烁 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataGridView_MouseDoubleClick(object sender, MouseEventArgs e) { int featureId = int.Parse((sender as DataGridView).CurrentRow.Cells[0].Value.ToString()); IFeatureClass curFeatureClass = null; switch (tabControl1.SelectedTab.Name) { case "tabPage0Road": { foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Name == "Road") { curFeatureClass = fc; } } } break; case "tabPage1Building": { foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Name == "Building") { curFeatureClass = fc; } } } break; case "tabPage2Trees": { foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Name == "Trees") { curFeatureClass = fc; } } } break; case "tabPage3Facility": { foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Name == "Facility") { curFeatureClass = fc; } } } break; case "tabPage4LandScape": { foreach (IFeatureClass fc in fcMap.Keys) { if (fc.Name == "Landscape") { curFeatureClass = fc; } } } break; } string filterString = string.Format("oid={0}", featureId); IQueryFilter filter = new QueryFilter(); filter.WhereClause = filterString; IFdeCursor cursor = null; try { cursor = curFeatureClass.Search(filter, true); if (cursor != null) { IRowBuffer fdeRow = null; if ((fdeRow = cursor.NextRow()) != null) { int nPos = fdeRow.FieldIndex("Geometry"); if (nPos != -1 && !fdeRow.IsNull(nPos)) { IModelPoint mp = fdeRow.GetValue(nPos) as IModelPoint; // 从库中读取值 IModelPointSymbol symbol = new ModelPointSymbol(); symbol.SetResourceDataSet(curFeatureClass.FeatureDataSet); IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, symbol, rootId); if (rmp != null) { // 定位 this.axRenderControl1.Camera.FlyToObject(rmp.Guid, gviActionCode.gviActionJump); // 闪烁 rmp.Glow(2000); this.axRenderControl1.ObjectManager.DelayDelete(rmp.Guid, 2000); } } } } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } finally { if (cursor != null) { //Marshal.ReleaseComObject(cursor); cursor = null; } } }
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 IPolygon polygonGC = null; if (rowGC != null) { nPose = rowGC.FieldIndex("Geometry"); IGeometry geo = rowGC.GetValue(nPose) as IGeometry; if (geo.GeometryType == gviGeometryType.gviGeometryPolygon) { polygonGC = geo as IPolygon; } } this.Text = "拾取成功"; //第一个Tab页:ExtrudePolygonToModel if (this.tabControl1.SelectedIndex == 0) { // 1.调接口构造模型 IGeometryConvertor gc = new GeometryConvertor(); gviRoofType rooftype = gviRoofType.gviRoofFlat; switch (this.comboxRoofType.Text) { case "Flat": rooftype = gviRoofType.gviRoofFlat; break; case "Gable": rooftype = gviRoofType.gviRoofGable; break; case "Hip": rooftype = gviRoofType.gviRoofHip; break; } string imgPath = (strMediaPath + @"\dds"); string roof = this.comboBoxRoofTexture.Text; string facade = this.comboBoxFacadeTexture.Text; IModelPoint mp = null; IModel model = null; if (!gc.ExtrudePolygonToModel(polygonGC, int.Parse(this.numFloorNumber.Value.ToString()), double.Parse(this.numFloorHeight.Value.ToString()), double.Parse(this.numSlopeAngle.Value.ToString()), rooftype, facade, roof, out mp, out model)) { MessageBox.Show("拉体块出错!"); return; } //2、将模型及贴图写入osg文件 string modelName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".osg");//输出osg文件路径 IResourceFactory resFactory = new ResourceFactory(); string[] imageNames = model.GetImageNames(); IPropertySet ps = new PropertySet(); for (int i = 0; i < imageNames.Length; i++) { string imgName = imageNames[i]; IImage img = resFactory.CreateImageFromFile(string.Format(@"{0}\{1}", imgPath + @"\facade", imgName)); if (img == null) { img = resFactory.CreateImageFromFile(string.Format(@"{0}\{1}", imgPath + @"\roof", imgName)); } ps.SetProperty(imgName, img); } model.WriteFile(modelName, ps); //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); } //第二个tab页:ExtrudePolygonToTriMesh else { // 1.调接口构造模型 IGeometryConvertor gc = new GeometryConvertor(); ITriMesh tm = gc.ExtrudePolygonToTriMesh(polygonGC, double.Parse(this.numHeight.Value.ToString()), true); if (tm == null) { MessageBox.Show("拉体块出错!"); return; } //2、显示三角面 //---- 渲染样式不是必须的 ----- ISurfaceSymbol surfaceSym = new SurfaceSymbol(); surfaceSym.Color = System.Drawing.Color.Red; surfaceSym.EnableLight = true; ICurveSymbol curveSym = new CurveSymbol(); curveSym.Color = System.Drawing.Color.Yellow; curveSym.Width = 10; surfaceSym.BoundarySymbol = curveSym; //---- ------------------ ----- IRenderTriMesh rmp = this.axRenderControl1.ObjectManager.CreateRenderTriMesh(tm, surfaceSym, rootId); rmp.MouseSelectMask = gviViewportMask.gviViewNone; rmp.MaxVisibleDistance = 100000; this.axRenderControl1.Camera.LookAtEnvelope(rmp.Envelope);//飞入 tmList.Add(rmp); } } } } catch (System.Exception ex) { if (ex.GetType().Name.Equals("UnauthorizedAccessException")) { MessageBox.Show("需要标准runtime授权"); } else { MessageBox.Show(ex.Message); } } }
private void ClickQuery() { DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } try { IFeatureLayer fl = this._drawTool.GetSelectFeatureLayerPickResult().FeatureLayer; if (fl == null) { return; } int featureId = this._drawTool.GetSelectFeatureLayerPickResult().FeatureId; FacilityClass facc = Dictionary3DTable.Instance.GetFacilityClassByDFFeatureClassID(fl.FeatureClassId.ToString()); if (facc == null || facc.Name != "PipeNode") { XtraMessageBox.Show("您选中的不是管点设施。", "提示"); return; } DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(fl.FeatureClassId.ToString()); if (dffc == null || dffc.GetFeatureClass() == null) { return; } IFeatureClass fc = dffc.GetFeatureClass(); if (this._bFinished) { Clear(); this._startFCGuid = fc.Guid.ToString(); this._startOid = featureId; this._bFinished = false; ILabel label = app.Current3DMapControl.ObjectManager.CreateLabel(app.Current3DMapControl.ProjectTree.RootID); label.Text = "起点"; ITextSymbol ts = new TextSymbol(); ts.TextAttribute.TextSize = SystemInfo.Instance.TextSize; ts.TextAttribute.TextColor = Convert.ToUInt32(SystemInfo.Instance.TextColor, 16); label.TextSymbol = ts; label.Position = this._drawTool.GetSelectPoint(); this._listRGuid.Add(label.Guid); } else { if (this._startFCGuid == fc.Guid.ToString() && this._startOid == featureId) { XtraMessageBox.Show("您选中的是同一个管点设施。", "提示"); return; } this._bFinished = true; ILabel label = app.Current3DMapControl.ObjectManager.CreateLabel(app.Current3DMapControl.ProjectTree.RootID); label.Text = "终点"; ITextSymbol ts = new TextSymbol(); ts.TextAttribute.TextSize = SystemInfo.Instance.TextSize; ts.TextAttribute.TextColor = Convert.ToUInt32(SystemInfo.Instance.TextColor, 16); label.TextSymbol = ts; label.Position = this._drawTool.GetSelectPoint(); this._listRGuid.Add(label.Guid); System.Threading.Thread.Sleep(1000); if (this._startFCGuid != fc.Guid.ToString()) { XtraMessageBox.Show("您选中的不是同一类管点设施。", "提示"); return; } else { WaitForm.Start("正在分析...", "请稍后"); FacClassReg reg = FacilityInfoService.GetFacClassRegByFeatureClassID(fc.Guid.ToString()); if (reg == null) { return; } TopoClass tc = FacilityInfoService.GetTopoClassByFacClassCode(reg.FacClassCode); if (tc == null) { return; } TopoNetwork net = tc.GetNetwork(); if (net == null) { XtraMessageBox.Show("构建拓扑网络失败!", "提示"); return; } else { string startId = this._startFCGuid + "_" + this._startOid.ToString(); string endId = fc.Guid.ToString() + "_" + featureId.ToString(); List <string> path; double shortestLength = net.SPFA(startId, endId, out path); if ((shortestLength > 0.0 && shortestLength != double.MaxValue) || (path != null && path.Count > 0)) { List <IPoint> listPt = new List <IPoint>(); foreach (string nodeId in path) { int index = nodeId.LastIndexOf("_"); string fcguid = nodeId.Substring(0, index); string oid = nodeId.Substring(index + 1, nodeId.Length - index - 1); DF3DFeatureClass dffcTemp = DF3DFeatureClassManager.Instance.GetFeatureClassByID(fcguid); if (dffcTemp == null || dffcTemp.GetFeatureClass() == null) { continue; } if (dffcTemp.GetFacilityClassName() != "PipeNode") { continue; } IQueryFilter filter = new QueryFilter(); filter.WhereClause = "oid = " + oid; filter.SubFields = "oid,Shape"; IRowBuffer row = null; IFdeCursor cursor = null; try { cursor = dffcTemp.GetFeatureClass().Search(filter, false); while ((row = cursor.NextRow()) != null) { if (!row.IsNull(1) && (row.GetValue(1) is IGeometry)) { IGeometry geo = row.GetValue(1) as IGeometry; switch (geo.GeometryType) { case gviGeometryType.gviGeometryPoint: IPoint pt = geo as IPoint; pt.Z = pt.Z + 1; listPt.Add(pt); break; } } } } 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; } } } IPolyline polyline = (new GeometryFactory()).CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline; foreach (IPoint pt in listPt) { ISimplePointSymbol ps = new SimplePointSymbol(); ps.Size = 5; ps.Style = gviSimplePointStyle.gviSimplePointCircle; ps.FillColor = Convert.ToUInt32(SystemInfo.Instance.LineColor, 16); IRenderPoint rp = app.Current3DMapControl.ObjectManager.CreateRenderPoint(pt, ps, app.Current3DMapControl.ProjectTree.RootID); rp.Glow(5000); polyline.AppendPoint(pt); this._listRGuid.Add(rp.Guid); } ICurveSymbol cs = new CurveSymbol(); cs.Color = Convert.ToUInt32(SystemInfo.Instance.LineColor, 16); cs.Width = -5; IRenderPolyline rpl = app.Current3DMapControl.ObjectManager.CreateRenderPolyline(polyline, cs, app.Current3DMapControl.ProjectTree.RootID); rpl.Glow(5000); this._listRGuid.Add(rpl.Guid); } else { XtraMessageBox.Show("两点不连通!", "提示"); } } } } } catch (Exception ex) { XtraMessageBox.Show("分析出错!", "提示"); } finally { WaitForm.Stop(); } }
private DataTable RegionAnalysis() { IGeometry geo = this._drawTool.GetGeo(); if (geo == null) { return(null); } ISpatialFilter filter = new SpatialFilter(); filter.Geometry = geo; filter.SpatialRel = gviSpatialRel.gviSpatialRelEnvelope; filter.GeometryField = "Geometry"; DataTable dtResult = new DataTable(); dtResult.Columns.AddRange(new DataColumn[] { new DataColumn("PIPELINETYPE"), new DataColumn("PVALUE"), new DataColumn("LENGTH", typeof(double)), new DataColumn("TOTALLENGTH", typeof(double)) }); foreach (MajorClass mc in LogicDataStructureManage3D.Instance.GetAllMajorClass()) { string[] arrFc3DId = mc.Fc3D.Split(';'); if (arrFc3DId == null) { continue; } double majorclasslength = 0.0; int indexStart = dtResult.Rows.Count; foreach (SubClass sc in mc.SubClasses) { if (!sc.Visible3D) { continue; } double subclasslength = 0.0; bool bHave = false; foreach (string fc3DId in arrFc3DId) { DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(fc3DId); if (dffc == null) { continue; } FacilityClass facc = dffc.GetFacilityClass(); IFeatureClass fc = dffc.GetFeatureClass(); if (fc == null || facc == null || facc.Name != "PipeLine") { continue; } DFDataConfig.Class.FieldInfo fiPipeLength = facc.GetFieldInfoBySystemName("PipeLength"); if (fiPipeLength == null) { continue; } int indexPipeLength = fc.GetFields().IndexOf(fiPipeLength.Name); int geometryIndex = fc.GetFields().IndexOf("Geometry"); if (indexPipeLength == -1 || geometryIndex == -1) { continue; } filter.WhereClause = "GroupId = " + sc.GroupId; filter.SubFields = fiPipeLength.Name + ",Geometry"; int count = fc.GetCount(filter); if (count == 0) { continue; } int loop = (int)Math.Ceiling(count / 800.0); for (int k = 1; k <= loop; k++) { if (k == 1) { filter.ResultBeginIndex = 0; } else { filter.ResultBeginIndex = (k - 1) * 800; } filter.ResultLimit = 800; IFdeCursor cursor = fc.Search(filter, true); IRowBuffer row = null; while ((row = cursor.NextRow()) != null) { IModelPoint modelPoint = row.GetValue(1) as IModelPoint; if ((geo as IRelationalOperator2D).Contains2D(modelPoint)) { subclasslength += double.Parse(row.GetValue(0).ToString()); bHave = true; } } } } if (bHave) { DataRow dr = dtResult.NewRow(); dr["PIPELINETYPE"] = mc; dr["PVALUE"] = sc; dr["LENGTH"] = subclasslength.ToString("0.00"); majorclasslength += subclasslength; dtResult.Rows.Add(dr); } } int indexEnd = dtResult.Rows.Count; for (int i = indexStart; i < indexEnd; i++) { DataRow dr = dtResult.Rows[i]; dr["TOTALLENGTH"] = majorclasslength.ToString("0.00"); } } return(dtResult); }
private void insertTags(Dictionary<string, int> domainAttributeFieldIndices, Dictionary<string, int> domainAttributeFieldLength, int tagCollectionFieldIndex, IRowBuffer row, tag[] tagsToInsert) { Dictionary<string, object> tagGdbStorageValues = new Dictionary<string, object>(domainAttributeFieldIndices.Count); foreach (var item in domainAttributeFieldIndices) { tagGdbStorageValues[item.Key] = null; } if (tagsToInsert != null) { foreach (tag tagItem in tagsToInsert) { if (domainAttributeFieldIndices.ContainsKey(tagItem.k)) { if (tagItem.v.Length <= domainAttributeFieldLength[tagItem.k]) { tagGdbStorageValues[tagItem.k] = tagItem.v; } } } } foreach (var item in domainAttributeFieldIndices) { row.set_Value(item.Value, tagGdbStorageValues[item.Key]); } if (tagCollectionFieldIndex > -1) { _osmUtility.insertOSMTags(tagCollectionFieldIndex, row, tagsToInsert); } tagGdbStorageValues.Clear(); tagGdbStorageValues = null; }
private void UpdateAttribute(object param) { DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } EditParameters editParameters = (EditParameters)param; if (editParameters == null) { return; } string featureClassGuid = editParameters.featureClassGuid; DF3DFeatureClass featureClassInfo = DF3DFeatureClassManager.Instance.GetFeatureClassByID(featureClassGuid); if (featureClassInfo == null) { return; } CommandManagerServices.Instance().StartCommand(); FDECommand cmd = new FDECommand(false, true); int nTotalCount = editParameters.nTotalCount; int num = 0; if (featureClassInfo.GetFeatureClass().HasTemporal() && CommonUtils.Instance().EnableTemproalEdit) { IConnectionInfo connectionInfo = new ConnectionInfoClass(); connectionInfo.FromConnectionString(featureClassInfo.GetFeatureClass().DataSource.ConnectionInfo.ToConnectionString()); IDataSource dataSource = ((IDataSourceFactory) new DataSourceFactoryClass()).OpenDataSource(connectionInfo); IFeatureDataSet featureDataSet = dataSource.OpenFeatureDataset(CommonUtils.Instance().GetCurrentFeatureDataset().Name); IFeatureClass featureClass = featureDataSet.OpenFeatureClass(featureClassInfo.GetFeatureClass().Name); ITemporalManager temporalManager = featureClass.TemporalManager; ITemporalCursor temporalCursor = temporalManager.Search(new TemporalFilterClass { IdsFilter = editParameters.fidList }); while (temporalCursor.MoveNext()) { this._manualResult.WaitOne(); num++; string userState = string.Format(StringParser.Parse("${res:feature_progress_finished}"), num, nTotalCount); int percentProgress = num * 100 / nTotalCount; this._bgWorker.ReportProgress(percentProgress, userState); bool flag = false; int currentId = temporalCursor.CurrentId; IRowBuffer row = featureClass.GetRow(currentId); base.UpdateRowBuffer(ref row, editParameters.colName, editParameters.regexDataList); ITemporalInstanceCursor temporalInstances = temporalCursor.GetTemporalInstances(false); TemporalInstance temporalInstance; while ((temporalInstance = temporalInstances.NextInstance()) != null) { if (temporalInstance.StartDatetime == editParameters.TemproalTime) { flag = true; temporalInstances.Update(row); break; } } System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalInstances); if (!flag) { temporalCursor.Insert(editParameters.TemproalTime, row); } } System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalCursor); System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalManager); System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass); System.Runtime.InteropServices.Marshal.ReleaseComObject(featureDataSet); System.Runtime.InteropServices.Marshal.ReleaseComObject(dataSource); } else { IFeatureClass featureClass2 = featureClassInfo.GetFeatureClass(); System.Collections.Generic.Dictionary <int, string> dictionary = new System.Collections.Generic.Dictionary <int, string>(); IRowBufferCollection rowBufferCollection = new RowBufferCollectionClass(); IRowBufferCollection rowBufferCollection2 = new RowBufferCollectionClass(); for (int i = 0; i < editParameters.fidList.Length; i++) { if (this._bgWorker.CancellationPending) { CommonUtils.Instance().FdeUndoRedoManager.UpdateFeatures(featureClass2, rowBufferCollection2); break; } this._manualResult.WaitOne(); System.Threading.Thread.Sleep(1); int num2 = editParameters.fidList[i]; IRowBuffer row2 = featureClass2.GetRow(num2); if (row2 != null) { string value = base.UpdateRowBuffer(ref row2, editParameters.colName, editParameters.regexDataList); rowBufferCollection.Add(row2); rowBufferCollection2.Add(row2); dictionary[num2] = value; num++; string userState2 = string.Format(StringParser.Parse("${res:feature_progress_finished}"), num, nTotalCount); int percentProgress2 = num * 100 / nTotalCount; this._bgWorker.ReportProgress(percentProgress2, userState2); } } if (dictionary.Count > 0) { CommonUtils.Instance().FdeUndoRedoManager.UpdateFeatures(featureClass2, rowBufferCollection2); object[] args = new object[] { featureClassInfo, editParameters.colName, dictionary }; //System.IAsyncResult asyncResult = MainFrmService.ResultSetPanel.BeginInvoke(this._updateSelection, args); //MainFrmService.ResultSetPanel.EndInvoke(asyncResult); } } CommandManagerServices.Instance().CallCommand(cmd); app.Workbench.UpdateMenu(); }
public object InsertRow(IRowBuffer Buffer) { return null; }
private void UpdateGeometry(object param) { try { DF3DApplication app = DF3DApplication.Application; if (app == null || app.Current3DMapControl == null) { return; } EditParameters editParameters = (EditParameters)param; if (editParameters != null) { System.Collections.Generic.Dictionary <DF3DFeatureClass, IRowBufferCollection> geometryMap = editParameters.geometryMap; if (geometryMap != null) { CommandManagerServices.Instance().StartCommand(); FDECommand cmd = new FDECommand(false, true); int nTotalCount = editParameters.nTotalCount; int num = 0; foreach (DF3DFeatureClass current in geometryMap.Keys) { if (this._bgWorker.CancellationPending) { break; } IRowBufferCollection rowBufferCollection = geometryMap[current]; if (current.GetFeatureClass().HasTemporal() && CommonUtils.Instance().EnableTemproalEdit) { IConnectionInfo connectionInfo = new ConnectionInfoClass(); connectionInfo.FromConnectionString(current.GetFeatureClass().DataSource.ConnectionInfo.ToConnectionString()); IDataSource dataSource = ((IDataSourceFactory) new DataSourceFactoryClass()).OpenDataSource(connectionInfo); IFeatureDataSet featureDataSet = dataSource.OpenFeatureDataset(CommonUtils.Instance().GetCurrentFeatureDataset().Name); IFeatureClass featureClass = featureDataSet.OpenFeatureClass(current.GetFeatureClass().Name); int position = featureClass.GetFields().IndexOf(featureClass.FidFieldName); System.Collections.Generic.Dictionary <int, IRowBuffer> dictionary = new System.Collections.Generic.Dictionary <int, IRowBuffer>(); for (int i = 0; i < rowBufferCollection.Count; i++) { IRowBuffer rowBuffer = rowBufferCollection.Get(i); int key = (int)rowBuffer.GetValue(position); dictionary[key] = rowBuffer; } ITemporalManager temporalManager = featureClass.TemporalManager; ITemporalCursor temporalCursor = temporalManager.Search(new TemporalFilterClass { IdsFilter = dictionary.Keys.ToArray <int>() }); while (temporalCursor.MoveNext() && !this._bgWorker.CancellationPending) { this._manualResult.WaitOne(); System.Threading.Thread.Sleep(1); num++; string userState = string.Format(StringParser.Parse("${res:feature_progress_finished}"), num, nTotalCount); int percentProgress = num * 100 / nTotalCount; this._bgWorker.ReportProgress(percentProgress, userState); bool flag = false; int currentId = temporalCursor.CurrentId; ITemporalInstanceCursor temporalInstances = temporalCursor.GetTemporalInstances(false); TemporalInstance temporalInstance; while ((temporalInstance = temporalInstances.NextInstance()) != null) { if (temporalInstance.StartDatetime == editParameters.TemproalTime) { flag = true; temporalInstances.Update(dictionary[currentId]); break; } } System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalInstances); if (!flag) { temporalCursor.Insert(editParameters.TemproalTime, dictionary[currentId]); } } System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalCursor); System.Runtime.InteropServices.Marshal.ReleaseComObject(temporalManager); System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass); System.Runtime.InteropServices.Marshal.ReleaseComObject(featureDataSet); System.Runtime.InteropServices.Marshal.ReleaseComObject(dataSource); } else { IFeatureClass featureClass2 = current.GetFeatureClass(); int num2 = 0; while (num2 < rowBufferCollection.Count && !this._bgWorker.CancellationPending) { this._manualResult.WaitOne(); System.Threading.Thread.Sleep(1); num++; string userState2 = string.Format(StringParser.Parse("${res:feature_progress_finished}"), num, nTotalCount); int percentProgress2 = num * 100 / nTotalCount; this._bgWorker.ReportProgress(percentProgress2, userState2); num2++; } CommonUtils.Instance().FdeUndoRedoManager.UpdateFeatures(featureClass2, rowBufferCollection); } } CommandManagerServices.Instance().CallCommand(cmd); app.Workbench.UpdateMenu(); } } } catch (System.Runtime.InteropServices.COMException ex) { XtraMessageBox.Show(ex.Message); } catch (System.UnauthorizedAccessException) { XtraMessageBox.Show(StringParser.Parse("${res:Dataset_InsufficientPermission}")); } catch (System.Exception e) { LoggingService.Error(e.Message); } }
public int QueryValues(IRowBuffer row) { try { if (m_currentOGRFeature == null) return -1; // Loop and only set values in the rowbuffer // that were requested by ArcGIS. // // Ignore the ArcObjects documentation because it says I should use the field map // and that is straight out incorrect. Only copy values if the fieldmap has any value // besides -1. Othewise, ignore whatever map it is asking to copy to and simply copy // to the right field. IFields pFields = m_pDataset.get_Fields(0); int fieldCount = pFields.FieldCount; for (int i = 0; i < fieldCount; i++) { int esriFieldIndex = (int)m_esriQueryFieldMap.GetValue(i); if (esriFieldIndex == -1 || i == m_pDataset.get_OIDFieldIndex(0) || i == m_pDataset.get_ShapeFieldIndex(0)) continue; IField pField = pFields.get_Field(i); object val = null; // DANGER - POTENTIAL BUG - Workaround. For some reason, in ArcGIS 10.1SP1 I am // getting fields that should not be editable passed in to map into!!!?!? I am // skipping those here. In theory, since we are the DataSource provider, we should be able to // use a lower level set value that skips polymorphic behavior and hence allows // the write to happen even in non-editable fields. Something analogous to // ITableWrite::WriteRow, but for Rows. We don't have that, so I skip those values for those // rows. if (!pFields.get_Field(i).Editable) continue; try { val = m_pDataset.GetMappedValue(m_currentOGRFeature, i); row.set_Value(i, val); } catch (Exception ex) { // skip values that fail to be set but continue doing it anyway string msg = String.Format("OGRFID:[{0}] esriFieldName:[{1}] esriFieldIndex:[{2}] esriValue:[{3}] Exception:[{4}]", m_currentOGRFeature.GetFID(), pField.Name, esriFieldIndex, val != null ? val.ToString() : "<not set>", ex.Message); System.Diagnostics.Debug.WriteLine(msg); } } return m_currentOGRFeature.GetFID(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); return -1; } }
/// <summary> /// Sets a database fields value /// /// Throws an exception if the field is not found. /// </summary> /// <param name="ipRowBuffer">The tables row buffer</param> /// <param name="strFieldName">The fields name</param> /// <param name="oFieldValue">The value to set</param> public static void SetDatabaseFieldValue(IRowBuffer ipRowBuffer, string strFieldName, object oFieldValue) { int iFieldIndex = ipRowBuffer.Fields.FindField(strFieldName); if (iFieldIndex >= 0) { ipRowBuffer.set_Value(iFieldIndex, oFieldValue); } else { throw new Exception(VisibilityLibrary.Properties.Resources.ExceptionFieldIndexNotFound); } }