将多边形中的属性添加到R​​中具有不同多边形的不同图层

问题描述

我一直在尝试进行似乎有点困难的地理处理。我有两个具有不同几何形状的形状图层,一个图层包含数据,另一图层包含空白。

我正在尝试从一层提取数据并将其与面积成比例地添加到另一层。例子....

Layer 1

Layer 2

形状看起来非常相似,但是多边形却不同。一个拥有有关给定区域总人口的数据。我想按比提取该信息并将其添加到另一层(想象第二层有一个多边形,该多边形适合一个多边形,另一半适合另一个多边形,所以我想按比获取该人口)。

我的第一种方法是将所有内容转换为栅格,然后提取栅格像素的数据。这适用于一些我可以获取的数据,但不适用于我必须对多边形中的所有数据求和的数据。我向您展示了这种方法

# 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 (将#修改为@)