在SpatialPolygonsDataFrame对象上使用Rcartogram [英] Use Rcartogram on a SpatialPolygonsDataFrame object

查看:129
本文介绍了在SpatialPolygonsDataFrame对象上使用Rcartogram的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行与此问题相同的事情, R ,但从SpatialPolygonsDataFrame开始,并希望以相同类型的对象结束.

I'm trying to do the same thing asked in this question, Cartogram + choropleth map in R, but starting from a SpatialPolygonsDataFrame and hoping to end up with the same type of object.

我可以将对象另存为shapefile,使用 scapetoad ,重新打开它并转换回去,但是我d宁愿将所有内容都包含在R中,以便该过程完全可重复,并且我可以自动编写数十种变体.

I could save the object as a shapefile, use scapetoad, reopen it and convert back, but I'd rather have it all within R so that the procedure is fully reproducible, and so that I can code dozens of variations automatically.

到目前为止,我已经在github上分发了Rcartogram代码,并且到目前为止已经加了我的努力

I've forked the Rcartogram code on github and added my efforts so far here.

本质上,此演示的工作是在地图上创建一个SpatialGrid,在网格的每个点上查找人口密度,然后将其转换为密度矩阵,并按cartogram()的格式进行处理.到目前为止一切顺利.

Essentially what this demo does is create a SpatialGrid over the map, look up the population density at each point of the grid and convert this to a density matrix in the format required for cartogram() to work on. So far so good.

但是,如何根据cartogram()的输出来插值原始地图点呢?

But, how to interpolate the original map points based on the output of cartogram()?

这里有两个问题.首先是将地图和网格划分为相同的单元以允许插值.第二个方法是访问每个多边形的每个点,对其进行插值,然后将它们保持正确的顺序.

There are two problems here. The first is to get the map and grid into the same units to allow interpolation. The second is to access every point of every polygon, interpolate it, and keep them all in right order.

网格以网格为单位,地图以投影为单位(在示例longlat中).要么必须将网格投影到longlat中,要么将地图投影到网格单位中.我的想法是制作一个伪造的CRS,并将其与package(rgdal)中的spTransform()函数一起使用,因为这可以最小程度地处理对象中的每个点.

The grid is in grid units and the map is in projected units (in the case of the example longlat). Either the grid must be projected into longlat, or the map into grid units. My thought is to make a fake CRS and use this along with the spTransform() function in package(rgdal), since this handles every point in the object with minimal fuss.

访问每个点很困难,因为它们位于SpPDF对象中几层:我认为是object> polygons> Polygons> lines> coords.有什么想法可以在保持整体地图结构完整的同时访问这些文件吗?

Accessing every point is difficult because they are several layers down into the SpPDF object: object>polygons>Polygons>lines>coords I think. Any ideas how to access these while keeping the structure of the overall map intact?

推荐答案

可以使用getcartr程序包解决此问题,该程序包在博客文章.

This problem can be solved with the getcartr package, available on Chris Brunsdon's GitHub, as beautifully explicated in this blog post.

quick.carto函数完全可以实现您想要的功能-以SpatialPolygonsDataFrame作为输入,以SpatialPolygonsDataFrame作为输出.

The quick.carto function does exactly what you want -- takes a SpatialPolygonsDataFrame as input and has a SpatialPolygonsDataFrame as output.

在此处的链接中复制示例的本质,以防链接失效,并且在&中混合了我自己的样式修正错别字:

Reproducing the essence of the example in the blog post here in case the link goes dead, with my own style mixed in & typos fixed:

( Shapefile ;

这篇关于在SpatialPolygonsDataFrame对象上使用Rcartogram的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆