使用函数raster::getData子集的状态看起来非常奇怪。

huangapple go评论77阅读模式
英文:

Subsetted states look very weird with function raster::getData

问题

我使用 raster::getData 获取了一个 Large SpatialPolygonsDataFrame,如下所示:

states <- raster::getData("GADM", country = "United States", level = 1)

我对 IL 和 WI 进行了子集化:

statesilwi <- states[states$NAME_1 == "Illinois" | states$NAME_1 == "Wisconsin",]

但当我绘制它时,伊利诺伊州看起来有点奇怪,为什么会这样,有没有办法修复它?

plot(statesilwi)

使用函数raster::getData子集的状态看起来非常奇怪。

英文:

I used raster::getData to obtain a Large SpatialPolygonsDataFrame details below

states &lt;- raster::getData(&quot;GADM&quot;, country = &quot;United States&quot;, level = 1

I subsetted IL and WI...

statesilwi &lt;- states[states$NAME_1 == &quot;Illinois&quot; | states$NAME_1 == &quot;Wisconsin&quot;,]

But when I plot it, it Illinois looks a little bit funky, why is this happening and is there a way to fix it?

plot(statesilwi)

使用函数raster::getData子集的状态看起来非常奇怪。

答案1

得分: 1

"looks a bit funky" 不太清楚。但我觉得 @rawr 是正确的。密歇根湖的一部分属于伊利诺伊州。

你可以像这样移除密歇根湖:

library(terra)
library(geodata)
us <- geodata::gadm("United States", level = 2, path=".")
us <- us[us$TYPE_2 != "Water body", ]
s <- us[us$NAME_1 %in% c("Illinois", "Wisconsin"),]
s <- aggregate(s, "NAME_1")
plot(s)
英文:

"looks a bit funky" is not very clear. But it seems to me that @rawr is correct. A part of Lake Michigan belongs to Illinois.

You can remove Lake Michigan like this:

library(terra)
library(geodata)
us &lt;- geodata::gadm(&quot;United States&quot;, level = 2, path=&quot;.&quot;)
us &lt;- us[us$TYPE_2 != &quot;Water body&quot;, ]
s &lt;- us[us$NAME_1 %in% c(&quot;Illinois&quot;, &quot;Wisconsin&quot;),]
s &lt;- aggregate(s, &quot;NAME_1&quot;)
plot(s)

huangapple
  • 本文由 发表于 2023年6月11日 22:18:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76450905.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定