将加拿大邮政编码转换为经度和纬度 [英] Convert Canadian Postal Code to Longitude and Latitude

查看:101
本文介绍了将加拿大邮政编码转换为经度和纬度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我列出了100个加拿大邮政编码(例如 M4B 1C7 ).无论如何,是否可以将这些邮政编码转换为近似的经度和纬度值?目前,我正在使用以下网站手动执行此操作:

使用条款(部分):

您不得(也不允许任何第三方)将Zip File纳入任何产品或服务中,进行转售,复制,分发,出售,披露,出借,转让,传达,修改,反编译,反汇编或反向工程Zip出于任何目的归档.

在任何情况下,您都不得:(i)使用来自Zip File的信息来建立数据库,以便转售或与Service Object直接竞争的第三方进行访问;(ii)允许以任何方式使用来自Zip File的信息来验证来自与服务对象直接竞争转售数据的第三方的信息;或(iii)向与服务对象直接竞争转售数据的第三方提供访问Zip File或从Zip File获得的信息,或向计划转售给另一第三方的第三方提供对Zip File或从Zip File获得的信息的访问权或信息.

您同意严格遵守与使用Zip文件有关的所有适用法律和法规.

I have a list of 100 Canadian postal codes (e.g. M4B 1C7). Is there anyway to convert these postal codes into approximate longitude and latitude values? Currently, I am using the following website to do this manually: https://geocoder.ca/

Is there a quicker way to do this in R? I came across the tidygeocoder package , but I am not sure if this will work for Canadian postal codes.

解决方案

As noted by @Dave2e above, the data are available for download here, although you have to register and agree to the terms of use (basically, you can't redistribute the data or break any other laws: I've quoted them below for convenience). It seems weird that the postal code data isn't more conveniently available, but apparently its intellectual property status is contentious - Canada Post sells access to the database.

This solution may not be robust into the future: I have used other sources for this data before, which have then disappeared from the web. The files were available as of 18 April 2021.

Once you've downloaded and unzipped the CSV files, it's pretty straightforward.

library(tidyverse)
cc <- (read_csv("CanadianPostalCodes202104.csv")
 ## if all you want is lat/long: file also includes city, province abbreviation,
 ## time zone - maybe useful for troubleshooting/proofreading
   %>% select(POSTAL_CODE, LATITUDE, LONGITUDE)
   %>% rename(postcode="POSTAL_CODE", lat="LATITUDE", lon="LONGITUDE")
)
mydata <- tibble(postcode=c("M4B 1C7","L8P 2V7"))
mydata_aug <- left_join(mydata, cc, by="postcode")
##   postcode   lat   lon
## 1 M4B 1C7   43.7 -79.3
## 2 L8P 2V7   43.2 -79.9

A picture of the locations (this would be prettier if I bothered to put this into a proper spatial context with province boundaries etc.): I'm not sure what's up with the dozen or so locations that are apparently south of the Canada-US border. For example, this database apparently thinks that Stouffville ON is at 44.8°N 93.3°W, which according to Google maps is smack in the middle of West Bloomington, Minnesota USA: it's actually at 43°58′N 79°15′W according to Wikipedia ...

Terms of use (in part):

You may not (nor allow any third party) to, resell, incorporate Zip File into in any product or services, copy, distribute, sell, disclose, lend, transfer, convey, modify, decompile, disassemble or reverse engineer Zip File for any purpose whatsoever.

You shall not under any circumstances: (i) use information from Zip File to build a database for resale or for access by a third party in direct competition with Service Objects; (ii) allow information from Zip File to be used in any way to verify information from a third party that resells data in direct competition with Service Objects; or (iii) provide access to or information from Zip File to a third party that resells data in direct competition with Service Objects or to a third party that plans to resell to a further third party access to Zip File or information obtained from Zip File.

You agree to comply strictly with all applicable laws and regulations in connection with your use of Zip File.

这篇关于将加拿大邮政编码转换为经度和纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆