natural neighbour interpolation. error in calculating polygon intersection area

老子叫甜甜 提交于 2019-12-03 20:30:36

The problem with this code is in the second for loop where the function gIntersection has been used. In this function the intersection of the polygon:

SpatialPolygons(vor.temp@polygons[110])

and all the polygons of vor.temp has been calculated and it is obvious that there will be no intersection between those polygons because they all are belong to one Voronoi. In the gIntersection the second argument should be changed from:

SpatialPolygons(vor.temp@polygons[i])

to:

SpatialPolygons(v2@polygons[i])

Now the gIntersection function will obtain the intersection polygon of the SpatialPolygons(vor.temp@polygons[110]) and all the polygons from the first Voronoi (v2)

The other problem is using gArea function. I did not get the purpose of using overlaid.poly. The input of function gArea is a polygon, so we can set input of this function as s since the intersection polygon has been obtain already using gIntersection function as object s. So in the if statement we would have:

gArea(s)

instead of

gArea(gIntersection(SpatialPolygons(vor.temp@polygons[i]),SpatialPolygons(vor.temp@polygons[overlaid.poly])))

The resultant object of int would be the weight matrix which can be used to perform interpolation.

Small but important error in the code: the inner loop is over j thus the second argument must be SpatialPolygons(v2$polygons[j]). Now the code does it perfectly for me!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!