コード例 #1
0
ファイル: GeoHash32.cs プロジェクト: lanicon/Styx
        /// <summary>
        /// Decode the geohash into latitude and longitude using the given
        /// delegate to transfor it into the resulting data structure.
        /// </summary>
        /// <typeparam name="T">The type of the resulting data structure.</typeparam>
        /// <param name="Processor">A delegate to transform the decoded latitude and longitude into the resulting data structure.</param>
        /// <param name="Digits">Rounds the double-precision latitude and longitude to the given number of fractional digits.</param>
        public T Decode <T>(Func <Latitude, Longitude, T> Processor, Byte Digits = 12)
        {
            #region Initial checks

            if (Processor == null)
            {
                throw new ArgumentNullException("The given delegate must not be null!");
            }

            #endregion

            var      bitmask           = 1U << 31;
            Double[] LatitudeInterval  = { -90, 90 };
            Double[] LongitudeInterval = { -180, 180 };

            while (bitmask > 0)
            {
                RefineInterval(ref LatitudeInterval, bitmask);
                bitmask >>= 1;

                RefineInterval(ref LongitudeInterval, bitmask);
                bitmask >>= 1;
            }

            return(Processor(
                       Latitude.Parse(Math.Round((LatitudeInterval[0] + LatitudeInterval[1]) / 2, Digits)),
                       Longitude.Parse(Math.Round((LongitudeInterval[0] + LongitudeInterval[1]) / 2, Digits))
                       ));
        }
コード例 #2
0
        /// <summary>
        /// Create line with geo coordinates.
        /// </summary>
        /// <param name="GeoCoordinate1">A geo coordinate.</param>
        /// <param name="GeoVector">A geo vector.</param>
        public GeoLine(GeoCoordinate GeoCoordinate1, GeoVector GeoVector)
        {
            #region Initial Checks

            if (GeoCoordinate1 == null)
            {
                throw new ArgumentNullException("The given left-coordinate must not be null!");
            }

            if (GeoVector == null)
            {
                throw new ArgumentNullException("The given right-coordinate must not be null!");
            }

            #endregion

            this.P1 = GeoCoordinate1;
            this.P2 = new GeoCoordinate(
                Latitude.Parse(GeoCoordinate1.Latitude.Value + GeoVector.P.Latitude.Value),
                Longitude.Parse(GeoCoordinate1.Longitude.Value + GeoVector.P.Longitude.Value)
                );

            this.Length = GeoCoordinate1.DistanceTo(P2);
            this.Tags   = new List <String>();
        }
コード例 #3
0
        /// <summary>
        /// Get the corresponding tile for the given geo coordinate.
        /// </summary>
        /// <param name="GeoCoordinates">An enumeration of geo coordinates.</param>
        public static GeoBoundingBox GeoCoordinate2BoundingBox(this IEnumerable <GeoCoordinate> GeoCoordinates)
        {
            var MinLat = Double.MaxValue;
            var MaxLat = Double.MinValue;

            var MinLng = Double.MaxValue;
            var MaxLng = Double.MinValue;

            var MinAlt = Double.MaxValue;
            var MaxAlt = Double.MinValue;

            foreach (var GeoCoordinate in GeoCoordinates)
            {
                if (GeoCoordinate.Latitude.Value < MinLat)
                {
                    MinLat = GeoCoordinate.Latitude.Value;
                }

                if (GeoCoordinate.Longitude.Value < MinLng)
                {
                    MinLng = GeoCoordinate.Longitude.Value;
                }

                if (GeoCoordinate.Altitude.HasValue &&
                    GeoCoordinate.Altitude.Value.Value < MinAlt)
                {
                    MinAlt = GeoCoordinate.Altitude.Value.Value;
                }


                if (GeoCoordinate.Latitude.Value > MaxLat)
                {
                    MaxLat = GeoCoordinate.Latitude.Value;
                }

                if (GeoCoordinate.Longitude.Value > MaxLng)
                {
                    MaxLng = GeoCoordinate.Longitude.Value;
                }

                if (GeoCoordinate.Altitude.HasValue &&
                    GeoCoordinate.Altitude.Value.Value > MaxAlt)
                {
                    MaxAlt = GeoCoordinate.Altitude.Value.Value;
                }
            }

            return(new GeoBoundingBox(

                       Latitude.Parse(MinLat),
                       Longitude.Parse(MinLng),
                       Altitude.Parse(MinAlt),

                       Latitude.Parse(MaxLat),
                       Longitude.Parse(MaxLng),
                       Altitude.Parse(MaxAlt)

                       ));
        }
コード例 #4
0
        /// <summary>
        /// Get the corresponding geo coordinate for the given tile.
        /// </summary>
        /// <param name="Tile">A mapping tile.</param>
        /// <param name="ZoomLevel">The current zoom level of the Aegir map.</param>
        public static GeoCoordinate TilesXY2GeoCoordinate(TilesXY Tile, UInt32 ZoomLevel)
        {
            var n = Math.PI - ((2.0 * Math.PI * Tile.Y) / Math.Pow(2.0, ZoomLevel));

            return(new GeoCoordinate(
                       Latitude.Parse((Tile.X / Math.Pow(2.0, ZoomLevel) * 360.0) - 180.0),
                       Longitude.Parse(180.0 / Math.PI * Math.Atan(Math.Sinh(n)))
                       ));
        }
コード例 #5
0
ファイル: Mouse2GeoCoordinate.cs プロジェクト: lanicon/Styx
        /// <summary>
        /// Get the geo coordinate for the given mouse position on the map.
        /// </summary>
        /// <param name="MouseX">The X position of the mouse on the map.</param>
        /// <param name="MouseY">The Y position of the mouse on the map.</param>
        /// <param name="ZoomLevel">The current zoom level of the Aegir map.</param>
        public static GeoCoordinate Mouse2GeoCoordinate(Double MouseX, Double MouseY, UInt32 ZoomLevel)
        {
            var MapSize = Math.Pow(2.0, ZoomLevel) * 256;

            var n = Math.PI - ((2.0 * Math.PI * MouseY) / MapSize);

            return(new GeoCoordinate(
                       Latitude.Parse((180.0 / Math.PI * Math.Atan(Math.Sinh(n))) % 90),
                       Longitude.Parse(((MouseX / MapSize * 360.0) - 180.0) % 90)
                       ));
        }
コード例 #6
0
ファイル: GeoVector.cs プロジェクト: lanicon/Styx
        /// <summary>
        /// Create a 2-dimensional vector of type T.
        /// </summary>
        /// <param name="GeoCoordinate">The x-component of the vector.</param>
        public GeoVector(GeoCoordinate GeoCoordinate)
        {
            #region Initial Checks

            if (GeoCoordinate == null)
            {
                throw new ArgumentNullException("The given y-component must not be null!");
            }

            #endregion

            this.P      = GeoCoordinate;
            this.Length = new GeoCoordinate(Latitude.Parse(0), Longitude.Parse(0)).
                          DistanceTo(GeoCoordinate);
        }
コード例 #7
0
ファイル: GeoJSON.cs プロジェクト: Vanaheimr/Aegir
        // 2.1.1. Positions
        // A position is the fundamental geometry construct. The "coordinates" member
        // of a geometry object is composed of one position (in the case of a Point
        // geometry), an array of positions (LineString or MultiPoint geometries), an
        // array of arrays of positions (Polygons, MultiLineStrings), or a
        // multidimensional array of positions (MultiPolygon).
        //
        // A position is represented by an array of numbers. There must be at least
        // two elements, and may be more. The order of elements must follow x, y, z
        // order (easting, northing, altitude for coordinates in a projected coordinate
        // reference system, or longitude, latitude, altitude for coordinates in a
        // geographic coordinate reference system). Any number of additional elements
        // are allowed -- interpretation and meaning of additional elements is beyond
        // the scope of this specification.


        // Point
        //
        // Point coordinates are in x, y order (easting, northing for projected
        // coordinates, longitude, latitude for geographic coordinates):
        //
        // {
        //    "type":        "Point",
        //    "coordinates": [100.0, 0.0]
        // }


        // LineString
        //
        // Coordinates of LineString are an array of positions (see 2.1.1. Positions):
        //
        // {
        //    "type":        "LineString",
        //    "coordinates": [ [100.0, 0.0], [101.0, 1.0] ]
        // }


        //Polygon

        //Coordinates of a Polygon are an array of LinearRing coordinate arrays. The first element in the array represents the exterior ring. Any subsequent elements represent interior rings (or holes).

        //No holes:

        //{ "type": "Polygon",
        //  "coordinates": [
        //    [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
        //    ]
        // }
        //With holes:

        //{ "type": "Polygon",
        //  "coordinates": [
        //    [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ],
        //    [ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ]
        //    ]
        // }
        //MultiPoint

        //Coordinates of a MultiPoint are an array of positions:

        //{ "type": "MultiPoint",
        //  "coordinates": [ [100.0, 0.0], [101.0, 1.0] ]
        //  }
        //MultiLineString

        //Coordinates of a MultiLineString are an array of LineString coordinate arrays:

        //{ "type": "MultiLineString",
        //  "coordinates": [
        //      [ [100.0, 0.0], [101.0, 1.0] ],
        //      [ [102.0, 2.0], [103.0, 3.0] ]
        //    ]
        //  }
        //MultiPolygon

        //Coordinates of a MultiPolygon are an array of Polygon coordinate arrays:

        //{ "type": "MultiPolygon",
        //  "coordinates": [
        //    [[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],
        //    [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
        //     [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]
        //    ]
        //  }
        //GeometryCollection

        //Each element in the geometries array of a GeometryCollection is one of the geometry objects described above:

        //{ "type": "GeometryCollection",
        //  "geometries": [
        //    { "type": "Point",
        //      "coordinates": [100.0, 0.0]
        //      },
        //    { "type": "LineString",
        //      "coordinates": [ [101.0, 0.0], [102.0, 1.0] ]
        //      }
        //  ]
        //}



        //        2.2. Feature Objects

        //A GeoJSON object with the type "Feature" is a feature object.

        //A feature object must have a member with the name "geometry". The value of the geometry member is a geometry object as defined above or a JSON null value.
        //A feature object must have a member with the name "properties". The value of the properties member is an object (any JSON object or a JSON null value).
        //If a feature has a commonly used identifier, that identifier should be included as a member of the feature object with the name "id".


        // { "type":     "FeatureCollection",
        //   "features": [

        //      {
        //          "type":       "Feature",
        //          "geometry":   {
        //                            "type":        "Point",
        //                            "coordinates": [102.0, 0.5]
        //                        },
        //          "properties": {
        //                            "prop0":       "value0"
        //                        }
        //      },


        //  { "type": "Feature",
        //    "geometry": {
        //      "type": "LineString",
        //      "coordinates": [
        //        [102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
        //        ]
        //      },
        //    "properties": {
        //      "prop0": "value0",
        //      "prop1": 0.0
        //      }
        //    },


        //  { "type": "Feature",
        //     "geometry": {
        //       "type": "Polygon",
        //       "coordinates": [
        //         [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
        //           [100.0, 1.0], [100.0, 0.0] ]
        //         ]
        //     },
        //     "properties": {
        //       "prop0": "value0",
        //       "prop1": {"this": "that"}
        //       }
        //     }
        //   ]
        // }


        public static GeoBoundingBox GetBoundingBox(JObject GeoJSON,
                                                    Int32 FeatureId = 0,
                                                    Int32 ObjectId  = 0)
        {
            Double lng, lat;
            var    min_lng = Double.MaxValue;
            var    max_lng = Double.MinValue;
            var    min_lat = Double.MaxValue;
            var    max_lat = Double.MinValue;

            var GeoCoordinates = GeoJSON?["features"]?[FeatureId]?["geometry"]?["coordinates"]?[ObjectId];

            if (GeoCoordinates == null)
            {
                return(new GeoBoundingBox(Latitude.Parse(0), Longitude.Parse(0), Altitude.Parse(0),
                                          Latitude.Parse(0), Longitude.Parse(0), Altitude.Parse(0)));
            }

            else
            {
                foreach (var value in GeoCoordinates)
                {
                    lng = Double.Parse(value[0].Value <String>());
                    lat = Double.Parse(value[1].Value <String>());

                    if (min_lat > lat)
                    {
                        min_lat = lat;
                    }
                    if (max_lat < lat)
                    {
                        max_lat = lat;
                    }
                    if (min_lng > lng)
                    {
                        min_lng = lng;
                    }
                    if (max_lng < lng)
                    {
                        max_lng = lng;
                    }
                }
            }

            return(new GeoBoundingBox(Latitude.Parse(min_lat), Longitude.Parse(min_lng), Altitude.Parse(0),
                                      Latitude.Parse(max_lat), Longitude.Parse(max_lng), Altitude.Parse(0)));
        }
コード例 #8
0
ファイル: GeoHash.cs プロジェクト: lanicon/Styx
        /// <summary>
        /// Decode the geohash into latitude and longitude using the given
        /// delegate to transfor it into the resulting data structure.
        /// </summary>
        /// <typeparam name="T">The type of the resulting data structure.</typeparam>
        /// <param name="Processor">A delegate to transform the decoded latitude and longitude into the resulting data structure.</param>
        /// <param name="Digits">Rounds the double-precision latitude and longitude to the given number of fractional digits.</param>
        public T Decode <T>(Func <Latitude, Longitude, T> Processor, Byte Digits = 12)
        {
            #region Initial checks

            if (Processor == null)
            {
                throw new ArgumentNullException("The given delegate must not be null!");
            }

            #endregion

            var even      = true;
            var CharValue = 0;
            var Bitmask   = 0;

            Double[] LatitudeInterval  = { -90, 90 };
            Double[] LongitudeInterval = { -180, 180 };

            foreach (var Character in InternalGeoHash)
            {
                //ToDo: Faster GeoHashAlphabet lookup!
                CharValue = GeoHashAlphabet.IndexOf(Character);

                for (int j = 0; j < 5; j++)
                {
                    Bitmask = 16 >> j;

                    if (even)
                    {
                        RefineInterval(ref LongitudeInterval, CharValue, Bitmask);
                    }

                    else
                    {
                        RefineInterval(ref LatitudeInterval, CharValue, Bitmask);
                    }

                    even = !even;
                }
            }

            return(Processor(
                       Latitude.Parse(Math.Round((LatitudeInterval[0] + LatitudeInterval[1]) / 2, Digits)),
                       Longitude.Parse(Math.Round((LongitudeInterval[0] + LongitudeInterval[1]) / 2, Digits))
                       ));
        }
コード例 #9
0
ファイル: GeoVector.cs プロジェクト: lanicon/Styx
        /// <summary>
        /// Create a 2-dimensional vector of type T.
        /// </summary>
        /// <param name="GeoVector1">A vector of type T.</param>
        /// <param name="GeoVector2">A vector of type T.</param>
        public GeoVector(GeoVector GeoVector1, GeoVector GeoVector2)
        {
            #region Initial Checks

            if (GeoVector1 == null)
            {
                throw new ArgumentNullException("The first vector must not be null!");
            }

            if (GeoVector2 == null)
            {
                throw new ArgumentNullException("The second vector must not be null!");
            }

            #endregion

            this.P = new GeoCoordinate(
                Latitude.Parse(GeoVector1.P.Latitude.Value - GeoVector2.P.Latitude.Value),
                Longitude.Parse(GeoVector1.P.Longitude.Value - GeoVector2.P.Longitude.Value)
                );

            this.Length = GeoVector1.P.DistanceTo(GeoVector2.P);
        }
コード例 #10
0
        CreateRaster(GeoBoundingBox BoundingBox,
                     Double LatitudeSize,
                     Double LongitudeSize,
                     IList <Point> Shape)

        {
            // Longitude west<->east

            var CurrentLatitude  = BoundingBox.Latitude2;
            var CurrentLongitude = BoundingBox.Longitude;
            var Boxes            = new List <GeoBoundingBox>();

            while (CurrentLatitude >= BoundingBox.Latitude)
            {
                CurrentLongitude = BoundingBox.Longitude;

                while (CurrentLongitude <= BoundingBox.Longitude2)
                {
                    if (PolyContainsPoint(Shape, new Point(CurrentLongitude.Value, CurrentLatitude.Value)) ||
                        PolyContainsPoint(Shape, new Point(CurrentLongitude.Value, CurrentLatitude.Value - LatitudeSize)) ||
                        PolyContainsPoint(Shape, new Point(CurrentLongitude.Value + LongitudeSize, CurrentLatitude.Value)) ||
                        PolyContainsPoint(Shape, new Point(CurrentLongitude.Value + LongitudeSize, CurrentLatitude.Value - LatitudeSize)))
                    {
                        Boxes.Add(new GeoBoundingBox(CurrentLatitude,
                                                     CurrentLongitude,
                                                     Latitude.Parse(CurrentLatitude.Value - LatitudeSize),
                                                     Longitude.Parse(CurrentLongitude.Value + LongitudeSize)));
                    }

                    CurrentLongitude = Longitude.Parse(CurrentLongitude.Value + LongitudeSize);
                }

                CurrentLatitude = Latitude.Parse(CurrentLatitude.Value - LatitudeSize);
            }

            return(Boxes);
        }
コード例 #11
0
        /// <summary>
        /// Checks if and where the given lines intersect.
        /// </summary>
        /// <param name="Line">A line.</param>
        /// <param name="IntersectionGeoCoordinate">The intersection of both lines.</param>
        /// <param name="InfiniteLines">Whether the lines should be treated as infinite or not.</param>
        /// <returns>True if the lines intersect; False otherwise.</returns>
        public Boolean IntersectsWith(GeoLine Line, out GeoCoordinate IntersectionGeoCoordinate, Boolean InfiniteLines = false, Boolean ExcludeEdges = false)
        {
            #region Initial Checks

            if (Line == null)
            {
                IntersectionGeoCoordinate = default(GeoCoordinate);
                return(false);
            }

            #endregion

            // Assume both lines are infinite in order to get their intersection...

            #region This line is just a pixel

            if (this.IsJustAPixel())
            {
                if (Line.Contains(P1))
                {
                    IntersectionGeoCoordinate = P1;
                    return(true);
                }

                IntersectionGeoCoordinate = default(GeoCoordinate);
                return(false);
            }

            #endregion

            #region The given line is just a pixel

            else if (Line.IsJustAPixel())
            {
                if (this.Contains(Line.P1))
                {
                    IntersectionGeoCoordinate = Line.P1;
                    return(true);
                }

                IntersectionGeoCoordinate = default(GeoCoordinate);
                return(false);
            }

            #endregion

            #region Both lines are parallel

            else if (this.Gradient == Line.Gradient)
            {
                IntersectionGeoCoordinate = default(GeoCoordinate);
                return(false);
            }

            #endregion

            #region Both lines are antiparallel

            else if (this.Gradient == -1 * Line.Gradient)
            {
                IntersectionGeoCoordinate = default(GeoCoordinate);
                return(false);
            }

            #endregion

            #region This line is parallel to the y-axis

            else if (Double.IsInfinity(Gradient))
            {
                IntersectionGeoCoordinate = new GeoCoordinate(
                    Latitude.Parse(Line.Gradient * P1.Longitude.Value + Line.YIntercept),
                    P1.Longitude
                    );
            }

            #endregion

            #region The given line is parallel to the y-axis

            else if (Double.IsInfinity(Line.Gradient))
            {
                IntersectionGeoCoordinate = new GeoCoordinate(
                    Latitude.Parse(Gradient * Line.P1.Longitude.Value + YIntercept),
                    Line.P1.Longitude
                    );
            }

            #endregion

            #region There is a real intersection

            else
            {
                //IntersectionGeoCoordinate = null;
                //// this Line
                //var A1 = this.P2.Latitude. Value - this.P1.Latitude. Value;
                //var B1 = this.P2.Longitude.Value - this.P1.Longitude.Value;
                //var C1 = A1 * this.P1.Longitude.Value + B1 * this.P1.Latitude.Value;

                //// Line2
                //var A2 = Line.P2.Latitude. Value - Line.P1.Latitude. Value;
                //var B2 = Line.P2.Longitude.Value - Line.P1.Longitude.Value;
                //var C2 = A2 * Line.P1.Longitude.Value + B2 * Line.P1.Latitude.Value;

                //var det = A1 * B2 - A2 * B1;
                //if (det == 0)
                //{
                //    //parallel lines
                //}
                //else
                //{
                //    var x = (B2 * C1 - B1 * C2) / det;
                //    var y = (A1 * C2 - A2 * C1) / det;
                //    IntersectionGeoCoordinate = new GeoCoordinate(new Latitude (y),
                //                                                  new Longitude(x));
                //}

                IntersectionGeoCoordinate = new GeoCoordinate(
                    Latitude.Parse((this.YIntercept * Line.Gradient - Line.YIntercept * this.Gradient) / (Line.Gradient - this.Gradient)),
                    Longitude.Parse((Line.YIntercept - this.YIntercept) / (this.Gradient - Line.Gradient))
                    );
            }

            #endregion

            if (InfiniteLines)
            {
                return(true);
            }

            else if (!ExcludeEdges)
            {
                return(this.Contains(IntersectionGeoCoordinate));
            }

            else
            {
                if (this.Contains(IntersectionGeoCoordinate))
                {
                    if (IntersectionGeoCoordinate.Equals(P1) ||
                        IntersectionGeoCoordinate.Equals(P2) ||
                        IntersectionGeoCoordinate.Equals(Line.P1) ||
                        IntersectionGeoCoordinate.Equals(Line.P2))
                    {
                        return(false);
                    }

                    return(true);
                }

                return(false);
            }
        }
コード例 #12
0
ファイル: Polyfile2ShapeInfo.cs プロジェクト: lanicon/Styx
        public static ShapeInfo Polyfile2ShapeInfo(IEnumerable <String> InputData, UInt32 min_resolution, UInt32 max_resolution)
        {
            #region Init

            var Integer     = 1U;
            var ShapeNumber = 1U;
            var IsFirstLine = true;
            var Description = String.Empty;

            var min_lat = Double.MaxValue;
            var min_lng = Double.MaxValue;
            var max_lat = Double.MinValue;
            var max_lng = Double.MinValue;

            var Shapes = new Dictionary <UInt32, Tuple <List <GeoCoordinate>,
                                                        Dictionary <UInt32,
                                                                    Tuple <List <ScreenXY>, StringBuilder> > > >();

            GeoCoordinate GeoCoordinate = default(GeoCoordinate);

            #endregion

            foreach (var Line in InputData)
            {
                #region Process first line

                if (IsFirstLine)
                {
                    Description = Line;
                    IsFirstLine = false;
                }

                #endregion

                #region A single Integer on a line indicates the start of a new shape

                else if (UInt32.TryParse(Line, out Integer))
                {
                    ShapeNumber = Integer;
                    Shapes.Add(ShapeNumber, new Tuple <List <GeoCoordinate>, Dictionary <UInt32, Tuple <List <ScreenXY>, StringBuilder> > >(
                                   new List <GeoCoordinate>(),
                                   new Dictionary <UInt32, Tuple <List <ScreenXY>, StringBuilder> >()));
                }

                #endregion

                #region "END" indicates the end of a shape

                else if (Line == "END")
                {
                    continue;
                }

                #endregion

                #region The rest of the file are "Longitude Latitude" encoded geo coordinates

                else if (GeoCoordinate.TryParseString(Line, out GeoCoordinate))
                {
                    // Polyfiles store "Longitude Latitude"!!!
                    Shapes[ShapeNumber].Item1.Add(new GeoCoordinate(
                                                      Latitude.Parse(GeoCoordinate.Longitude.Value),
                                                      Longitude.Parse(GeoCoordinate.Latitude.Value)
                                                      ));

                    if (min_lat > GeoCoordinate.Longitude.Value)
                    {
                        min_lat = GeoCoordinate.Longitude.Value;
                    }

                    if (min_lng > GeoCoordinate.Latitude.Value)
                    {
                        min_lng = GeoCoordinate.Latitude.Value;
                    }

                    if (max_lat < GeoCoordinate.Longitude.Value)
                    {
                        max_lat = GeoCoordinate.Longitude.Value;
                    }

                    if (max_lng < GeoCoordinate.Latitude.Value)
                    {
                        max_lng = GeoCoordinate.Latitude.Value;
                    }
                }

                #endregion

                #region Unknown data found...

                else
                {
                    throw new Exception("Unknown data found!");
                }

                #endregion
            }


            //var Output1 = new StreamWriter("PolyfileReader/" + Filename.Name.Replace(".poly", ".data"));
            //var Array = new StringBuilder();

            //var Output2 = new StreamWriter("PolyfileReader/" + "ghjk".Replace(".poly", ".geo"));
            //var Language = new StringBuilder();

            //Shapes.ForEach((shape) =>
            //{
            //    Array.AppendLine(shape.Key.ToString());
            //    shape.Value.Item1.ForEach(c =>
            //    {
            //        Array.AppendLine("            { " + c.Latitude.ToString("00.000000").Replace(",", ".") + ", " + c.Longitude.ToString("00.000000").Replace(",", ".") + " },");
            //    });
            //});

            //Output1.WriteLine(Array.ToString());
            //Output1.Flush();
            //Output1.Close();


            var diff_lat = Math.Abs(min_lat - max_lat);
            var diff_lng = Math.Abs(min_lng - max_lng);

            //Output2.WriteLine("From:       " + max_lat.ToString("00.000000").Replace(",", ".")  + ", " +  min_lng.ToString("00.000000").Replace(",", "."));
            //Output2.WriteLine("To:         " + min_lat.ToString("00.000000").Replace(",", ".")  + ", " +  max_lng.ToString("00.000000").Replace(",", "."));
            //Output2.WriteLine("Diff:       " + diff_lat.ToString("00.000000").Replace(",", ".") + ", " + diff_lng.ToString("00.000000").Replace(",", "."));
            //Output2.WriteLine("Resolution: " + min_resolution + " -> " + max_resolution);

            Shapes.ForEach(shape => {
                for (var resolution = min_resolution; resolution <= max_resolution; resolution++)
                {
                    shape.Value.Item2.Add(resolution, new Tuple <List <ScreenXY>, StringBuilder>(new List <ScreenXY>(), new StringBuilder()));

                    shape.Value.Item1.ForEach(GeoCoord =>
                                              shape.Value.Item2[resolution].Item1.Add(GeoCalculations.GeoCoordinate2ScreenXY(GeoCoord, resolution))
                                              );
                }
            });

            var min_x = 0L;
            var min_y = 0L;

            for (var resolution = min_resolution; resolution <= max_resolution; resolution++)
            {
                min_x = Int64.MaxValue;
                min_y = Int64.MaxValue;

                Shapes.ForEach((shape) => {
                    shape.Value.Item2[resolution].Item1.ForEach(XY => {
                        if (XY.X < min_x)
                        {
                            min_x = XY.X;
                        }
                        if (XY.Y < min_y)
                        {
                            min_y = XY.Y;
                        }
                    });
                });

                Shapes.ForEach((shape) =>
                {
                    var Char = "M ";

                    shape.Value.Item2[resolution].Item1.ForEach(XY => {
                        shape.Value.Item2[resolution].Item2.Append(Char + (XY.X - min_x) + " " + (XY.Y - min_y) + " ");
                        if (Char == "L ")
                        {
                            Char = "";
                        }
                        if (Char == "M ")
                        {
                            Char = "L ";
                        }
                    });

                    shape.Value.Item2[resolution].Item2.Append("Z ");
                });
            }


            var ShapeLanguage = String.Empty;

            var ShapeDic = new Dictionary <UInt32, String>();

            for (var resolution = min_resolution; resolution <= max_resolution; resolution++)
            {
                ShapeLanguage = "\"";
                Shapes.ForEach((shape) => ShapeLanguage += shape.Value.Item2[resolution].Item2.ToString().Trim() + " ");
                ShapeDic.Add(resolution, ShapeLanguage.TrimEnd() + "\",");
            }

            return(new ShapeInfo(Description, max_lat, max_lng, min_lat, min_lng, ShapeDic));
        }
コード例 #13
0
        public GeoCoordinate Transform(Double Hochwert,
                                       Double Rechtswert,
                                       Double Hoehe,
                                       String Bezugsmeridian = "Automatische Ermittlung")

        {
            //  Based on: GK_in_WGS84.cs
            //  Copyright (c) 2008 by Ingo Peczynski
            //  http://www.sky-maps.de
            //  [email protected]

            // Compare to http://calc.gknavigation.de/


            #region Konstante Parameter

            // WGS84 Ellipsoid
            var WGS84_a  = 6378137.0;                                                               // große Halbachse
            var WGS84_b  = 6356752.3141;                                                            // kleine Halbachse
            var WGS84_e2 = (Math.Pow(WGS84_a, 2) - Math.Pow(WGS84_b, 2)) / Math.Pow(WGS84_a, 2);    // 1.Numerische Exzentrität
            var WGS84_f  = (WGS84_a - WGS84_b) / WGS84_a;                                           // Abplattung 1: fW

            // Bessel Ellipsoid
            var Bessel_a  = 6377397.155;
            var Bessel_b  = 6356078.962;
            var Bessel_e2 = (Bessel_a * Bessel_a - Bessel_b * Bessel_b) / (Bessel_a * Bessel_a);

            #endregion

            #region MeridianUmrechnung

            Int32 Meridianneu;

            if (Bezugsmeridian == "Automatische Ermittlung")
            {
                Meridianneu = 3 * Convert.ToInt32(Rechtswert.ToString().Substring(0, 1));
            }

            else
            {
                Meridianneu = Convert.ToInt32(Bezugsmeridian);
            }

            #endregion

            #region GK nach BL

            // Bessel Ellipsoid
            var n       = (Bessel_a - Bessel_b) / (Bessel_a + Bessel_b);
            var alpha   = (Bessel_a + Bessel_b) / 2.0 * (1.0 + 1.0 / 4.0 * n * n + 1.0 / 64.0 * Math.Pow(n, 4));
            var beta    = 3.0 / 2.0 * n - 27.0 / 32.0 * Math.Pow(n, 3) + 269.0 / 512.0 * Math.Pow(n, 5);
            var gamma   = 21.0 / 16.0 * n * n - 55.0 / 32.0 * Math.Pow(n, 4);
            var delta   = 151.0 / 96.0 * Math.Pow(n, 3) - 417.0 / 128.0 * Math.Pow(n, 5);
            var epsilon = 1097.0 / 512.0 * Math.Pow(n, 4);

            var y0 = Meridianneu / 3.0;
            var y  = Rechtswert - y0 * 1000000 - 500000;

            var B0 = Hochwert / alpha;
            var Bf = B0 + beta * Math.Sin(2 * B0) + gamma * Math.Sin(4 * B0) + delta * Math.Sin(6 * B0) + epsilon * Math.Sin(8 * B0);

            var Nf   = Bessel_a / Math.Sqrt(1.0 - Bessel_e2 * Math.Pow(Math.Sin(Bf), 2));
            var ETAf = Math.Sqrt((Bessel_a * Bessel_a) / (Bessel_b * Bessel_b) * Bessel_e2 * Math.Pow(Math.Cos(Bf), 2));
            var tf   = Math.Tan(Bf);

            var b1 = tf / 2.0 / (Nf * Nf) * (-1.0 - (ETAf * ETAf)) * (y * y);
            var b2 = tf / 24.0 / Math.Pow(Nf, 4) * (5.0 + 3.0 * (tf * tf) + 6.0 * (ETAf * ETAf) - 6.0 * (tf * tf) * (ETAf * ETAf) - 4.0 * Math.Pow(ETAf, 4) - 9.0 * (tf * tf) * Math.Pow(ETAf, 4)) * Math.Pow(y, 4);

            var g_B = (Bf + b1 + b2) * 180 / Math.PI;

            var l1 = 1.0 / Nf / Math.Cos(Bf) * y;
            var l2 = 1.0 / 6.0 / Math.Pow(Nf, 3) / Math.Cos(Bf) * (-1.0 - 2.0 * (tf * tf) - (ETAf * ETAf)) * Math.Pow(y, 3);

            var g_L = Meridianneu + (l1 + l2) * 180 / Math.PI;

            #endregion

            #region Ellipsoid Vektoren in DHDN

            // Querkrümmunsradius
            var N = Bessel_a / Math.Sqrt(1.0 - Bessel_e2 * Math.Pow(Math.Sin(g_B / 180 * Math.PI), 2));

            // Ergebnis Vektoren
            var Bessel_x = (N + Hoehe) * Math.Cos(g_B / 180 * Math.PI) * Math.Cos(g_L / 180 * Math.PI);
            var Bessel_y = (N + Hoehe) * Math.Cos(g_B / 180 * Math.PI) * Math.Sin(g_L / 180 * Math.PI);
            var Bessel_z = (N * (Bessel_b * Bessel_b) / (Bessel_a * Bessel_a) + Hoehe) * Math.Sin(g_B / 180 * Math.PI);

            #endregion

            #region Parameter HelmertTransformation

            Double g_dx;
            Double g_dy;
            Double g_dz;
            Double g_ex;
            Double g_ey;
            Double g_ez;
            Double g_m;

            // HelmertTransformation
            switch (HelmerttransformationsArt)
            {
            // Deutschland von WGS84 nach DNDH/Potsdamm2001
            default:
                g_dx = 598.1;           // Translation in X
                g_dy = 73.7;            // Translation in Y
                g_dz = 418.2;           // Translation in Z
                g_ex = -0.202;          // Drehwinkel in Bogensekunden un die x-Achse
                g_ey = -0.045;          // Drehwinkel in Bogensekunden un die y-Achse
                g_ez = 2.455;           // Drehwinkel in Bogensekunden un die z-Achse
                g_m  = 6.7;             // Maßstabsfaktor in ppm
                break;

            // Österreich von WGS84 nach MGI Ferro
            case HelmerttransformationsArt.OesterreichWGS84nachMGIFerro:
                g_dx = 577.326;         // Translation in X
                g_dy = 90.129;          // Translation in Y
                g_dz = 463.919;         // Translation in Z
                g_ex = -5.137;          // Drehwinkel in Bogensekunden un die x-Achse
                g_ey = -1.474;          // Drehwinkel in Bogensekunden un die y-Achse
                g_ez = -5.297;          // Drehwinkel in Bogensekunden un die z-Achse
                g_m  = 2.423;           // Maßstabsfaktor  in ppm
                break;
            }

            #endregion

            #region Helmert

            // Umrechnung der Drehwinkel in Bogenmaß
            var exRad = (g_ex * Math.PI / 180.0) / 3600.0;
            var eyRad = (g_ey * Math.PI / 180.0) / 3600.0;
            var ezRad = (g_ez * Math.PI / 180.0) / 3600.0;

            // Maßstabsumrechnung
            var mEXP = 1 - g_m * Math.Pow(10, -6);

            // Drehmatrix
            //   1       Ez    -Ez
            // -Ez        1     Ex
            //  Ey      -Ex      1

            // Rotierende Vektoren = Drehmatrix * Vektoren in WGS84
            var RotVektor1 = 1.0 * Bessel_x + ezRad * Bessel_y + (-1.0 * eyRad * Bessel_z);
            var RotVektor2 = (-1.0 * ezRad) * Bessel_x + 1 * Bessel_y + exRad * Bessel_z;
            var RotVektor3 = (eyRad) * Bessel_x + (-1.0 * exRad) * Bessel_y + 1 * Bessel_z;

            // Maßstab berücksichtigen
            var RotVectorM1 = RotVektor1 * mEXP;
            var RotVectorM2 = RotVektor2 * mEXP;
            var RotVectorM3 = RotVektor3 * mEXP;

            // Translation anbringen
            // dxT = Drehmatrix * dx * m
            var dxT = 1.0 * g_dx * mEXP + ezRad * g_dy * mEXP + (-1.0 * eyRad) * g_dz * mEXP;
            var dyT = (-1.0 * ezRad) * g_dx * mEXP + 1.0 * g_dy * mEXP + exRad * g_dz * mEXP;
            var dzT = (eyRad) * g_dx * mEXP + (-1.0 * exRad) * g_dy * mEXP + 1 * g_dz * mEXP;

            // Vektoren jetzt in WGS84
            var WGS84_x = RotVectorM1 + dxT;
            var WGS84_y = RotVectorM2 + dyT;
            var WGS84_z = RotVectorM3 + dzT;

            #endregion

            #region Vektorenumrechnung

            var s  = Math.Sqrt(WGS84_x * WGS84_x + WGS84_y * WGS84_y);
            var T  = Math.Atan(WGS84_z * WGS84_a / (s * WGS84_b));
            var Bz = Math.Atan((WGS84_z + WGS84_e2 * (WGS84_a * WGS84_a) / WGS84_b * Math.Pow(Math.Sin(T), 3)) / (s - WGS84_e2 * WGS84_a * Math.Pow(Math.Cos(T), 3)));

            var Lz = Math.Atan(WGS84_y / WGS84_x);
            var N2 = WGS84_a / Math.Sqrt(1 - WGS84_e2 * Math.Pow(Math.Sin(Bz), 2));

            #endregion

            return(new GeoCoordinate(Latitude.Parse(Bz * 180 / Math.PI),
                                     Longitude.Parse(Lz * 180 / Math.PI),
                                     Altitude.Parse(s / Math.Cos(Bz))));
        }