将栅格识别为地图/shapefile [英] Identifying grids into a map/shapefile

查看:58
本文介绍了将栅格识别为地图/shapefile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对地图/shapefile有一些疑问.我不是R方面的专家,因此,为了便于理解我要做什么,我将列举一下:

1-标识地图上的每个网格,并可能省略其中一些网格.2-通过数据框中的值为每个网格着色

我只是使用Photoshop做了自己想做的事情,以帮助说明我的目标

用所需的颜色填充它们可能需要最多的工作,创建一张表格以将填充量映射到网格.看来,这个答案可以为您指明正确的方向. R ggplot2与shapefile和csv数据合并以填充多边形

这里是R中映射的很好概述.here

I made this map using the 'intersect' function with a shapefile I got from internet and a grid i made using 'rastertoPolygons' function, but I'm not sure if using a .shp is the best way to get what I want, altough it has been the only way I found to do this, since I got lost trying with ggplot2 options (and I'm very familiar with the package)

Any help or suggestion will be awesome.

Sorry if I made a stupid question and sorry for my bad english.

解决方案

If you are asking how you can do this in ggplot, you can pretty easily. If not, can you clarify what you are asking?

You can draw the map of Brazil easily, and use your shapefile either directly, or with some adjustments. Since I don't have your shapefile, I'll use one of my own and you can adjust for yourself. I just made two arbitrary boxes, and labelled them with a field called id. Your grouping name may be different.

library(ggplot2)
library(maps)
library(rgdal)

brasilia <- borders("world", regions = "Brazil")
brazil <- ggplot() + brasilia + theme_bw() + xlab("Longitude (decimals)") + ylab("Latitude (decimals)") + 
  theme(panel.border = element_blank(), panel.grid.major = element_line(colour = "grey80"), panel.grid.minor = element_blank()) +
  coord_fixed(1.0)
brazil # You can see just the map of Brazil

Next, import your shapefile using rgdal, which should read all the metadata so you don't have to tell it what projection, etc. Just tell it where it is, and what the shape file name is. See ?readOGR for help.

shapes <- readOGR(dsn = "C:/foo/GIS/Brazil", layer = "brazil_grid")
brazil_shapes <- brazil + geom_path(data = shapes, aes(x = long, y = lat, group = id), color = "red")
brazil_shapes

Filling them with the colors you want may take the most work, creating a table to map your fill levels to the grids. It looks like this answer can point you in the right direction though. R ggplot2 merge with shapefile and csv data to fill polygons

Here's a good overview of mapping in R. http://eriqande.github.io/rep-res-web/lectures/making-maps-with-R.html

这篇关于将栅格识别为地图/shapefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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