从纬度和经度列表中点计算与实际略有不同势 [英] Calculation of Center Point from List of Latitude and Longitude are slightly diffrent from actual

查看:201
本文介绍了从纬度和经度列表中点计算与实际略有不同势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以计算纬度/液化天然气使用C#的中心纬度/液化天然气弗朗名单和渲染上OpenLayer地图。

I am calculating center Lat/Lng fron list of available Lat/Lng using C# and rendering on OpenLayer Map.

我观察得到中心经纬度的计算/ LNG会给我在纬度/经度略有差异。我指的是这个链接进行计算
。计算多个纬度/经度坐标对的中心点

I observed the calculation of getting center lat/lng will give me slightly difference in lat/lng. I am referring this link for the calculation Calculate the center point of multiple latitude/longitude coordinate pairs.

C#代码:

static void Main(string[] args)
        {
            List<GeoCoordinate> listCoordinate = new List<GeoCoordinate>();
            listCoordinate.Add(new GeoCoordinate() { Latitude = 22.9833, Longitude = 72.5000 }); //Sarkhej
            listCoordinate.Add(new GeoCoordinate() { Latitude = 18.9750, Longitude = 72.8258 }); //Mumbai
            listCoordinate.Add(new GeoCoordinate() { Latitude = 22.3000, Longitude = 73.2003 }); //Vadodara
            listCoordinate.Add(new GeoCoordinate() { Latitude = 26.9260, Longitude = 75.8235 }); //Jaipur
            listCoordinate.Add(new GeoCoordinate() { Latitude = 28.6100, Longitude = 77.2300 }); //Delhi
            listCoordinate.Add(new GeoCoordinate() { Latitude = 22.3000, Longitude = 70.7833 }); //Rajkot

            GeoCoordinate centerCoordinate = GetCentralGeoCoordinate(listCoordinate); //Output (Latitude:23.696708071960074, Longitude:73.681549202080149)
            Console.WriteLine("Lat:" + centerCoordinate.Latitude + ",Lon:" + centerCoordinate.Longitude);
            Console.ReadKey();
        }
        public static GeoCoordinate GetCentralGeoCoordinate(List<GeoCoordinate> geoCoordinates)
        {
            if (geoCoordinates.Count == 1)
            {
                return geoCoordinates.Single();
            }
            double x = 0, y = 0, z = 0;
            foreach (var geoCoordinate in geoCoordinates)
            {
                var latitude = geoCoordinate.Latitude * Math.PI / 180;
                var longitude = geoCoordinate.Longitude * Math.PI / 180;

                x += Math.Cos(latitude) * Math.Cos(longitude);
                y += Math.Cos(latitude) * Math.Sin(longitude);
                z += Math.Sin(latitude);
            }
            var total = geoCoordinates.Count;
            x = x / total;
            y = y / total;
            z = z / total;
            var centralLongitude = Math.Atan2(y, x);
            var centralSquareRoot = Math.Sqrt(x * x + y * y);
            var centralLatitude = Math.Atan2(z, centralSquareRoot);
            return new GeoCoordinate(centralLatitude * 180 / Math.PI, centralLongitude * 180 / Math.PI);
        }



的javascrip代码:

Javascrip Code:

var arrLonLat = [
                {'Lon' : 72.5000, 'Lat' : 22.9833},
                {'Lon' : 72.8258, 'Lat' : 18.9750},
                {'Lon' : 73.2003, 'Lat' : 22.3000},
                {'Lon' : 75.8235, 'Lat' : 26.9260},
                {'Lon' : 77.2300, 'Lat' : 28.6100},
                {'Lon' : 70.7833, 'Lat' : 22.3000}];
            var centerLonLat = getCenterLonLat(arrLonLat);

            var lonLatSarkhej = new OpenLayers.LonLat(arrLonLat[0].Lon,arrLonLat[0].Lat).transform(epsg4326,projectTo);
            var lonLatMumbai = new OpenLayers.LonLat(arrLonLat[1].Lon,arrLonLat[1].Lat).transform(epsg4326,projectTo);
            var lonLatVadodara = new OpenLayers.LonLat(arrLonLat[2].Lon,arrLonLat[2].Lat).transform(epsg4326,projectTo);
            var lonLatJaipur = new OpenLayers.LonLat(arrLonLat[3].Lon,arrLonLat[3].Lat).transform(epsg4326,projectTo);
            var lonLatDelhi = new OpenLayers.LonLat(arrLonLat[4].Lon,arrLonLat[4].Lat).transform(epsg4326,projectTo);
            var lonLatRajkot = new OpenLayers.LonLat(arrLonLat[5].Lon,arrLonLat[5].Lat).transform(epsg4326,projectTo);
            //Center Point of Average Markers
            var lonLatCenter = new OpenLayers.LonLat(73.681549202080149,23.696708071960074).transform(epsg4326,projectTo);

            var markers = new OpenLayers.Layer.Markers("Markers");
            map.addLayer(markers);
            var size = new OpenLayers.Size(24,24);
            var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
            var icon = new OpenLayers.Icon('icon/Marker-Pink.png', size, offset);
            var iconCenter = new OpenLayers.Icon('icon/Marker-Green.png', size, offset);

            markers.addMarker(new OpenLayers.Marker(lonLatSarkhej,icon)); //Sarkhej
            markers.addMarker(new OpenLayers.Marker(lonLatMumbai,icon.clone())); //Mumbai
            markers.addMarker(new OpenLayers.Marker(lonLatVadodara,icon.clone())); //Vadodara
            markers.addMarker(new OpenLayers.Marker(lonLatJaipur,icon.clone())); //Jaipur
            markers.addMarker(new OpenLayers.Marker(lonLatDelhi,icon.clone())); //Delhi
            markers.addMarker(new OpenLayers.Marker(lonLatRajkot,icon.clone())); //Rajkot



我呈现6种不同的位置是粉红标记,然后中心,绿色标记

请参见下图更多的澄清。

Please see below image for more clarification.

现在有画箱,以获取有关中央标志(绿),这是不实际的想法中心。我认为它应该被放置在其上用绿色的水平和垂直线穿过绿点。

Now have drawn box to get idea about the center marker (Green) which is not actually center. I think it should be positioned on Green dot which is crossed by green Horizontal and Vertical line.


  • 任何人都可以让我知道,其实我的心点正确计算
    不?

  • 为什么它没有在框的中央显示?

我也加入了标尺中心点的计算。

请帮我找到实际的解决方案,请做让我知道如果你需要为同一更多的细节。

Please help me to find the actual solution, please do let me know if you need more details for the same.

推荐答案

正确的中心的决定实际上是在为定义的中心的有几个possibilites:

The correct center depends actually on the definition for center and there are several possibilites:


  1. 也许有人会计算包含了所有的最小矩形点和
    用这个矩形的中心,你与你的绿线
    和绿色的点一样。 (这是不寻常的)

  1. One might calculate the smallest rectangle containing all points and use the center of this rectangle as you did with your green lines and green point. (This is unusual)

也许有人会问这一点的最近的所有其他的点,即
找到一个中心点,以便所有距离这个中心和
其他所有点都最小(ABS-规范,用于实际
问题)之间

One might ask which point is closest to all other points, i.e. find a center point so that all distances between this center and all other points are smallest (abs-norm, used for practical problems)

也许有人会问这在最小误差中心点的结果,即使用
最小(的总和)的二次距离以所有其他点
(INS数学,统计等)

One might ask which center point results in the least error, i.e. the smallest (sum of) quadratic distances to all other points (used ins math, statistics, etc)

您看,根据不同的定义,你将不得不使用不同的算法并会在不同的中心的点。

You see, depending on the definition, you'll have to use a different algorithm and will arrive on a different center point.

在你的问题告诉你的算法似乎计算(2)

The algorithm you show in your question seems to calculate (2.)

这篇关于从纬度和经度列表中点计算与实际略有不同势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆