给出地球表面(等矩形)上的正方形ABCD,A&B位于格林威奇子午线,B&C在经度上= 10⁰:
A( 0.0; 50.0) C(10.0; 50.0)
B( 0.0; 40.0) B(10.0; 40.0)考虑到我的D3js dataviz在d3.geo.mercator()投影中的工作,我的正方形垂直转换为约1.5的比率r= mercator_height in px/width in px。
如何准确计算墨卡托变换比r
注意:这是非线性的,因为它暗示了一些1/cos() 2.
编辑:I很想认为我们应该首先使用屏幕上的d3.geo.mercator()重新规划每一点(,怎么做?)哪种语法?),所以D3做所有困难的数学。然后我们可以得到点的像素坐标,这样我们就可以计算出长度AB和长度AC (以像素为单位),最后是r=AC/AB。此外,如何将十进制坐标转换为选定的d3.geo.<PROJECTIONNAME>() 的投影像素坐标函数,这也是一个小问题。
发布于 2014-08-20 13:52:10
假设点为A:(0,50),B:(0,40),C:(10,50)和D:(10,40)。点(A,C,D,B)所包围的特征将使用等矩形投影看起来像一个正方形。现在,点是经度,纬度对,你可以用d3.geo.distance计算点之间的大弧距离。这会给你点之间的角度距离。例如:
// Points (lon, lat)
var A = [ 0, 50],
B = [ 0, 40],
C = [10, 50],
D = [10, 40];
// Geographic distance between AB and AC
var distAB = d3.geo.distance(A, B), // 0.17453292519943306 radians
distAC = d3.geo.distance(A, C); // 0.11210395570214343 radians现在,这些距离是点之间的角度,正如你所看到的,这个特征不是一个正方形。如果我们使用D3墨卡托投影投射点
// The map will fit in 800 px horizontally
var width = 800;
var mercator = d3.geo.mercator()
.scale(width / (2 * Math.PI));
// Project (lon, lat) points using the projection, to get pixel coordinates.
var pA = mercator(A), // [480, 121] (rounded)
pB = mercator(B), // [480, 152] (rounded)
pC = mercator(C); // [502, 121] (rounded)现在用欧氏距离来计算投影点pA、pB和pC之间的距离。
function dist(p, q) {
return Math.sqrt(Math.pow(p[0] - q[0], 2) + Math.pow(p[1] - q[1], 2));
}
var pDistAB = dist(pA, pB), // 31.54750649588999 pixels
pDistAC = dist(pA, pC); // 22.22222222222223 pixels如果你以角距离作为参考,你将得到两个比率,一个是AB,另一个是AC:
var ratioAB = distAB / pDistAB, // 0.005532384159178197 radians/pixels
ratioAC = distAC / pDistAC; // 0.005044678006596453 radians/pixels如果使用等长线投影作为参考,则可以使用点之间的欧几里德距离(就像它们在平面上一样):
var ratioAB = dist(A, B) / pDistAB, // 0.3169822629659431 degrees/pixels
ratioAC = dist(A, C) / pDistAC; // 0.44999999999999984 degrees/pixelshttps://stackoverflow.com/questions/25393163
复制相似问题