如何解决将多边形中的属性添加到R中具有不同多边形的不同图层
我一直在尝试进行似乎有点困难的地理处理。我有两个具有不同几何形状的形状图层,一个图层包含数据,另一图层包含空白。
我正在尝试从一层提取数据并将其与面积成比例地添加到另一层。例子....
形状看起来非常相似,但是多边形却不同。一个拥有有关给定区域总人口的数据。我想按比例提取该信息并将其添加到另一层(想象第二层有一个多边形,该多边形适合一个多边形,另一半适合另一个多边形,所以我想按比例获取该人口)。
我的第一种方法是将所有内容转换为栅格,然后提取栅格像素的数据。这适用于一些我可以获取的数据,但不适用于我必须对多边形中的所有数据求和的数据。我向您展示了这种方法:
# Lecture of the first layer
Zonificacion <- shapefile("Zonificacion.shp")
proj4string(Zonificacion) <- CRS("+init=EPSG:4326")here
# Lecture of the second layer
zoificacion_2 <- readOGR("marginacion.shp")
### Transform the first layer in raster
r <- raster(extent(Zonificacion_2)) # creates a raster with the extent of this layer
projection(r) <- proj4string(Zonificacion_2) # uses the projection of the shapefile for the raster
res(r)= 0.001 # sets the resolution of the raster to 10 m
r10 <- rasterize(Zonificacion_2,field="IMU2010",r)
plot(r10)
# Extracting the values of the raster to the other layer
rasValue=extract(r10,Zonificacion,fun= mean)
#Tranform it to a data frame
df <- data.frame(matrix(unlist(rasValue),nrow=length(rasValue),byrow=T))
names(agebs)[names(agebs) == "CVE_AGEB"] <- "AGEB"
希望您能帮助我,我已经表示清楚了。
最好的问候, 奥兰多
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。