Пример #1
0
        protected virtual IPolygon <TPolygonHeader> readPolygon(BinaryReader reader, bool closePolygons)
        {
            var result = getNewPolygon();

            result.Header = readPolygonHeader(reader);
            var points        = new LatLonCoordinates[result.Header.PointsCount];
            var lastLongitude = Double.NaN;

            for (int i = 0; i < points.Length; i++)
            {
                var point = readPoint(reader);
                if (!Double.IsNaN(lastLongitude) && Math.Abs(point.Longitude - lastLongitude) >= 180)
                {
                    point.Longitude = point.Longitude.FixCoordinate(false);
                }
                lastLongitude = point.Longitude;
                points[i]     = point;
            }
            if (closePolygons && points[0] != points[points.Length - 1])
            {
                // Make sure the list is closed
                var pointsList = new List <LatLonCoordinates>(points);
                pointsList.Add(new LatLonCoordinates()
                {
                    Latitude = points[0].Latitude, Longitude = points[0].Longitude
                });
                points = pointsList.ToArray();
            }
            result.Points = points;
            return(result);
        }
Пример #2
0
        /// <summary>Creates an AXPoint from WGS84 lat/lon coordinates. Time is unknown and altitude is not barometric
        /// </summary>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <param name="altitude"></param>
        /// <returns></returns>
        public AXPoint FromLatLonToAXPoint(double latitude, double longitude, double altitude)
        {
            var llc  = new LatLonCoordinates(Datum.GetInstance("WGS84"), latitude, longitude, altitude);
            var utmc = llc.ToUtm(Datum.GetInstance(DatumName), UtmZone);

            return(new AXPoint(Date.Date, utmc));
        }
Пример #3
0
 public virtual PixelCoordinates LatLonToPixel(LatLonCoordinates latLonCoordinates)
 {
     if (this.Map.RotateReference)
     {
         double latitudeOffset  = latLonCoordinates.Latitude - latLonCoordinates.Latitude.FixCoordinate(true);
         double longitudeOffset = latLonCoordinates.Longitude - latLonCoordinates.Longitude.FixCoordinate(false);
         if (latitudeOffset != 0 || longitudeOffset != 0)
         {
             latLonCoordinates = new LatLonCoordinates()
             {
                 Latitude  = latLonCoordinates.Latitude - latitudeOffset,
                 Longitude = latLonCoordinates.Longitude - longitudeOffset
             };
         }
         latLonCoordinates = this.Map.Boundaries.Center.GetNewCoordinates(latLonCoordinates);
         if (latitudeOffset != 0 || longitudeOffset != 0)
         {
             latLonCoordinates.Latitude  += latitudeOffset;
             latLonCoordinates.Longitude += longitudeOffset;
         }
         return(new PixelCoordinates()
         {
             X = this.Map.Size.Width * (latLonCoordinates.Longitude + this.Map.Boundaries.LongitudeHalfSpan) / this.Map.Boundaries.LongitudeSpan,
             Y = this.Map.Size.Height * (this.Map.Boundaries.LatitudeHalfSpan - latLonCoordinates.Latitude) / this.Map.Boundaries.LatitudeSpan
         });
     }
     else
     {
         return(new PixelCoordinates()
         {
             X = this.Map.Size.Width * (latLonCoordinates.Longitude - this.Map.Boundaries.LeftNotBound) / this.Map.Boundaries.LongitudeSpan,
             Y = this.Map.Size.Height * (this.Map.Boundaries.TopNotBound - latLonCoordinates.Latitude) / this.Map.Boundaries.LatitudeSpan
         });
     }
 }
Пример #4
0
        public virtual PixelCoordinates LatLonToPixel(LatLonCoordinates latLonCoordinates)
        {
            var longitude = latLonCoordinates.Longitude;
            var latitude  = latLonCoordinates.Latitude;

            // TODO: make sure they are "in phase"
            if (latitude == 90)
            {
                latitude -= double.Epsilon;
            }
            else if (latitude == -90)
            {
                latitude += double.Epsilon;
            }
            return(new PixelCoordinates()
            {
                X = _formulae.LongitudeToX(longitude),
                Y = _formulae.LatitudeToY(latitude)
            });
        }
Пример #5
0
 public virtual LatLonCoordinates PixelToLatLon(PixelCoordinates pixelCoordinates)
 {
     if (this.Map.RotateReference)
     {
         var result = new LatLonCoordinates()
         {
             Longitude = pixelCoordinates.X * this.Map.Boundaries.LongitudeSpan / this.Map.Size.Width - this.Map.Boundaries.LongitudeHalfSpan,
             Latitude  = this.Map.Boundaries.LatitudeHalfSpan - pixelCoordinates.Y * this.Map.Boundaries.LatitudeSpan / this.Map.Size.Height
         };
         return(this.Map.Boundaries.Center.GetOldCoordinates(result));
     }
     else
     {
         return(new LatLonCoordinates()
         {
             Longitude = this.Map.Boundaries.LeftNotBound + pixelCoordinates.X * this.Map.Boundaries.LongitudeSpan / this.Map.Size.Width,
             Latitude = this.Map.Boundaries.TopNotBound - pixelCoordinates.Y * this.Map.Boundaries.LatitudeSpan / this.Map.Size.Height
         });
     }
 }
Пример #6
0
        private void buttonCoords_Click(object sender, RoutedEventArgs e)
        {
            var wgs84  = Datum.GetInstance("WGS84");
            var ed50   = Datum.GetInstance("European 1950");
            var osgb36 = Datum.GetInstance("OSGB36");

            Coordinates p1, p2, p3;


            Print("From latlon WGS84 to UTM ED50 and back");
            p1 = new LatLonCoordinates(wgs84, 41.973256, 2.780310, 87.0);
            p2 = p1.ToUtm(ed50);
            p3 = p2.ToLatLon(wgs84);
            Print(p1.ToString());
            Print(p2.ToString());
            Print(p3.ToString());
            Print("");

            Print("From UTM ED50 to UTM WGS84 and back");
            p1 = new UtmCoordinates(ed50, "31T", 365000, 4612000, 56);
            p2 = p1.ToUtm(wgs84);
            p3 = p2.ToUtm(ed50);
            Print(p1.ToString());
            Print(p2.ToString());
            Print(p3.ToString());
            Print("");

            Print("From UTM ED50 (default zone) to UTM ED50 (different zone) and back");
            p1 = new UtmCoordinates(ed50, "31T", 365000, 4612000, 56);
            p2 = p1.ToUtm(ed50, "30T");
            p3 = p2.ToUtm(ed50);
            Print(p1.ToString());
            Print(p2.ToString());
            Print(p3.ToString());
            Print("");
        }