久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何計算兩個 ZIP 之間的距離?

How to calculate Distance between two ZIPs?(如何計算兩個 ZIP 之間的距離?)
本文介紹了如何計算兩個 ZIP 之間的距離?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個美國郵政編碼列表,我必須計算所有郵政編碼點之間的距離.它是一個 6k 長的 ZIP 列表,每個實體都有 ZIP、City、State、Lat、Long、Area 和 Population.

I have a list of US ZIP codes and I have to calculate distance between all the ZIP Code Points. Its a 6k ZIPs long list, each entity has ZIP, City, State, Lat, Long, Area and Population.

所以,我必須計算所有點之間的距離,即;6000C2組合.

So, I have to calculate distance between all the points, ie; 6000C2 combinations.

這是我的數據示例

我已經在 SAS 中嘗試過,但它太慢且效率低下,因此我正在尋找一種使用 Python 或 R 的方法.

I've tried this in SAS but its too slow and inefficient, hence I'm looking for a way using Python or R.

任何線索將不勝感激.

推薦答案

Python解決方案

如果您有郵政編碼對應的緯度和經度,您可以通過使用'mpu'庫的Haversine公式直接計算它們之間的距離,該庫確定球體上兩點之間的大圓距離.

If you have the corresponding latitudes and longitudes for the Zip codes, you can directly calculate the distance between them by using Haversine formula using 'mpu' library which determines the great-circle distance between two points on a sphere.

示例代碼:

import mpu

zip_00501 =(40.817923,-73.045317)
zip_00544 =(40.788827,-73.039405)

dist =round(mpu.haversine_distance(zip_00501,zip_00544),2)
print(dist)

您將獲得以公里為單位的合成距離.輸出:

You will get the resultant distance in kms. Output:

3.27

PS.如果您沒有相應的郵政編碼坐標,您可以使用uszipcode"庫的SearchEngine"模塊獲得相同的坐標(僅適用于美國郵政編碼)

PS. If you don't have the corresponding coordinates for the zip codes, you can get the same using 'SearchEngine' module of 'uszipcode' library (only for US zip codes)

from uszipcode import SearchEngine
#for extensive list of zipcodes, set simple_zipcode =False
search = SearchEngine(simple_zipcode=True)

zip1 = search.by_zipcode('92708')
lat1 =zip1.lat
long1 =zip1.lng

zip2 =search.by_zipcode('53404')
lat2 =zip2.lat
long2 =zip2.lng

mpu.haversine_distance((lat1,long1),(lat2,long2))

希望這會有所幫助!

這篇關于如何計算兩個 ZIP 之間的距離?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How should I verify a log message when testing Python code under nose?(在鼻子下測試 Python 代碼時,我應該如何驗證日志消息?)
Patch __call__ of a function(修補函數的 __call__)
How to call self in a mock method of an object in Python?(如何在 Python 中對象的模擬方法中調用 self?)
Mocking only a single method on an object(僅模擬對象上的單個方法)
Mocking a subprocess call in Python(在 Python 中模擬子進程調用)
Checking call order across multiple mocks(檢查多個模擬的調用順序)
主站蜘蛛池模板: 精品免费国产一区二区三区四区 | 国产在线观看一区二区三区 | 亚洲一区在线日韩在线深爱 | 免费观看黄色片视频 | 国产成人免费视频 | 午夜大片 | 国产午夜精品一区二区三区嫩草 | 北条麻妃视频在线观看 | 日本精品久久 | 亚洲成人播放器 | 91久久国产综合久久 | 精品在线一区二区 | 日本午夜精品 | 国产精品美女久久久久aⅴ国产馆 | 久久中文一区二区 | 欧美一区二区三区国产 | 国产高清精品网站 | 国产精品久久久久久久久久久免费看 | 国产精品成人一区二区三区 | 国产毛片久久久久久久久春天 | 国产电影一区 | 日韩精品免费视频 | 中文字幕在线第二页 | 美女一级毛片 | 成人在线中文字幕 | 国产一区二区三区四区hd | 色精品视频 | 久久成 | 夜久久 | 亚洲精品www | 中文字幕日本一区二区 | 日韩午夜一区二区三区 | 一区免费观看 | 成人一级片在线观看 | 伊人最新网址 | 国产一区免费视频 | 欧美精品久久 | 欧美黑人狂野猛交老妇 | 亚洲福利视频网 | 免费一区二区三区 | 免费黄色在线 |