- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想为大约 200 个邮政编码以及与这些邮政编码相关的相邻邮政编码创建一个矩阵。矩阵将为 200*200,其中两个邮政编码接触的单元格为 1,当它们不是相邻邮政编码时为 0。
我如何创建或获得这样的矩阵?非常感谢。
最好,
最佳答案
如果您有权访问 shapefile,那么在 spdep
包的帮助下,这相对简单。
这是一个使用加州邮政编码数据的独立示例(约 3.5MB 下载):
# load libraries
library(rgdal)
library(spdep)
# download, unzip and import shapefile
download.file('http://geocommons.com/overlays/305142.zip', {f<-tempfile()})
unzip(f, exdir=tempdir())
shp <- readOGR(tempdir(), 'tigerline_shapefile_2010_2010_state_california_2010_census_5-digit_zip_code_tabulation_area_zcta5_state-based')
# identify neighbours for each poly
nbs <- setNames(poly2nb(shp), shp$ZCTA5CE10)
# convert to a binary neighbour matrix
nbs.mat <- nb2mat(nbs, zero.policy=TRUE, style='B')
# see?rgeos::gTouches for an alternative to the above steps
# assign zip codes as dimension names
dimnames(nbs.mat) <- list(shp$ZCTA5CE10, shp$ZCTA5CE10)
对于我们的数据集,这会返回一个 1769 x 1769 矩阵,指示哪些邮政编码是相邻的。前 10 行和 10 列如下所示:
nbs.mat[1:10, 1:10]
## 94601 94501 94560 94587 94580 94514 94703 95601 95669 95901
## 94601 0 1 0 0 0 0 0 0 0 0
## 94501 1 0 0 0 0 0 0 0 0 0
## 94560 0 0 0 0 0 0 0 0 0 0
## 94587 0 0 0 0 0 0 0 0 0 0
## 94580 0 0 0 0 0 0 0 0 0 0
## 94514 0 0 0 0 0 0 0 0 0 0
## 94703 0 0 0 0 0 0 0 0 0 0
## 95601 0 0 0 0 0 0 0 0 0 0
## 95669 0 0 0 0 0 0 0 0 0 0
## 95901 0 0 0 0 0 0 0 0 0 0
如果您想要一个两列矩阵,给出相邻的邮政编码对(即第 1 列中的邮政编码和第 2 列中的相邻邮政编码),您可以使用以下内容。
nbs.list <- sapply(row.names(nbs.mat), function(x) names(which(nbs.mat[x, ] == 1)))
nbs.pairs <- data.frame(zipcode=rep(names(nbs.list), sapply(nbs.list, length)),
neighbour=unlist(nbs.list))
head(nbs.pairs)
## zipcode neighbour
## 946011 94601 94501
## 946012 94601 94602
## 946013 94601 94605
## 946014 94601 94606
## 946015 94601 94621
## 946016 94601 94619
关于r - 如何查找与特定邮政编码相关的其他邮政编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22652069/
我正在编写一个 VBA 脚本,用于查找指定半径内的邮政编码。我有一个 Access 数据库,表中有多个记录。每条记录在表中都有一个名称、地址和邮政编码字段。 Access 时的 VBA 代码提示用户输
我遇到了以下问题: 定义一个函数 postalValidate(S) ,它首先检查 S 是否代表一个有效的邮政编码:首先,删除所有空格;余数必须是 L#L#L# 的形式,其中 L 是字母(小写或大写)
我试图仅检索此脚本中的邮政编码字段。 有没有办法只返回这个值? function LookuptableWend(query) { var tr = document.get
我正在开发一个自定义验证器来验证和替换(如果可能)邮政编码。这是荷兰邮政编码,应类似于“5050 AA”。当用户输入“5050AA”时,该邮政编码应替换为“5050 AA”。我通过将以下脚本添加到我的
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求提供代码的问题必须表现出对所解决问题的最低限度的了解。包括尝试的解决方案、为什么它们不起作用以及预期结果
我有一个工作板,用户可以通过 Google-Maps API 提交他的位置,该 API 在 map 上绘制工作。 问题是,因为它是一个基于位置的工作板,所以我想允许最广泛的输入是邮政编码(这样用户可以
在我的 php 文件上使用此功能时,我不断出现空屏幕,XML 文件中没有属性 // Get parameters from URL $center_lat = ( isset( $_GET["
我如何防止接收带有子站点的城市并只接收最大的村庄。 示例: 目前我得到 2 条记录,第一个是主要城市,第二个是邻居。但我只想要主要城镇。 CH 8280 Kreuzlingen CH
对不起,我迷路了。我正在尝试构建一个搜索页面,该页面使用英国邮政编码或位置来查找气枪网站(我们称它们为“商店”,这样我就不必向那些不知道气枪是什么的人解释),每个store 我在邮政编码、县、城镇/城
我对 SQL 查询有点困惑。 用户应该能够搜索邮政编码、公司名称或位置 我有下表: 公司表 companyid | name | location 1 Sh
是的,我一直在努力研究如何将给定的邮政编码与商店地址的数据库进行比较,并根据哪个最接近给定的邮政编码(我猜是邮政编码)对它们进行排序。 这主要是出于兴趣,而不是我征求你的意见然后卖给客户:-O 首先,
我想从地址字符串中提取阿尔伯塔(加拿大)地区的邮政编码。 例如: addr = '12345-67 Ave, Edmonton, AB T1A 2B3, Canada' 应该提取T1A 2B3。 匹
我需要重新格式化英国邮政编码列表,并从以下内容开始去除空格和大写: postcode.upcase.gsub(/\s/,'') 我现在需要更改邮政编码,以便新邮政编码的格式与以下正则表达式匹配: ^(
我创建了一个基于列名检索范围的函数。这是我的代码: Sub sep_Filter() Dim zip_rng As String With Sheet2 zip_rng
获取给定国家的给定邮政编码/邮政编码的坐标(纬度/经度)的最完整、精确和可靠的方法是什么?我需要发出大量请求,因此高 API 限制率(甚至可能不存在)会很有用。 GeoNames转储会很酷,但它似乎有
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
如何在 Opencart 版本 2.1.0.2 的付款方式选项卡中发布发货城市或邮政编码的数据 我想将 COD 限制在某些城市。有人可以帮我吗? 最佳答案 创建自定义表来存储可用的邮政编码。为产品列表
将其设置为名为customers / customer的索引/类型。 此集合的每个文档都有一个邮政编码属性。 邮政编码基本上可以像这样: 字符串-字符串(例如:8907-1009) 字符串字符串(例如
我现在正在使用 Map Kit 和 Core Location,需要从邮政编码或城市/州获取位置信息。有什么办法吗? 最佳答案 您可以使用 CLGeocoder支持将地址转换为坐标以及反向转换的类。例
我当前的应用程序需要存储用户的地址信息。我目前正在争论是使用惯用的街道地址/城市/州/ zip 文本框和下拉菜单,还是采用 Google 的方法,将所有内容都放在一行上。关于以这两种方式存储地址信息的
我是一名优秀的程序员,十分优秀!