我有一个地址列表,我对其进行了地理编码以查找其纬度和经度。 地址有两个实体块名和医院。 我有两个latlong列表。现在我想找出哪个医院在哪个区块?怎么做到这一点? 我从列表中输入一些条目,以便可以提高可理解性,原始列表每个块和医院都有大约100个条目。
Blocks List
address lat long accuracy
Ajabpur 30.0431765 78.8255226 locality
UHC Ajabpur 30.0431765 78.8255226 locality
Asan Bag 30.5829083 77.7523608 locality
Ashtad 30.6865869 77.8453043 locality
Badripur 30.2843949 78.0656264 sublocality_level_1
Balawala 30.2661801 78.1062092 sublocality_level_1
Hospitals List
hospitals lat long accuracy
CHC Chakrata 30.7016208 77.8695996 locality
PHC Tuni 30.066753 79.0192997 administrative_area_level_1
SC- Bayala 30.7540332 77.7509303 locality
SAD Bulhar 30.066753 79.0192997 administrative_area_level_1
SAD Hatal 30.066753 79.0192997 administrative_area_level_1
SAD Lakhwar 30.5345496 77.9610158 locality
答案 0 :(得分:3)
这是让你入门的东西。这是over()
(https://cran.r-project.org/web/packages/sp/vignettes/over.pdf)的绝佳资源。
首先,为data_table数据集创建一个缓冲区(gbuffer()
)(多边形)。您可以更改缓冲区的大小。您还需要将data_hop数据集转换为空间数据框。现在你需要验证你的积分是否落入+ zone = 47并确保你有正确的epsg:24047(http://spatialreference.org/ref/epsg/indian-1975-utm-zone-47n/)。我没有得到我想要的输出但我注意到你的某些块的坐标完全相同。请确保解决此问题。
希望这段代码可以帮助您实现目标!
library(sp)
library(rgdal)
library(geosphere)
library(rgeos)
data_table <- read.table(text="
add lat long
Ajabpur 30.0431765 78.8255226
UHCAjabpur 30.0431765 78.8255226
AsanBag 30.5829083 77.7523608
Ashtad 30.6865869 77.8453043
Badripur 30.2843949 78.0656264
Balawala 30.2661801 78.1062092
Ballupur 30.3335862 78.0115041
Barontha 30.066753 79.0192997",
header = TRUE)
#
data_hop <- read.table(text="
hospitals lat long accuracy
CHCChakrata 30.7016208 77.8695996 locality
PHCTuni 30.066753 79.0192997 administrative_area_level_1
SC-Bayala 30.7540332 77.7509303 locality
SADBulhar 30.066753 79.0192997 administrative_area_level_1
SADHatal 30.066753 79.0192997 administrative_area_level_1
SADLakhwar 30.5345496 77.9610158 locality",
header = TRUE)
#
coordinates(data_table) <- ~ long + lat
proj4string(data_table) <- CRS("+proj=utm +zone=47 +ellps=WGS84 +datum=WGS84")
pc <- spTransform(data_table, CRS( "+init=epsg:24047"))
pc10m <- gBuffer(pc, width=10, byid=TRUE)
#
coordinates(data_hop) <- ~ long + lat
proj4string(data_hop) <- CRS("+proj=utm +zone=47 +ellps=WGS84 +datum=WGS84")
WWc <- spTransform(data_hop, CRS("+init=epsg:24047"))
#
testb <- over(WWc, pc10m, returnList = TRUE) #will return a list
test <- over(WWc, pc10m)
#
data_hop2 <- data_hop@data
finalb <- cbind(data_hop2, test)
> finalb
hospitals accuracy add
1 CHCChakrata locality Ajabpur
2 PHCTuni administrative_area_level_1 Ajabpur
3 SC-Bayala locality Ajabpur
4 SADBulhar administrative_area_level_1 Ajabpur
5 SADHatal administrative_area_level_1 Ajabpur
6 SADLakhwar locality Ajabpur