public async Task <AppResult> Distance([FromBody] PositionModel model)
        {
            if (ModelState.IsValid == false)
            {
                return(ErrorMessage("error validation "));
            }

            if (model.FromLat == null || model.FromLng == null ||
                model.DistLat == null || model.DistLng == null)
            {
                return(ErrorMessage("error . enter 2 point latlng "));
            }

            var d = new DistanceOp(
                new Point(model.FromLat.Value, model.FromLng.Value),
                new Point(model.DistLat.Value, model.DistLng.Value));
            var distance = d.Distance();

            var histories = new List <GeoHistory>();

            _dbContext.GeoHistories.Add(new GeoHistory
            {
                Date     = DateTime.UtcNow,
                FromLng  = model.FromLng ?? 0,
                FromLat  = model.FromLat ?? 0,
                DistLat  = model.DistLat ?? 0,
                DistLng  = model.DistLng ?? 0,
                UserId   = CurrentUserId,
                Distance = distance
            });
            await _dbContext.SaveChangesAsync();

            return(SuccessfullMessage(distance));
        }
예제 #2
0
        /// <summary>
        /// Checks that two geometries are at least a minimum distance apart.
        /// </summary>
        /// <param name="g1">A geometry</param>
        /// <param name="g2">A geometry</param>
        /// <param name="minDist">The minimum distance the geometries should be separated by</param>
        private void CheckMinimumDistance(Geometry g1, Geometry g2, double minDist)
        {
            var distOp = new DistanceOp(g1, g2, minDist);

            _minDistanceFound = distOp.Distance();

            if (_minDistanceFound < minDist)
            {
                _isValid = false;
                var pts = distOp.NearestPoints();
                _errorLocation  = pts[1];
                _errorIndicator = g1.Factory.CreateLineString(pts);
                _errMsg         = "Distance between buffer curve and input is too small "
                                  + "(" + _minDistanceFound
                                  + " at " + WKTWriter.ToLineString(pts[0], pts[1]) + " )";
            }
        }
        public bool TryCalculate(Coordinate c1, Coordinate c2, Units unit, out double distance)
        {
            distance = 0;

            if (TryGetTransformation(c1, c2, out ICoordinateTransformation transformation))
            {
                var geoCoord1 = Transform(c1, transformation);
                var geoCoord2 = Transform(c2, transformation);

                var point1 = _factory.CreatePoint(geoCoord1);
                var point2 = _factory.CreatePoint(geoCoord2);

                distance = DistanceOp.Distance(point1, point2);
                distance = unit == Units.Meters ? distance : Constants.MilesPerMeter * distance;

                return(true);
            }

            return(false);
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="wktA"></param>
        /// <param name="wktB"></param>
        public virtual void  FindClosestPoint(string wktA, string wktB)
        {
            Console.WriteLine("-------------------------------------");
            try
            {
                var A = wktRdr.Read(wktA);
                var B = wktRdr.Read(wktB);
                Console.WriteLine("Geometry A: " + A);
                Console.WriteLine("Geometry B: " + B);
                var distOp = new DistanceOp(A, B);

                double distance = distOp.Distance();
                Console.WriteLine("Distance = " + distance);

                var closestPt     = distOp.NearestPoints();
                var closestPtLine = fact.CreateLineString(closestPt);
                Console.WriteLine("Closest points: " + closestPtLine + " (distance = " + closestPtLine.Length + ")");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
        }
 public void RunSimpleLinePoint()
 {
     double dist = DistanceOp.Distance(geom1, pt2);
 }
 public void RunSimpleLines()
 {
     double dist = DistanceOp.Distance(geom1, geom2);
 }
예제 #7
0
 private static double GetDistance(Point point1, Point point2) => DistanceOp.Distance(point1, point2);
예제 #8
0
		/// <summary>
		/// Returns the minimum distance between this Geometry and the Geometry g.
		/// </summary>
		/// <param name="g">The Geometry from which to compute the distance.</param>
		/// <returns>Returns the minimum distance between this Geometry and the Geometry g.</returns>
		public double Distance(Geometry g)
		{
			return DistanceOp.Distance(this, g);
		}
예제 #9
0
 private static double GetDistance(IPoint point1, IPoint point2)
 {
     return(DistanceOp.Distance(point1, point2));
 }