首页 > 解决方案 > 将带有坐标的数据框和带有 shapefile 的数据框结合起来,以创建带有多边形和点的地图

问题描述

我在这个 .gdb文件夹中有以下地图边界

在这里我有一个 csv,其中包含我要绘制的变量以及需要在地图上显示的点的坐标。我的最终目标是创建一个带有多边形的地图,并且在每个多边形内都应该有学生 ID 的点。

我用 :

library(rgeos)
library(sp)
library(rgdal)


# The input file geodatabase-change the filepath when you download the gdb folder
fgdb <- "C:/Users/makis/Documents/school/TPS_school_boundaries_2017.gdb"

fc <- readOGR(dsn=fgdb,layer="TPS_high_school_bdy" )


#Load the csv file and name it s
    s2<-data.frame(s)


# Assignment modified according
coordinates(s2) <-  c('lon', 'lat')


# Set the projection of the SpatialPointsDataFrame using the projection of the shapefile
proj4string(s2) <- proj4string(fc)

final<-over(fc,s2)

但是我得到了一个充满 NA 的无用数据框

标签: rsprgdal

解决方案


推荐阅读