私はPythonを初めて使用していて、このexampleを再構築したいと考えています。私はNYCタクシーのピックアップとドロップオフに関する経度と緯度のデータを持っていますが、データをWeb Mercartorフォーマットに変更する必要があります(これは上記の例では見つかりません)。 私は次のように見え、経度と緯度の値のペアを1つ取り、hereから撮影されたWeb Mercartor形式に変更することができます機能が見つかりました:Pandas Dataframeのすべての行に関数を適用します。
import math
def toWGS84(xLon, yLat):
# Check if coordinate out of range for Latitude/Longitude
if (abs(xLon) < 180) and (abs(yLat) > 90):
return
# Check if coordinate out of range for Web Mercator
# 20037508.3427892 is full extent of Web Mercator
if (abs(xLon) > 20037508.3427892) or (abs(yLat) > 20037508.3427892):
return
semimajorAxis = 6378137.0 # WGS84 spheriod semimajor axis
latitude = (1.5707963267948966 - (2.0 * math.atan(math.exp((-1.0 * yLat)/semimajorAxis)))) * (180/math.pi)
longitude = ((xLon/semimajorAxis) * 57.295779513082323) - ((math.floor((((xLon/semimajorAxis) * 57.295779513082323) + 180.0)/360.0)) * 360.0)
return [longitude, latitude]
def toWebMercator(xLon, yLat):
# Check if coordinate out of range for Latitude/Longitude
if (abs(xLon) > 180) and (abs(yLat) > 90):
return
semimajorAxis = 6378137.0 # WGS84 spheriod semimajor axis
east = xLon * 0.017453292519943295
north = yLat * 0.017453292519943295
northing = 3189068.5 * math.log((1.0 + math.sin(north))/(1.0 - math.sin(north)))
easting = semimajorAxis * east
return [easting, northing]
def main():
print(toWebMercator(-105.816001, 40.067633))
print(toWGS84(-11779383.349100526, 4875775.395628653))
if __name__ == '__main__':
main()
私はすべてのペアに、このデータを適用するにはどうすればよいです私のpandas Dataframeのlong/lat座標系を使用し、出力を同じpandasDFに保存しますか?
df.tail()
| longitude | latitude
____________|__________________|______________
11135465 | -73.986893 | 40.761093
1113546 | -73.979645 | 40.747814
11135467 | -74.001244 | 40.743172
11135468 | -73.997818 | 40.726055
...
ありがとう、これは本当に非常に速く、とても役に立ちました。 – CFM