如何确定地理点绘制的比例因子

时间:2022-06-17 21:23:37

I'm trying to calculate a scale factor in order to roughly place some points in a pseudo-map. The map is centered around a certain (lat,long) point. The points I want to place are inside an area with a set distance d (radius), and are also expressed in terms of latitude and longitude.

我正在尝试计算比例因子,以便在伪图中粗略地放置一些点。地图以某个(纬度,长度)点为中心。我想要放置的点位于具有设定距离d(半径)的区域内,并且还以纬度和经度表示。

Now my problem is that in order for me to scale the positioning of those points in my "map" - an SVG element of fixed dimensions - I need a "scale factor". For instance, should the SVG element represent an area with 5km radius and my SVG is a square of 500px, how can I place those points with some precision? Some precision is enough, as the assumption of a perfectly spherical planet is sufficient for my objectives.

现在我的问题是,为了让我在我的“地图”(一个固定维度的SVG元素)中缩放这些点的位置,我需要一个“比例因子”。例如,如果SVG元素表示半径为5km的区域,而我的SVG是500px的正方形,那么如何以一定的精度放置这些点?一些精度就足够了,因为完美球形行星的假设足以实现我的目标。

The reason why I place this question relates to the facts explained here. This, from what I understood, implies that the decimal difference between two points express in latitude and longitude varies in different areas of the planet.

我提出这个问题的原因与这里解释的事实有关。根据我的理解,这意味着在纬度和经度上表示的两点之间的小数差异在行星的不同区域中变化。

As such, if I want to know how many pixels does 5km represent in this area of the globe in order to place the points knowing their latitude and longitude, how can I calculate that?

因此,如果我想知道在地球的这个区域中5km代表了多少像素,以便知道它们的纬度和经度,我该如何计算?

All I have right now is this formula to calculate the distance between two points knowing their latitude and longitude:

我现在所拥有的只是这个公式来计算两点之间的距离,知道它们的纬度和经度:

function distance(lat1, lat2, lon1, lon2){

    var R = 6371; // km
    var dLat = (lat2-lat1).toRad();
    var dLon = (lon2-lon1).toRad();
    var lat1 = lat1.toRad();
    var lat2 = lat2.toRad();

    var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
    Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2); 
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
    var d = R * c;
    return d;

}

Can I change this to tell me the decimal difference (ie, in terms of latitude), given a point and a distance?

在给定点和距离的情况下,我可以更改此值以告诉我小数差(即纬度方面)吗?

1 个解决方案

#1


0  

Geographical maps are 2D planes representing a pseudo sphere. To get such a map, you need to apply a projection. There are many projections used around, but Google Maps and Open Street Map use the Mercator projection.

地理地图是表示伪球的2D平面。要获得这样的地图,您需要应用投影。周围有许多投影,但谷歌地图和开放街道地图使用墨卡托投影。

In this projection, the latitude is easier to convert. Let's assume you have W pixels in your 2D map. You want longitude -180° to be X=0 and longitude 180° to be X=W.

在此投影中,纬度更容易转换。假设您的2D地图中有W像素。您希望经度-180°为X = 0,经度180°为X = W。

function lng2x(lng, W) {
    lng = ((lng + 180) % 360) - 180;
    return W * lng / 360;
}

Now you want to get Y=0 for Lat=90 and Y=H for Lat=-90. This case is not linear and the function is slightly more complex:

现在你想得到Lat = 90的Y = 0和Lat = -90的Y = H.这种情况不是线性的,功能稍微复杂一些:

function lat2y(lat, H) {
    // The deformation is very intense at the poles.
    // Mercator projection is suitable only for lat in [-85, 85].
    lat = Math.min(lat, 85);
    lat = Math.max(lat, -85);
    var y = lat * Math.PI / 180;
    return H * (
        1 - Math.log(
            Math.tan(y) + 1 / Math.cos(y)
        ) / Math.PI
    ) / 2;
};

#1


0  

Geographical maps are 2D planes representing a pseudo sphere. To get such a map, you need to apply a projection. There are many projections used around, but Google Maps and Open Street Map use the Mercator projection.

地理地图是表示伪球的2D平面。要获得这样的地图,您需要应用投影。周围有许多投影,但谷歌地图和开放街道地图使用墨卡托投影。

In this projection, the latitude is easier to convert. Let's assume you have W pixels in your 2D map. You want longitude -180° to be X=0 and longitude 180° to be X=W.

在此投影中,纬度更容易转换。假设您的2D地图中有W像素。您希望经度-180°为X = 0,经度180°为X = W。

function lng2x(lng, W) {
    lng = ((lng + 180) % 360) - 180;
    return W * lng / 360;
}

Now you want to get Y=0 for Lat=90 and Y=H for Lat=-90. This case is not linear and the function is slightly more complex:

现在你想得到Lat = 90的Y = 0和Lat = -90的Y = H.这种情况不是线性的,功能稍微复杂一些:

function lat2y(lat, H) {
    // The deformation is very intense at the poles.
    // Mercator projection is suitable only for lat in [-85, 85].
    lat = Math.min(lat, 85);
    lat = Math.max(lat, -85);
    var y = lat * Math.PI / 180;
    return H * (
        1 - Math.log(
            Math.tan(y) + 1 / Math.cos(y)
        ) / Math.PI
    ) / 2;
};