Пример #1
0
        public RouteMarker(LatitudeLongitudeCoordinate location, string label)
        {
            Location = location;
            double tileX;
            double tileZ;

            Tile  = Coordinates.ConvertToTile(Coordinates.ConvertToIgh(location), out tileX, out tileZ);
            TileX = tileX;
            TileZ = tileZ;
            Label = label;
        }
Пример #2
0
        // Lat/Lon -> MSTS IGH
        public static IghCoordinate ConvertToIgh(LatitudeLongitudeCoordinate coordinates)
        {
            // Latitude/Longitude -> Line/Sample Algorithm
            // Based on C code provided by the USGS, available at ftp://edcftp.cr.usgs.gov/pub/software/misc/gihll2ls.c.
            // By D. Steinwand, HSTX/EROS Data Center, June, 1993.

            Debug.Assert(coordinates.Latitude >= -90, "latitude is off the bottom");
            Debug.Assert(coordinates.Latitude <= 90, "latitude is off the top");
            Debug.Assert(coordinates.Longitude >= -180, "longitude is off the left");
            Debug.Assert(coordinates.Longitude <= 180, "longitude is off the right");

            double lat = coordinates.Latitude * Math.PI / 180;
            double lon = coordinates.Longitude * Math.PI / 180;

            int region = -1;

            if (lat >= IghParallel41)                             /* If on or above 40 44' 11.8" */
            {
                if (lon <= -IghMeridian40)                        /* If to the left of -40 */
                {
                    region = 0;
                }
                else
                {
                    region = 2;
                }
            }
            else if (lat >= 0.0)                               /* Between 0.0 and 40 44' 11.8" */
            {
                if (lon <= -IghMeridian40)                     /* If to the left of -40 */
                {
                    region = 1;
                }
                else
                {
                    region = 3;
                }
            }
            else if (lat >= -IghParallel41)                       /* Between 0.0 & -40 44' 11.8" */
            {
                if (lon <= -IghMeridian100)                       /* If between -180 and -100 */
                {
                    region = 4;
                }
                else if (lon <= -IghMeridian20)                       /* If between -100 and -20 */
                {
                    region = 5;
                }
                else if (lon <= IghMeridian80)                        /* If between -20 and 80 */
                {
                    region = 8;
                }
                else                                               /* If between 80 and 180 */
                {
                    region = 9;
                }
            }
            else                                               /* Below -40 44' 11.8" */
            {
                if (lon <= -IghMeridian100)                    /* If between -180 and -100 */
                {
                    region = 6;
                }
                else if (lon <= -IghMeridian20)                       /* If between -100 and -20 */
                {
                    region = 7;
                }
                else if (lon <= IghMeridian80)                        /* If between -20 and 80 */
                {
                    region = 10;
                }
                else                                               /* If between 80 and 180 */
                {
                    region = 11;
                }
            }

            double y = 0;
            double x = 0;

            if ((region == 1) || (region == 3) || (region == 4) || (region == 5) || (region == 8) || (region == 9))
            {
                var delta_lon = adjust_lon(lon - IghLongitudeCenter[region]);
                y = lat;
                x = IghLongitudeCenter[region] + delta_lon * Math.Cos(lat);
            }
            else
            {
                var delta_lon = adjust_lon(lon - IghLongitudeCenter[region]);
                var theta     = lat;
                var constant  = Math.PI * Math.Sin(lat);

                /* Iterate using the Newton-Raphson method to find theta
                 * -----------------------------------------------------*/
                for (var i = 0; ; i++)
                {
                    var delta_theta = -(theta + Math.Sin(theta) - constant) / (1.0 + Math.Cos(theta));
                    theta += delta_theta;
                    if (Math.Abs(delta_theta) < 0.00000000001)
                    {
                        break;
                    }
                    if (i >= 30)
                    {
                        //giherror("Iteration failed to converge", "Goode-forward");
                        return(null);
                    }
                }
                theta /= 2.0;
                y      = 1.4142135623731 * Math.Sin(theta) - 0.0528035274542 * Math.Sign(lat);
                x      = IghLongitudeCenter[region] + 0.900316316158 * delta_lon * Math.Cos(theta);
            }

            Debug.Assert(y >= -Math.PI / 2, "y is off the bottom");
            Debug.Assert(y <= +Math.PI / 2, "y is off the top");
            Debug.Assert(x >= -Math.PI, "x is off the left");
            Debug.Assert(x <= +Math.PI, "x is off the right");

            var igh = new IghCoordinate(IghImageTop - y * IghRadius, x * IghRadius - IghImageLeft);

            Debug.Assert(igh.Line >= 0, "line is off the top");
            Debug.Assert(igh.Line <= IghImageHeight, "line is off the bottom");
            Debug.Assert(igh.Sample >= 0, "line is off the left");
            Debug.Assert(igh.Sample <= IghImageWidth, "line is off the right");

            return(igh);
        }