如何获取网格中相交的多边形的面积?

时间:2019-07-19 17:19:23

标签: r gis polygon

我一直在尝试在250m x 250m的网格中获得大量多边形的面积。但是当我在gIntersection中使用函数regos时,与250 x 250网格相交的某些多边形区域的面积大于250 x 250。 250 * 250 = 62500 因此,我真的很想解决此问题,并且听说如果使用函数spTransform,原始区域没有更改,对吗? 我完全想要我的问题和解决方案。 我的代码如下。谢谢。

seoul <- rgdal :: readOGR(dsn = 'D:/seoul_inform/seoullayer',
                      layer = 'seoulreal',
                      encoding = 'UTF-8')

proj4string(seoul) <- CRS(" +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")

seoul_t <- spTransform(seoul, CRS("+proj=tmerc +lat_0=38 +lon_0=127 +k=1 +x_0=200000 +y_0=600000 +ellps=GRS80 +units=m +no_defs"))

Seoulbb <- bbox(seoul_t)

Seoulgrd <- GridTopology(cellcentre.offset = c(Seoulbb[1,1]+100,                         Seoulbb[2,1]+100), 
                     cellsize = c(250, 250), 
                     cells.dim = c(149,122))


int.layer <- SpatialPolygonsDataFrame(as.SpatialPolygons.GridTopology(Seoulgrd), 
                                  data = data.frame(c(1:18178)), 
                                  match.ID = FALSE)

names(int.layer) <- "ID"

proj4string(int.layer) <- CRS("+proj=tmerc +lat_0=38 +lon_0=127 +k=1     +x_0=200000 +y_0=600000 +ellps=GRS80 +units=m +no_defs")

int.layer <- spTransform(int.layer, CRS(" +proj=longlat +datum=WGS84     +no_defs +ellps=WGS84 +towgs84=0,0,0"))
#+proj=tmerc +lat_0=38 +lon_0=127 +k=1 +x_0=200000 +y_0=600000     +ellps=GRS80 +units=m +no_defs
#Intersection
int.res <- gIntersection(int.layer, seoul, byid = T)

tmp <- strsplit(names(int.res)," ")

seoul_t.id <- (sapply(tmp, "[[", 2))

intlayer.id <- (sapply(tmp,"[[",1))

int.areas <- gArea(int.res, byid = T)

tracts.areas.seoul <- gArea(seoul_t, byid = T)

index <- match(seoul_t.id, row.names(seoul_t))

tracts.areas.seoul <- tracts.areas.seoul[index]

prop.seoul <- zapsmall(int.areas/tracts.areas.seoul, 3)

areas_seoul <- zapsmall(tracts.areas.seoul*prop.seoul, 1)

df <- data.frame(intlayer.id, prop.seoul)

df <- data.frame(df, areas_seoul)

int.res.seoul.areas <- xtabs(df$areas_seoul ~ df$intlayer.id)

index <- as.numeric(gsub("g", " ", names(int.res.seoul.areas)))

tmp <- vector("numeric", length = dim(data.frame(int.layer))[1])

tmp[index] <- int.res.seoul.areas

i.seoul <- tmp

int.layer.seoul <- SpatialPolygonsDataFrame(int.layer,
                                           data =              data.frame(data.frame(int.layer), i.seoul), match.ID = FALSE)

0 个答案:

没有答案