<p>邮政编码之间的距离可以通过<a href="https://github.com/symerio/pgeocode" rel="nofollow noreferrer">pgeocode</a>库获得。与上述响应不同,它不查询web API,因此更适合处理大量数据</p>
<pre><code> >>> import pgeocode
>>> dist = pgeocode.GeoDistance('GB')
>>> dist.query_postal_code('WC2N', 'EH53')
536.5 # retured distance in km
</code></pre>
<p>有关这些邮政编码的更多信息,包括纬度和经度,可以使用</p>
<pre><code> >>> nomi = pgeocode.Nominatim('GB')
>>> nomi.query_postal_code(['WC2N', 'EH53'])
postal_code country code place_name \
0 WC2N GB London
1 EH53 GB Pumpherston, Mid Calder, East Calder, Oakbank
state_name state_code county_name county_code community_name \
0 England ENG Greater London 11609024 NaN
1 Scotland SCT West Lothian WLN NaN
community_code latitude longitude accuracy
0 NaN 51.5085 -0.125700 4.0
1 NaN 55.9082 -3.479025 4.0
</code></pre>
<p>这使用<a href="http://download.geonames.org/export/zip/" rel="nofollow noreferrer">GeoNames postal code dataset</a>获得GPS坐标,然后计算这些坐标上的Haversine(大圆)距离。大多数国家都得到支持。</p>
<p>在英国的特定情况下,只有向外的代码包含在<code>GB</code>数据集中,完整的数据集也可以作为<code>GB_full</code>使用,但它目前是<a href="https://github.com/symerio/pgeocode/issues/4" rel="nofollow noreferrer">not supported</a>在pgeocode中。</p>