public void TestOneHop() { // build test data. var tagsIndex = new TagsTableCollectionIndex(); var tags = new TagsCollection(new Tag() { Key = "highway", Value = "residential" }); var tagsId = tagsIndex.Add(tags); var graph = new DynamicGraphRouterDataSource <LiveEdge>(tagsIndex); var vertex1 = graph.AddVertex(50.909909938361324f, 4.452434778213501f); var vertex2 = graph.AddVertex(50.916698097895550f, 4.459059834480286f); graph.AddEdge(vertex1, vertex2, new LiveEdge() { Distance = 890.65f, Forward = true, Tags = tagsId }); // calculate route. var router = new BasicRouter(); var route = router.Calculate(new BasicRouterDataSource <LiveEdge>(graph), OsmSharp.Routing.Vehicle.Car, vertex1, vertex2, true); // verify result. Assert.IsNotNull(route); Assert.AreEqual(vertex2, route.Vertex); Assert.AreEqual(OsmSharp.Routing.Vehicle.Car.Weight(tags, 890.65f), route.Weight); Assert.AreEqual(vertex1, route.From.Vertex); Assert.AreEqual(0, route.From.Weight); }
public ShowTag(BasicRouter br) { InitializeComponent(); this.br = br; if (null != br) { if (null != br.Name && !"".Equals(br.Name)) { this.Text = "當前的參考點:" + br.Name + "(" + br.ID[0].ToString("X2") + br.ID[1].ToString("X2") + ")"; } else { this.Text = "當前的參考點:" + br.ID[0].ToString("X2") + br.ID[1].ToString("X2"); } } }
public void TestOneHopShape() { // build test data. var tagsIndex = new TagsTableCollectionIndex(); var tags = new TagsCollection(new Tag() { Key = "highway", Value = "residential" }); var tagsId = tagsIndex.Add(tags); var graph = new DynamicGraphRouterDataSource <LiveEdge>(tagsIndex); var vertex1 = graph.AddVertex(50.909909938361324f, 4.452434778213501f); var vertex2 = graph.AddVertex(50.916698097895550f, 4.459059834480286f); graph.AddEdge(vertex1, vertex2, new LiveEdge() { Distance = 890.65f, Forward = true, Tags = tagsId }, new CoordinateArrayCollection <GeoCoordinate>( new GeoCoordinate [] { new GeoCoordinate(50.910408852752770, 4.4531670212745670), new GeoCoordinate(50.911362694534270, 4.4543391466140750), new GeoCoordinate(50.912018872212215, 4.4550552964210500), new GeoCoordinate(50.913280466188610, 4.4562461972236630), new GeoCoordinate(50.914614742177996, 4.4574183225631705), new GeoCoordinate(50.915686870323930, 4.4582659006118770), new GeoCoordinate(50.916354824109910, 4.4587942957878110) })); // calculate route. var router = new BasicRouter(); var route = router.Calculate(new BasicRouterDataSource <LiveEdge>(graph), OsmSharp.Routing.Vehicle.Car, vertex1, vertex2, true); // verify result. Assert.IsNotNull(route); Assert.AreEqual(vertex2, route.Vertex); Assert.AreEqual(OsmSharp.Routing.Vehicle.Car.Weight(tags, 890.65f), route.Weight); Assert.AreEqual(vertex1, route.From.Vertex); Assert.AreEqual(0, route.From.Weight); }
private void EditRouter_Load(object sender, EventArgs e) { this.MaximumSize = new Size(254, 308); this.MinimumSize = new Size(254, 308); if (null == StrRouterID || "".Equals(StrRouterID)) { RID_1TB.Text = "00"; RID_2TB.Text = "00"; NodeTypeCB.SelectedIndex = 0; } else { RID_1TB.Text = StrRouterID.Substring(0, 2); RID_2TB.Text = StrRouterID.Substring(2, 2); if (1 == type) { NodeTypeCB.SelectedIndex = 1; BasicNode MyBasicNode = null; area.AreaNode.TryGetValue(StrRouterID, out MyBasicNode); if (null != MyBasicNode) { RouterVisibleCB.Checked = MyBasicNode.isVisible; ReferNameTB.Text = MyBasicNode.Name; } } else { NodeTypeCB.SelectedIndex = 0; BasicRouter MyBasicRouter = null; area.AreaRouter.TryGetValue(StrRouterID, out MyBasicRouter); if (null != MyBasicRouter) { RouterVisibleCB.Checked = MyBasicRouter.isVisible; ReferNameTB.Text = MyBasicRouter.Name; } } } }
public void DecodeReferencedPointAlongLineLocation() { double delta = 0.0001; // build the location to decode. var location = new PointAlongLineLocation(); location.First = new LocationReferencePoint(); location.First.Coordinate = new Coordinate() { Latitude = 49.60597, Longitude = 6.12829 }; location.First.DistanceToNext = 92; location.First.FuntionalRoadClass = FunctionalRoadClass.Frc2; location.First.FormOfWay = FormOfWay.MultipleCarriageWay; location.First.LowestFunctionalRoadClassToNext = FunctionalRoadClass.Frc2; location.First.Bearing = 203; location.Last = new LocationReferencePoint(); location.Last.Coordinate = new Coordinate() { Latitude = 49.60521, Longitude = 6.12779 }; location.Last.DistanceToNext = 10; location.Last.FuntionalRoadClass = FunctionalRoadClass.Frc2; location.Last.FormOfWay = FormOfWay.MultipleCarriageWay; location.Last.Bearing = 23; location.PositiveOffsetPercentage = (float)((28.0 / 92.0) * 100.0); location.Orientation = Orientation.FirstToSecond; location.SideOfRoad = SideOfRoad.Left; // build a graph to decode onto. var tags = new TagsTableCollectionIndex(); var graphDataSource = new DynamicGraphRouterDataSource <LiveEdge>(tags); var vertex1 = graphDataSource.AddVertex(49.60597f, 6.12829f); var vertex2 = graphDataSource.AddVertex(49.60521f, 6.12779f); graphDataSource.AddEdge(vertex1, vertex2, new LiveEdge() { Distance = 10, Forward = true, Tags = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary"))) }, null); graphDataSource.AddEdge(vertex2, vertex1, new LiveEdge() { Distance = 10, Forward = true, Tags = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary"))) }, null); // decode the location var graph = new BasicRouterDataSource <LiveEdge>(graphDataSource); var decoder = new PointAlongLineDecoder(); var router = new BasicRouter(); var mainDecoder = new ReferencedOsmDecoder(graph, new BinaryDecoder()); var referencedDecoder = new ReferencedPointAlongLineDecoder(mainDecoder, decoder); var referencedLocation = referencedDecoder.Decode(location); // confirm result. Assert.IsNotNull(referencedLocation); Assert.IsNotNull(referencedLocation.Route); Assert.IsNotNull(referencedLocation.Route.Edges); Assert.AreEqual(vertex1, referencedLocation.Route.Vertices[0]); Assert.AreEqual(vertex2, referencedLocation.Route.Vertices[1]); var longitudeReference = (location.Last.Coordinate.Longitude - location.First.Coordinate.Longitude) * (location.PositiveOffsetPercentage.Value / 100.0) + location.First.Coordinate.Longitude; var latitudeReference = (location.Last.Coordinate.Latitude - location.First.Coordinate.Latitude) * (location.PositiveOffsetPercentage.Value / 100.0) + location.First.Coordinate.Latitude; Assert.AreEqual(longitudeReference, referencedLocation.Longitude, delta); Assert.AreEqual(latitudeReference, referencedLocation.Latitude, delta); Assert.AreEqual(Orientation.FirstToSecond, referencedLocation.Orientation); }
public void DecodeReferencedLineLocation() { // build the location to decode. var location = new LineLocation(); location.First = new LocationReferencePoint(); location.First.Coordinate = new Coordinate() { Latitude = 49.60851, Longitude = 6.12683 }; location.First.DistanceToNext = 517; location.First.FuntionalRoadClass = FunctionalRoadClass.Frc3; location.First.FormOfWay = FormOfWay.MultipleCarriageWay; location.First.LowestFunctionalRoadClassToNext = FunctionalRoadClass.Frc3; location.First.Bearing = 0; location.Intermediate = new LocationReferencePoint[1]; location.Intermediate[0] = new LocationReferencePoint(); location.Intermediate[0].Coordinate = new Coordinate() { Latitude = 49.60398, Longitude = 6.12838 }; location.Intermediate[0].DistanceToNext = 104; location.Intermediate[0].FuntionalRoadClass = FunctionalRoadClass.Frc3; location.Intermediate[0].FormOfWay = FormOfWay.SingleCarriageWay; location.Intermediate[0].LowestFunctionalRoadClassToNext = FunctionalRoadClass.Frc5; location.Intermediate[0].Bearing = 0; location.Last = new LocationReferencePoint(); location.Last = new LocationReferencePoint(); location.Last.Coordinate = new Coordinate() { Latitude = 49.60305, Longitude = 6.12817 }; location.Last.DistanceToNext = 0; location.Last.FuntionalRoadClass = FunctionalRoadClass.Frc5; location.Last.FormOfWay = FormOfWay.SingleCarriageWay; location.Last.Bearing = 0; // build a graph to decode onto. var tags = new TagsTableCollectionIndex(); var graphDataSource = new DynamicGraphRouterDataSource <LiveEdge>(tags); uint vertex1 = graphDataSource.AddVertex(49.60851f, 6.12683f); uint vertex2 = graphDataSource.AddVertex(49.60398f, 6.12838f); uint vertex3 = graphDataSource.AddVertex(49.60305f, 6.12817f); graphDataSource.AddEdge(vertex1, vertex2, new LiveEdge() { Distance = 517, Forward = true, Tags = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary"))) }, null); graphDataSource.AddEdge(vertex2, vertex1, new LiveEdge() { Distance = 517, Forward = true, Tags = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary"))) }, null); graphDataSource.AddEdge(vertex2, vertex3, new LiveEdge() { Distance = 104, Forward = true, Tags = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary"))) }, null); graphDataSource.AddEdge(vertex3, vertex2, new LiveEdge() { Distance = 104, Forward = true, Tags = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary"))) }, null); // decode the location var graph = new BasicRouterDataSource <LiveEdge>(graphDataSource); var decoder = new LineLocationDecoder(); var router = new BasicRouter(); var mainDecoder = new ReferencedOsmDecoder(graph, new BinaryDecoder()); var referencedDecoder = new ReferencedLineDecoder(mainDecoder, decoder); var referencedLocation = referencedDecoder.Decode(location); // confirm result. Assert.IsNotNull(referencedLocation); Assert.IsNotNull(referencedLocation.Vertices); Assert.AreEqual(3, referencedLocation.Vertices.Length); Assert.IsNotNull(referencedLocation.Edges); Assert.AreEqual(2, referencedLocation.Edges.Length); }
/// <summary> /// 查找按钮,用于查找Tag和设备讯息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SearchBtn_Click(object sender, EventArgs e) { String StrIDorName = TagIDorNameTB.Text.ToUpper(); if ("".Equals(StrIDorName)) { MessageBox.Show("設備的ID或名稱不能為空!"); return; } if (tagrb.Checked) { #region 查找Tag设备 PersonOperation curpersonoper = new PersonOperation(frm.CurPerson.ID, OperType.SearchTag); CommonCollection.personOpers.Add(curpersonoper); TagPack MyTag = null; MyTag = SysParam.GetPackTag(StrIDorName); if (null == MyTag) { MyTag = SysParam.GetPackTag_Name(StrIDorName); } if (null == MyTag) { MessageBox.Show("查詢" + StrIDorName + "的Tag設備不存在!"); return; } Area curarea = CommonBoxOperation.GetAreaFromRouterID(MyTag.RD_New[0].ToString("X2") + MyTag.RD_New[1].ToString("X2")); if (null == curarea) { MessageBox.Show("對不起,卡片所在的區域不存在!"); return; } try { SysParam.isTracking = true; MyAllRegInfoWin = new AllRegInfoWin(frm, SpeceilAlarm.PersonHelp, MyTag.TD[0].ToString("X2") + MyTag.TD[1].ToString("X2")); MyAllRegInfoWin.ShowDialog(); } catch (Exception ex) { FileOperation.WriteLog("搜索Tag設備出現異常!異常原因:" + ex.ToString()); } finally { this.Close(); } #endregion } else if (rfrb.Checked) { #region 查找Refer设备 PersonOperation curpersonoper = new PersonOperation(frm.CurPerson.ID, OperType.SearchRefer); CommonCollection.personOpers.Add(curpersonoper); string strareaid = ""; BasicRouter mrt = null; foreach (KeyValuePair <string, Area> marea in CommonCollection.Areas) { if (null == marea.Value) { continue; } marea.Value.AreaRouter.TryGetValue(StrIDorName, out mrt); if (mrt != null) { strareaid = marea.Key; break; } foreach (KeyValuePair <string, BasicRouter> router in marea.Value.AreaRouter) { if (null == router.Value) { continue; } if (StrIDorName.Equals(router.Value.Name)) { mrt = router.Value; break; } } if (null != mrt) { strareaid = marea.Key; break; } } if (null == strareaid || "".Equals(strareaid)) { MessageBox.Show("查詢" + StrIDorName + @"的參考點設備不存在!"); return; } RegInfoWin myregwin = new RegInfoWin(frm, strareaid); myregwin.ShowDialog(); this.Close(); #endregion } else if (ndrb.Checked) { #region 查找Node设备 PersonOperation curpersonoper = new PersonOperation(frm.CurPerson.ID, OperType.SearchNode); CommonCollection.personOpers.Add(curpersonoper); string strareaid = ""; BasicNode mnd = null; foreach (KeyValuePair <string, Area> marea in CommonCollection.Areas) { if (null == marea.Value) { continue; } marea.Value.AreaNode.TryGetValue(StrIDorName, out mnd); if (mnd != null) { strareaid = marea.Key; break; } foreach (KeyValuePair <string, BasicNode> node in marea.Value.AreaNode) { if (null == node.Value) { continue; } if (StrIDorName.Equals(node.Value.Name)) { mnd = node.Value; break; } } if (null != mnd) { strareaid = marea.Key; break; } } if (null == strareaid || "".Equals(strareaid)) { MessageBox.Show("查詢" + StrIDorName + @"的數據節點設備不存在!"); return; } RegInfoWin myregwin = new RegInfoWin(frm, strareaid); myregwin.ShowDialog(); this.Close(); #endregion } }
/// <summary> /// 设置参考点 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SetBt_Click(object sender, EventArgs e) { #region 获取设置的参考点及节点讯息 string StrID1, StrID2, StrName, StrArea; StrID1 = RID_1TB.Text.ToUpper(); StrID2 = RID_2TB.Text.ToUpper(); //参考点名称 StrName = ReferNameTB.Text.ToUpper(); //判断区域是否存在 StrArea = Ps.ShowAreaCB.Text; //取出区域的ID Area are = SysParam.GetArea_IDName(StrArea); int index = NodeTypeCB.SelectedIndex; #endregion #region 檢查ID是否有误 if ("".Equals(StrID1) || "".Equals(StrID2)) { MessageBox.Show("對不起,ID不能为空!"); return; } if (StrID1.Length != 2 || StrID2.Length != 2) { MessageBox.Show("對不起,ID格式有誤,正常格式為ID1和ID2的長度都為2!"); return; } byte[] ID = new byte[2]; try { ID[0] = Convert.ToByte(StrID1, 16); ID[1] = Convert.ToByte(StrID2, 16); }catch (Exception) { MessageBox.Show("對不起,ID格式有误!"); return; } if (0 == ID[0] && 0 == ID[1]) { MessageBox.Show("對不起,參考點和數據節點的ID不能為0000!"); return; } if (0xFF == ID[0] && 0xFF == ID[1]) { MessageBox.Show("對不起,參考點和數據節點的ID不能為FFFF!"); return; } #endregion #region 检查添加或修改的参考点或数据节点是否已经存在 Area marea = null; Group mygroup = null; string strarea = "", strgrpid = "", strgroup = ""; int res = IsAreaContainNodeOrRefer(StrID1 + StrID2, out marea); if (null != marea) { if ("".Equals(marea.Name) || null == marea.Name) { strarea = marea.ID[0].ToString("X2") + marea.ID[1].ToString("X2"); } else { strarea = marea.Name; } strgrpid = marea.GroupID[0].ToString("X2") + marea.GroupID[1].ToString("X2"); } if (CommonCollection.Groups.TryGetValue(strgrpid, out mygroup)) {//获取到组别讯息 if ("".Equals(mygroup.Name) || null == mygroup.Name) { strgroup = mygroup.ID[0].ToString("X2") + mygroup.ID[1].ToString("X2"); } else { strgroup = mygroup.Name; } } #endregion if (StrRouterID != null && !"".Equals(StrRouterID)) { #region 修改参考点和数据节点讯息 if (!StrRouterID.Equals(StrID1 + StrID2)) { MessageBox.Show("對不起,參考點及數據節點的ID不能修改!"); return; } if (type != index) { //说明修改了节点的类型 if (index == 1) { //从参考点修改为数据节点 if (res == 1) { //包含数据节点 MessageBox.Show("在" + strgroup + "組別的" + strarea + "區域中" + "已經存在數據節點" + (StrID1 + StrID2) + "..."); return; } else { if (area.AreaRouter.Remove(StrRouterID)) { BasicNode Bn = new BasicNode(); Bn.ID = ID; Bn.Name = StrName; Bn.isVisible = true; Bn.x = ex.X; Bn.y = ex.Y; Bn.isVisible = RouterVisibleCB.Checked; are.AreaNode.Add(StrID1 + StrID2, Bn); this.Close(); return; } } } else {//从数据节点修改为参考点 if (res == 2) { MessageBox.Show("在" + strgroup + "組別的" + strarea + "區域中" + "已經存在參考點" + (StrID1 + StrID2) + "..."); return; } else { if (area.AreaNode.Remove(StrRouterID)) { BasicRouter BR = new BasicRouter(); BR.ID = ID; BR.Name = StrName; BR.isVisible = true; BR.x = ex.X; BR.y = ex.Y; BR.isVisible = RouterVisibleCB.Checked; are.AreaRouter.Add(StrID1 + StrID2, BR); this.Close(); return; } } } return; } //没有修改数据节点类型 if (index == 1) {//设置数据节点 BasicNode MyBasicNode = null; area.AreaNode.TryGetValue(StrRouterID, out MyBasicNode); if (null != MyBasicNode) { MyBasicNode.Name = StrName; MyBasicNode.isVisible = RouterVisibleCB.Checked; this.Close(); return; } } else {//设置参考点 BasicRouter MyBasicRouter = null; area.AreaRouter.TryGetValue(StrRouterID, out MyBasicRouter); if (null != MyBasicRouter) { MyBasicRouter.Name = StrName; MyBasicRouter.isVisible = RouterVisibleCB.Checked; this.Close(); return; } } #endregion } #region 添加参考点及节点 if (res == 1) { //包含节点 if (index == 1) { //数据节点 MessageBox.Show("在" + strgroup + "組別的" + strarea + "區域中" + "已經存在數據節點" + (StrID1 + StrID2) + "..."); } else {//参考点 MessageBox.Show("對不起,參考點ID與數據節點ID不能相同,在組別" + strgroup + "的" + strarea + "區域中" + "已經存在數據節點" + (StrID1 + StrID2) + "..."); } return; } else if (res == 2) { //包含参考点 if (index == 1) { //数据节点 MessageBox.Show("對不起,參考點ID與數據節點ID不能相同,在組別" + strgroup + "的" + strarea + "區域中" + "已經存在參考點" + (StrID1 + StrID2) + "..."); } else {//参考点 MessageBox.Show("對不起,在組別" + strgroup + "的" + strarea + "區域中" + "已經存在參考點" + (StrID1 + StrID2) + "..."); } return; } else if (res < 0) { //添加参考点与数据节点 if (index == 1) { //数据节点 BasicNode Bn = new BasicNode(); Bn.ID = ID; Bn.Name = StrName; Bn.isVisible = true; Bn.x = ex.X; Bn.y = ex.Y; Bn.isVisible = RouterVisibleCB.Checked; if (are.AreaNode.ContainsKey(StrID1 + StrID2)) { MessageBox.Show("Sorry,該區域上已經包含了" + StrID1 + StrID2 + "數據節點!"); return; } are.AreaNode.Add(StrID1 + StrID2, Bn); } else {//参考点 BasicRouter BR = new BasicRouter(); BR.ID = ID; BR.Name = StrName; BR.isVisible = true; BR.x = ex.X; BR.y = ex.Y; BR.isVisible = RouterVisibleCB.Checked; if (are.AreaRouter.ContainsKey(StrID1 + StrID2)) { MessageBox.Show("Sorry,該區域上已經包含了" + StrID1 + StrID2 + "參考點!"); return; } are.AreaRouter.Add(StrID1 + StrID2, BR); } SysParam.RestoreShow(); this.Close(); return; } #endregion }
public void DrawTimer_Tick(Object obj, EventArgs args) { StartDTe = StartDTe.AddMilliseconds(1000);//每次增加1s label7.Text = "當前時間:" + StartDTe.ToString(); if (CurIndex >= PickTags.Length) { Stop(); return; } float scalew, scaleh; if (DateTime.Compare(StartDTe, PickTags[CurIndex].ReportTime) >= 0) {//画出当前的地图 string StrTagID = PickTags[CurIndex].TD[0].ToString("X2") + PickTags[CurIndex].TD[1].ToString("X2"); string StrRouterID = PickTags[CurIndex].RD_New[0].ToString("X2") + PickTags[CurIndex].RD_New[1].ToString("X2"); Area CurArea = CommonBoxOperation.GetAreaFromRouterID(StrRouterID); if (CurArea != null) { if (null == CurArea.Name || "".Equals(CurArea.Name)) { CurAreaLabel.Text = "當前區域:" + CurArea.ID[0].ToString("X2") + CurArea.ID[1].ToString("X2"); } else { CurAreaLabel.Text = "當前區域:" + CurArea.Name + "(" + CurArea.ID[0].ToString("X2") + CurArea.ID[1].ToString("X2") + ")"; } BasicRouter CurBasic = CommonBoxOperation.GetBasicRouter(StrRouterID); CurBasic.isReport = true; string StrTagInfor = ""; string StrTagName = CommonBoxOperation.GetTagName(StrTagID); if (null == StrTagName || "".Equals(StrTagName)) { StrTagInfor = StrTagID; } else { StrTagInfor = StrTagName + "(" + StrTagID + ")"; } scalew = (float)TrackPanel.Width / CurArea.AreaBitMap.MyBitmap.Width; scaleh = (float)TrackPanel.Height / CurArea.AreaBitMap.MyBitmap.Height; TrackBtm = new Bitmap(655, 358); TrackBtm = new Bitmap(CurArea.AreaBitMap.MyBitmap, TrackPanel.Width, TrackPanel.Height); //画Router的信息 DrawAreaMap.DrawBasicRouter(TrackBtm, CurArea.ID[0].ToString("X2") + CurArea.ID[1].ToString("X2"), 1, scalew, scaleh); //画Tag的信息 if (null != CurBasic) { if (PickTags[CurIndex].isAlarm == 0x03) { Graphics.FromImage(TrackBtm).FillEllipse(SimpleBrush, CurBasic.x * scalew - 8, CurBasic.y * scaleh - 32, ConstInfor.TagR * 2, ConstInfor.TagR * 2); Graphics.FromImage(TrackBtm).DrawString(StrTagInfor, new Font("宋体", 10), SimpleBrush, CurBasic.x * scalew - 5, CurBasic.y * scaleh - 42); } else if (PickTags[CurIndex].isAlarm == 0x04) { Graphics.FromImage(TrackBtm).FillEllipse(AlarmBrush, CurBasic.x * scalew - 8, CurBasic.y * scaleh - 32, ConstInfor.TagR * 2, ConstInfor.TagR * 2); Graphics.FromImage(TrackBtm).DrawString(StrTagInfor, new Font("宋体", 10), AlarmBrush, CurBasic.x * scalew - 5, CurBasic.y * scaleh - 42); } } TrackPanel_Paint(null, null); } CurIndex++; } }