为什么提供的tidycensus区域与sf :: _ st_area()计算的不同。
我正在使用tidycensus r软件包来吸收人口普查数据和几何形状。我希望能够计算人口密度,并使结果与我在。我注意到使用SF软件包SF :: ST_AREA()函数与我计算的内容相比,从Tidycenus返回的地理变量之间有所不同。
library(tidyverse)
library(tidycensus)
census_api_key("my_api_key")
library(sf)
options(tigris_use_cache = TRUE)
pop_texas <-
get_acs(geography = 'state',
variables = "B01003_001", # Total Population
year = 2020,
survey = 'acs5',
keep_geo_vars = TRUE,
geometry = TRUE) %>%
filter(GEOID == '48') # Filter to Texas
由于我将keep_geo_vars参数包括为true,因此它返回了一个aland列,我认为这是返回平方米(M^2)的地理区域的正确区域。
> pop_texas$ALAND %>% format(big.mark=",")
[1] "676,680,588,914"
# Conversion to square miles
> (pop_texas$ALAND / 1000000 / 2.5899881) %>% format(big.mark=",")
[1] "261,267.8"
当我将Aland数量转换为平方英里时,我得到的数字与Censusreporter.org上所示的数字相同:
我还尝试使用sf :: st_area()函数来计算该区域,但是我得到一个不同的结果:
> sf::st_area(pop_texas) %>% format(big.mark=",", scientific=FALSE)
[1] "688,276,954,146 [m^2]"
# Conversion to square miles
> (sf::st_area(pop_texas) / 1000000 / 2.5899881) %>%
+ as.numeric() %>%
+ format(big.mark=",", scientific=FALSE)
[1] "265,745.2"
请让我知道是否有一些我缺少来调和这些数字的东西。我希望直接通过平局直接获得相同的结果,或使用sf :: st_area()计算区域。
现在,我已经离开了很多:
> (pop_texas$ALAND - as.numeric(st_area(pop_texas)) ) %>%
+ format(big.mark=",")
[1] "-11,596,365,232"
I am using the tidycensus R package to pull in census data and geometries. I want to be able to calculate population densities and have the results match what I see on censusreporter.org. I am noticing a difference between the geography variables returned from tidycenus compared to what I calculate myself using the sf package sf::st_area() function.
library(tidyverse)
library(tidycensus)
census_api_key("my_api_key")
library(sf)
options(tigris_use_cache = TRUE)
pop_texas <-
get_acs(geography = 'state',
variables = "B01003_001", # Total Population
year = 2020,
survey = 'acs5',
keep_geo_vars = TRUE,
geometry = TRUE) %>%
filter(GEOID == '48') # Filter to Texas
Since I included the keep_geo_vars argument as TRUE it returned an ALAND column which I believe is the correct area for the geography returned in square meters (m^2).
> pop_texas$ALAND %>% format(big.mark=",")
[1] "676,680,588,914"
# Conversion to square miles
> (pop_texas$ALAND / 1000000 / 2.5899881) %>% format(big.mark=",")
[1] "261,267.8"
When I convert the ALAND amount to square miles I get the same number as shown on censusreporter.org:
I have also tried to calculate the area using the sf::st_area() function, but I get a different result:
> sf::st_area(pop_texas) %>% format(big.mark=",", scientific=FALSE)
[1] "688,276,954,146 [m^2]"
# Conversion to square miles
> (sf::st_area(pop_texas) / 1000000 / 2.5899881) %>%
+ as.numeric() %>%
+ format(big.mark=",", scientific=FALSE)
[1] "265,745.2"
Please let me know if there is something I am missing to reconcile these numbers. I would expect to get the same results either directly through tidycensus or calculating the area using sf::st_area().
Right now I am off by a lot:
> (pop_texas$ALAND - as.numeric(st_area(pop_texas)) ) %>%
+ format(big.mark=",")
[1] "-11,596,365,232"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想要像德克萨斯州这样的形状的“官方”区域,则应始终使用
aland
或已发布的区域值。ST_AREA()
正在使用几何形状来计算多边形的面积,这将始终是德克萨斯州(或任何其他区域)的简化和不完美的表示。对于较小的形状(例如人口普查区),计算可能会非常接近;对于更大的状态(尤其是那些具有复杂沿海地区的国家,如德克萨斯州),您将越来越远。If you want the "official" area of a shape like Texas you should always use the
ALAND
or published area value.st_area()
is using geometry to calculate the area of the polygon which is always going to be a simplified and imperfect representation of Texas (or any other area). For smaller shapes (like Census tracts) the calculations will probably be pretty close; for larger shapes like states (especially those with complex coastal geography, like Texas) you're going to be further off.这些差异通常是由于CRS(在您的
sf
对象上使用的投影)。一些预测扭曲区域,其他投影会扭曲形状。请参阅此信息以了解更多 http://wiki.gis.com/wiki/wiki/wiki/index.php/distortion#:~: text = text = 20个方向%2C%20型%20和%20 rea 。These differences are usually due to the CRS (the projection used on your
sf
objects). Some projections distort area, other projections distors the shape. See this to learn more http://wiki.gis.com/wiki/index.php/Distortion#:~:text=There%20are%20four%20main%20types,%2C%20direction%2C%20shape%20and%20area.