SASGIS

Веб-картография и навигация

Позиция пикселя в тайле Google Map.

Обсуждаем сервисы Google Maps и Google Earth™

Модератор: Tolik

Позиция пикселя в тайле Google Map.

Сообщение movnet » 12 дек 2009, 15:35

Как определить позицию пикселя в тайле Google Map?
movnet
Новичок
 
Сообщения: 8
Зарегистрирован: 11 июл 2009, 14:48
Откуда: Украина, Тернополь
Благодарил (а): 2 раз.
Поблагодарили: 0 раз.

Re: Позиция пикселя в тайле Google Map.

Сообщение zed » 12 дек 2009, 16:47

movnet писал(а):Как определить позицию пикселя в тайле Google Map?

Странный вопрос... А какой пиксел интересует? И что значит "позицию"?
zed
Гуру
 
Сообщения: 2888
Зарегистрирован: 16 авг 2008, 20:21
Благодарил (а): 89 раз.
Поблагодарили: 525 раз.

Re: Позиция пикселя в тайле Google Map.

Сообщение kalinovsky » 12 дек 2009, 18:44

думаю здесь есть то, что вас интересует и даже больше

Код: Выделить всё
using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;

namespace SmartSystems.GeoTransform
{
    public enum GeoCoordFormat
    {
        LDD_MM_SSSS,
        LDD_MMMMMM,
        LDD_DDDDDD,
        SDD_MM_SSSS,
        SDD_MMMMMM,
        SDD_DDDDDD
    }

    public enum GeoPositionFormat
    {
        LON_LAT,
        LAT_LON
    }

    public enum GeoHemisphere
    {
        N_E,
        S_W
    }

    public enum ProjectionType
    {
        SPHEROID,
        KRASSOVSKY_ELLIPSOID
    }

    public class GeoPosition
    {
        private double lon;
        private double lat;

        public double Lon
        {
            get { return lon; }
            set
            {
                if ((value < -180.0) || (value > 180.0))
                {
                    throw new ArgumentException();
                }
                lon = value;
            }
        }

        public double Lat
        {
            get { return lat; }
            set
            {
                if ((value < -90.0) || (value > 90.0))
                {
                    throw new ArgumentException();
                }
                lat = value;
            }
        }

        public GeoPosition(double lon, double lat)
        {
            if ((lon > 180.0) || (lat > 90.0))
            {
                throw new ArgumentOutOfRangeException();
            }
            this.lon = lon;
            this.lat = lat;
        }
       
        public GeoPosition(GeoHemisphere lonH, int lonDD, int lonMM, double lonSS, GeoHemisphere latH, int latDD, int latMM, double latSS)
        {
            if ((lonDD > 180) || (lonDD < 0) || (lonMM > 60) || (lonMM < 0) || (lonSS > 60.0) || (lonSS < 0.0)
             || (latDD > 90) || (latDD < 0) || (latMM > 60) || (latMM < 0) || (latSS > 60.0) || (latSS < 0.0))
            {
                throw new ArgumentException();
            }
            if (((lonDD == 180) & ((lonMM > 0) || (lonSS > double.Epsilon)))
             || ((latDD == 90) & ((latMM > 0) || (latSS > double.Epsilon))))
            {
                throw new ArgumentException();
            }
            this.lon = (double)lonDD + (double)lonMM / 60.0 + lonSS / 3600.0;
            if (lonH == GeoHemisphere.S_W)
            {
                this.lon = -this.lon;
            }
            this.lat = (double)latDD + (double)latMM / 60.0 + latSS / 3600.0;
            if (latH == GeoHemisphere.S_W)
            {
                this.lat = -this.lat;
            }
        }

        public GeoPosition() : this(0.0, 0.0)
        {
        }

        public string LonToString(GeoCoordFormat f)
        {
            GeoHemisphere hs = (lon > 0.0) ? GeoHemisphere.N_E : GeoHemisphere.S_W;
            double l = Math.Abs(lon);
            switch (f)
            {
                case GeoCoordFormat.SDD_DDDDDD:
                    return ((hs == GeoHemisphere.S_W) ? "-" : "") + Math.Round(l, 6).ToString(CultureInfo.CurrentCulture) + "°";
                case GeoCoordFormat.SDD_MMMMMM:
                    return ((hs == GeoHemisphere.S_W) ? "-" : "") + ((int)l).ToString(CultureInfo.CurrentCulture) + "°" + Math.Round((l - (double)(int)l) * 60, 4).ToString(CultureInfo.CurrentCulture) + "'";
                case GeoCoordFormat.SDD_MM_SSSS:
                    return ((hs == GeoHemisphere.S_W) ? "-" : "") + ((int)l).ToString(CultureInfo.CurrentCulture) + "°" + ((int)((l - (double)(int)l) * 60)).ToString(CultureInfo.CurrentCulture) + "'" + Math.Round((((l - (double)(int)l) * 60) - (double)(int)((l - (double)(int)l) * 60)) * 60, 2).ToString(CultureInfo.CurrentCulture) + "\"";
                case GeoCoordFormat.LDD_DDDDDD:
                    return ((hs == GeoHemisphere.S_W) ? "W" : "E") + Math.Round(l, 6).ToString(CultureInfo.CurrentCulture) + "°";
                case GeoCoordFormat.LDD_MMMMMM:
                    return ((hs == GeoHemisphere.S_W) ? "W" : "E") + ((int)l).ToString(CultureInfo.CurrentCulture) + "°" + Math.Round((l - (double)(int)l) * 60, 4).ToString(CultureInfo.CurrentCulture) + "'";
                case GeoCoordFormat.LDD_MM_SSSS:
                    return ((hs == GeoHemisphere.S_W) ? "W" : "E") + ((int)l).ToString(CultureInfo.CurrentCulture) + "°" + ((int)((l - (double)(int)l) * 60)).ToString(CultureInfo.CurrentCulture) + "'" + Math.Round((((l - (double)(int)l) * 60) - (double)(int)((l - (double)(int)l) * 60)) * 60, 2).ToString(CultureInfo.CurrentCulture) + "\"";
                default:
                    return "";
            }
        }

        public string LatToString(GeoCoordFormat f)
        {
            GeoHemisphere hs = (lat > 0.0) ? GeoHemisphere.N_E : GeoHemisphere.S_W;
            double l = Math.Abs(lat);
            switch (f)
            {
                case GeoCoordFormat.SDD_DDDDDD:
                    return ((hs == GeoHemisphere.S_W) ? "-" : "") + Math.Round(l, 6).ToString(CultureInfo.CurrentCulture) + "°";
                case GeoCoordFormat.SDD_MMMMMM:
                    return ((hs == GeoHemisphere.S_W) ? "-" : "") + ((int)l).ToString(CultureInfo.CurrentCulture) + "°" + Math.Round((l - (double)(int)l) * 60, 4).ToString(CultureInfo.CurrentCulture) + "'";
                case GeoCoordFormat.SDD_MM_SSSS:
                    return ((hs == GeoHemisphere.S_W) ? "-" : "") + ((int)l).ToString(CultureInfo.CurrentCulture) + "°" + ((int)((l - (double)(int)l) * 60)).ToString(CultureInfo.CurrentCulture) + "'" + Math.Round((((l - (double)(int)l) * 60) - (double)(int)((l - (double)(int)l) * 60)) * 60, 2).ToString(CultureInfo.CurrentCulture) + "\"";
                case GeoCoordFormat.LDD_DDDDDD:
                    return ((hs == GeoHemisphere.S_W) ? "S" : "N") + Math.Round(l, 6).ToString(CultureInfo.CurrentCulture) + "°";
                case GeoCoordFormat.LDD_MMMMMM:
                    return ((hs == GeoHemisphere.S_W) ? "S" : "N") + ((int)l).ToString(CultureInfo.CurrentCulture) + "°" + Math.Round((l - (double)(int)l) * 60, 4).ToString(CultureInfo.CurrentCulture) + "'";
                case GeoCoordFormat.LDD_MM_SSSS:
                    return ((hs == GeoHemisphere.S_W) ? "S" : "N") + ((int)l).ToString(CultureInfo.CurrentCulture) + "°" + ((int)((l - (double)(int)l) * 60)).ToString(CultureInfo.CurrentCulture) + "'" + Math.Round((((l - (double)(int)l) * 60) - (double)(int)((l - (double)(int)l) * 60)) * 60, 2).ToString(CultureInfo.CurrentCulture) + "\"";
                default:
                    return "";
            }
        }

        public string ToString(GeoPositionFormat pf, GeoCoordFormat cf)
        {
            switch (pf)
            {
                case GeoPositionFormat.LON_LAT:
                    return LonToString(cf) + " " + LatToString(cf);
                case GeoPositionFormat.LAT_LON:
                    return LatToString(cf) + " " + LonToString(cf);
                default:
                    return "";
            }
        }
    }

    public class GeoTransformation
    {
        private static readonly double e = 0.081819790992;

        public static double GetTileX(double lon, int zoom, ProjectionType pt)
        {
            switch (pt)
            {
                case ProjectionType.SPHEROID:
                case ProjectionType.KRASSOVSKY_ELLIPSOID:
                    return Math.Pow(2, (double)(zoom - 2)) * (1 + lon / 180.0);       
                default:
                    return 0.0;
            }
           
        }

        public static double GetTileY(double lat, int zoom, ProjectionType pt)
        {
            switch (pt)
            {
                case ProjectionType.SPHEROID:
                    return Math.Pow(2, (double)(zoom - 2)) * (1 - ((Math.Log((1 + Math.Sin(lat * Math.PI / 180.0)) / (1 - Math.Sin(lat * Math.PI / 180.0)))) / 2.0) / Math.PI);
                case ProjectionType.KRASSOVSKY_ELLIPSOID:
                    return Math.Pow(2, (double)(zoom - 2)) * (1 - ((Math.Log((1 + Math.Sin(lat * Math.PI / 180.0)) / (1 - Math.Sin(lat * Math.PI / 180.0)))) / 2.0 - e * (Math.Log((1 + e * Math.Sin(lat * Math.PI / 180.0)) / (1 - e * Math.Sin(lat * Math.PI / 180.0)))) / 2.0) / Math.PI);
                default:
                    return 0.0;
            }
        }

        public static double GetLon(double tileX, int zoom, ProjectionType pt)
        {
            switch (pt)
            {
                case ProjectionType.SPHEROID:
                case ProjectionType.KRASSOVSKY_ELLIPSOID:
                    return (tileX / Math.Pow(2.0, (double)(zoom - 2)) - 1) * 180.0;
                default:
                    return 0.0;
            }
        }

        public static double GetLat(double tileY, int zoom, ProjectionType pt)
        {
            bool S = false;
            if (tileY > Math.Pow(2.0, (double)(zoom - 2)))
            {
                S = true;
                tileY = Math.Pow(2.0, (double)(zoom - 1)) - tileY;
            }
            double y1 = (1.0 - (tileY / Math.Pow(2.0, (double)(zoom - 2)))) * Math.PI;
            double teta0 = 2.0 * Math.Atan(Math.Pow(Math.E, y1)) - Math.PI / 2.0;

            switch (pt)
            {
                case ProjectionType.SPHEROID:
                    return (S ? -1 : 1) * teta0 * 180.0 / Math.PI;
                case ProjectionType.KRASSOVSKY_ELLIPSOID:
                    double teta = CalcTeta(teta0, y1);
                    while (Math.Abs(teta - teta0) > 0.0000001)
                    {
                        teta0 = teta;
                        teta = CalcTeta(teta, y1);
                    }
                    return (S ? -1 : 1) * teta * 180.0 / Math.PI;
                default:
                    return 0.0;
            }
        }

        private static double CalcTeta(double teta0, double y1)
        {
            return Math.Asin(1.0 - (1.0 + Math.Sin(teta0)) * Math.Pow(1.0 - e * Math.Sin(teta0), e) / (Math.Pow(Math.E, 2.0 * y1 / 1.0) * Math.Pow(1 + e * Math.Sin(teta0), e)));
        }

    }
}
kalinovsky
Новичок
 
Сообщения: 6
ICQ: 556186517
Зарегистрирован: 14 авг 2009, 17:09
Откуда: Смоленск
Благодарил (а): 0 раз.
Поблагодарили: 0 раз.

Re: Позиция пикселя в тайле Google Map.

Сообщение movnet » 13 дек 2009, 13:21

Большое спасибо. посмотрим.
movnet
Новичок
 
Сообщения: 8
Зарегистрирован: 11 июл 2009, 14:48
Откуда: Украина, Тернополь
Благодарил (а): 2 раз.
Поблагодарили: 0 раз.

Re: Позиция пикселя в тайле Google Map.

Сообщение movnet » 13 дек 2009, 17:13

zed писал(а):
movnet писал(а):Как определить позицию пикселя в тайле Google Map?

Странный вопрос... А какой пиксел интересует? И что значит "позицию"?


Позицию XY в тайле зная широту, долготу и маштаб. возможно я не так обяснюю, извините.
movnet
Новичок
 
Сообщения: 8
Зарегистрирован: 11 июл 2009, 14:48
Откуда: Украина, Тернополь
Благодарил (а): 2 раз.
Поблагодарили: 0 раз.


Вернуться в Google Maps + Google Earth™

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 1

cron