private void drawTempLine(INetworkRoute route) { // 画出停靠点到映射点的虚线 int segmentCount = route.SegmentCount; INetworkRouteSegment segment = null; INetworkLocation startLocation = null; INetworkLocation endLocation = null; IPoint pointOnNetwork = null; ICurveSymbol tmpLineSym = new CurveSymbol(); tmpLineSym.Color = System.Drawing.Color.Yellow; tmpLineSym.Width = -2; for (int i = 0; i < segmentCount; i++) { segment = route.GetSegment(i); startLocation = segment.StartLocation; pointOnNetwork = startLocation.NetworkPosition; fdepoint = startLocation.Position; IPolyline tmpLine = geoFac.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline; tmpLine.AppendPoint(fdepoint); tmpLine.AppendPoint(pointOnNetwork); tmpRenderLineArray.Add(this.axRenderControl1.ObjectManager.CreateRenderPolyline(tmpLine, tmpLineSym, rootId)); if (i == segmentCount - 1) { endLocation = segment.EndLocation; pointOnNetwork = endLocation.NetworkPosition; fdepoint = endLocation.Position; tmpLine = geoFac.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline; tmpLine.AppendPoint(fdepoint); tmpLine.AppendPoint(pointOnNetwork); tmpRenderLineArray.Add(this.axRenderControl1.ObjectManager.CreateRenderPolyline(tmpLine, tmpLineSym, rootId)); } } }
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; } } }