/// <summary> /// 设置三维点符号 /// </summary> public void SettingPoint3D(int Marker3DIndex) { isDraw = true; m_marker3DIndex = Marker3DIndex; try { flag = false; // 新建数据集 if (m_workspace.Datasources[0].Datasets.Contains("Point3D")) { DatasetVector datasetPoint3D = m_workspace.Datasources[0].Datasets["Point3D"] as DatasetVector; if (m_sceneControl.Scene.Layers.Contains("stylePoint3D")) { m_layer3DPoint = m_sceneControl.Scene.Layers["stylePoint3D"] as Layer3DDataset; } else { m_layer3DPoint = m_sceneControl.Scene.Layers.Add(datasetPoint3D, new Layer3DSettingVector(), true, "stylePoint3D"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//将数据集分成若干分数据集 private void CopyToNewDataset(DatasetVector sour_dtSet, string strDatasetName, string strFilter) { try { DatasetVector destdtSet = CreateNewDataset(sour_dtSet, strDatasetName); if (destdtSet == null) { return; } Recordset dest_recdst = destdtSet.GetRecordset(true, CursorType.Dynamic); if (dest_recdst != null) { // Recordset sour_recdst = sour_dtSet.Query(strFilter, CursorType.Static); // if (sour_recdst != null && sour_recdst.RecordCount > 0) { CopyRecordset(sour_recdst, dest_recdst); } } } catch (SystemException sysEx) { MessageBox.Show(sysEx.Message); } }
public void SetRegionPoint() { try { if (m_workspace.Datasources[0].Datasets.Contains("New_Point3D")) { DatasetVector datasetPoint3D = m_workspace.Datasources[0].Datasets["New_Point3D"] as DatasetVector; if (m_sceneControl.Scene.Layers.Contains("New_Point3D@gongyuan")) { m_sceneControl.Scene.Layers.Remove("New_Point3D@gongyuan"); } { Layer3DSettingVector pointSetting = new Layer3DSettingVector(); pointSetting.Style.AltitudeMode = AltitudeMode.RelativeToGround; pointSetting.Style.MarkerSize = 1; pointSetting.Style.IsMarkerSizeFixed = true; pointSetting.Style.MarkerScale = 1; pointSetting.Style.MarkerSymbolID = m_marker3DIndex; pointSetting.Style.IsMarker3D = true; m_layer3DRegionPoint = m_sceneControl.Scene.Layers.Add(datasetPoint3D, pointSetting, true, "New_Point3D@gongyuan"); } m_layer3DRegionPoint.UpdateData(); m_sceneControl.Scene.Refresh(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
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 { } }
//追加新纪录到数据集 private void AppandToDataset(DatasetVector sour_dtSet, string strDatasetName, string strFilter) { if (sour_dtSet == null) { return; } try { int iDex = sour_dtSet.Datasource.Datasets.IndexOf(strDatasetName); if (iDex > -1) { // DatasetVector destdtSet = sour_dtSet.Datasource.Datasets[iDex] as DatasetVector; //Appand new record Recordset dest_recdst = destdtSet.GetRecordset(true, CursorType.Dynamic); if (dest_recdst != null) { // Recordset sour_recdst = sour_dtSet.Query(strFilter, CursorType.Static); CopyRecordset(sour_recdst, dest_recdst); } } } catch { } }
/// <summary> /// 导入为Dwg,保留参数化对象 /// Import to Dwg, and reserve the parameterized objects /// </summary> public void ImportToDwg1() { try { m_dataImport.ImportSettings.Clear(); ImportSettingDWG dwgSetting = new ImportSettingDWG(); dwgSetting.ImportMode = ImportMode.Overwrite; dwgSetting.SourceFilePath = @"..\..\SampleData\DataExchange\DwgImport\ParametricPart.dwg"; dwgSetting.TargetDatasource = m_desDatasource; dwgSetting.ImportingAsCAD = true; dwgSetting.KeepingParametricPart = true; m_dataImport.ImportSettings.Add(dwgSetting); m_dataImport.Run(); DatasetVector importResult = m_desDatasource.Datasets["ParametricPart"] as DatasetVector; m_mapControl.Map.Layers.Clear(); m_mapControl.Map.Layers.Add(importResult, true); m_mapControl.Map.ViewEntire(); m_mapControl.Map.Refresh(); } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
/// <summary> /// 打开需要的工作空间文件及地图 /// Open the workspace and the map /// </summary> private void Initialize() { try { // 打开工作空间及地图 // Open the workspace and the map. WorkspaceConnectionInfo conInfo = new WorkspaceConnectionInfo(@"..\..\SampleData\DataExchange\DataExchange.smwu"); m_workspace.Open(conInfo); m_srcDatasource = m_workspace.Datasources["SrcDatasource"]; m_desDatasource = m_workspace.Datasources["DesDatasource"]; m_sourceRegion = m_srcDatasource.Datasets["China400"] as DatasetVector; m_sourceImg = m_srcDatasource.Datasets["Day"] as DatasetImage; m_dataExport = new DataExport(); m_dataImport = new DataImport(); this.m_mapControl.Map.Layers.Add(m_sourceRegion, true); this.m_mapControl.Map.Refresh(); } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
public void OwnerBar() { try { Layer3Ds mLayer3D = mSceneControl.Scene.Layers; Layer3DDataset mLayer = null; Recordset mRecord = null; DatasetVector mData = null; String str = ""; String str1 = ""; for (int i = 0; i < mOwnerStatist.GetPipeStatist.Count; i++) { mLayer = mLayer3D[mOwnerStatist.GetPipeStatist[i].ToString() + "@" + mDataSourceName] as Layer3DDataset; mData = mLayer.Dataset as DatasetVector; for (int k = 0; k < mOwnerStatist.GetOwnerStatist.Count; k++) { mRecord = mData.Query("OwnerShip='" + mOwnerStatist.GetOwnerStatist[k].ToString() + "'", CursorType.Dynamic); mOwnerCount.Add(mRecord.RecordCount.ToString()); } } OwnerCreate(); } catch (System.Exception ex) { Trace.WriteLine(ex.Message); } }
//处理后的数据 存储在新建要素集 private void CopyToNewDataset(List <Vehicle> vehicleList) { this.MyLog(vehicleList.Count.ToString()); DatasetVector dataset = DatasetVectorInfoSample(this.currentDatasource, this.currentDataset.Name); if (!dataset.IsOpen) { dataset.Open(); this.MyLog(dataset.FieldCount.ToString()); } Recordset rd = dataset.GetRecordset(false, CursorType.Dynamic); foreach (Vehicle v in vehicleList) { Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("ID", v.Id); dic.Add("NAME", v.Name); dic.Add("XBH", v.Xbh); dic.Add("X", v.X); dic.Add("Y", v.Y); GeoPoint point = new GeoPoint(v.X, v.Y); rd.AddNew(point, dic); rd.Update(); } rd.Close(); rd.Dispose(); }
/// <summary> /// 打开需要的工作空间文件及地图 /// Open the workspace and the map /// </summary> private void Initialize() { try { // 打开工作空间及地图 // Open the workspace and the map WorkspaceConnectionInfo conInfo = new WorkspaceConnectionInfo(@"..\..\SampleData\ThematicMaps\ThematicMaps.smwu"); m_workspace.Open(conInfo); m_datasource = m_workspace.Datasources[0]; m_dataset = m_workspace.Datasources["Thematicmaps"].Datasets["BaseMap_R"] as DatasetVector; if (SuperMap.Data.Environment.CurrentCulture != "zh-CN") { m_mapControl.Map.Open("Beijing-Tianjin Area Division Map"); } else { m_mapControl.Map.Open("京津地区地图"); } m_mapControl.Map.Refresh(); // 调整mapControl的状态 // Adjust the condition of mapControl m_mapControl.Action = SuperMap.UI.Action.Pan; m_mapControl.IsWaitCursorEnabled = false; } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
/// <summary> /// 添加等级符号专题图 /// Add the theme of graduated symbol /// </summary> public void ThemeRangeThemeDisplay() { try { Map map = m_mapControl.Map; Layers layers = map.Layers; Int32 count = layers.Count; Datasources datasources = m_workspace.Datasources; Datasource datasource = datasources[0]; Datasets datasets = datasource.Datasets; DatasetVector datasetVector = datasets["BaseMap_R"] as DatasetVector; ThemeGraduatedSymbol themeGraduatedSymbol = new ThemeGraduatedSymbol(); themeGraduatedSymbol.Expression = "Urban"; themeGraduatedSymbol.BaseValue = 150.00000; themeGraduatedSymbol.GraduatedMode = GraduatedMode.SquareRoot; themeGraduatedSymbol.IsFlowEnabled = false; GeoStyle geoStyle = themeGraduatedSymbol.PositiveStyle; geoStyle.LineColor = Color.Pink; m_layer = layers.Add(datasetVector, themeGraduatedSymbol, true); m_themeLayerName = m_layer.Name; m_mapControl.Map.Refresh(); } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
/// <summary> /// 打开文件形工作空间 /// </summary> public void fileWorkSpaceOpen() { this.fileWorkspace = new SuperMap.Data.Workspace(); try { //打开工作空间及地图文件类型 WorkspaceConnectionInfo conInfo = new WorkspaceConnectionInfo(@"..\..\template\temp.smwu"); fileWorkspace.Open(conInfo); m_srcDatasource = fileWorkspace.Datasources["temp"]; m_sourceRegion = m_srcDatasource.Datasets["gkfqd"] as DatasetVector; dataImport = new DataImport(); this.mapControl1.Map.Workspace = fileWorkspace; mapControl1.Map.Layers.Clear(); mapControl1.Map.Layers.Add(m_sourceRegion, true); mapControl1.Map.ViewEntire(); mapControl1.Map.Refresh(); } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
public void QuarebuBuffer() { Recordset recordset = result.GetRecordset(false, SuperMap.Data.CursorType.Dynamic); //获取缓冲区记录集 // 设置查询参数 // Set the query parameter. QueryParameter parameter = new QueryParameter(); parameter.SpatialQueryObject = recordset; parameter.SpatialQueryMode = SuperMap.Data.SpatialQueryMode.Contain; //包含查询 // 对指定查询的图层进行查询 // Query the specified layer. Layer layer = this.GetLayerByCaption(m_queriedLayerName); DatasetVector quare_dataset = layer.Dataset as DatasetVector; Recordset recordset2 = quare_dataset.Query(parameter); layer.Selection.FromRecordset(recordset2); layer.Selection.Style.LineColor = Color.Red; layer.Selection.Style.LineWidth = 0.6; layer.Selection.SetStyleOptions(StyleOptions.FillSymbolID, true); layer.Selection.Style.FillSymbolID = 1; layer.Selection.IsDefaultStyleEnabled = false; // 刷新地图 // Refresh the map. m_srcMapControl.Map.Refresh(); }
private void PathAnalysisMouseClick(object sender, MouseEventArgs e) { try { mRodeNetWork = mUseData.RodeNetwork; mClickPoint.X = e.X; mClickPoint.Y = e.Y; if (e.Button == MouseButtons.Left && mSceneControl.Action == SuperMap.UI.Action3D.Select) { Point3D clickPoint3D = mSceneControl.Scene.PixelToGlobe(mClickPoint, SuperMap.Realspace.PixelToGlobeMode.TerrainAndModel); Point3D antualPoint3D = Point3D.Empty; if (StartOrEnd == 1) { if (clickPoint3D != Point3D.Empty && CheckPoint(clickPoint3D)) { SetStartPoint(clickPoint3D); DisplayStartPoint(); } } else if (StartOrEnd == 2) { if (clickPoint3D != Point3D.Empty && CheckPoint(clickPoint3D)) { SetEndPoint(clickPoint3D); DisplayEndPoint(); } } } mSceneControl.Action = Action3D.Pan; } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
public static void OpenWorkspace() { // 打开工作空间,取出工作空间中名为“World”的数据集,查询其描述信息 Workspace workspace = new Workspace(); WorkspaceConnectionInfo workspaceConnectionInfo = new WorkspaceConnectionInfo { Type = WorkspaceType.SXWU }; String file = @"D:\gitrep\dme\src\database\supermap-data\ws-rule.smwu"; workspaceConnectionInfo.Server = file; workspace.Open(workspaceConnectionInfo); Datasource datasource = workspace.Datasources[0]; DatasetVector dataset = (DatasetVector)datasource.Datasets["World"]; Console.WriteLine("数据集的描述信息为:" + dataset.Description); // 保存工作空间 workspace.Save(); // 另存工作空间 String file_saveAs = @"D:\gitrep\dme\src\database\supermap-data\world_saveAs.sxwu"; WorkspaceConnectionInfo workspaceConnectionInfo_saveAs = new WorkspaceConnectionInfo(file_saveAs); if (workspace.SaveAs(workspaceConnectionInfo_saveAs)) { Console.WriteLine("另存工作空间成功!"); } // 释放资源 dataset.Close(); workspaceConnectionInfo.Dispose(); workspaceConnectionInfo_saveAs.Dispose(); workspace.Close(); workspace.Dispose(); }
/// <summary> /// 设置三维水面符号 /// </summary> public void SettingRegion3D(int region3DIndex, bool point) { isRegion = true; flag = true; ispointRegion = point; m_region3DIndex = region3DIndex; try { m_sceneControl.Action = Action3D.MeasureArea; // 新建数据集 if (m_workspace.Datasources[0].Datasets.Contains("Region3D")) { DatasetVector datasetRegion3D = m_workspace.Datasources[0].Datasets["Region3D"] as DatasetVector; if (m_sceneControl.Scene.Layers.Contains("styleRegion3D")) { m_layer3DRegion = m_sceneControl.Scene.Layers["styleRegion3D"] as Layer3DDataset; } else { m_layer3DRegion = m_sceneControl.Scene.Layers.Add(datasetRegion3D, new Layer3DSettingVector(), true, "styleRegion3D"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void buttonX1_Click(object sender, EventArgs e) { try { string[] a = new string[2]; a[0] = "ClassId00"; a[1] = "Class_Name"; string[] b = new string[2]; b[0] = "ClassId09"; b[1] = "name"; Datasource Ds = SampleRun.workspace1.Datasources[0]; string name_1 = comboBoxEx2.SelectedItem.ToString(); //图层1 string name_2 = comboBoxEx3.SelectedItem.ToString(); //图层2 DatasetVector dataset = SampleRun.mapControl1.Map.Layers[name_1].Dataset as DatasetVector; //第一数据集 DatasetVector eraseDataset = SampleRun.mapControl1.Map.Layers[name_2].Dataset as DatasetVector; //第二数据集 OverlayAnalystParameter parameter = new OverlayAnalystParameter(); DatasetVectorInfo datasetvectorInfoUpdate = new DatasetVectorInfo(); String DtName = Ds.Datasets.GetAvailableDatasetName("new"); datasetvectorInfoUpdate.Type = dataset.Type; datasetvectorInfoUpdate.Name = DtName; parameter.SourceRetainedFields = a; parameter.OperationRetainedFields = b; DatasetVector exdv = Ds.Datasets.Create(datasetvectorInfoUpdate); bool c = OverlayAnalyst.Union(dataset, eraseDataset, exdv, parameter); SampleRun.layersControl1.Map.Layers.Add(exdv, true); SampleRun.layersControl1.Map.Refresh(); } catch { MessageBox.Show("两图层不在同一坐标系中!"); } }
public ShowRecordset(Recordset recordset1, DatasetVector dataset1, String [] Values1) { InitializeComponent(); recordset = recordset1; dataset = dataset1; values = Values1; }
public gk061() { InitializeComponent(); #region 添加地图 workspace1 = new SuperMap.Data.Workspace(); workspace1.Open(gkfqd.Common.Tool.GetConnectionInfo()); importDatasource = workspace1.Datasources[gkfqd.Common.Tool.GetWorkspaceDataDatasources()]; mapLayoutControl1.MapLayout.Workspace = workspace1; datasetVector = importDatasource.Datasets["gkfqd"] as DatasetVector; mapLayoutControl1.IsHorizontalScrollbarVisible = true; mapLayoutControl1.IsVerticalScrollbarVisible = true; AddMap("temp"); mapLayoutControl1.MapLayout.Zoom(4); #endregion //添加系统默认打印服务 foreach (String printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters) { toolStripComboBox2.Items.Add(printer); } toolStripComboBox2.SelectedIndex = 0; //不显示dataGridView1最后一行 // dataGridView1.AllowUserToAddRows = false; comboBox1.SelectedIndex = 0; //区县comboBox列表加载 LoadComboBox(); }
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> /// 拓扑构面 /// Build regions /// </summary> public Boolean LineToRegion() { Boolean result = false; // 数据不为空才执行下面的操作 // Implement the operation when the data is not null if (m_dataset != null) { try { this.ResetDatasetAddMap(); m_dataset.Datasource.Datasets.Delete(m_createRegionName); m_resultDataset = TopologyProcessing.BuildRegions(m_bufDataset, m_workspace.Datasources[0], m_createRegionName, m_topoOptions); m_mapControl.Map.Layers.Add(m_resultDataset, true); SetLayerStyle(m_mapControl.Map.Layers[0], Color.Red, 0.2); m_mapControl.Map.Refresh(); result = true; } catch (Exception ex) { Trace.Write(ex.Message); result = false; } } return(result); }
private void buttonX1_Click(object sender, EventArgs e) { string sp = comboBox1.SelectedItem.ToString(); try { srcDatasource1 = SampleRun.workspace1.Datasources[0]; sourceRegion1 = srcDatasource1.Datasets[sp] as DatasetVector; if (sourceRegion1 == null) { MessageBox.Show(this, "图层不符条件,无法转换!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { String targetDirectory = @"..\..\SampleData"; if (!Directory.Exists(targetDirectory)) { Directory.CreateDirectory(targetDirectory); } String targetFilePath = targetDirectory + @"\EShape.shp"; this.SetExportSettings(FileType.SHP, targetFilePath); SampleRun.mapControl1.Map.Layers.Clear(); dataExport1.Run(); SampleRun.mapControl1.Map.Layers.Add(sourceRegion1, true); SampleRun.mapControl1.Map.ViewEntire(); SampleRun.mapControl1.Map.Refresh(); System.Diagnostics.Process.Start("explorer.exe", "/n,/select, " + targetFilePath); } } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
/// <summary> /// 打开需要的工作空间文件及地图 /// </summary> private void Initialize() { try { //打开工作空间及地图 // WorkspaceConnectionInfo conInfo = new WorkspaceConnectionInfo(@"..\..\SampleData\City\Changchun.smwu"); //WorkspaceConnectionInfo conInfo = new WorkspaceConnectionInfo() { Type = WorkspaceType.Oracle, Server = "ORCL", Database = "", Name = "workspace", User = "******", Password = "******" }; //m_workspace.Open(conInfo); //m_dataset = m_workspace.Datasources[0].Datasets["ClipResult"] as DatasetVector; //mapControl1.Map.Layers.Add(m_dataset, true); //mapControl1.Map.Refresh(); Workspace x_workspace = new Workspace(); WorkspaceConnectionInfo wci = new WorkspaceConnectionInfo() { Type = WorkspaceType.Oracle, Server = "ORCL", Database = "", Name = "workspace", User = "******", Password = "******" }; x_workspace.Open(wci); importDatasource = x_workspace.Datasources["ORCL_gkfqd"]; importResultShp = importDatasource.Datasets["ClipResult"] as DatasetVector; mapControl1.Map.Workspace = x_workspace; mapControl1.Map.Layers.Clear(); mapControl1.Map.Layers.Add(importResultShp, true); mapControl1.Map.ViewEntire(); mapControl1.Map.Refresh(); } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
/// <summary> /// 删除缓冲区 /// </summary> public void DeleteWhole() { try { mRecordset.DeleteAll(); if (mLayerBuffer != null) { mSceneControl.Scene.Layers.Remove(mLayerBuffer.Name); mLayerBuffer = null; } mSceneControl.Scene.Refresh(); if (mBufferDataset != null) { mDatasource.Datasets.Delete(mBufferDataset.Name); mBufferDataset = null; } Layer3Ds mlayer = mSceneControl.Scene.Layers; foreach (Layer3D layer in mlayer) { if (layer.Selection != null) { layer.Selection.Clear(); } } } catch (System.Exception ex) { Trace.WriteLine(ex.Message); } }
/// <summary> /// 向地图中添加面数据集 /// </summary> /// <param name="isWithStyle">是否自定义风格</param> public void AddRegion(Boolean isWithStyle) { try { DatasetVector dataset = m_datasource.Datasets[m_datasetRegion] as DatasetVector; //设置风格并添加数据集 Layer layer = null; if (isWithStyle) { LayerSettingVector setting = new LayerSettingVector(); setting.Style.LineColor = Color.Teal; setting.Style.LineSymbolID = 11; setting.Style.LineWidth = 0.5; setting.Style.FillForeColor = Color.FromArgb(2, 138, 226); setting.Style.FillBackColor = Color.FromArgb(232, 245, 254); setting.Style.FillGradientMode = FillGradientMode.Radial; layer = m_mapControl.Map.Layers.Add(dataset, setting, true); } else { layer = m_mapControl.Map.Layers.Add(dataset, true); } //全幅显示添加的图层 m_mapControl.Map.EnsureVisible(layer); m_mapControl.Map.Refresh(); } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
/// <summary> /// 向地图中添加线数据集 /// </summary> /// <param name="isWithStyle">是否自定义风格</param> public void AddLine(Boolean isWithStyle) { try { DatasetVector dataset = m_datasource.Datasets[m_datasetLine] as DatasetVector; //设置风格并添加数据集 Layer layer = null; if (isWithStyle) { LayerSettingVector setting = new LayerSettingVector(); setting.Style.LineColor = Color.Gray; setting.Style.LineSymbolID = 2; setting.Style.LineWidth = 0.3; layer = m_mapControl.Map.Layers.Add(dataset, setting, true); } else { layer = m_mapControl.Map.Layers.Add(dataset, true); } //全幅显示添加的图层 m_mapControl.Map.EnsureVisible(layer); m_mapControl.Map.Refresh(); } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
/// <summary> /// 向地图中添加点数据集 /// </summary> /// <param name="isWithStyle">是否自定义风格</param> public void AddPoint(Boolean isWithStyle) { try { DatasetVector dataset = m_datasource.Datasets[m_datasetPoint] as DatasetVector; //设置风格并添加数据集 Layer layer = null; if (isWithStyle) { LayerSettingVector setting = new LayerSettingVector(); setting.Style.LineColor = Color.SeaGreen; setting.Style.MarkerSize = new Size2D(4, 4); setting.Style.MarkerSymbolID = 12; layer = m_mapControl.Map.Layers.Add(dataset, setting, true); } else { layer = m_mapControl.Map.Layers.Add(dataset, true); } //全幅显示添加的图层 m_mapControl.Map.EnsureVisible(layer); m_mapControl.Map.Refresh(); } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
/// <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); } }
// private void InitSetting() { if (m_Workspace != null) { DatasetVector dtVector = m_Workspace.Datasources[m_strDatasourceName].Datasets[m_strDatasetName] as DatasetVector; m_ChinaXZQH = dtVector; } }
/// <summary> /// 初始化控件及数据。 /// Initialize data and control /// </summary> private void Initialize() { try { DatasourceConnectionInfo connectionInfo = new DatasourceConnectionInfo( @"..\..\SampleData\City\Changchun.udb", "findClosestFacility", ""); connectionInfo.EngineType = EngineType.UDB; m_workspace.Datasources.Open(connectionInfo); m_datasetLine = (DatasetVector)m_workspace.Datasources[0] .Datasets[m_datasetName] as DatasetVector; m_datasetPoint = m_datasetLine.ChildDataset; m_selectFacilityNode = true; m_selectBarrier = false; m_selectEventNode = false; m_Points = new Point2Ds(); m_barrierEdges = new List <Int32>(); m_barrierNodes = new List <Int32>(); m_selectMode = SelectMode.SELECTPOINT; m_nodesList = new List <Int32>(); m_trackingLayer = m_mapControl.Map.TrackingLayer; // 加载点数据集及线数据集并设置各自风格 // Add point, line datasets and set their styles m_layerLine = m_mapControl.Map.Layers.Add(m_datasetLine, true); LayerSettingVector lineSetting = (LayerSettingVector)m_layerLine .AdditionalSetting; GeoStyle lineStyle = new GeoStyle(); lineStyle.LineColor = Color.LightGray; lineStyle.LineWidth = 0.1; lineSetting.Style = lineStyle; m_layerPoint = m_mapControl.Map.Layers.Add( m_datasetPoint, true); LayerSettingVector pointSetting = (LayerSettingVector)m_layerPoint .AdditionalSetting; GeoStyle pointStyle = new GeoStyle(); pointStyle.LineColor = Color.DarkGray; pointStyle.MarkerSize = new Size2D(2.5, 2.5); pointSetting.Style = pointStyle; // 调整mapControl的状态 // Adjust the status of mapControl m_mapControl.Action = SuperMap.UI.Action.Select; m_mapControl.IsWaitCursorEnabled = false; m_mapControl.Map.Refresh(); m_mapControl.MouseDown += new MouseEventHandler(m_mapControl_MouseDown); m_mapControl.MouseMove += new MouseEventHandler(m_mapControl_MouseMove); // 加载模型 // Add model Load(); } catch (System.Exception ex) { Trace.WriteLine(ex.Message); } }
void addBox(DatasetVector dv, string file) { FileStream f; StreamWriter sw; Recordset rc = dv.GetRecordset(false, CursorType.Dynamic); Console.WriteLine(dv.Name + "\t::\t" + dv.Type.ToString() + "\t::\t" + dv.RecordCount); Dictionary<int, Feature> feas = rc.GetAllFeatures(); f = new FileStream(file, FileMode.OpenOrCreate); sw = new StreamWriter(f); foreach (Feature item in feas.Values) { Point3D lower, uper, center; if ((item.GetGeometry() as Geometry3D) != null) { lower = (item.GetGeometry() as Geometry3D).BoundingBox.Lower; uper = (item.GetGeometry() as Geometry3D).BoundingBox.Upper; center = (item.GetGeometry() as Geometry3D).BoundingBox.Center; sw.WriteLine(string.Format("{0},{1},{2},{3},{4},{5},{6}", item.GetID(), lower.X, lower.Y, lower.Z, uper.X, uper.Y, uper.Z)); if (!dv.IsOpen) { dv.Open(); } Dictionary<string, double> fields = new Dictionary<string, double>(); fields.Add("Lx", lower.X); fields.Add("Ly", lower.Y); fields.Add("Lz", lower.Z); fields.Add("Ux", uper.X); fields.Add("Uy", uper.Y); fields.Add("Uz", uper.Z); foreach (KeyValuePair<string, double> field in fields) { if (dv.FieldInfos.IndexOf(field.Key) < 0) { FieldInfo fieldInf = new FieldInfo(field.Key, FieldType.Double); dv.FieldInfos.Add(fieldInf); } string fieldName = field.Key; double fieldValue = field.Value; try { rc.SeekID(item.GetID()); rc.Edit(); rc.SetFieldValue(fieldName, fieldValue); rc.Update(); } catch { Console.WriteLine("error!"); } //Console.WriteLine(string.Format("{0},{1},{2}", item.GetID(), fieldName, fieldValue)); } //Console.WriteLine("=="+item.GetID()+"=="); } } Console.WriteLine(dv.Name + " done!"); sw.Close(); f.Close(); rc.Close(); dv.Close(); }
// 通过线性参考 处理数据 private void DataHandling(Dataset currentDs, DatasetVector routesDataset) { if(currentDs.Type==DatasetType.Tabular){ SuperMap.Desktop.Application.ActiveApplication.Output.Output("DatasetType.Tabular"); } DatasetVector datasetVector=currentDs as DatasetVector; Recordset rd = datasetVector.GetRecordset(false, CursorType.Dynamic); Recordset routeRd = routesDataset.GetRecordset(false, CursorType.Dynamic); rd.MoveFirst(); while (!rd.IsEOF) { String _id = rd.GetFieldValue("ID").ToString(); String _name = rd.GetFieldValue("NAME").ToString(); String _xbh = rd.GetFieldValue("XBH").ToString(); String _licheng = rd.GetFieldValue("LICHENG").ToString(); String _x = rd.GetFieldValue("X").ToString(); String _y = rd.GetFieldValue("Y").ToString(); //质量差的数据过滤 if (_id.Trim() == "" || _xbh.Trim() == "" || _licheng.Trim() == "") { rd.MoveNext(); continue; } // 如果有xy坐标,使用xy坐标;如果没有,使用线性参考获得坐标 if (_x.Trim() != "" && _y.Trim() != "") { //使用xy try { double x=0, y=0; double.TryParse(_x, out x); double.TryParse(_y, out y); //add list Vehicle vehicle = new Vehicle(); vehicle.Id = _id; vehicle.Name = _name; vehicle.X = x; vehicle.Y = y; vehicle.Xbh = _xbh; vehicleList.Add(vehicle); } catch (Exception) { this.MyLog("经纬度坐标格式有误,请使用如下格式:111.67,23.89"); } } else { //使用 线性参考 GeoLineM geoLineM = new GeoLineM(); //游标移到开头 routeRd.MoveFirst(); while (!routeRd.IsEOF) { String xbh = routeRd.GetFieldValue("线编号").ToString(); if (xbh == _xbh) { geoLineM = (GeoLineM)routeRd.GetGeometry(); double mValue = 0; //解析里程值 mValue = GetMValue(_licheng); Point2D point = geoLineM.GetPointAtM(mValue); this.MyLog("坐标:" + point.X + "," + point.Y); rd.SetFieldValue("X", point.X.ToString()); rd.SetFieldValue("Y", point.Y.ToString()); //add list Vehicle vehicle = new Vehicle(); vehicle.Id = _id; vehicle.Name = _name; vehicle.X = point.X; vehicle.Y = point.Y; vehicle.Xbh = _xbh; vehicleList.Add(vehicle); break; } // routeRd.MoveNext(); } }//---else end rd.MoveNext(); } //update //rd.Update(); rd.Close(); rd.Dispose(); routeRd.Close(); routeRd.Dispose(); this.MyLog("rd---------end"); //creat new dataset //处理后的数据 存储在新建要素集 CopyToNewDataset(vehicleList); }