地理坐标表示方法

LatLon23的Python项目详细描述


板条

许可证/分叉信息

Copyright (c) 2014-2015 Gen Del Raye
Copyright (c) 2015 Ryan Vennell

This is a derivative, forked from the original work by:
Gen Del Raye <gdelraye@hawaii.edu> and located at:
https://pypi.python.org/pypi/LatLon

Licensed under the GPLv3: http://www.gnu.org/licenses/gpl-3.0.html

The purpose of this fork is to provide full Python3 (and Python2)
support in light of the fact that the original work has no public
repository which can be contributed to or traditionally forked.

功能

表示地理坐标(纬度和经度)的方法,包括:

  • Convert lat/lon strings from almost any format into a LatLon object (analogous to the datetime library’s stptime method)
  • Automatically store decimal degrees, decimal minutes, and degree, minute, second information in a LatLon object
  • Output lat/lon information into a formatted string (analogous to the datetime library’s strftime method)
  • Project lat/lon coordinates into some other proj projection
  • Calculate distance and heading between lat/lon pairs using either the FAI or WGS84 approximation
  • Create a new LatLon object by offsetting an initial coordinate by a distance and heading
  • Subtracting one LatLon object from another creates a GeoVector object with distance and heading attributes (analogous to the datetime library’s timedelta object)
  • Adding or subtracting a Latlon object and a GeoVector object creates a new LatLon object with the coordinates adjusted by the GeoVector object’s distance and heading
  • GeoVector objects can be added, subtracted, multiplied or divided

安装

latlon只在python 2.7中测试过

通过PIP安装:

$ pip install LatLon23

通过PIP安装:

$ pip3 install LatLon23

需要以下非标准库:

  • pyproj

使用说明

使用latlon主要是通过类latlon来实现的,该类旨在容纳 纬度经度对象。使用此方法可以将字符串转换为latlon对象 string2laton,并使用string2geocord指向latitudelongitude对象。或者,拿铁条 对象可以通过减去两个latlon对象,或加上或减去latlon对象来构造。 以及一个geoviector对象。

纬度或经度结构

经度构造的纬度分别通过latitudelongitude类。你可以 以十进制度数、度数和分钟的任意组合传递纬度或经度坐标,或 度分秒。或者,可以使用函数string2geocord传递格式化字符串。 对于包含单个纬度或经度的字符串,或者对于表示 纬度和经度。

字符串格式:

string2latonstring2geocoord都采用formatter字符串,该字符串松散地基于formatdatetime的strftime函数中使用的关键字。指示符(例如hd)放在 一个特定的分隔符(%),用于指定坐标字符串的格式。可能的 值如下:

*H* is a hemisphere identifier (e.g. N, S, E or W)

*D* is a coordinate in decimal degrees notation (e.g. 5.833)

*d* is a coordinate in degrees notation (e.g. 5)

*M* is a coordinate in decimal minutes notation (e.g. 54.35)

*m* is a coordinate in minutes notation (e.g. 54)

*S* is a coordinate in seconds notation (e.g. 28.93)

Any other characters (e.g. ' ' or ', ') will be treated as a separator between the above components.

All components should be separated by the *%* character. For example, if the coord_str is '5, 52,
59.88_N', the format_str would be 'd%, %m%, %S%_%H'

重要

一种当前不起作用的格式是半球标识符和度数或十进制度数 不被任何字符分隔。例如,“55259.88N”有效,而“55259.88N”无效。

字符串输出:

latlonlatitudelongitude对象都包含用于输出格式化的 协调。

投影:

使用latlon.project将地理坐标转换为选定的投影。要求你通过 pyprojbasemap投影。

距离和航向计算:

latlon对象有一个distance()方法,该方法接受第二个latlon对象作为参数。distance()将 默认情况下,使用WGS84椭球计算两个坐标之间的大圆距离。使用 更近似的FAI球,将^ {EM1}椭圆“EEM”设为“球面”。可以计算初始和反向航向(以度为单位) 以类似的方式使用heading_initial()heading_reverse()方法。或者,减去一 latlon另一个对象将返回一个带有属性heading和distance的geoviector对象。

通过与另一个对象的偏移量创建新的latlon对象:

使用latlon对象的offset()方法,它将初始航向(以度为单位)和距离(以公里为单位)设置为 在偏移坐标处返回一个新的latlon对象。此外,您还可以执行通过添加或 用地理矢量对象减去latlon对象。

示例

从坐标创建一个latlon对象:

>> palmyra = LatLon(Latitude(5.8833), Longitude(-162.0833)) # Location of Palmyra Atoll in decimal degrees
>> palmyra = LatLon(5.8833, -162.0833) # Same thing but simpler!
>> palmyra = LatLon(Latitude(degree = 5, minute = 52, second = 59.88),
>>                  Longitude(degree = -162, minute = -4.998) # or more complicated!
>> print palmyra.to_string('d% %m% %S% %H') # Print coordinates to degree minute second
('5 52 59.88 N', '162 4 59.88 W')

从格式化字符串创建latlon对象:

>> palmyra = string2latlon('5 52 59.88 N', '162 4 59.88 W', 'd% %m% %S% %H')
>> print palmyra.to_string('d%_%M') # Print coordinates as degree minutes separated by underscore
('5_52.998', '-162_4.998')

执行一些计算:

>> palmyra = LatLon(Latitude(5.8833), Longitude(-162.0833)) # Location of Palmyra Atoll
>> honolulu = LatLon(Latitude(21.3), Longitude(-157.8167)) # Location of Honolulu, HI
>> distance = palmyra.distance(honolulu) # WGS84 distance in km
>> print distance
1766.69130376
>> print palmyra.distance(honolulu, ellipse = 'sphere') # FAI distance in km
1774.77188181
>> initial_heading = palmyra.heading_initial(honolulu) # Heading from Palmyra to Honolulu on WGS84 ellipsoid
>> print initial_heading
14.6907922022
>> hnl = palmyra.offset(initial_heading, distance) # Reconstruct Honolulu based on offset from Palmyra
>> print hnl.to_string('D') # Coordinates of Honolulu
('21.3', '-157.8167')

使用geovestors操作latlon对象:

>> vector = (honolulu - palmyra) * 2 # A GeoVector with 2x the magnitude of a vector from palmyra to honolulu
>> print vector # Print heading and magnitude
14.6907922022 3533.38260751
print palmyra + (vector/2.0) # Recreate the coordinates of Honolulu by adding half of vector to palmyra
21.3, -157.8167

版本

更改日志

1.0.7(2015年3月29日)

  • Forked from original work: https://pypi.python.org/pypi/LatLon
  • Added Python3 support and refactored a bit of the code
  • Updated Readme to correct issues and provide proper attribution
  • Adding MANIFEST.in

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
带有嵌套JAR的java RCP ClassNotFoundException   java在输入框中设置默认值,crud应用程序使用spring   java如何在Heroku中使用fs创建新文件   java将JPanel放在JFrame中   java这个正则表达式会匹配“i.imgur.com/xxx”吗?   java在片段内创建RecylerView,而无需在Android中设置片段   Android上Groovy导致java错误的双精度浮点精度损失   swing Java查找JFrame属于JPanel的内容   java Spring junit自连线自定义类本身必须有构造函数吗?   java textswitcher支持前面的文本   从Android客户端到JAXRS的java Post自定义对象   java如何检索JSON数据并使用MPAndroidChart绘制折线图,以及在安卓上的改进   拒绝用户“root”@“localhost”的java c3p0访问(使用密码“是”)   使用Selenium Webdriver自动化ExtJS应用程序时java面临的问题