/// <summary> /// 打开mxd地图文档 /// </summary> public void LoadMapDocument() { Core.Generic.myXML xml = new Core.Generic.myXML(System.Windows.Forms.Application.StartupPath + "\\Setting.xml"); pDcument = new MapDocumentClass(); try { string mxdData = xml.GetElement("MapDocument", "mxd"); //将数据载入pDocument并与map控件联系起来 mxdData = System.Windows.Forms.Application.StartupPath + mxdData; pDcument.Open(mxdData, ""); //Load the same pre-authored map document into the MapControl. mapControl.LoadMxFile(mxdData, null, null); //Set the extent of the MapControl to the full extent of the data. mapControl.Extent = mapControl.FullExtent; //int i; //for (i = 0; i <= pDcument.MapCount - 1; i++) //{ // //一个IMapDocument对象中可能有多个Map对象,遍历每个map对象 // mapControl.Map = pDcument.get_Map(i); //} mapControl.Refresh(); } catch (Exception ex) { throw (ex); } finally { xml = null; } }
/// <summary> /// 设置地图初始化范围 /// </summary> public void InitExtent() { Core.Generic.myXML xml = new Core.Generic.myXML(System.Windows.Forms.Application.StartupPath + "\\Setting.xml"); try { float xmin, ymin, xmax, ymax; float.TryParse(xml.GetElement("InitExtent", "Xmin"), out xmin); float.TryParse(xml.GetElement("InitExtent", "Ymin"), out ymin); float.TryParse(xml.GetElement("InitExtent", "Xmax"), out xmax); float.TryParse(xml.GetElement("InitExtent", "Ymax"), out ymax); IEnvelope env = new Envelope() as IEnvelope; env.XMin = xmin; env.YMin = ymin; env.XMax = xmax; env.YMax = ymax; //mapControl.Extent = mapControl.FullExtent; this.mapControl.Extent = env; this.mapControl.Refresh(); } catch (Exception ex) { throw (ex); } finally { xml = null; } }
/// <summary> /// 获取网络数据集 /// </summary> /// <param name="pFeatureClass"></param> public void getNetWorkData(ref IFeatureClass pFeatureClass) { Core.Generic.myXML xml = new Core.Generic.myXML(System.Windows.Forms.Application.StartupPath + "\\Setting.xml"); pMapDcument = new MapDocumentClass(); IFeatureLayer pFeatureLayer; try { string NetWorkData = xml.GetElement("MapDocument", "RoadNetData"); //将数据载入pMapDocument并与map控件联系起来 NetWorkData = System.Windows.Forms.Application.StartupPath + NetWorkData; pMapDcument.Open(NetWorkData, ""); for (int index = 0; index < pMapDcument.get_Map(0).LayerCount; index++) { if (pMapDcument.get_Map(0).get_Layer(index).Name == "实验区路网数据") { pFeatureLayer = pMapDcument.get_Map(0).get_Layer(index) as IFeatureLayer; pFeatureClass = pFeatureLayer.FeatureClass; } else { continue; } } } catch (Exception ex) { throw (ex); } finally { xml = null; } }
/// <summary> /// 加载网络数据集 /// </summary> public void LoadNetWorkDataSet() { Core.Generic.myXML xml = new Core.Generic.myXML(System.Windows.Forms.Application.StartupPath + "\\Setting.xml"); pMapDcument = new MapDocumentClass(); try { string NetWorkData = xml.GetElement("MapDocument", "RoadNetData"); //将数据载入pMapDocument并与map控件联系起来 NetWorkData = System.Windows.Forms.Application.StartupPath + NetWorkData; pMapDcument.Open(NetWorkData, ""); int i; for (i = 0; i <= pMapDcument.MapCount - 1; i++) { //一个IMapDocument对象中可能有多个Map对象,遍历每个map对象 mapControl.Map = pMapDcument.get_Map(i); } mapControl.Refresh(); } catch (Exception ex) { throw (ex); } finally { xml = null; } }
/// <summary> /// 加载配置文件设置的SHP文件 /// </summary> public void LoadShape() { Core.Generic.myXML xml = new Core.Generic.myXML(System.Windows.Forms.Application.StartupPath + "\\Setting.xml"); try { int shpCount; int.TryParse(xml.GetElement("Shape", "Count"), out shpCount); string shpFile; for (int i = 0; i < shpCount; i++) { shpFile = xml.GetElement("Shape", "Shp" + i); if (shpFile.StartsWith(".")) { shpFile = System.Windows.Forms.Application.StartupPath + shpFile.Substring(1); } LoadShape(shpFile); } mapControl.Refresh(); } catch (Exception ex) { throw (ex); } finally { xml = null; } }
/// <summary> /// 加载配置文件设置的DME文件 /// </summary> public void LoadDEM() { Core.Generic.myXML xml = new Core.Generic.myXML(System.Windows.Forms.Application.StartupPath + "\\Setting.xml"); try { int DEMCount; int.TryParse(xml.GetElement("RDEM", "Count"), out DEMCount); string shpFile; Program.SetProgressVal(0); Program.SetProgreeMax(DEMCount); for (int i = 0; i < DEMCount; i++) { shpFile = xml.GetElement("RDEM", "Dem" + i); if (shpFile.StartsWith(".")) { shpFile = System.Windows.Forms.Application.StartupPath + shpFile.Substring(1); } if (System.IO.File.Exists(shpFile)) { LoadDem(shpFile); } Program.SetProgressVal(i); } this.mapControl.Refresh(); Program.SetProgressVal(DEMCount); } catch (Exception ex) { throw (ex); } finally { xml = null; } }
/// <summary> /// 加载地图服务 /// </summary> public void LoadMapService() { Core.Generic.myXML xml = new Core.Generic.myXML(System.Windows.Forms.Application.StartupPath + "\\Setting.xml"); try { int serviceCount; int.TryParse(xml.GetElement("MapServices", "Count"), out serviceCount); string url; for (int i = 0; i < serviceCount; i++) { url = xml.GetElement("MapServices", "URL" + i); LoadMapService(url); } this.mapControl.Refresh(); } catch (Exception ex) { throw (ex); } finally { xml = null; } }
/// <summary> /// 获取交点 /// </summary> /// <param name="TaskAreas"></param> /// <param name="map"></param> public static void getIntersect(ESRI.ArcGIS.Controls.AxMapControl pMapCtr) { Core.Map.MapHelper map = new Core.Map.MapHelper(pMapCtr); Core.Generic.myXML xml = new Core.Generic.myXML(System.Windows.Forms.Application.StartupPath + "\\Setting.xml"); try { IFeatureClass pFeatureClass = null; Core.Model.DisaCrossPoint gatherPoint = new Core.Model.DisaCrossPoint(); Core.DAL.DisaCrossPoint dal = new Core.DAL.DisaCrossPoint(); //删除以前生成的交点 dal.Deletes(list_model[0].PID); map.getNetWorkData(ref pFeatureClass); if (list_model.Count == 0) { MessageBox.Show("该灾区尚未生成任务区!"); return; } //pIntersectPoint = new List<IPoint>(); string Roadtype = xml.GetElement("FilterPara", "RoadType"); string[] typeArray = Roadtype.Split(','); string whereclause = ""; if (Roadtype != null) { for (int i = 0; i < typeArray.Length; i++) { if (i != (typeArray.Length - 1)) { whereclause += "Type=" + typeArray[i] + " or "; } else { whereclause += "Type=" + typeArray[i]; } } } foreach (Core.Model.TaskAreas taskarea in list_model) { IPolygon pPolygon = CoScheduling.Core.Generic.Convertor.ToPolygon(taskarea.PolygonString); //过滤道路网 IGeometry pGeometry = pPolygon as IGeometry; ISpatialFilter pSpatialfilter = new SpatialFilterClass(); pSpatialfilter.Geometry = pGeometry; pSpatialfilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pSpatialfilter.WhereClause = whereclause; pSpatialfilter.GeometryField = "Shape"; IFeatureCursor FeatureCursor = pFeatureClass.Search(pSpatialfilter, false); IFeature pFeature = FeatureCursor.NextFeature(); int count = 1; while (pFeature != null) { IPolyline pPolyline = pFeature.ShapeCopy as IPolyline; ITopologicalOperator pTopologicalOperator = pPolyline as ITopologicalOperator; IGeometry pGeometry1 = pTopologicalOperator.Intersect(pPolygon, esriGeometryDimension.esriGeometry0Dimension) as IGeometry; if (!pGeometry1.IsEmpty) { IPointCollection Pc = pGeometry1 as IPointCollection; ISymbol symbol = map.CreateSimpleSymbol(Color.Red, 8, ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle); for (int i = 0; i < Pc.PointCount; i++) { //将交点显示在地图上 IPoint point = Pc.get_Point(i); map.AddElement(Pc.get_Point(i), symbol, "Intersect|" + taskarea.ID + "|" + taskarea.PID); //将交点存储到数据库中 gatherPoint.LON = point.X; gatherPoint.LAT = point.Y; gatherPoint.PID = taskarea.ID; gatherPoint.PName = "交点(" + count++ + ")"; dal.Add(gatherPoint); //pIntersectPoint.Add(Pc.get_Point(i)); } } pFeature = FeatureCursor.NextFeature(); } } } catch (Exception ex) { throw ex; } finally { TaskAreas = null; } }
/// <summary> /// 获取交点 /// </summary> /// <param name="pMapCtr"></param> /// <param name="id"></param> public static void getIntersect(ESRI.ArcGIS.Controls.AxMapControl pMapCtr, int id) { Core.Map.MapHelper map = new Core.Map.MapHelper(pMapCtr); Core.Generic.myXML xml = new Core.Generic.myXML(System.Windows.Forms.Application.StartupPath + "\\Setting.xml"); try { IFeatureClass pFeatureClass = null; Core.Model.DisaAreaInfo model = new Core.Model.DisaAreaInfo(); Core.DAL.DisaAreaInfo dal0 = new Core.DAL.DisaAreaInfo(); Core.Model.DisaCrossPoint gatherPoint = new Core.Model.DisaCrossPoint(); Core.DAL.DisaCrossPoint dal = new Core.DAL.DisaCrossPoint(); //删除以前生成的交点 dal.Deletes(id); map.getNetWorkData(ref pFeatureClass); //pIntersectPoint = new List<IPoint>(); string Roadtype = xml.GetElement("FilterPara", "RoadType"); string[] typeArray = Roadtype.Split(','); string whereclause = ""; if (Roadtype != null) { for (int i = 0; i < typeArray.Length; i++) { if (i != (typeArray.Length - 1)) { whereclause += "Type=" + typeArray[i] + " or "; } else { whereclause += "Type=" + typeArray[i]; } } } //生成灾区影响范围Geometry model = dal0.GetModel(id); IPoint pPoint = new PointClass(); pPoint.PutCoords(model.LON, model.LAT); ITopologicalOperator pTopoOp = default(ITopologicalOperator); IGeometry geoBuffer = null; pTopoOp = pPoint as ITopologicalOperator; geoBuffer = pTopoOp.Buffer(model.AffectedRadius / Core.Generic.SysEnviriment.LengthPerRad); ISpatialFilter pSpatialfilter = new SpatialFilterClass(); pSpatialfilter.Geometry = geoBuffer; pSpatialfilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses; pSpatialfilter.WhereClause = whereclause; pSpatialfilter.GeometryField = "Shape"; IFeatureCursor FeatureCursor = pFeatureClass.Search(pSpatialfilter, false); IFeature pFeature = FeatureCursor.NextFeature(); int count = 1; while (pFeature != null) { IPolyline pPolyline = pFeature.ShapeCopy as IPolyline; ITopologicalOperator pTopologicalOperator = pPolyline as ITopologicalOperator; IGeometry pGeometry1 = pTopologicalOperator.Intersect(geoBuffer as IPolygon, esriGeometryDimension.esriGeometry0Dimension) as IGeometry; if (!pGeometry1.IsEmpty) { IPointCollection Pc = pGeometry1 as IPointCollection; ISymbol symbol = map.CreateSimpleSymbol(Color.Red, 8, ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle); for (int i = 0; i < Pc.PointCount; i++) { //将交点显示在地图上 IPoint point = Pc.get_Point(i); map.AddElement(Pc.get_Point(i), symbol, "Intersect|" + id); //将交点存储到数据库中 gatherPoint.LON = point.X; gatherPoint.LAT = point.Y; gatherPoint.PID = id; gatherPoint.PName = "交点(" + count++ + ")"; dal.Add(gatherPoint); //pIntersectPoint.Add(Pc.get_Point(i)); } } pFeature = FeatureCursor.NextFeature(); } pMapCtr.ActiveView.Refresh(); } catch (Exception ex) { throw ex; } finally { TaskAreas = null; } }
/// <summary> /// 加载数据(绝对路径——YJ1008) /// </summary> public void LoadMapData() { Core.Generic.myXML xml = new Core.Generic.myXML(System.Windows.Forms.Application.StartupPath + "\\Setting.xml"); try { string shpFile; shpFile = xml.GetElement("MapData", "Resident"); if (!string.IsNullOrEmpty(shpFile)) { //if (shpFile.StartsWith(".")) // shpFile = System.Windows.Forms.Application.StartupPath + shpFile.Substring(1); if (System.IO.File.Exists(shpFile)) { OpenResidentLayer(shpFile); } } shpFile = xml.GetElement("MapData", "Road"); if (!string.IsNullOrEmpty(shpFile)) { //if (shpFile.StartsWith(".")) // shpFile = System.Windows.Forms.Application.StartupPath + shpFile.Substring(1); if (System.IO.File.Exists(shpFile)) { OpenRoadLayer(shpFile); } } shpFile = xml.GetElement("MapData", "Hydrographic"); if (!string.IsNullOrEmpty(shpFile)) { //if (shpFile.StartsWith(".")) // shpFile = System.Windows.Forms.Application.StartupPath + shpFile.Substring(1); if (System.IO.File.Exists(shpFile)) { OpenHydroLayer(shpFile); } } shpFile = xml.GetElement("MapData", "GeographicaNames"); if (!string.IsNullOrEmpty(shpFile)) { if (shpFile.StartsWith(".")) { shpFile = System.Windows.Forms.Application.StartupPath + shpFile.Substring(1); } if (System.IO.File.Exists(shpFile)) { OpenAreaNameLayer(shpFile); } } shpFile = xml.GetElement("MapData", "DEM"); if (!string.IsNullOrEmpty(shpFile)) { //if (shpFile.StartsWith(".")) // shpFile = System.Windows.Forms.Application.StartupPath + shpFile.Substring(1); if (System.IO.File.Exists(shpFile)) { OpenDEMLayer(shpFile); } } } catch (Exception ex) { throw (ex); } }