那里有什么工具?我应该使用什么?
#1 楼
以下是一些可能有用的链接:http://www.koders.com/python/fid0A930D7924AE856342437CA1F5A9A3EC0CAEACE2.aspx
http://code.activestate.com/recipes/393241-calculating -the-distance-between-zip-codes /
#2 楼
pyproj具有Geod.npts函数,该函数将沿路径返回一个点数组。请注意,它在数组中不包含终端点,因此您需要考虑它们:import pyproj
# calculate distance between points
g = pyproj.Geod(ellps='WGS84')
(az12, az21, dist) = g.inv(startlong, startlat, endlong, endlat)
# calculate line string along path with segments <= 1 km
lonlats = g.npts(startlong, startlat, endlong, endlat,
1 + int(dist / 1000))
# npts doesn't include start/end points, so prepend/append them
lonlats.insert(0, (startlong, startlat))
lonlats.append((endlong, endlat))
评论
谢谢!由知名和大量使用的图书馆在这里提供的解决方案:)
–tdihp
2015年11月6日,凌晨2:14
#3 楼
GeographicLib具有python界面:它可以在椭球体上进行大地测量(将展平设置为零以获得大圆),并可以在大地测量上生成中间点(请参见示例中的“ Line”命令) 。
以下是在从肯尼迪国际机场(JFK)到樟宜机场(新加坡)的测地线上打印点的方法:
from geographiclib.geodesic import Geodesic
geod = Geodesic.WGS84
g = geod.Inverse(40.6, -73.8, 1.4, 104)
l = geod.Line(g['lat1'], g['lon1'], g['azi1'])
num = 15 # 15 intermediate steps
for i in range(num+1):
pos = l.Position(i * g['s12'] / num)
print(pos['lat2'], pos['lon2'])
->
(40.60, -73.8)
(49.78, -72.99)
(58.95, -71.81)
(68.09, -69.76)
(77.15, -65.01)
(85.76, -40.31)
(83.77, 80.76)
(74.92, 94.85)
...
评论
现在可以在pypi.python.org/pypi/geographiclib中获得GeographicLib的python端口
– cffk
2011年10月8日12:28
另请参阅本文:C. F. F. Karney,《大地测量学算法》,J。Geod,DOI:dx.doi.org/10.1007/s00190-012-0578-z
– cffk
2012年9月1日19:12在
#4 楼
其他人提供的答案则稍微优雅一些,但这是一个超简单的,有点怪异的Python,提供了基础知识。该函数采用两个坐标对和用户指定的段数。它沿着大圆路径产生了一组中间点。输出:准备写为KML的文本。注意事项:该代码未考虑对映体,并假定是球形地球。Alan Glennon的代码,http://enj.com,2010年7月(作者将此代码置于公共领域。请自行使用风险)。
-
定义过渡段(经度1,纬度1,经度2,纬度2,段数):
import math
ptlon1 = longitude1
ptlat1 = latitude1
ptlon2 = longitude2
ptlat2 = latitude2
numberofsegments = num_of_segments
onelessthansegments = numberofsegments - 1
fractionalincrement = (1.0/onelessthansegments)
ptlon1_radians = math.radians(ptlon1)
ptlat1_radians = math.radians(ptlat1)
ptlon2_radians = math.radians(ptlon2)
ptlat2_radians = math.radians(ptlat2)
distance_radians=2*math.asin(math.sqrt(math.pow((math.sin((ptlat1_radians-ptlat2_radians)/2)),2) + math.cos(ptlat1_radians)*math.cos(ptlat2_radians)*math.pow((math.sin((ptlon1_radians-ptlon2_radians)/2)),2)))
# 6371.009 represents the mean radius of the earth
# shortest path distance
distance_km = 6371.009 * distance_radians
mylats = []
mylons = []
# write the starting coordinates
mylats.append([])
mylons.append([])
mylats[0] = ptlat1
mylons[0] = ptlon1
f = fractionalincrement
icounter = 1
while (icounter < onelessthansegments):
icountmin1 = icounter - 1
mylats.append([])
mylons.append([])
# f is expressed as a fraction along the route from point 1 to point 2
A=math.sin((1-f)*distance_radians)/math.sin(distance_radians)
B=math.sin(f*distance_radians)/math.sin(distance_radians)
x = A*math.cos(ptlat1_radians)*math.cos(ptlon1_radians) + B*math.cos(ptlat2_radians)*math.cos(ptlon2_radians)
y = A*math.cos(ptlat1_radians)*math.sin(ptlon1_radians) + B*math.cos(ptlat2_radians)*math.sin(ptlon2_radians)
z = A*math.sin(ptlat1_radians) + B*math.sin(ptlat2_radians)
newlat=math.atan2(z,math.sqrt(math.pow(x,2)+math.pow(y,2)))
newlon=math.atan2(y,x)
newlat_degrees = math.degrees(newlat)
newlon_degrees = math.degrees(newlon)
mylats[icounter] = newlat_degrees
mylons[icounter] = newlon_degrees
icounter += 1
f = f + fractionalincrement
# write the ending coordinates
mylats.append([])
mylons.append([])
mylats[onelessthansegments] = ptlat2
mylons[onelessthansegments] = ptlon2
# Now, the array mylats[] and mylons[] have the coordinate pairs for intermediate points along the geodesic
# My mylat[0],mylat[0] and mylat[num_of_segments-1],mylat[num_of_segments-1] are the geodesic end points
# write a kml of the results
zipcounter = 0
kmlheader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><kml xmlns=\"http://www.opengis.net/kml/2.2\"><Document><name>LineString.kml</name><open>1</open><Placemark><name>unextruded</name><LineString><extrude>1</extrude><tessellate>1</tessellate><coordinates>"
print kmlheader
while (zipcounter < numberofsegments):
outputstuff = repr(mylons[zipcounter]) + "," + repr(mylats[zipcounter]) + ",0 "
print outputstuff
zipcounter += 1
kmlfooter = "</coordinates></LineString></Placemark></Document></kml>"
print kmlfooter
#5 楼
geopy适用于Python的地理编码工具箱
http://code.google.com/p/geopy/wiki/GettingStarted#Calculating_distances
评论
+1没看到沿测地线做中间点的功能,但是知道的很好的工具集(处理椭球体计算)。谢谢。
– Glennon
2010年8月6日在17:09
#6 楼
我还没有使用过这个软件包,但是它看起来很有趣,并且是一个可能的解决方案:http://trac.gispython.org/lab/wiki/Shapely
评论
AFAIK,shapely不进行球面计算:Shapely是一个Python软件包,用于集理论分析和“ **”功能的处理
–fmark
2010年7月25日在20:03
评论
请注意,koders.com链接已死,已重定向到ohloh。
–scruss
13年7月26日在12:04