/// <summary> /// Returns an instance of <see cref="IRectangle"/> representing the bounding box of the specified GeoJSON <paramref name="collection"/>. /// </summary> /// <param name="collection">The feature collection.</param> /// <returns>An instance of <see cref="IRectangle"/>.</returns> /// <exception cref="ArgumentNullException"><paramref name="collection"/> is <c>null</c>.</exception> /// <exception cref="InvalidOperationException"><paramref name="collection"/> is empty.</exception> public static IRectangle GetBoundingBox(GeoJsonFeatureCollection collection) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } if (collection.Features.Count == 0) { throw new InvalidOperationException(nameof(collection)); } List <IPoint> points = new List <IPoint>(); foreach (GeoJsonFeature feature in collection.Features) { IRectangle bbox = GetBoundingBox(feature); if (bbox != null) { points.Add(bbox.SouthWest); points.Add(bbox.NorthEast); } } return(points.Count == 0 ? null : MapsUtils.GetBoundingBox(points)); }
public void ComputeOffset() { const double r = 6378137; IPoint o = new Point(55.861858, 9.824622); IPoint r1 = MapsUtils.ComputeOffset(o, 100, 0, r); IPoint r2 = MapsUtils.ComputeOffset(o, 100, 45, r); IPoint r3 = MapsUtils.ComputeOffset(o, 100, 90, r); IPoint r4 = MapsUtils.ComputeOffset(o, 100, 135, r); IPoint r5 = MapsUtils.ComputeOffset(o, 100, 180, r); IPoint r6 = MapsUtils.ComputeOffset(o, 100, 225, r); IPoint r7 = MapsUtils.ComputeOffset(o, 100, 270, r); IPoint r8 = MapsUtils.ComputeOffset(o, 100, 315, r); IPoint r9 = MapsUtils.ComputeOffset(o, 100, 360, r); Assert.AreEqual("100.0000", DistanceUtils.GetDistance(o, r1, r).ToString("N4")); Assert.AreEqual("100.0000", DistanceUtils.GetDistance(o, r2, r).ToString("N4")); Assert.AreEqual("100.0000", DistanceUtils.GetDistance(o, r3, r).ToString("N4")); Assert.AreEqual("100.0000", DistanceUtils.GetDistance(o, r4, r).ToString("N4")); Assert.AreEqual("100.0000", DistanceUtils.GetDistance(o, r5, r).ToString("N4")); Assert.AreEqual("100.0000", DistanceUtils.GetDistance(o, r6, r).ToString("N4")); Assert.AreEqual("100.0000", DistanceUtils.GetDistance(o, r7, r).ToString("N4")); Assert.AreEqual("100.0000", DistanceUtils.GetDistance(o, r8, r).ToString("N4")); Assert.AreEqual("100.0000", DistanceUtils.GetDistance(o, r9, r).ToString("N4")); }
/// <summary> /// Returns the bounding box of the specified collection of <paramref name="polygons"/>. /// </summary> /// <param name="polygons">A collection of polygons.</param> /// <returns>An instance of <see cref="IRectangle"/> representing the bounding box.</returns> public static IRectangle GetBoundingBox(this IEnumerable <IPolygon> polygons) { if (polygons == null) { throw new ArgumentNullException(nameof(polygons)); } return(MapsUtils.GetBoundingBox(polygons.SelectMany(x => x.Outer))); }
/// <inheritdoc /> public IRectangle GetBoundingBox() { if (_lineStrings.Count == 0) { throw new InvalidOperationException("This MultiLineString does not contain any LineString."); } return(MapsUtils.GetBoundingBox(_lineStrings.SelectMany(x => x.Points))); }
/// <summary> /// Returns a two-dimensional array of coordinates from the specified <paramref name="polygon"/>. /// </summary> /// <param name="polygon">The plogyon.</param> /// <returns>A two-dimensional array of coordinates of <paramref name="polygon"/>.</returns> /// <exception cref="ArgumentNullException"><paramref name="polygon"/> is <c>null</c>.</exception> public static WktPoint[][] ToWktPoints(IPolygon polygon) { if (polygon == null) { throw new ArgumentNullException(nameof(polygon)); } return(ToWkt(MapsUtils.GetCoordinates(polygon))); }
/// <summary> /// Returns the area of the rectangle in square metres. /// </summary> /// <param name="radius">The radius of the spheroid.</param> /// <returns>The area in square metres.</returns> public double GetArea(double radius) { Point southWest = new Point(SouthWest.Latitude, SouthWest.Longitude); Point northEast = new Point(NorthEast.Latitude, NorthEast.Longitude); Point southEast = new Point(SouthWest.Latitude, NorthEast.Longitude); Point northWest = new Point(NorthEast.Latitude, SouthWest.Longitude); return(MapsUtils.GetArea(new IPoint[] { northEast, northWest, southWest, southEast }, radius)); }
/// <summary> /// Returns whether the polygon contains the specified <paramref name="point"/>. /// </summary> /// <param name="point">The point.</param> /// <returns><c>true</c> if the polygon contains <paramref name="point"/>; otheerwise <c>false</c>.</returns> public bool Contains(IPoint point) { bool contains = MapsUtils.Contains(Outer, point); if (contains == false) { return(false); } return(Inner.Length == 0 || Inner.Any(x => MapsUtils.Contains(x, point) == false)); }
/// <summary> /// Converts the specified <paramref name="circle"/> to a polygon. /// </summary> /// <param name="circle">The circle to be converted.</param> /// <param name="delta"></param> /// <returns>A new instance of <see cref="IPolygon"/>.</returns> public static IPolygon ToPolygon(this ICircle circle, float delta) { List <IPoint> path = new List <IPoint>(); for (float i = 0; i <= 360; i += delta) { path.Add(MapsUtils.ComputeOffset(circle.Center, circle.Radius, i)); } return(new Polygon(path)); }
public async System.Threading.Tasks.Task iniciaAsync(MotoristaRetornoInfo info) { if (MapsUtils.IsLocationAvailable()) { var ret = await CrossGeolocator.Current.GetLastKnownLocationAsync(); apresentaInfo(info, new Position(ret.Latitude, ret.Longitude)); if (CrossGeolocator.Current.IsListening) { await CrossGeolocator.Current.StopListeningAsync(); } await CrossGeolocator.Current.StartListeningAsync(new TimeSpan(5000), 20); CrossGeolocator.Current.PositionChanged += testeAsync; } }
private void inicializarComponente() { _EnviarButton = new Button { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, Margin = new Thickness(8, 0), Style = Estilo.Current[Estilo.BTN_PRINCIPAL], Text = "Procurar Motorista" }; _EnviarButton.Clicked += async(sender, e) => { UserDialogs.Instance.ShowLoading("Enviando..."); _Info.Situacao = FreteSituacaoEnum.ProcurandoMotorista; await FreteFactory.create().alterar(_Info); UserDialogs.Instance.HideLoading(); Navigation.PopToRootAsync(); }; _CustomMap = new CustomMap { MapType = MapType.Street, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.Fill }; var pontos = MapsUtils.DecodePolyline(_Info.Polyline); foreach (var ponto in pontos) { _CustomMap.RouteCoordinates.Add(ponto); } foreach (var pin in _Info.Locais) { _CustomMap.Pins.Add(new Pin() { Position = new Position(pin.Latitude, pin.Longitude), Label = getTextItem(pin.Tipo) }); } var aux = _Info.Locais.First(); var midleLat = pontos.Average(x => x.Latitude); var midleLon = pontos.Average((x => x.Longitude)); var degressLat = Math.Abs(pontos.Max(x => x.Latitude) - pontos.Min(x => x.Latitude)); var degressLon = Math.Abs(pontos.Max(x => x.Longitude) - pontos.Min(x => x.Longitude)); _CustomMap.MoveToRegion(new MapSpan(new Position(midleLat, midleLon), degressLat + (degressLat * 0.2), degressLon + (degressLon * 0.2))); }
/// <summary> /// Returns the area of the specified <paramref name="polygon"/> measured in sqaure metres. /// </summary> /// <param name="polygon">The polygon.</param> /// <returns>A <see cref="double"/> representing the area in square metres.</returns> /// <remarks>For this method to work, it is assumed that coordinates are specified using the /// <strong>WGS 84</strong> coordinate system (eg. used by the Global Positioning System).</remarks> /// <see> /// <cref>https://en.wikipedia.org/wiki/World_Geodetic_System#WGS84</cref> /// </see> /// <see> /// <cref>https://en.wikipedia.org/wiki/Global_Positioning_System</cref> /// </see> /// <exception cref="ArgumentNullException"><paramref name="polygon"/> is <c>null</c>.</exception> public static double GetArea(WktPolygon polygon) { if (polygon == null) { throw new ArgumentNullException(nameof(polygon)); } // Get the overall area from the outer points double area = MapsUtils.GetArea(polygon.Outer.Select(x => new Point(x.Y, x.X))); // Substract the area of the inner points foreach (WktPoint[] inner in polygon.Inner) { area -= MapsUtils.GetArea(inner.Select(x => new Point(x.Y, x.X))); } return(area); }
public async Task <MotoristaRetornoInfo> listarPedidosAsync() { try{ if (MapsUtils.IsLocationAvailable() && pegarAtual() != null) { var args = new List <object>(); var posicao = await CrossGeolocator.Current.GetLastKnownLocationAsync(); args.Add(new { id_motorista = pegarAtual().Id, latitude = posicao.Latitude, longitude = posicao.Longitude, cod_disponibilidade = 1 }); return(await queryPut <MotoristaRetornoInfo>(GlobalUtils.URLAplicacao + "/api/motorista/atualizar", args.ToArray())); } return(null); } catch (Exception e) { throw e; } }
public bool IsLocationAvailable() { return(MapsUtils.IsLocationAvailable()); }
/// <summary> /// Returns a new rectangle representing the bounding box of this multi polygon. /// </summary> /// <returns>An instance of <see cref="IRectangle"/>.</returns> public IRectangle GetBoundingBox() { return(MapsUtils.GetBoundingBox(Polygons.SelectMany(x => x.Outer))); }
/// <summary> /// Returns an instance of <see cref="IRectangle"/> representing the bounding box of the polygon. /// </summary> /// <returns>An instance of <see cref="IRectangle"/>.</returns> public IRectangle GetBoundingBox() { return(MapsUtils.GetBoundingBox(Outer)); }
/// <summary> /// Returns the circumference of the polygon in metres. /// </summary> /// <returns>The circumference in metres.</returns> public double GetCircumference() { return(MapsUtils.GetCircumference(Outer)); }
/// <summary> /// Returns the area of the polygon in square metres. /// </summary> /// <returns>The area in square metres.</returns> public double GetArea() { return(MapsUtils.GetArea(Outer)); }
/// <summary> /// Returns a new rectangle representing the bounding box of this line string. /// </summary> /// <returns>An instance of <see cref="IRectangle"/>.</returns> public IRectangle GetBoundingBox() { return(MapsUtils.GetBoundingBox(Points)); }
/// <summary> /// Returns a new point representing the center of this line string. /// </summary> /// <returns>An instance of <see cref="IPoint"/>.</returns> public IPoint GetCenter() { return(MapsUtils.GetCenter(this)); }
/// <summary> /// Returns the total length of this line string. /// </summary> /// <returns>The total length in metres.</returns> public double GetLength() { return(MapsUtils.GetLength(_points)); }