【发布时间】:2011-12-13 22:12:37
【问题描述】:
我有东/北格式的位置坐标,但我需要将其转换为适当的纬度,以便在 bing 地图中居中。任何公式或详细信息如何将东/北转换为纬度/经度?
编辑:更具体地说,我需要将 SVY21 坐标转换为 WGS84
【问题讨论】:
我有东/北格式的位置坐标,但我需要将其转换为适当的纬度,以便在 bing 地图中居中。任何公式或详细信息如何将东/北转换为纬度/经度?
编辑:更具体地说,我需要将 SVY21 坐标转换为 WGS84
【问题讨论】:
Eastings 和 northings 分别是基点向东和向北的距离。基点通常是纬度和经度,东向和北向通常以米或英尺表示。然而,东移和北移通常会偏移一个特定的值,以使其为正值,并允许它们表示基点以西和以南的位置。
一般来说,从一个坐标系转换到另一个坐标系并不简单,因为两者可能有不同的椭球体(地球模型)和基准面。据我了解,从一个坐标系转换到另一个坐标系的公式相当复杂。
SVY21 但是,使用与 WGS84 完全相同的基准面和椭球体,使任务更简单。在 SVY21 中,东向和北向的基点是Base 7 at Pierce Reservoir,1 度。 22 分钟。 02.9154 秒。北纬103度。 49 分 31.9752 秒。东(即大约 1.3674765 度的纬度和大约 103.8255487 度的经度;然而,众所周知的文本分别使用 1.3666... 度和 103.8333... 度)。东距偏移量为 28001.642 米,北距偏移量为 38744.572 米。 EPSG 代码是 3414。我假设您的东向和北向以米表示。
由于 SVY21 使用与 WGS84 相同的系统,您所要做的就是:
【讨论】:
我已将 Javascript 实现转换为 T-SQL 函数,用于 WGS84 到纬度/经度值。随意使用您认为合适的。如果您需要不同的坐标系,请查看我用作来源的威斯康星大学 - 绿湾网页并获取更新后的常量。
drop function UF_utm_to_lat
go
create function UF_utm_to_lat(@utmz float, @x float, @y float) returns float
as
begin
--Based on code from this page: http://www.uwgb.edu/dutchs/usefuldata/ConvertUTMNoOZ.HTM
declare @latitude float;
declare @longitude float;
set @latitude = 0.00;
set @longitude = 0.00;
--Declarations
declare @a float;
declare @f float;
declare @drad float;
declare @k0 float;
declare @b float;
declare @e float;
declare @e0 float;
declare @esq float;
declare @e0sq float;
declare @zcm float;
declare @e1 float;
declare @M float;
declare @mu float;
declare @phi1 float;
declare @C1 float;
declare @T1 float;
declare @N1 float;
declare @R1 float;
declare @D float;
declare @phi float;
declare @lng float;
declare @lngd float;
--Datum Info here: Name, a, b, f, 1/f
--WGS 84 6,378,137.0 6356752.314 0.003352811 298.2572236
set @a = 6378137.0;
set @b = 6356752.314;
set @f = 0.003352811;
set @drad = PI()/180.0;
set @k0 = 0.9996; --scale on central meridian
set @e = SQRT(1.0 - (@b/@a)*(@b/@a)); --Eccentricity
--e = Math.sqrt(1 - (b/a)*(b/a));//eccentricity
set @e0 = @e/SQRT(1.0 - @e*@e); --Called e prime in reference
--e0 = e/Math.sqrt(1 - e*e);//Called e prime in reference
set @esq = (1.0 - (@b/@a)*(@b/@a)); --e squared for use in expansions
--esq = (1 - (b/a)*(b/a));//e squared for use in expansions
set @e0sq = @e*@e/(1.0-@e*@e); --e0 squared - always even powers
--e0sq = e*e/(1-e*e);// e0 squared - always even powers
set @zcm = 3.0 + 6.0*(@utmz-1.0) - 180.0; --Central meridian of zone
--zcm = 3 + 6*(utmz-1) - 180;//Central meridian of zone
set @e1 = (1.0 - SQRT(1.0 - @e*@e))/(1.0 + SQRT(1.0 - @e*@e)); --Called e1 in USGS PP 1395 also
--e1 = (1 - Math.sqrt(1 - e*e))/(1 + Math.sqrt(1 - e*e));//Called e1 in USGS PP 1395 also
set @M = 0.0 + @y / @k0; --Arc length along standard meridian
--M = M0 + y/k0;//Arc length along standard meridian.
set @mu = @M/(@a*(1.0 - @esq*(1.0/4.0 + @esq*(3.0/64.0 + 5.0*@esq/256.0))));
--mu = M/(a*(1 - esq*(1/4 + esq*(3/64 + 5*esq/256))));
set @phi1 = @mu + @e1*(3.0/2.0 - 27.0*@e1*@e1/32.0)*SIN(2.0*@mu) + @e1*@e1*(21.0/16.0 - 55.0*@e1*@e1/32.0)*SIN(4.0*@mu); --Footprint Latitude
--phi1 = mu + e1*(3/2 - 27*e1*e1/32)*Math.sin(2*mu) + e1*e1*(21/16 -55*e1*e1/32)*Math.sin(4*mu);//Footprint Latitude
set @phi1 = @phi1 + @e1*@e1*@e1*(SIN(6.0*@mu)*151.0/96.0 + @e1*SIN(8.0*@mu)*1097.0/512.0);
--phi1 = phi1 + e1*e1*e1*(Math.sin(6*mu)*151/96 + e1*Math.sin(8*mu)*1097/512);
set @C1 = @e0sq*POWER(COS(@phi1),2.0);
--C1 = e0sq*Math.pow(Math.cos(phi1),2);
set @T1 = POWER(TAN(@phi1),2.0);
--T1 = Math.pow(Math.tan(phi1),2);
set @N1 = @a/SQRT(1.0-POWER(@e*SIN(@phi1),2.0));
--N1 = a/Math.sqrt(1-Math.pow(e*Math.sin(phi1),2));
set @R1 = @N1*(1.0-@e*@e)/(1.0-POWER(@e*SIN(@phi1),2.0));
--R1 = N1*(1-e*e)/(1-Math.pow(e*Math.sin(phi1),2));
set @D = (@x-500000.0)/(@N1*@k0);
--D = (x-500000)/(N1*k0);
set @phi = (@D*@D)*(1.0/2.0 - @D*@D*(5.0 + 3.0*@T1 + 10.0*@C1 - 4.0*@C1*@C1 - 9.0*@e0sq)/24.0);
--phi = (D*D)*(1/2 - D*D*(5 + 3*T1 + 10*C1 - 4*C1*C1 - 9*e0sq)/24);
set @phi = @phi + POWER(@D,6.0)*(61.0 + 90.0*@T1 + 298.0*@C1 + 45.0*@T1*@T1 - 252.0*@e0sq - 3.0*@C1*@C1)/720.0;
--phi = phi + Math.pow(D,6)*(61 + 90*T1 + 298*C1 + 45*T1*T1 -252*e0sq - 3*C1*C1)/720;
set @phi = @phi1 - (@N1*TAN(@phi1)/@R1)*@phi;
--phi = phi1 - (N1*Math.tan(phi1)/R1)*phi;
set @latitude = FLOOR(1000000.0*@phi/@drad)/1000000.0;
set @lng = @D*(1.0 + @D*@D*((-1.0 - 2.0*@T1 - @C1)/6.0 + @D*@D*(5.0 - 2.0*@C1 + 28.0*@T1 - 3.0*@C1*@C1 + 8.0*@e0sq + 24.0*@T1*@T1)/120))/COS(@phi1);
set @lngd = @zcm+@lng/@drad;
set @longitude = FLOOR(1000000.0*@lngd)/1000000.0;
return @latitude;
end
go
drop function UF_utm_to_long
go
create function UF_utm_to_long(@utmz float, @x float, @y float) returns float
as
begin
--Based on code from this page: http://www.uwgb.edu/dutchs/usefuldata/ConvertUTMNoOZ.HTM
declare @latitude float;
declare @longitude float;
set @latitude = 0.00;
set @longitude = 0.00;
--Declarations
declare @a float;
declare @f float;
declare @drad float;
declare @k0 float;
declare @b float;
declare @e float;
declare @e0 float;
declare @esq float;
declare @e0sq float;
declare @zcm float;
declare @e1 float;
declare @M float;
declare @mu float;
declare @phi1 float;
declare @C1 float;
declare @T1 float;
declare @N1 float;
declare @R1 float;
declare @D float;
declare @phi float;
declare @lng float;
declare @lngd float;
--Datum Info here: Name, a, b, f, 1/f
--WGS 84 6,378,137.0 6356752.314 0.003352811 298.2572236
set @a = 6378137.0;
set @b = 6356752.314;
set @f = 0.003352811;
set @drad = PI()/180.0;
set @k0 = 0.9996; --scale on central meridian
set @e = SQRT(1.0 - (@b/@a)*(@b/@a)); --Eccentricity
--e = Math.sqrt(1 - (b/a)*(b/a));//eccentricity
set @e0 = @e/SQRT(1.0 - @e*@e); --Called e prime in reference
--e0 = e/Math.sqrt(1 - e*e);//Called e prime in reference
set @esq = (1.0 - (@b/@a)*(@b/@a)); --e squared for use in expansions
--esq = (1 - (b/a)*(b/a));//e squared for use in expansions
set @e0sq = @e*@e/(1.0-@e*@e); --e0 squared - always even powers
--e0sq = e*e/(1-e*e);// e0 squared - always even powers
set @zcm = 3.0 + 6.0*(@utmz-1.0) - 180.0; --Central meridian of zone
--zcm = 3 + 6*(utmz-1) - 180;//Central meridian of zone
set @e1 = (1.0 - SQRT(1.0 - @e*@e))/(1.0 + SQRT(1.0 - @e*@e)); --Called e1 in USGS PP 1395 also
--e1 = (1 - Math.sqrt(1 - e*e))/(1 + Math.sqrt(1 - e*e));//Called e1 in USGS PP 1395 also
set @M = 0.0 + @y / @k0; --Arc length along standard meridian
--M = M0 + y/k0;//Arc length along standard meridian.
set @mu = @M/(@a*(1.0 - @esq*(1.0/4.0 + @esq*(3.0/64.0 + 5.0*@esq/256.0))));
--mu = M/(a*(1 - esq*(1/4 + esq*(3/64 + 5*esq/256))));
set @phi1 = @mu + @e1*(3.0/2.0 - 27.0*@e1*@e1/32.0)*SIN(2.0*@mu) + @e1*@e1*(21.0/16.0 - 55.0*@e1*@e1/32.0)*SIN(4.0*@mu); --Footprint Latitude
--phi1 = mu + e1*(3/2 - 27*e1*e1/32)*Math.sin(2*mu) + e1*e1*(21/16 -55*e1*e1/32)*Math.sin(4*mu);//Footprint Latitude
set @phi1 = @phi1 + @e1*@e1*@e1*(SIN(6.0*@mu)*151.0/96.0 + @e1*SIN(8.0*@mu)*1097.0/512.0);
--phi1 = phi1 + e1*e1*e1*(Math.sin(6*mu)*151/96 + e1*Math.sin(8*mu)*1097/512);
set @C1 = @e0sq*POWER(COS(@phi1),2.0);
--C1 = e0sq*Math.pow(Math.cos(phi1),2);
set @T1 = POWER(TAN(@phi1),2.0);
--T1 = Math.pow(Math.tan(phi1),2);
set @N1 = @a/SQRT(1.0-POWER(@e*SIN(@phi1),2.0));
--N1 = a/Math.sqrt(1-Math.pow(e*Math.sin(phi1),2));
set @R1 = @N1*(1.0-@e*@e)/(1.0-POWER(@e*SIN(@phi1),2.0));
--R1 = N1*(1-e*e)/(1-Math.pow(e*Math.sin(phi1),2));
set @D = (@x-500000.0)/(@N1*@k0);
--D = (x-500000)/(N1*k0);
set @phi = (@D*@D)*(1.0/2.0 - @D*@D*(5.0 + 3.0*@T1 + 10.0*@C1 - 4.0*@C1*@C1 - 9.0*@e0sq)/24.0);
--phi = (D*D)*(1/2 - D*D*(5 + 3*T1 + 10*C1 - 4*C1*C1 - 9*e0sq)/24);
set @phi = @phi + POWER(@D,6.0)*(61.0 + 90.0*@T1 + 298.0*@C1 + 45.0*@T1*@T1 - 252.0*@e0sq - 3.0*@C1*@C1)/720.0;
--phi = phi + Math.pow(D,6)*(61 + 90*T1 + 298*C1 + 45*T1*T1 -252*e0sq - 3*C1*C1)/720;
set @phi = @phi1 - (@N1*TAN(@phi1)/@R1)*@phi;
--phi = phi1 - (N1*Math.tan(phi1)/R1)*phi;
set @latitude = FLOOR(1000000.0*@phi/@drad)/1000000.0;
set @lng = @D*(1.0 + @D*@D*((-1.0 - 2.0*@T1 - @C1)/6.0 + @D*@D*(5.0 - 2.0*@C1 + 28.0*@T1 - 3.0*@C1*@C1 + 8.0*@e0sq + 24.0*@T1*@T1)/120))/COS(@phi1);
set @lngd = @zcm+@lng/@drad;
set @longitude = FLOOR(1000000.0*@lngd)/1000000.0;
return @longitude;
end
【讨论】:
perl中有一个比较简单的解决方案:
所以,首先,请确保您已安装 Perl。然后,安装 以下四个模块:
Geo::HelmertTransform Geography::NationalGrid CAM::DBF mySociety::GeoUtil
您可以通过多种方式做到这一点。我是这样做的:
# Geo::HelmertTransform
wget http://search.cpan.org/CPAN/authors/id/M/MY/MYSOCIETY/Geo-HelmertTransform-1.13.tar.gz
tar xzf Geo-HelmertTransform-1.13.tar.gz
perl Makefile.PL
make
make install
# Geography::NationalGrid
http://search.cpan.org/CPAN/authors/id/P/PK/PKENT/Geography-NationalGrid-1.6.tar.gz
tar xzf Geography-NationalGrid-1.6.tar.gz
perl Makefile.PL
make
make install
# CAM::DBF
wget http://search.cpan.org/CPAN/authors/id/C/CL/CLOTHO/CAM-DBF-1.02.tgz
tar xzf CAM-DBF-1.02.tgz
perl Makefile.PL
make
make install
# mySociety::GeoUtil
# See: http://parlvid.mysociety.org:81/os/ -> https://github.com/mysociety/commonlib/blob/master/perllib/mySociety/GeoUtil.pm
mkdir -p mySociety
wget -O mySociety/GeoUtil.pm 'https://raw.githubusercontent.com/mysociety/commonlib/master/perllib/mySociety/GeoUtil.pm'
- 获取 GB 数据。
点击此处下载英国“Code-Point® Open”数据集 并按照说明进行操作。下载 codepo_gb.zip 后 您可以按如下方式提取它:
解压代码po_gb.zip
假设解压后的文件现在在当前目录下, 然后,您可以运行以下 perlscript 以解析数据, 提取 GB 东向/北向并将它们转换为 纬度/经度。
use strict;
use mySociety::GeoUtil qw/national_grid_to_wgs84/;
while (<>) {
my @x=split(/,/); # split csv
my ($pc, $east, $north) = ($x[0], $x[10], $x[11]);
$pc=~s/\"//g; # remove quotes around postcode
my ($lat, $lng) = national_grid_to_wgs84($east, $north, "G"); # "G" means Great Britain
print "$pc,$lat,$lng\n";
}
(要调用,将最后一个代码块保存到.pl文件中,然后调用perl script.pl your.csv ...还要记住,$x[0]、$x[10]和$x[11]应该是邮政编码、东距和北距的列号。
感谢http://baroque.posterous.com/uk-postcode-latitudelongitude
【讨论】:
有数百种不同的坐标系 - 东/北和纬度/经度是坐标的类型,但它们不足以唯一标识获得这些坐标的系统。 p>
您需要有一个 EPSG 代码(例如 4326、4269、27700、32701)或空间参考系统的详细信息(基准面、投影、本初子午线和测量单位)。选择的目标格式。 您在问题标题中提到“GPS”,所以我假设您需要的纬度/经度是相对于全球定位系统使用的 WGS84 基准定义的,但是该基准仍有许多预测可能导致不同的东移/北移值。
获得所用投影的详细信息后,您可以使用 Proj.4 库 (http://trac.osgeo.org/proj/) 之类的代码在代码中执行转换
【讨论】: