地理坐标表示方法

LatLon的Python项目详细描述


功能

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

  • 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 LatLon

需要以下非标准库:

  • 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.2-使用EclipseIdle在Python2.7上测试。有什么问题请告诉我。

变更日志

1.0.2(2014年10月14日)

  • Class GeoVector is now an abstract class to ensure that any subclasses use the correct API
  • Added methods range180 and range360 to class Longitude to interconvert between longitudes reported -180 to 180 format and those reported in 0 to 360 format. To ensure that all operations such as hemisphere assignment work as expected, longitudes reported in 0 to 360 format are automatically converted into -180 to 180 format when the Longitude object is initialized.

1.0.1(2014年9月2日)

  • Fixed issue with where attribute theta in GeoVector was treated in some cases like a heading (i.e. starting with due north and continuing clockwise) even though it was in fact an angle (i.e. starting with (1, 0) and continuing anti-clockwise). The attribute name has now been changed to heading to eliminate confusion. The local variable theta is used for computations involving angle.
  • Added testing functions with pytest for class LatLon and GeoVector
  • Added almost_equal methods to class LatLon and GeoVector to deal with float errors in decimal degree specification
  • LatLon.project now returns (x, y) instead of (y, x) to be more consistent with the accepted convention.

^{str 1}0.91美元(2014年8月28日)

  • degree, minute and second attributes for GeoCoord class are now coerced to type float

^{str 1}0.90美元(2014年8月28日)

  • Updated magic methods for GeoCoord class
  • Added option for instantiating LatLon from scalars

^{str 1}0.80美元(2014年8月27日)

  • Added GeoVector class to handle vectors between two LatLon objects
  • Cleaned up __str__ and __repr__ methods for LatLon, Latitude, Longitude, GeoCoord, and GeoVector classes

^{str 1}0.70美元(2014年8月27日)

  • Deprecated LatLon.distance_sphere method. From now on use distance(other, ellipse = ‘sphere’) instead
  • Added LatLon.bearing method to return the initial bearing between two LatLon objects
  • Added LatLon.offset method to return a new LatLon object that is computed from an initial LatLon object plus a bearing and distance

^{str 1}0.60美元(2014年8月27日)

  • Added compatibility with comparison, negation, addition and multiplication magic methods

^{str 1}0.50美元(2014年8月20日)

  • First release

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

推荐PyPI第三方库


热门话题
安卓在java中加入字符串组以创建复合字符串   java系统甚至不点击“下一步”或“上一步”按钮就将我返回到上一页,而不是进入下一页   java如何在arrayList中获取特定列的不同值   CXF GZIP REST JAVA   Java:使用大量半恒定标志检查优化循环中的循环?   java如何在两个应用程序之间进行会话管理?   java SVG文件使用蜡染(但没有轴线)转换为PNG   使用协议缓冲区和内部数据模型的java   java如何在logtag 安卓中打印和查看字符串的值   javascript如何在NodeJs中应用Java/Spring的分层架构?   java Spring URL在JSP中编码不正确   模式对话框后面的java工具提示   java WSRPC生成日历对象而不是日期   在对象外部无法识别类变量   java将图像从文件读/写到BuffereImage的最快方法?   JavaSpring数据存储库对具有不同Id的子类使用抽象超类   安全在Java 5.0上运行web应用程序服务器有危险吗?