//设置区划中心点和边界 private void SetRegionInfo(csGovRegion csGR) { try { //获取GIS信息 Recordset recdst2 = GetRecordsetByCode(csGR.RegionCode); if (recdst2 != null && recdst2.RecordCount > 0) { csGR.RegionCenter = new csCenter(); csGR.RegionBounds = new csBounds(); GeoLine geoLine1 = recdst2.GetGeometry() as GeoLine; csGR.RegionCenter.center = GetCenterPoint(csGR.RegionCode); double dKey = 10714896 / 111000 / 0.08; while (!recdst2.IsEOF) { try { GeoLine geoLine2 = recdst2.GetGeometry() as GeoLine; for (int i = 0; i < geoLine2.PartCount; i++) { GeoLine geoL = new GeoLine(geoLine2[i]); GeoLine geoLine = null; if (geoL[0].Count < 400) { geoLine = geoL; } else { double dTolerance = geoL.Length / dKey; { //dTolerance = GetTolerance(csGR.RegionCode); } geoLine = Geometrist.Resample(geoL, ResampleType.RTGeneral, dTolerance) as GeoLine; } csGR.RegionBounds.bounds.Add(geoLine[0].Clone()); } } catch (SystemException sysEx) { string strErr = sysEx.Message; } recdst2.MoveNext(); } } } catch {} }
/// <summary> /// 使当前被选中对象所在的图层为当前图层 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void m_sceneControl_ObjectSelected(object sender, ObjectSelectedEventArgs e) { try { if (e.Count > 0) { Selection3D[] selection = m_sceneContorl.Scene.FindSelection(true); Recordset recordeset = selection[0].ToRecordset(); geometry = recordeset.GetGeometry() as Geometry3D; if (geometry.Type == GeometryType.GeoLine3D) { //ButtonFlyLine.Enabled = true; } else { //ButtonFlyLineStop.Enabled = false; //ButtonFlyLine.Enabled = false; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
// public static GeoRegion GetRegionByQHBM(string strQHBM) { GeoRegion geoR = null; if (strQHBM.Length > 0) { try { if (m_ChinaXZQH != null) { string strFilter = string.Format("code ='{0}'", strQHBM); { Recordset recdst = m_ChinaXZQH.Query(strQHBM, CursorType.Static); if (recdst.RecordCount == 0) { strQHBM = string.Format("{0}00", strQHBM.Substring(0, 4)); recdst = m_ChinaXZQH.Query(strQHBM, CursorType.Static); } geoR = recdst.GetGeometry() as GeoRegion; } } } catch { } } return(geoR); }
public void UpdateMapView(string strID) { if (m_workspace.Datasources.Count <= 0) { return; } Datasource datasource = m_workspace.Datasources[0]; for (int ModelIndex = 0; ModelIndex < UserHelper.nDeviceNum; ModelIndex++) { DatasetVector pointDataset = datasource.Datasets[UserHelper.sDeviceName[ModelIndex]] as DatasetVector; Recordset recordSet = null; try { if (pointDataset != null) { recordSet = pointDataset.Query(m_filedName + "='" + strID + "'", CursorType.Dynamic); int recCount = recordSet.RecordCount; if (recCount == 1) { //if (pointColor >= 255) //{ // pointColor = 0; //} pointColor = pointColor == 120 ? 255 : 120; GeoStyle style = new GeoStyle(); style.MarkerSize = new Size2D(8, 8); style.LineColor = Color.FromArgb(0, 0, pointColor, 0); //pointColor += 60; GeoPoint point = recordSet.GetGeometry() as GeoPoint; point.Style = style; int index = m_MapControl.Map.TrackingLayer.IndexOf(strID); if (index >= 0) { m_MapControl.Map.TrackingLayer.Remove(index); } m_MapControl.Map.TrackingLayer.Add(point, strID); //recordSet.Edit(); //recordSet.Update(); //recordSet.Close(); //recordSet.Dispose(); break; } //recordSet.Close(); //recordSet.Dispose(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } m_MapControl.Map.Refresh(); }
/// <summary> /// 选择事件点。 /// Select events /// </summary> public void FindEventNode() { try { Recordset recordset = m_layerPoint.Selection.ToRecordset(); Geometry geometry = recordset.GetGeometry(); m_selectFacilityNode = false; m_selectBarrier = false; m_selectEventNode = true; m_eventNode = m_recordset.GetID(); if (geometry.Type == GeometryType.GeoPoint) { int index = m_trackingLayer.IndexOf("EventNode"); if (index != -1) { m_trackingLayer.Remove(index); } m_trackingLayer.Add(m_geoPoint, "EventNode"); } } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
private void dataGridView2_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { if (dataGridView2.CurrentRow == null) { return; } DataGridViewRow dgvr = dataGridView2.CurrentRow; string strName = dgvr.Cells["地块编号"].Value.ToString();//获取smid值 // 构造一个查询参数对象,查询选中的记录 QueryParameter para = new QueryParameter(); para.AttributeFilter = "SMID =" + strName; para.CursorType = CursorType.Dynamic; Recordset recordset = null; try { recordset = importResultShp.Query(para); Selection selection = mapControl1.Map.Layers[0].Selection; selection.FromRecordset(recordset); mapControl1.Map.EnsureVisible(recordset.GetGeometry(), 0.8); mapControl1.Map.Refresh(); } catch (Exception ex) { Trace.WriteLine(ex.Message); } finally { recordset.Dispose(); } }
private void button4_Click_1(object sender, EventArgs e) { //string strDatasourceName = "行政区划"; string strDatasetName = "省会城市"; string strTableName = "T_GIS_REGION"; try { Datasource dtSource = m_wrkSpace.Datasources[0]; foreach (Dataset dtSet in dtSource.Datasets) { if (dtSet.Name.Equals(strDatasetName)) { DatasetVector dtVector = dtSet as DatasetVector; Recordset recdst = dtVector.GetRecordset(false, CursorType.Static); while (!recdst.IsEOF) { string strName = string.Format("{0}", recdst.GetFieldValue("PROVINCE")); GeoPoint geoPt = recdst.GetGeometry() as GeoPoint; csCenter c = new csCenter(); c.center = geoPt.InnerPoint; string strCenter = JSONHelper.ObjectToJSON(c.center); string strSQL = string.Format("update {0} t set t.centerpoint = '{1}' where t.regionname = '{2}' and rlevel=1", strTableName, strCenter, strName); DbHelperOra.ExecuteSql(DbHelperOra.connectionString_172, strSQL); recdst.MoveNext(); } } } } catch { } }
/// <summary> /// 飞向管线ID /// </summary> /// <param name="flag">判断是第几个管线或管点对象</param> /// <param name="ID">获取该ID值</param> public void FlyToConnectID(int flag, int ID) { try { Recordset selected = null; DatasetVector network = mConNetWorkName; mSceneControl.Bubbles.Clear(); Bubble bubble = new Bubble(); mInformationBubble.Visible = true; //定义经纬度,为方便飞行定位 Double mFlylongitude = 0; Double mFlylatitude = 0; //区分类型 按点飞 还是 按线飞 if (recordsetTypeConId1 == GeometryType.GeoLine3D) { String expression = "SmID = " + ID; selected = network.Query(expression, CursorType.Static); Geometry3D geometry = selected.GetGeometry() as Geometry3D; mInformationBubble.Description.Text = "管线ID-" + flag + ":" + ID + "的位置如下";; bubble.Pointer = new Point3D(geometry.InnerPoint3D.X, geometry.InnerPoint3D.Y, mPipeAltitude); bubble.ClientWidth = mInformationBubble.Width; bubble.ClientHeight = mInformationBubble.Height; mInformationBubble.Location = new Point(bubble.ClientLeft, bubble.ClientTop); mSceneControl.Bubbles.Add(bubble); mFlylongitude = geometry.InnerPoint3D.X; mFlylatitude = geometry.InnerPoint3D.Y; } else if (recordsetTypeConId1 == GeometryType.GeoPoint3D) { String expression = "SmID = " + ID; selected = network.ChildDataset.Query(expression, CursorType.Static); object mAnalongitude = selected.GetFieldValue("SmX"); object mAnalatitude = selected.GetFieldValue("SmY"); mInformationBubble.Description.Text = "管点ID-" + flag + ":" + ID + "的位置如下"; bubble.Pointer = new Point3D(Convert.ToDouble(mAnalongitude), Convert.ToDouble(mAnalatitude), mPipeAltitude); bubble.ClientWidth = mInformationBubble.Width; bubble.ClientHeight = mInformationBubble.Height; mInformationBubble.Location = new Point(bubble.ClientLeft, bubble.ClientTop); mSceneControl.Bubbles.Add(bubble); mFlylongitude = Convert.ToDouble(mAnalongitude); mFlylatitude = Convert.ToDouble(mAnalatitude); } Camera camera = new Camera(); camera.Longitude = Convert.ToDouble(mFlylongitude); camera.Latitude = Convert.ToDouble(mFlylatitude); camera.AltitudeMode = AltitudeMode.RelativeToGround; camera.Tilt = 0; camera.Altitude = 25; mSceneControl.Scene.Fly(camera, 10); mSceneControl.Scene.Refresh(); } catch (Exception ex) { Trace.WriteLine(ex); } }
/// <summary> /// 对象选择事件。 /// GeometrySelectedEvent /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void m_mapControl_GeometrySelected(Object sender, SuperMap.UI.GeometrySelectedEventArgs e) { if (m_selectMode != SelectMode.SelectBarrier) { return; } Selection selection = m_layerPoint.Selection; if (selection.Count <= 0) { selection = m_layerLine.Selection; } GeoStyle style = new GeoStyle(); style.LineColor = Color.Red; Recordset recordset = selection.ToRecordset(); try { Geometry geometry = recordset.GetGeometry(); // 捕捉到点时,将捕捉到的点添加到障碍点列表中 // If a point is snapped, the point is added to the barrier list if (geometry.Type == GeometryType.GeoPoint) { GeoPoint geoPoint = (GeoPoint)geometry; int id = recordset.GetID(); m_barrierNodes.Add(id); style.MarkerSize = new Size2D(4, 4); geoPoint.Style = style; m_trackingLayer.Add(geoPoint, "barrierNode"); } // 捕捉到线时,将线对象添加到障碍线列表中 // If a line is snapped, the line is added to the barrier list if (geometry.Type == GeometryType.GeoLine) { GeoLine geoLine = (GeoLine)geometry; int id = recordset.GetID(); m_barrierEdges.Add(id); style.LineWidth = 0.6; geoLine.Style = style; m_trackingLayer.Add(geoLine, "barrierEdge"); } m_mapControl.Map.Refresh(); } catch (Exception ex) { Trace.WriteLine(ex.Message); } finally { recordset.Dispose(); } }
public bool layerExist(Recordset tempRecordset) { bool flag = false; //项目地块是否存在标记 bool isExit = false; if (formatRecordset == null) { return(flag); } //地块编号 string strDkbh = ""; if (formatRecordset.RecordCount > 0) { for (int i = 0; i <= formatRecordset.RecordCount; i++) { formatRecordset.MoveTo(i); //判断该图斑是否已经由临时图层导入正式图层 if (formatRecordset.GetGeometry().Bounds.Equals(tempRecordset.GetGeometry().Bounds)) { //取得地块编号 strDkbh = formatRecordset.GetFieldValue("DKBH").ToString(); flag = true; break; } } } //补耕地块录入时同一个旗县可能存在多个复垦项目的情况,该种情况下,判断该项目下是否存在上面处理中取得的地块编号 //获取项目名称值 if (textBox2.Text == "补耕") { sqlQuery.Clear(); sqlQuery.Append("SELECT DKBH AS 地块编号, "); sqlQuery.Append(" FKXMMC AS 所属复垦项目名称, "); sqlQuery.Append(" XMSZXM AS 项目所在县名称 "); sqlQuery.Append(", BZ AS 备注 "); sqlQuery.Append(" FROM " + "BG" + gkfqd.Common.DbUse.GetTownCode(textBox3.Text)); sqlQuery.Append(" WHERE FKXMMC='" + textBox1.Text + "'AND DKBH='" + strDkbh + "'"); gkfqd.Common.DbUse.GetOleDbconnection().Close(); gkfqd.Common.DbUse.GetOleDbconnection().Open(); dataSet6.Clear(); OleDbDataAdapter MyAdapter = new OleDbDataAdapter(sqlQuery.ToString(), gkfqd.Common.DbUse.GetOleDbconnection()); MyAdapter.Fill(dataSet6); gkfqd.Common.DbUse.GetOleDbconnection().Close(); if (dataSet6.Tables[0].Rows.Count > 0) { isExit = true; } //当地块存在,并且该项目名称下有该地块的情况 return(flag && isExit); } return(flag); }
public int PickNodeToLine(int nID) { m_SelectedGeoNetwork.Clear(); DatasetVector DvLine = m_workspace.Datasources["Pipeline3D"].Datasets["PipeLine3D"] as DatasetVector; DatasetVector DvNode = m_workspace.Datasources["Pipeline3D"].Datasets["PipePoint3D"] as DatasetVector; int[] id = { nID }; Recordset recordset = DvNode.Query(id, CursorType.Static); Geometry pGeoNode = recordset.GetGeometry(); string strNodeID = "PtID"; int nNodeID = Convert.ToInt32(recordset.GetFieldValue(strNodeID)); string strFNode = "FNode"; string strTNode = "ENode"; QueryParameter queryparameter = new QueryParameter(); queryparameter.CursorType = CursorType.Static; queryparameter.AttributeFilter = String.Format("{0}={1} or {2}={3}", strFNode, nNodeID, strTNode, nNodeID); Recordset Rs = DvLine.Query(queryparameter); int nCount = Rs.RecordCount;; Rs.MoveFirst(); while (!Rs.IsEOF) { GeoLine3D geoline3D = Rs.GetGeometry() as GeoLine3D; NetworkGeometry NetWorkGeometry = new NetworkGeometry(); NetWorkGeometry.nID = geoline3D.ID; NetWorkGeometry.nFNode = Convert.ToInt32(Rs.GetFieldValue(strFNode)); NetWorkGeometry.nTNode = Convert.ToInt32(Rs.GetFieldValue(strTNode)); if (!m_SelectedGeoNetwork.Contains(NetWorkGeometry)) { if (NetWorkGeometry.nTNode == nNodeID) { NetWorkGeometry.geometry = geoline3D; m_SelectedGeoNetwork.Add(NetWorkGeometry);//流入对象在第一位 } else { NetWorkGeometry.bIsIn = false; NetWorkGeometry.geometry = geoline3D; m_SelectedGeoNetwork.Add(NetWorkGeometry);//线对象 } } Rs.MoveNext(); } Rs.Dispose(); return(nCount); }
/// <summary> /// MapControl MouseMove事件。 /// MapControl MouseMove event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void m_mapControl_MouseMove(object sender, MouseEventArgs e) { try { m_mapControl.DoMouseMove(e); if (m_mapControl.Action == SuperMap.UI.Action.Select || m_mapControl.Action == SuperMap.UI.Action.Select2) { // 获取鼠标点对应的地图点 // Get the map point that corresponds to the mouse point m_mousePoint = new Point(e.X, e.Y); Point2D point2D = m_mapControl.Map.PixelToMap(m_mousePoint); // 根据当前比例尺设置捕捉框的大小 // Set the snap box size according to the current scale double scale = (3 * 10E-4) / m_mapControl.Map.Scale; Selection selection = m_layerPoint.HitTest(point2D, 4 / 3 * scale); int index = m_trackingLayer.IndexOf("geoLine"); if (index != -1) { m_trackingLayer.Remove(index); } if (selection != null && selection.Count > 0) { Recordset recordset = selection.ToRecordset(); GeoPoint geoPoint = (GeoPoint)recordset.GetGeometry(); recordset.Dispose(); double pointX = geoPoint.X; double pointY = geoPoint.Y; // 构造捕捉框 // Build snap box Point2Ds point2Ds = new Point2Ds(); point2Ds.Add(new Point2D(pointX - scale, pointY - scale)); point2Ds.Add(new Point2D(pointX + scale, pointY - scale)); point2Ds.Add(new Point2D(pointX + scale, pointY + scale)); point2Ds.Add(new Point2D(pointX - scale, pointY + scale)); point2Ds.Add(new Point2D(pointX - scale, pointY - scale)); GeoLine geoLine = new GeoLine(point2Ds); // 刷新地图 // Refresh the map m_mapControl.SelectionTolerance = 2; m_trackingLayer.Add(geoLine, "geoLine"); m_mapControl.Map.Refresh(); } } } catch (System.Exception ex) { Trace.WriteLine(ex.Message); } }
private DatasetVector DatasetConvertRegionToLine(DatasetVector dtVector2) { DatasetVector dtVector = null; if (dtVector2 != null) { DatasetVectorInfo dvi = new DatasetVectorInfo(); dvi.Name = m_selLayer.Dataset.Datasource.Datasets.GetAvailableDatasetName("C_geoLine"); dvi.Type = DatasetType.Line; //DatasetVector dtVector = m_selLayer.Dataset.Datasource.Datasets.Create(dvi); foreach (FieldInfo fi in dtVector2.FieldInfos) { if (dtVector.FieldInfos.IndexOf(fi.Name) < 0 && !fi.IsSystemField) { dtVector.FieldInfos.Add(fi.Clone()); } } Recordset recdst = dtVector.GetRecordset(true, CursorType.Dynamic); recdst.Batch.Begin(); try { Recordset recdst2 = dtVector2.GetRecordset(false, CursorType.Static); while (!recdst2.IsEOF) { GeoRegion geoR = recdst2.GetGeometry() as GeoRegion; if (geoR != null) { GeoLine geoLine = geoR.ConvertToLine(); recdst.AddNew(geoLine); foreach (FieldInfo fi in dtVector2.FieldInfos) { if (dtVector.FieldInfos.IndexOf(fi.Name) > -1 && !fi.IsSystemField) { recdst.SetFieldValue(fi.Name, recdst2.GetFieldValue(fi.Name)); } } geoR.Dispose(); } recdst2.MoveNext(); } recdst2.Dispose(); } catch { } recdst.Batch.Update(); recdst.Dispose(); } return(dtVector); }
private void dataGridView1_MouseUp(object sender, MouseEventArgs e) { string tableName = gkfqd.Common.DbUse.FXGetTownCode(comboBox3.Text) + "_" + comboBox4.Text; MapShow(tableName); if (dataGridView1.CurrentRow == null) { return; } DataGridViewRow dgvr = dataGridView1.CurrentRow; string strSmid = dgvr.Cells["SMID"].Value.ToString(); QueryParameter para = new QueryParameter(); //para.AttributeFilter = " select SMID from "+ tableName ; para.AttributeFilter = " SMID > 0 "; para.CursorType = CursorType.Dynamic; //string strSmid = dgvr.Cells["项目名称"].Value.ToString(); //QueryParameter para = new QueryParameter(); //para.AttributeFilter = "FKXMMC = '" + strSmid + "'"; //para.CursorType = CursorType.Dynamic; try { recordset = importResultShp.Query(para); Selection selection = mapControl1.Map.Layers[0].Selection; selection.FromRecordset(recordset); //缩放比例设定 mapControl1.Map.ViewEntire(); //mapControl1.Map.EnsureVisible(recordset.GetGeometry(), 0.8); mapControl1.Map.EnsureVisible(recordset.GetGeometry(), 0.8); mapControl1.Map.ViewEntire(); // mapControl1.Map.EnsureVisible(recordset.GetGeometry(), 0.8); mapControl1.Map.Refresh(); } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
/// <summary> /// 鼠标移动时绘制捕捉框 /// Draw the snap box when the mouse moves /// </summary> /// <param name="point"></param> public void SetBound(Point point) { try { // 清除跟踪图层上的捕捉框 // Clear snap box on the tracking layer Int32 indexSnapPane = m_trackingLayer.IndexOf("snapPane"); if (indexSnapPane != -1) { m_trackingLayer.Remove(indexSnapPane); m_mapControl.Map.RefreshTrackingLayer(); } // 将屏幕坐标转换为地图坐标 // Transform the pixel coordinates to the map coordinates Point2D mapPoint = m_mapControl.Map.PixelToMap(point); Double scale = (3 * 10E-4) / m_mapControl.Map.Scale; m_selection = m_layerStop.HitTest(mapPoint, 4 / 3 * scale); if (m_selection != null && m_selection.Count > 0) { Recordset recordset = m_selection.ToRecordset(); GeoPoint stopPoint = recordset.GetGeometry() as GeoPoint; // 构造捕捉框 // Build the snap box Point2Ds points = new Point2Ds(); points.Add(new Point2D(stopPoint.X - scale, stopPoint.Y - scale)); points.Add(new Point2D(stopPoint.X + scale, stopPoint.Y - scale)); points.Add(new Point2D(stopPoint.X + scale, stopPoint.Y + scale)); points.Add(new Point2D(stopPoint.X - scale, stopPoint.Y + scale)); points.Add(new Point2D(stopPoint.X - scale, stopPoint.Y - scale)); GeoLine snapPane = new GeoLine(points); m_mapControl.SelectionTolerance = 2.0; m_trackingLayer.Add(snapPane, "snapPane"); m_mapControl.Map.RefreshTrackingLayer(); recordset.Dispose(); } } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
//获取线数据的点集 private Point2Ds GetPoint2DsFromLine(string strFilter) { Point2Ds resPts = null; try { Datasource dtSource = m_Workspace.Datasources[0]; Dataset dtSet = dtSource.Datasets["公路"]; DatasetVector dtVector = dtSet as DatasetVector; Recordset recdst = dtVector.Query(strFilter, CursorType.Static); if (recdst != null && recdst.RecordCount > 0) { Point2Ds pt2Ds = new Point2Ds(); if (recdst.RecordCount > 2) { Random r = new Random(); int iAt = r.Next(0, recdst.RecordCount - 2); recdst.MoveTo(iAt); } while (!recdst.IsEOF) { GeoLine geoLine = recdst.GetGeometry() as GeoLine; if (geoLine != null) { pt2Ds.AddRange(geoLine[0].ToArray()); } recdst.MoveNext(); } if (pt2Ds != null && pt2Ds.Count > 0) { resPts = pt2Ds.Clone(); //对线进行插值平滑处理 int smoothness = 8; resPts = Geometrist.Smooth(pt2Ds, smoothness); } } } catch { } return(resPts); }
/// <summary> /// MapControl MouseDown事件 /// MapControl MouseDown event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void m_mapControl_MouseDown(object sender, MouseEventArgs e) { try { if (e.Button == MouseButtons.Left) { Selection selection = m_layerPoint.Selection; if (selection == null || selection.Count == 0) { selection = m_layerLine.Selection; } if (m_mapControl.Action == SuperMap.UI.Action.Select && e.Clicks == 1 && (m_selectMode == SelectMode.SELECTPOINT || m_selectMode == SelectMode.SELECTBARRIER || m_selectMode == SelectMode.SELECTEVENT)) { if (selection.Count <= 0) { if (SuperMap.Data.Environment.CurrentCulture != "zh-CN") { MessageBox.Show("The coordinates exceed the tolerance. Invalid!"); } else { MessageBox.Show("坐标点超出选择容限,不能作为分析点"); } } else { //根据选择的不同,构造点对象 m_recordset = selection.ToRecordset(); Geometry geometry = m_recordset.GetGeometry(); AddPoint(geometry); m_recordset.Dispose(); } } } } catch (System.Exception ex) { Trace.WriteLine(ex.Message); } }
/// <summary> /// 选择障碍点。 /// Select barriers /// </summary> public void FindBarrierNodes() { try { Recordset recordset = m_layerPoint.Selection.ToRecordset(); Geometry geometry = recordset.GetGeometry(); m_selectFacilityNode = false; m_selectBarrier = true; m_selectEventNode = false; Int32 id = m_recordset.GetID(); if (geometry.Type == GeometryType.GeoPoint) { m_nodesList.Add(m_recordset.GetID()); m_trackingLayer.Add(m_geoPoint, "FacilityNode" + id); } } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
// 对象选择事件 private void m_mapControl_GeometrySelected(object sender, SuperMap.UI.GeometrySelectedEventArgs e) { try { Recordset recordset = GetSelectedRecordset(false); GeoPoint gp = recordset.GetGeometry() as GeoPoint; sender = gp; if (CameraDataAdjustHandler != null) { CameraDataAdjustHandler(sender); } if (WndDataViewer != null) { WndDataViewer(sender, e); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
///// <summary> ///// 从实体的超图单位对象获取几何对象 ///// </summary> ///// <param name="Unit"></param> ///// <returns></returns> //public static T GetGeometryObject<T>(this SMUnit Unit) // where T : new() //{ // T tObj = new T(); // Geometry geo = tObj as Geometry; // if (Unit != null) // { // if (Unit.GeoObject != null) // { // geo = Unit.GeoObject; // } // else if (geo != null) // { // geo.FromXML(Unit.GeometrySerialize); // } // } // return (T)((object)geo); //} #region 查询几何对象 /// <summary> /// 查询几何对象 /// </summary> /// <param name="MapObj">地图对象</param> /// <param name="LayerName">图层名称</param> /// <param name="SMID">编号</param> /// <returns></returns> public static Geometry QueryGeometry(this Map MapObj, string LayerName, int SMID) { Geometry result = null; Layer tagLayer = MapObj.Layers[LayerName]; tagLayer.Selection.Clear(); DatasetVector dv = (DatasetVector)tagLayer.Dataset; QueryParameter qp = new QueryParameter(); qp.AttributeFilter = "SMID='" + SMID.ToString() + "'"; qp.CursorType = CursorType.Static; qp.HasGeometry = true; Recordset rcd = dv.Query(qp); if (rcd != null) { result = rcd.GetGeometry(); } rcd.Close(); rcd.Dispose(); return(result); }
private void timer_Blink_Tick(object sender, EventArgs e) { if (_blinkCount > 3) { _currentMapCtl.Map.TrackingLayer.Clear(); _currentMapCtl.Map.RefreshTrackingLayer(); _blinkCount = 0; timer_Blink.Stop(); _blinkRs.Close(); _blinkRs.Dispose(); } else { if (_isBlink) { _blinkRs.MoveFirst(); while (!_blinkRs.IsEOF) { var geo = _blinkRs.GetGeometry(); var blinkStyle = new GeoStyle { FillForeColor = Color.Red, FillOpaqueRate = 60, LineColor = Color.Red, LineWidth = 2, MarkerSize = new Size2D(10, 10) }; geo.Style = blinkStyle; _currentMapCtl.Map.TrackingLayer.Add(geo, "blink"); _currentMapCtl.Map.RefreshTrackingLayer(); _blinkRs.MoveNext(); } _blinkCount++; } else { _currentMapCtl.Map.TrackingLayer.Clear(); _currentMapCtl.Map.RefreshTrackingLayer(); } } _isBlink = !_isBlink; }
//复制某记录到另外记录中 private void CopyRecordset(Recordset sour_recdst, Recordset dest_recdst) { try { FieldInfos dest_fis = dest_recdst.GetFieldInfos(); FieldInfos sour_fis = sour_recdst.GetFieldInfos(); dest_recdst.Batch.Begin(); while (!sour_recdst.IsEOF) { if (dest_recdst.AddNew(sour_recdst.GetGeometry())) { Dictionary <string, object> arrValues = new Dictionary <string, object>(); foreach (FieldInfo item in dest_fis) { if (!item.IsSystemField) { int iDex = GetIndexByCaption(sour_fis, item.Name); if (iDex > -1) { object obj = sour_recdst.GetFieldValue(iDex); arrValues.Add(item.Name, obj); } } } //增加主体类型 { arrValues.Add("ZTLX", m_strZTLX); } bool bRes = dest_recdst.SetValues(arrValues); } sour_recdst.MoveNext(); } dest_recdst.Batch.Update(); } catch { } }
/// <summary> /// 静态展示地铁和管道 /// </summary> /// <param routestopName="selectID"></param> public void comBoxDisplayLine3D(int selectID) { try { int selectinonID = selectID; //先进行地表挖方 m_sceneControl.Scene.Refresh(); m_sceneControl.Scene.Underground.IsVisible = true; m_sceneControl.Scene.GlobalImage.Transparency = 0; DatasetVector dataSet_Region = m_workspace.Datasources["Pipeline3D"].Datasets["Region"] as DatasetVector; int[] id = { 1 }; Recordset recordset = dataSet_Region.Query(id, CursorType.Static); GeoRegion georegion = recordset.GetGeometry() as GeoRegion; int i = m_sceneControl.Scene.GlobalImage.AddExcavationRegion(georegion, "地表局部透明"); switch (selectinonID) { case 0: { LoadSubway(); break; } case 1: { LoadPipeLine3D(); break; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private GeoPoint GetGeoPoint() { GeoPoint geoPt = null; // string strDatasetName = "县面层"; try { Datasource dtSource = m_Workspace.Datasources[0]; Dataset dtSet = dtSource.Datasets[strDatasetName]; DatasetVector dtVector = dtSet as DatasetVector; Recordset recdst = dtVector.Query("gb like '3204%'", CursorType.Static); int nPos = m_Random.Next(0, recdst.RecordCount - 1); recdst.MoveTo(nPos); GeoRegion geoR = recdst.GetGeometry() as GeoRegion; if (geoR != null) { Random r = new Random(); Rectangle2D rect2D = geoR.Bounds; double dx_min = rect2D.Left; double dy_min = rect2D.Bottom; double dx_max = rect2D.Right; double dy_max = rect2D.Top; double xDiff = dx_max - dx_min; double yDiff = dy_max - dy_min; double dx = dx_min + xDiff * r.Next(9, 95) / 100.0; double dy = dy_min + yDiff * r.Next(9, 95) / 100.0; Point2D pt2D = new Point2D(dx, dy); geoPt = new GeoPoint(pt2D); } } catch { } // return(geoPt); }
void mSceneControlSelected(object sender, ObjectSelectedEventArgs e) { Recordset recordset = null; Selection3D[] selection3d = null; mGeoLine3D = new GeoLine3D(); //水平及竖直净距 if (mSceneControl.Action == Action3D.Select && mFlag == 1 || mSceneControl.Action == Action3D.Select && mFlag == 2) { if (e.Count > 0) { selection3d = mSceneControl.Scene.FindSelection(true); recordset = selection3d[0].ToRecordset(); if (recordset.GetGeometry().Type != mGeoLine3D.Type) { MessageBox.Show("请选择三维线对象!"); } else { mGeoLine3D = recordset.GetGeometry() as GeoLine3D; if (TempGeoLine.Count > 0 && TempGeoLine[0].Bounds == mGeoLine3D.Bounds) { MessageBox.Show("请不要选择同一条三维线对象!"); } else { mTextPoint3Ds.Add(mGeoLine3D.InnerPoint3D); TempGeoLine.Add(mGeoLine3D); } } if (TempGeoLine.Count == 2) { this.SetPoint(TempGeoLine); } } } //覆土分析 if (mSceneControl.Action == Action3D.Select && mFlag == 3) { string str = ""; object obj; selection3d = mSceneControl.Scene.FindSelection(true); recordset = selection3d[0].ToRecordset(); if (e.Count > 0) { selection3d = mSceneControl.Scene.FindSelection(true); recordset = selection3d[0].ToRecordset(); if (recordset.GetGeometry().Type != mGeoLine3D.Type) { MessageBox.Show("请选择三维线对象!"); } else { mGeoLine3D = recordset.GetGeometry() as GeoLine3D; mTextPoint3Ds.Add(mGeoLine3D.InnerPoint3D); Point3D cPoint3D = new Point3D(mGeoLine3D.InnerPoint3D.X, mGeoLine3D.InnerPoint3D.Y, 0); mTextPoint3Ds.Add(cPoint3D); for (int i = 0; i < recordset.FieldCount; i++) { str = recordset.GetFieldInfos()[i].Name; if (str == "BottomAltitude") { obj = recordset.GetFieldValue(i); mAltitude = Convert.ToDouble(obj); } if (str == "PipeDiameter") { obj = recordset.GetFieldValue(i); mDiameter = new double[] { Convert.ToDouble(obj) }; } } } GetCoverRusult(); } } //碰撞检测 if (mSceneControl.Action == Action3D.Select && mFlag == 4) { if (e.Count > 0) { string str = ""; object obj; selection3d = mSceneControl.Scene.FindSelection(true); recordset = selection3d[0].ToRecordset(); if (recordset.GetGeometry().Type != mGeoLine3D.Type) { MessageBox.Show("请选择三维线对象!"); } else { mGeoLine3D = recordset.GetGeometry() as GeoLine3D; if (TempGeoLine.Count > 0 && TempGeoLine[0].Bounds == mGeoLine3D.Bounds) { MessageBox.Show("请不要选择同一条三维线对象!"); } else if (TempGeoLine.Count > 0 && recordset.Dataset.Name == TempRecordset.Dataset.Name) { MessageBox.Show("请不要选择同一数据集线对象!"); } else { mTextPoint3Ds.Add(mGeoLine3D.InnerPoint3D); TempGeoLine.Add(mGeoLine3D); TempRecordset = recordset; for (int i = 0; i < recordset.FieldCount; i++) { str = recordset.GetFieldInfos()[i].Name; if (str == "PipeDiameter") { obj = recordset.GetFieldValue(i); if (TempGeoLine.Count == 2) { mDiameter[1] = Convert.ToDouble(obj); } else { mDiameter = new double[2]; mDiameter[0] = Convert.ToDouble(obj); } } } } } if (TempGeoLine.Count == 2) { this.SetPoint(TempGeoLine); } } } }
private void button4_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "导出建新地块信息文件(*.xml)|*.xml"; sfd.FileName = "建新地块信息导出文件" + DateTime.Now.ToString("yyyyMMddhhmmss"); if (sfd.ShowDialog() == DialogResult.OK) { FileStream fs = new FileStream(sfd.FileName, FileMode.Create); StreamWriter sw = new StreamWriter(fs); if (dataGridView2.CurrentRow == null) { MessageBox.Show("请点击地块表行头,选择地块信息!"); return; } DataGridViewRow dgvr = dataGridView2.CurrentRow; //取得当前行项目名称值 string strProjectName = dgvr.Cells["项目名称"].Value.ToString(); //取得当前行地块编号该编号为用户输入的 string strDkbh = dgvr.Cells["地块逻辑编号"].Value.ToString(); string tableName = gkfqd.Common.DbUse.GetTownCodeByProjectNameJx(strProjectName); sqlQuery.Clear(); sqlQuery.Append("SELECT DKBH AS 建新地块编号, "); sqlQuery.Append(" DKWZ AS 位置, "); sqlQuery.Append(" DKMC AS 地块名称, "); sqlQuery.Append(" DKMJ AS 地块面积, "); sqlQuery.Append(" ZBX AS 坐标系, "); sqlQuery.Append(" JDFD AS 几度分带, "); sqlQuery.Append(" TYLX AS 投影类型, "); sqlQuery.Append(" JLDW AS 计量单位, "); sqlQuery.Append(" JD AS 精度, "); sqlQuery.Append(" JZDS AS 界址点数, "); sqlQuery.Append(" JLTCSX AS 记录图形属性 "); sqlQuery.Append(" FROM " + tableName); sqlQuery.Append(" WHERE FKXMMC = '" + strProjectName + "'"); sqlQuery.Append(" AND DKBH = '" + strDkbh + "'"); gkfqd.Common.DbUse.GetOleDbconnection().Close(); gkfqd.Common.DbUse.GetOleDbconnection().Open(); dataSetOutPut.Clear(); OleDbDataAdapter MyAdapter = new OleDbDataAdapter(sqlQuery.ToString(), gkfqd.Common.DbUse.GetOleDbconnection()); MyAdapter.Fill(dataSetOutPut); gkfqd.Common.DbUse.GetOleDbconnection().Close(); sw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); sw.WriteLine("<CL_BUILD_NEW_BLOCK>"); sw.WriteLine(" <BUILDNLANDNO name=\"建新地块编号\">" + dataSetOutPut.Tables[0].Rows[0]["建新地块编号"].ToString() + "</BUILDNLANDNO>"); sw.WriteLine(" <BLOCATION name=\"位置\"> " + dataSetOutPut.Tables[0].Rows[0]["位置"].ToString() + "</BLOCATION>"); sw.WriteLine(" <LANDNAME name=\"地块名称\">" + dataSetOutPut.Tables[0].Rows[0]["地块名称"].ToString() + "</LANDNAME>"); sw.WriteLine(" <LANDAREA name=\"地块面积\">" + dataSetOutPut.Tables[0].Rows[0]["地块面积"].ToString() + "</LANDAREA>"); sw.WriteLine(" <COORSYSTEM name=\"坐标系\">" + dataSetOutPut.Tables[0].Rows[0]["坐标系"].ToString() + "</COORSYSTEM>"); sw.WriteLine(" <CUTNU name=\"几度分带\">" + dataSetOutPut.Tables[0].Rows[0]["几度分带"].ToString() + "</CUTNU>"); sw.WriteLine(" <SHADOWTYPE name=\"投影类型\">" + dataSetOutPut.Tables[0].Rows[0]["投影类型"].ToString() + "</SHADOWTYPE>"); sw.WriteLine(" <MEASUREMENT name=\"计量单位\">" + dataSetOutPut.Tables[0].Rows[0]["计量单位"].ToString() + "</MEASUREMENT>"); sw.WriteLine(" <PRECISION name=\"精度\">" + dataSetOutPut.Tables[0].Rows[0]["精度"].ToString() + "</PRECISION>"); sw.WriteLine(" <DROPNU name=\"界址点数\">" + dataSetOutPut.Tables[0].Rows[0]["界址点数"].ToString() + "</DROPNU>"); sw.WriteLine(" <DRAWINGPROPERTY name=\"记录图形属性\"> " + dataSetOutPut.Tables[0].Rows[0]["记录图形属性"].ToString() + "</DRAWINGPROPERTY>"); sw.Write(" <param ZB=\"@1$"); //"1,3795840.7720,39534660.2200;2,3795836.7200,39534645.9400;3,3795824.1590,39534648.6700;4,3795780.9330,39534495.1600;5,3796003.2890,39534435.7600;6,3796049.6000,39534601.4200;7,3795840.7720,39534660.2200;" />"); DataGridViewRow dgvr1 = dataGridView2.CurrentRow; string strSmid = dgvr1.Cells["地块编号"].Value.ToString(); // 构造一个查询参数对象,查询选中的记录 QueryParameter para = new QueryParameter(); para.AttributeFilter = "SMID =" + strSmid; para.CursorType = CursorType.Dynamic; DatasetVector importResultShp = null; SuperMap.Data.Workspace workspace1; workspace1 = new SuperMap.Data.Workspace(); /*WorkspaceconnectionInfo workspaceconnectionInfo = new WorkspaceconnectionInfo(); * workspaceconnectionInfo.Type = WorkspaceType.Oracle; * workspaceconnectionInfo.Server = "ORCL"; * workspaceconnectionInfo.Database = ""; * workspaceconnectionInfo.Name = "workspace"; * workspaceconnectionInfo.User = "******"; * workspaceconnectionInfo.Password = "******"; * workspace1.Open(workspaceconnectionInfo);*/ workspace1.Open(gkfqd.Common.Tool.GetConnectionInfo()); importDatasource = workspace1.Datasources[gkfqd.Common.Tool.GetWorkspaceDataDatasources()]; importResultShp = importDatasource.Datasets[tableName] as DatasetVector; Recordset recordset = null; try { recordset = importResultShp.Query(para); while (!recordset.IsEOF) { Geometry geometry = recordset.GetGeometry(); GeoRegion region = geometry as GeoRegion; for (int i = 0; i < region.PartCount; i++) { Point2Ds point2ds = region[i]; for (int k = 0; k < point2ds.Count; k++) { Point2D point2d = point2ds[k]; sw.Write((k + 1).ToString() + "," + point2d.X.ToString() + "," + point2d.Y.ToString() + ";"); } } recordset.MoveNext(); } } catch (Exception ex) { Trace.WriteLine(ex.Message); } finally { recordset.Dispose(); } sw.WriteLine(" \" />"); sw.WriteLine("</CL_BUILD_NEW_BLOCK>"); //清空缓冲区 sw.Flush(); //关闭流 sw.Close(); fs.Close(); MessageBox.Show("建新地块信息导出成功!"); } }
//private void CreatePointDataset(string tableName) //{ // Workspace workspace = new Workspace(); // DatasourceConnectionInfo info = new DatasourceConnectionInfo(); // Datasource datasource = GetDbDatasource(workspace, info); // var datasetVector = (DatasetVector)datasource.Datasets[tableName]; // if (datasetVector == null) // { // CreateDataset(datasource, DatasetType.Point, tableName); // } // //只取了数据结构,没有取数据 // var recordset = datasetVector.GetRecordset(true, SuperMap.Data.CursorType.Dynamic); // recordset.Edit(); // recordset.fi //} private void InsertRecordSetToDb(string shapeFieldName, string tableName) { Workspace workspace = new Workspace(); DatasourceConnectionInfo info = new DatasourceConnectionInfo(); var filePath = $"{Directory.GetCurrentDirectory()}\\{Guid.NewGuid().ToString()}"; var files = new List <string> { $"{filePath}.udb", $"{filePath}.udd" }; Datasource datasource = GetDbDatasource(workspace, info); if (datasource != null) { //临时数据源 DatasourceConnectionInfo tempInfo = new DatasourceConnectionInfo(); //设置数据源连接的引擎类型 tempInfo.EngineType = EngineType.UDB; tempInfo.Alias = tableName; tempInfo.Server = filePath; // 创建/打开数据库数据源 Datasource tempDatasource = workspace.Datasources.Create(tempInfo); Recordset recordset = null, tempRecordset = null; if (tempDatasource != null) { ImportResult result = ImportShpToTemp(shapeFieldName, tempDatasource, tableName); if (result.FailedSettings.Length == 0) { Console.WriteLine($"导入{shapeFieldName}成功!"); try { for (int index = 0; index < tempDatasource.Datasets.Count; index++) { DatasetVector tempDatasetVector = (DatasetVector)tempDatasource.Datasets[index]; tempRecordset = tempDatasetVector.GetRecordset(false, SuperMap.Data.CursorType.Dynamic); //没有数据 if (tempRecordset.RecordCount == 0) { continue; } var tempFieldInfos = tempDatasetVector.FieldInfos; //注意:数据集是手工录入的,不是超图sdk生成的,所以不能删除数据集 //如果更新数据集中的记录,则应该操纵记录集(删除、修改、新增) var datasetVector = (DatasetVector)datasource.Datasets[tableName]; if (datasetVector == null) { CreateDataset(datasource, DatasetType.Point, tableName); //throw new Exception($"不存在数据集名称为{tableName}的数据集!"); } //删去之前的所有记录 //datasetVector.GetRecordset(false, SuperMap.Data.CursorType.Dynamic).DeleteAll(); //只取了数据结构,没有取数据 recordset = datasetVector.GetRecordset(true, SuperMap.Data.CursorType.Dynamic); //设置批量提交 // 设置批量更新的限度为5000,注意一定要在开始批量更新前设置MaxRecordCount! recordset.Batch.MaxRecordCount = 500; // 开始批量更新,当添加到设置的MaxRecordCount的下一条记录时,将会将MaxRecordCount条记录自动提交到数据库中。 recordset.Batch.Begin(); tempRecordset.MoveFirst(); //遍历临时记录集 for (Int32 i = 0; i < tempRecordset.RecordCount; i++) { //往mysql新增记录 SuperMap.Data.Geometry geoPoint = tempRecordset.GetGeometry(); recordset.AddNew(geoPoint); //SeekID:在记录中搜索指定 ID 号的记录,并定位该记录为当前记录。 recordset.MoveLast(); foreach (SuperMap.Data.FieldInfo fileInfo in tempFieldInfos) { if (!fileInfo.IsSystemField && IsHaveField(datasetVector.FieldInfos, fileInfo.Name)) { recordset.Edit(); recordset.SetFieldValue(fileInfo.Name, tempRecordset.GetFieldValue(fileInfo.Name)); Object valueID = recordset.GetFieldValue(fileInfo.Name); } } //处理业务数据 tempRecordset.MoveNext(); //recordset.Update(); } // 使用批量更新的Update,提交没有自动提交的记录 recordset.Batch.Update(); } } catch (Exception ex) { throw ex; } finally { //示例程序BatchAdd说明要释放记录集 if (recordset != null) { recordset.Dispose(); } if (tempRecordset != null) { tempRecordset.Dispose(); } } } else { throw new Exception($"导入{shapeFieldName}失败!"); } } else { throw new Exception($"创建临时数据源{filePath}失败!"); } } // 释放工作空间资源 info.Dispose(); workspace.Dispose(); foreach (var file in files) { if (File.Exists(file)) { File.Delete(file); } } MessageBox.Show("成功!"); }
/// <summary> /// 捕捉公交站点 /// Snap the bus stops /// </summary> public void SnapPoint() { try { if (m_selection != null) { // 获取被选中的站点对象 // Get the selected stop object Recordset recordset = m_selection.ToRecordset(); GeoPoint snapPoint = recordset.GetGeometry() as GeoPoint; // 构造文本对象,用于在跟踪层上显示站点的名称 // Construct the text object, which is used to display the stop name on the tracking name GeoText stopText = new GeoText(); // 站点名称 // Stop name String stopName = ""; if (SuperMap.Data.Environment.CurrentCulture != "zh-CN") { stopName = recordset.GetFieldValue("Name_en").ToString(); } else { stopName = recordset.GetFieldValue("Name").ToString(); } TextPart textPart = new TextPart(stopName, new Point2D(snapPoint.X, snapPoint.Y)); stopText.AddPart(textPart); if (m_isStartPoint) { // 绘制之前先清空跟踪层上的点和文字 // Clear all points and words on the tracking layer before drawing Int32 indexStartStop = m_trackingLayer.IndexOf("StartStop"); if (indexStartStop != -1) { m_trackingLayer.Remove(indexStartStop); } Int32 indexStartText = m_trackingLayer.IndexOf("StartStopName"); if (indexStartText != -1) { m_trackingLayer.Remove(indexStartText); } // 分别设置站点及其名称文本的风格,并添加到跟踪层上 // Set the stop and name style and add them to the tracking layer snapPoint.Style = GetStopStyle(new Size2D(8, 8), Color.FromArgb(236, 118, 0)); m_trackingLayer.Add(snapPoint, "StartStop"); stopText.TextStyle = GetStopTextStyle(6.0, Color.FromArgb(0, 0, 0)); m_trackingLayer.Add(stopText, "StartStopName"); // 设置为起始站点ID // Set the strat stop ID m_startStopID = recordset.GetInt64("STOPID"); } else { // 绘制之前先清空跟踪层上的点和文字 // Clear all points and words on the tracking layer before drawing Int32 indexEndStop = m_trackingLayer.IndexOf("EndStop"); if (indexEndStop != -1) { m_trackingLayer.Remove(indexEndStop); } Int32 indexEndText = m_trackingLayer.IndexOf("EndStopName"); if (indexEndText != -1) { m_trackingLayer.Remove(indexEndText); } // 分别设置站点及其名称文本的风格,并添加到跟踪层上 // Set the stop and name style and add them to the tracking layer snapPoint.Style = GetStopStyle(new Size2D(8, 8), Color.FromArgb(22, 255, 0)); m_trackingLayer.Add(snapPoint, "EndStop"); stopText.TextStyle = GetStopTextStyle(6.0, Color.FromArgb(0, 0, 0)); m_trackingLayer.Add(stopText, "EndStopName"); // 设置为起始站点ID // Set the strat stop ID m_endStopID = recordset.GetInt64("STOPID"); } recordset.Dispose(); } } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
private void button5_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "导出txt坐标文件(*.txt)|*.txt"; sfd.FileName = "坐标导出文件" + DateTime.Now.ToString("yyyyMMddhhmmss"); if (sfd.ShowDialog() == DialogResult.OK) { FileStream fs = new FileStream(sfd.FileName, FileMode.Create); StreamWriter sw = new StreamWriter(fs); if (dataGridView2.CurrentRow == null) { return; } DataGridViewRow dgvr = dataGridView2.CurrentRow; string strSmid = dgvr.Cells["地块编号"].Value.ToString();//获取smid值 // 构造一个查询参数对象,查询选中的记录 QueryParameter para = new QueryParameter(); para.AttributeFilter = "SMID =" + strSmid; para.CursorType = CursorType.Dynamic; // DataGridViewRow dgvr1 = dataGridView2.CurrentRow; //取得当前行项目名称值 string strProjectName = dgvr.Cells["项目名称"].Value.ToString(); //取得当前行地块编号该编号为用户输入的 string strDkbh = dgvr.Cells["地块逻辑编号"].Value.ToString(); string tableName = gkfqd.Common.DbUse.GetTownCodeByProjectNameJx(strProjectName); DatasetVector importResultShp = null; SuperMap.Data.Workspace workspace1; workspace1 = new SuperMap.Data.Workspace(); workspace1.Open(gkfqd.Common.Tool.GetConnectionInfo()); importDatasource = workspace1.Datasources[gkfqd.Common.Tool.GetWorkspaceDataDatasources()]; importResultShp = importDatasource.Datasets[tableName] as DatasetVector; Recordset recordset = null; //取系统时间 DateTime dt = DateTime.Now; if (dataGridView2.CurrentRow == null) { MessageBox.Show("请点击地块表行头,选择地块信息!"); return; } sqlQuery.Clear(); sqlQuery.Append("SELECT DKMC AS 地块名称, "); sqlQuery.Append(" DKMJ AS 地块面积, "); sqlQuery.Append(" ZBX AS 坐标系, "); sqlQuery.Append(" JZDS AS 界址点数, "); sqlQuery.Append(" JDFD AS 几度分带, "); sqlQuery.Append(" JD AS 精度, "); sqlQuery.Append(" JLDW AS 计量单位, "); sqlQuery.Append(" JLTCSX AS 记录图形属性, "); sqlQuery.Append(" TYLX AS 投影类型 "); sqlQuery.Append(" FROM " + tableName); sqlQuery.Append(" WHERE FKXMMC = '" + strProjectName + "'"); sqlQuery.Append(" AND DKBH = '" + strDkbh + "'"); gkfqd.Common.DbUse.GetOleDbconnection().Close(); gkfqd.Common.DbUse.GetOleDbconnection().Open(); dataSetOutPutZb.Clear(); OleDbDataAdapter MyAdapter = new OleDbDataAdapter(sqlQuery.ToString(), gkfqd.Common.DbUse.GetOleDbconnection()); MyAdapter.Fill(dataSetOutPutZb); gkfqd.Common.DbUse.GetOleDbconnection().Close(); sw.WriteLine("[属性描述]"); sw.WriteLine("格式版本号=1.01版本"); sw.WriteLine("数据产生单位=国土资源部"); sw.WriteLine("数据产生日期=" + dt.ToLongDateString().ToString()); sw.WriteLine("坐标系=" + dataSetOutPutZb.Tables[0].Rows[0]["坐标系"].ToString()); sw.WriteLine("几度分带=" + dataSetOutPutZb.Tables[0].Rows[0]["几度分带"].ToString()); sw.WriteLine("投影类型=" + dataSetOutPutZb.Tables[0].Rows[0]["投影类型"].ToString()); sw.WriteLine("计量单位=" + dataSetOutPutZb.Tables[0].Rows[0]["计量单位"].ToString()); sw.WriteLine("带号=" + dataSetOutPutZb.Tables[0].Rows[0]["几度分带"].ToString()); sw.WriteLine("精度=" + dataSetOutPutZb.Tables[0].Rows[0]["精度"].ToString()); sw.WriteLine("转换参数=0,0,0,0,0,0,0"); sw.WriteLine("[地块坐标]"); //保留该行记录导出结果,界址点数,地块面积,地块编号,地块名称,记录图形属性(点、线、面),图幅号,地块用途,地类编码,@ //以上记录信息如界址点数、地块面积、地块用途、地类编码需进一步编码取得 //sw.WriteLine("9,0.018,2003-10,双桥乡地块1,面,I-50-77-(22),公共基础设施,,@"); try { recordset = importResultShp.Query(para); while (!recordset.IsEOF) { Geometry geometry = recordset.GetGeometry(); GeoRegion region = geometry as GeoRegion; for (int i = 0; i < region.PartCount; i++) { Point2Ds point2ds = region[i]; for (int k = 0; k < point2ds.Count; k++) { Point2D point2d = point2ds[k]; //点号,地块圈号,X坐标,Y坐标 sw.WriteLine((k + 1).ToString() + "," + (i + 1).ToString() + "," + point2d.X.ToString() + "," + point2d.Y.ToString()); } } recordset.MoveNext(); } } catch (Exception ex) { Trace.WriteLine(ex.Message); } finally { recordset.Dispose(); } //清空缓冲区 sw.Flush(); //关闭流 sw.Close(); fs.Close(); MessageBox.Show("建新属性坐标信息导出成功!"); } }
/// <summary> /// 标注流向 /// </summary> public void FlowLabel() { Selection3D[] selection = mSceneControl.Scene.FindSelection(true); //判断选择集是否为空 if (selection == null || selection.Length == 0) { MessageBox.Show("请选择要标注流向的空间对象"); return; } //将选择集转换为记录 Recordset recordset = selection[0].ToRecordset(); GeoLine3D m_line = recordset.GetGeometry() as GeoLine3D; Point3D m_Point3D1 = m_line.InnerPoint3D; double x1 = System.Convert.ToDouble(recordset.GetFieldValue("SmSdriE")); double y1 = System.Convert.ToDouble(recordset.GetFieldValue("SmSdriS")); double z = System.Convert.ToDouble(recordset.GetFieldValue("BottomAltitude")); Point3D m_Point3D2 = new Point3D(x1, y1, z); Point3Ds m_Point3Ds = new Point3Ds(new Point3D[] { m_Point3D1, m_Point3D2 }); m_Point3Ds = coordinateTrans3D(m_Point3Ds); GeoLine3D m_Line3D = new GeoLine3D(m_Point3Ds); // GeoModel3D m_model=m_Line3D.ConvertToGeoModel3D(false); //设置线样式 GeoStyle3D m_Style3D = new GeoStyle3D(); m_Style3D.IsMarker3D = true; m_Style3D.AltitudeMode = AltitudeMode.Absolute; m_Style3D.FillForeColor = Color.FromArgb(0x64, 0x40, 0xFF, 0x5F); m_Style3D.FillMode = FillMode3D.Fill; m_Style3D.LineColor = Color.Lime; m_Style3D.LineWidth = 3; m_Line3D.Style3D = m_Style3D.Clone(); TrackingLayer3D trackinglayer = mSceneControl.Scene.TrackingLayer; trackinglayer.IsEditable = true; trackinglayer.IsVisible = true; trackinglayer.Add(m_Line3D, "FlowLine"); // mSceneControl.Scene.Refresh(); //double x2 = System.Convert.ToDouble(mPoint3D.X); //double y2 = System.Convert.ToDouble(mPoint3D.Y); //Point3D m_Point3D1 = new Point3D(x1, y1, 0); //Point3D m_Point3D2 = new Point3D(x1, y1, 0); // Point3Ds m_Point3Ds = new Point3Ds(new Point3D[] { m_Point3D1, m_Point3D2 }); //m_Point3Ds = coordinateTrans3D(m_Point3Ds); //m_Point3D1 = m_Point3Ds[0]; //m_Point3D2 = m_Point3Ds[1]; //x1 = m_Point3D1.X; //y1 = m_Point3D1.Y; //x2 = m_Point3D2.X; //y2 = m_Point3D2.Y; //double m_Roation = Math.Atan(Math.Abs((y1 - y2) / (x1 - x2))); //m_Roation=m_Roation * 180 / Math.PI; // String m_text = string.Empty; // String m_Start = System.Convert.ToString(recordset.GetFieldValue("SmFNode")); // m_Start=""; // String m_End = System.Convert.ToString(recordset.GetFieldValue("SmTNode")); // m_End=""; // m_text = m_Start + "→→→→→→→→→" + m_End; // TextPart3D mText1 = new TextPart3D(); // mText1.Text = m_text; // mText1.AnchorPoint = m_Point3D1; // TextStyle mTextStyle1 = new TextStyle(); // mTextStyle1.FontName = "微软雅黑"; // mTextStyle1.ForeColor = Color.Red; // mTextStyle1.FontHeight = 7; // mTextStyle1.IsSizeFixed = false; // mTextStyle1.Alignment = TextAlignment.BaselineCenter; //// mTextStyle1.Rotation = m_Roation; // GeoText3D geoText_1 = new GeoText3D(mText1, mTextStyle1); // GeoStyle3D geostyle_1 = new GeoStyle3D(); // geostyle_1.AltitudeMode = AltitudeMode.RelativeToGround; // geoText_1.Style3D = geostyle_1; // TrackingLayer3D trackinglayer = mSceneControl.Scene.TrackingLayer; // trackinglayer.IsEditable = true; // trackinglayer.IsVisible = true; // trackinglayer.Add(geoText_1, "FlowLa"); // mSceneControl.Scene.Refresh(); // //得到所选对象的起点和终点坐标 // double x1=System.Convert.ToDouble(recordset.GetFieldValue("SmSdriW")); // double y1=System.Convert.ToDouble(recordset.GetFieldValue("SmSdriN")); // double x2 = System.Convert.ToDouble(recordset.GetFieldValue("SmSdriE")); // double y2 = System.Convert.ToDouble(recordset.GetFieldValue("SmSdriS")); // double z = System.Convert.ToDouble(recordset.GetFieldValue("BottomAltitude")); // Point3D m_Point3D1 = new Point3D(x1, y1, z); // Point3D m_Point3D2 = new Point3D(x2, y2, z); // Point3Ds m_Point3Ds = new Point3Ds(new Point3D[]{mPoint3D,m_Point3D2}); // m_Point3Ds=coordinateTrans3D(m_Point3Ds); // //根据坐标画线 // GeoLine3D m_Line3D = new GeoLine3D(m_Point3Ds); // //设置线样式 // GeoStyle3D m_Style3D = new GeoStyle3D(); //// m_Style3D.IsMarker3D = true; // m_Style3D.AltitudeMode = AltitudeMode.RelativeToGround; // m_Style3D.LineColor = Color.Lime; // m_Style3D.LineWidth = 3; // m_Line3D.Style3D = m_Style3D; // TrackingLayer3D trackinglayer = mSceneControl.Scene.TrackingLayer; // trackinglayer.IsEditable = true; // trackinglayer.IsVisible = true; // trackinglayer.Add(m_Line3D, "FlowLine"); // mSceneControl.Scene.Refresh(); }