private static void ReportResult(SpatialFunction overlayOp, Location[] location, bool expectedInterior) { System.Diagnostics.Debug.WriteLine(overlayOp + ":" + " A:" + LocationUtility.ToLocationSymbol(location[0]) + " B:" + LocationUtility.ToLocationSymbol(location[1]) + " expected:" + (expectedInterior ? 'i' : 'e') + " actual:" + LocationUtility.ToLocationSymbol(location[2]) ); }
public void IsInPolygonTest() { var point = new Location(22.409439, 113.735414); // 深圳市南山区 var points = new List <Location>(); points.Add(new Location(22.506303, 113.997266)); points.Add(new Location(22.513987, 114.006482)); points.Add(new Location(22.529682, 113.999479)); points.Add(new Location(22.539055, 114.003994)); points.Add(new Location(22.55302, 114.00266)); points.Add(new Location(22.555931, 114.006308)); points.Add(new Location(22.560939, 114.003886)); points.Add(new Location(22.562909, 114.012577)); points.Add(new Location(22.570114, 114.00892)); points.Add(new Location(22.582217, 114.012039)); points.Add(new Location(22.589529, 114.030786)); points.Add(new Location(22.606064, 114.029787)); points.Add(new Location(22.612017, 114.019419)); points.Add(new Location(22.63413, 114.009938)); points.Add(new Location(22.635255, 114.001227)); points.Add(new Location(22.643759, 113.997029)); points.Add(new Location(22.644023, 113.981667)); points.Add(new Location(22.648414, 113.974815)); points.Add(new Location(22.656977, 113.973232)); points.Add(new Location(22.658642, 113.956087)); points.Add(new Location(22.655666, 113.949057)); points.Add(new Location(22.643623, 113.943025)); points.Add(new Location(22.640058, 113.936492)); points.Add(new Location(22.613872, 113.937102)); points.Add(new Location(22.604535, 113.931339)); points.Add(new Location(22.598716, 113.933979)); points.Add(new Location(22.593551, 113.930993)); points.Add(new Location(22.58658, 113.936156)); points.Add(new Location(22.579901, 113.933197)); points.Add(new Location(22.571698, 113.922604)); points.Add(new Location(22.562977, 113.922503)); points.Add(new Location(22.547586, 113.900917)); points.Add(new Location(22.531673, 113.857115)); points.Add(new Location(22.516216, 113.836299)); points.Add(new Location(22.409449, 113.735253)); points.Add(new Location(22.398465, 113.764399)); points.Add(new Location(22.371004, 113.79039)); points.Add(new Location(22.347731, 113.802364)); points.Add(new Location(22.290004, 113.813838)); points.Add(new Location(22.240159, 113.837116)); points.Add(new Location(22.270685, 113.850441)); points.Add(new Location(22.276198, 113.858777)); points.Add(new Location(22.336642, 113.880412)); points.Add(new Location(22.432119, 113.880408)); points.Add(new Location(22.475107, 113.959233)); points.Add(new Location(22.506303, 113.997266)); Assert.True(LocationUtility.IsInPolygon(point, points)); }
public void GetDistanceTest() { // 采用百度坐标(09) Assert.Equal(0.5575, LocationUtility.GetDistance(22.4977230000, 113.9220230000, 22.4943320000, 113.9260120000)); // 采用高德腾讯坐标(02) Assert.Equal(0.5432, LocationUtility.GetDistance(22.4918523806, 113.9155480930, 22.4885799188, 113.9194658604)); // 采用硬件坐标(84) Assert.Equal(0.5437, LocationUtility.GetDistance(new Location(22.4948556106, 113.9106398730), new Location(22.4916106488, 113.9145906104))); }
private static void ReportResult(SpatialFunction overlayOp, Location[] location, bool expectedInterior) { // ReSharper disable RedundantStringFormatCall // String.Format needed to build 2.0 release! Debug.WriteLine(string.Format("{0}:" + " A:{1} B:{2} expected:{3} actual:{4}", overlayOp, LocationUtility.ToLocationSymbol(location[0]), LocationUtility.ToLocationSymbol(location[1]), expectedInterior ? 'i' : 'e', LocationUtility.ToLocationSymbol(location[2]))); // ReSharper restore RedundantStringFormatCall }
/// <summary> /// /// </summary> /// <returns></returns> public override string ToString() { StringBuilder sb = new StringBuilder(); if (_location.Length > 1) { sb.Append(LocationUtility.ToLocationSymbol(_location[(int)Positions.Left])); } sb.Append(LocationUtility.ToLocationSymbol(_location[(int)Positions.On])); if (_location.Length > 1) { sb.Append(LocationUtility.ToLocationSymbol(_location[(int)Positions.Right])); } return(sb.ToString()); }
private bool GetDistanceString(out string distanceString) { bool output = false; distanceString = String.Empty; try { if (this.Device != null) { if (this.Device.Location != null) { if (this.Device.Location.Latitude.GetValueOrDefault() != 0 && this.Device.Location.Longitude.GetValueOrDefault() != 0) { output = true; double meters = LocationUtility.DistanceInMetersFrom(this.Device.Location.Latitude.Value, this.Device.Location.Longitude.Value); if (meters < 0) { distanceString = String.Empty; output = false; } else { if (meters > 1000) { double km = (meters / 1000); distanceString = km.ToString("#,###.#") + " km away"; } else { distanceString = Convert.ToInt32(meters).ToString() + " meters away"; } } } } } } catch (Exception e) { LogUtility.LogException(e); } return(output); }
public void IsInRangeTest() { Assert.True(LocationUtility.IsInRange(new Location(22.4943320000, 113.9260120000), new Location(22.4977230000, 113.9220230000), 1)); Assert.True(new Location(22.4943320000, 113.9260120000).IsInRange(22.4977230000, 113.9220230000, 1)); }
public void GetPositionTest() { var a = LocationUtility.GetPosition(22.4977230000, 113.9220230000, 0.5); var b = LocationUtility.GetPosition(new Location(22.4977230000, 113.9220230000), 0.5); }
public void ParseTest() { Assert.NotNull(LocationUtility.Parse("22.4977230000,113.9220230000")); Assert.Null(LocationUtility.Parse("22.4977230000[113.9220230000]")); }
public static AssignOrderPushContent PushAddAssignOrderPushContent(long orderID) { using (var db = new DataContext()) { var legworkOrder = db.Legwork_Order.Where(q => q.OrderID == orderID).FirstOrDefault(); if (legworkOrder != null) { var deliveryModel = GetAddress(legworkOrder.RequiredDeliveryAddressID); #region 计算区域ID var listAreaID = db.Legwork_AreaConfig.Select(q => q.AreaID).ToArray(); bool result = false; int AreaID = 0; foreach (var i in listAreaID) { //获取开通跑腿区域 var openAreas = db.Legwork_AreaConfig.Where(p => p.AreaID == i).Select(t => t.OpenAreas).FirstOrDefault().Split(',').Select(p => p.ToInt32()); if (!openAreas.HasValue()) { return(null); } //获取区域经纬度 try { var listArea = db.System_Area.Where(q => openAreas.Contains(q.AreaID)).Select(t => t.Points).Select(p => Newtonsoft.Json.JsonConvert.DeserializeObject <List <List <AreaModel> > >(p)); if (!listArea.HasValue()) { return(null); } foreach (var list1 in listArea) { foreach (var list2 in list1) { result = LocationUtility.IsInPolygon(new Location(deliveryModel.Latitude, deliveryModel.Longitude), list2.Select(p => new Location(p.lat, p.lng)).ToList()); if (result) { AreaID = i; break; ; } } if (result) { break; } } if (result) { break; } } catch { continue; } } #endregion string PushCode = ""; var userList = (from a in db.Worker_Account join b in db.Worker_BusinessRelation on a.WorkerID equals b.WorkerID where a.AccountStatus == (short)WorkerAccountStatus.Normal && a.WorkingState == (short)WorkingState.Enabled && a.DefaultAreaID == AreaID && b.AuditStatus == (int)WorkerBusinessAuditStatus.Passed && b.BusinessType == (int)BusinessType.LegworkService select new { a.PushCode }).ToArray(); if (!userList.Any()) { return(null); } foreach (var item in userList) { if (!string.IsNullOrWhiteSpace(item.PushCode)) { PushCode += item.PushCode + ","; } } AssignOrderPushContent assignOrder = new AssignOrderPushContent() { PushCode = PushCode.TrimEnd(new char[] { ',' }), CreateTime = legworkOrder.SubmitTime, OrderID = legworkOrder.OrderID, OrderType = legworkOrder.OrderType, OrderCode = legworkOrder.OrderCode, }; return(assignOrder); } return(null); } }