如何在 python 或 Javascript 中从 UTM 转换为 LatLng
我有一堆带有 UTM 形式坐标的文件。 对于每个坐标,我都有东距、北距和区域。 我需要将其转换为 LatLng 以便与 Google Map API 一起使用以在地图中显示信息。
我找到了一些可以执行此操作的在线计算器,但没有实际的代码或库。 http://trac.osgeo.org/proj4js/ 是一个 Javascript 投影库,但是看看该演示不包括 UTM 投影。
我对整个 GIS 领域还很陌生,所以我想要的是:
(lat,lng) = transform(easting, northing, zone)
I have a bunch of files with coordinates in UTM form. For each coordinate I have easting, northing and zone. I need to convert this to LatLng for use with Google Map API to show the information in a map.
I have found some online calculators that does this, but no actual code or libraries. http://trac.osgeo.org/proj4js/ is a projection library for Javascript, but looking at the demo it doesn't include UTM projection.
I am still pretty fresh to the entire GIS domain, so what I want is something ala:
(lat,lng) = transform(easting, northing, zone)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
我最终找到了 IBM 的 java 代码来解决这个问题: http:// /www.ibm.com/developerworks/java/library/j-coordconvert/index.html
仅供参考,这是我所需方法的 python 实现:
在这里我认为它很简单,例如
easting*x+zone*y
之类的。I ended up finding java code from IBM that solved it: http://www.ibm.com/developerworks/java/library/j-coordconvert/index.html
Just for reference, here is my python implementation of the method I needed:
And here I thought it was something simple like
easting*x+zone*y
or something.我发现的是以下网站: http://home.hiwaay.net /~taylorc/toolbox/geography/geoutm.html
它有一个 javascript 转换器,你应该检查那里的算法。 从页面:
What I found is the following site: http://home.hiwaay.net/~taylorc/toolbox/geography/geoutm.html
It has a javascript converter, you should check the algorithm there. From the page:
根据此页面,proj4js 支持 UTM。
http://trac.osgeo.org/proj4js/wiki/UserGuide#Supportedprojectionclasses
您可能还想查看 GDAL。 gdal 库具有出色的 python 支持,但如果您只进行投影转换,它可能有点矫枉过正。
According to this page, UTM is supported by proj4js.
http://trac.osgeo.org/proj4js/wiki/UserGuide#Supportedprojectionclasses
You may also want to take a look at GDAL. The gdal library has excellent python support, though it may be a bit overkill if you're only doing projection conversion.
Staale 答案的 Javascript 版本
A Javascript version of Staale answer
我也是新手,最近一直在研究这个主题。
这是我使用 python gdal pacakge (osr 包)找到的方法包含在 gdal 中)。 gdal 包非常强大,但文档还可以更好。
这是从这里的讨论得出的:
http://www.mail-archive.com/< span class="__cf_email__" data-cfemail="f493909598d9909182b4989d878087da9b8793919bda9b8693">[email protected]/msg12398.html
这是从 wgs84 中的纬度、经度转换的方法(大多数 gps 单位报告的内容) )到 utm:
我还发现,如果您已经安装了 django/gdal 并且您知道 EPSG 代码,您只需使用
Point() transform() 方法。
I'm new to this as well and have been studying up on the subject recently.
Here's a method I found using the python gdal pacakge (the osr package is included in gdal). The gdal package is pretty powerful, but the documentation could be better.
This is derived from a discussion here:
http://www.mail-archive.com/[email protected]/msg12398.html
And here's the method for converting from a lat, lon in wgs84 (what most gps units report) to utm:
I also found that if you've already got django/gdal installed and you know the EPSG code for the UTM zone you're working on, you can just use the
Point()
transform() method.有一个Python库(utm)“Bi Direction UTM-WGS84 converter for python”可以管理单个坐标点或系列。
将(纬度、经度)元组转换为 UTM 坐标:
结果
返回的形式为
(EASTING, NORTHING, ZONE_NUMBER, ZONE_LETTER)
。如果使用系列,结果 EASTING 和 NORTHING 将具有相同的形状。
相反
,将 UTM 坐标转换为(纬度、经度)元组:
使用语法 utm.to_latlon(EASTING, NORTHING, ZONE_NUMBER, ZONE_LETTER)。 如果要使用系列,则在这种情况下也是如此。
根据文档,传递一系列函数比对函数进行多个单点调用更快。
There is a library for Python (utm) "Bidirectional UTM-WGS84 converter for python" that can manage single coordinate points or series.
Convert a (latitude, longitude) tuple into an UTM coordinate:
resulting
The return has the form
(EASTING, NORTHING, ZONE_NUMBER, ZONE_LETTER)
.If series are used, in the result EASTING and NORTHING will have the same shape.
resulting
And for the opposite, convert an UTM coordinate into a (latitude, longitude) tuple:
with the syntax
utm.to_latlon(EASTING, NORTHING, ZONE_NUMBER, ZONE_LETTER)
. Same in this case if series are to be used.According to the documentation is faster to pass a series than multiple one point calls to the function.
您可以使用 Proj4js,如下所示。
使用 此 链接从 GitHub 下载 Proj4JS。
以下代码将从 UTM 转换为经度纬度
在此代码中,UTM 区域为 32,这应该是显而易见的。 东经是 539884,北经是 4942158。结果是:
也就是说 44.631671014204365N,9.502832656648073E。 我有 已验证正确。
如果您需要其他投影,可以在此处找到它们的字符串。
You could use Proj4js, as follows.
Download Proj4JS from GitHub, using this link.
The following code will convert from UTM to longitude latitude
In this code, the UTM zone is 32, as should be obvious. The Easting is 539884, and the Northing is 4942158. The result is:
Which is to say 44.631671014204365N, 9.502832656648073E. Which I have verified is correct.
If you need other projections, you can find their strings here.
我在使用 proj4js 时遇到的一个问题是它需要精确的区域,正如 @Richard 指出的那样。 我在这里找到了一个很棒的资源,它可以将WGS转换为UTM并写道JavaScript 中更简洁的包装器:
https://github.com/urbanetic/utm-converter
One problem I had with using proj4js was that it needed the exact zone as @Richard points out. I found a great resource here which can convert WGS to UTM and wrote a cleaner wrapper in JavaScript:
https://github.com/urbanetic/utm-converter
通过 CPAN 有一个名为 Geography::NationalGrid 的 Perl 模块,它可以将东向/北向转换为纬度/经度。 这可能有帮助。
另外,可移动类型网站上有很多脚本让您可以转换纬度/经度和东距/北距。
There is a perl module via CPAN called Geography::NationalGrid which can convert easting/northing to lat/longs. That may help.
Alternatively there are lots of scripts on the movable-type site that let you convert lat/long and easting/northings.
Staale 的答案对我有用,做了一些小小的修改 -
数学模块无法处理 Pandas Series,因此我用 numpy 替换了所有数学函数。
然而,在 QGIS 中检查,我发现 UTM 和 LAT/LON 坐标之间有大约 4m 的差异。
代码如下:
这样我就可以直接这样做:
The answer by Staale worked for me with a small modification -
The math module cannot handle Pandas Series, so I replaced all math functions with numpy.
However, checking in QGIS, I see about 4m difference between the UTM and LAT/LON coordinates.
Code below:
That way I can do this directly:
将 @TreyA 转换为 kotlin(java 库中的一些数学函数),只是为了它的情况。 似乎比@Staale 和@sandino 更准确一些
Converted @TreyA to kotlin (some Math functions in java libraries), just for the case of it. Seems to be a bit more accurate than @Staale and @sandino
在Python中,您还可以使用pyproj< /a> 包。 找到您的 UTM 的 EPSG 代码(例如,此处)。 然后:
从lat-lon到UTM:
从UTM到lat-lon:
In Python, you can also use the pyproj package. Find the EPSG code of your UTM (e.g., here). Then:
From lat-lon to UTM:
From UTM to lat-lon:
除了
utm
包之外,还有sentinelhub
值得考虑。 它们给出的结果略有不同,但它们比其他贡献者提供的 func utmToLatLng 更接近预期坐标。 Sentinelhub 包有更好的文档记录(可能也维护得更好),并且具有许多其他有用的几何函数。In addition to the
utm
package, there is also thesentinelhub
worth considering. They give slightly different results, but they are closer to the expected coordinates than the funcutmToLatLng
provided by another contributor. Thesentinelhub
package is better documented (probably better maintained too), and has a number of other useful geometric functions.