我有
1)带有新加坡地图子区域的Shapefile(分段区域 国家地图)
2)Excel电子表格,其中包含每个位置的纬度和经度
如何根据给定的纬度和经度数据确定Excel电子表格中数据的子区域。
提前非常感谢!
答案 0 :(得分:2)
ArcGIS是一个非常强大的GIS软件包,它提供了一系列工具,用于将地理编码点与其他空间数据集进行匹配。我建议你查看空间连接的在线帮助(http://desktop.arcgis.com/en/arcmap/10.3/manage-data/tables/about-joining-the-attributes-of-features-by-their-location.htm)。如果Excel文件只有坐标,则最有可能选择空间连接或内置多边形点工具。如果Excel数据中有子区名称或标识符,则可以使用该字段作为连接的公共标识符直接连接到shapefile数据。
由于ArcGIS始终拥有进行此类点匹配的工具,因此您不需要使用R来执行这些任务,尽管有专业的空间库可用于提供多边形点功能。
答案 1 :(得分:0)
你不应该浪费1,500美元来做这样的事情。
假设我们有一个带有(除其他外)子区边界的新加坡shapefile:
library(sf)
library(tidyverse)
# read in shapefile
singapore <- st_read("~/data/master-plan-2014-subzone-boundary-no-sea-shp/MP14_SUBZONE_NO_SEA_PL.shp", quiet=TRUE, stringsAsFactors=FALSE)
# check CRS
st_crs(singapore)
## Coordinate Reference System:
## No EPSG code
## proj4string: "+proj=tmerc +lat_0=1.366666666666667 +lon_0=103.8333333333333 +k=1 +x_0=28001.642 +y_0=38744.572 +datum=WGS84 +units=m +no_defs"
# your spreadsheet is likely in lat/lng but this shapefile isn't so we'll convert the CRS to lat/lng
singapore <- st_transform(singapore, 4326)
st_crs(singapore)
## Coordinate Reference System:
## EPSG: 4326
## proj4string: "+proj=longlat +datum=WGS84 +no_defs"
# to prove this is, indeed, a singapore map
plot(singapore, max.plot=1)
这是一个“电子表格”(如果您想直接从Excel readxl::read_excel()
读取而不是将其导出为CSV,请使用xlsx
来回复Sinagpore的回收中心:
centers <- read_csv("~/data/recycl.csv")
glimpse(centers)
## Observations: 407
## Variables: 10
## $ lng <dbl> 104.0055, 103.7677, 103.7456, 103.7361, 103.8106, 103.962...
## $ lat <dbl> 1.316764, 1.296245, 1.319204, 1.380412, 1.286512, 1.33355...
## $ inc_crc <chr> "F8907D68D7EB64A1", "ED1F74DC805CEC8B", "F48D575631DCFECB...
## $ name <chr> "RENEW (Recycling Nation's Electronic Waste)", "RENEW (Re...
## $ block_house_num <chr> "10", "84", "698", "3", "2", "1", "1", "1", "357", "50", ...
## $ bldg_name <chr> "Changi Water Reclamation Plant", "Clementi Woods", "Comm...
## $ floor <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N...
## $ post_code <int> 498785, 126811, 608784, 689814, 159047, 486036, 39393, 55...
## $ street <chr> "Changi East Close", "West Coast Road , Clementi Woods Co...
## $ unit <chr> "(Lobby)", "#B1-01 (Management Office)", "(School foyer)"...
我们可以将其转换为简单的功能对象:
map2(centers$lng, centers$lat, ~st_point(c(.x, .y))) %>%
st_sfc(crs = 4326) %>%
st_sf(centers[,-(1:2)], .) -> centers_sf
然后查看每个分区属于哪个分区:
bind_cols(
centers,
singapore[as.numeric(st_within(centers_sf, singapore)),]
) %>%
select(lng, lat, inc_crc, subzone_name=SUBZONE_N) %>% # being selective of fields to display purely for brevity
mutate(subzone_name = str_to_title(subzone_name))
## # A tibble: 407 x 4
## lng lat inc_crc subzone_name
## <dbl> <dbl> <chr> <chr>
## 1 104.0055 1.316764 F8907D68D7EB64A1 Changi Airport
## 2 103.7677 1.296245 ED1F74DC805CEC8B Clementi Woods
## 3 103.7456 1.319204 F48D575631DCFECB Teban Gardens
## 4 103.7361 1.380412 1F910E0086FD4798 Peng Siang
## 5 103.8106 1.286512 55A0B9E7CBD34AFE Alexandra Hill
## 6 103.9624 1.333555 C664D09D9CD5325F Xilin
## 7 103.8542 1.292778 411F79EAAECFE609 City Hall
## 8 103.8712 1.375876 F4516742CFD4228E Serangoon North Ind Estate
## 9 103.8175 1.293319 B05B32DF52D922E7 Alexandra North
## 10 103.9199 1.335878 58E9EAF06206C772 Bedok Reservoir
## # ... with 397 more rows
拿下你节省的1,500美元+,度过一个愉快的假期。