【问题标题】:Why am I unable to build data frame with census block and lat/long outline?为什么我无法使用人口普查块和纬度/经度轮廓构建数据框?
【发布时间】:2021-11-14 23:51:51
【问题描述】:

我是 R 新手,正在处理人口普查数据,我正在尝试构建一个 csv 文件,该文件可以传递给另一个团队,以显示人口普查区的纬度/经度轮廓。

有了这个,我可以到达佛罗里达州的 3 个特定人口普查区。

FL_blocks <- blocks("FL", year = 2010, )
FL_blocks_Alachua <- filter(FL_blocks, COUNTYFP == "001")
NTIA_FL_CB <- FL_blocks_Alachua %>%
  filter(FL_blocks_Alachua$GEOID10 %in% c ("120010019071008", "120010019071007", "120010019071009"))

现在我想制作一个表格,仅显示纬度/经度以及与纬度/经度相关联的相应人口普查区块。这将为我提供每个人口普查区块的纬度/经度列表,我可以用人口普查区块的多边形绘制它们,但为了将其传递给不熟悉 R 的团队,我需要 csv 数据输出。

NTIA_FL_CB_Shape_xy <- as.data.frame(st_coordinates(NTIA_FL_CB$geometry))
NTIA_FL_CB_Shape_xy <- NTIA_FL_CB_Shape_xy %>%
    rename( Longitude = X, Latitude = Y) %>%
    select(Latitude,Longitude )

# save lat/long as csv
st_write(NTIA_FL_CB_Shape_xy, "fl_3cb_ntia_latlong.csv", coords = TRUE)

# plot the 3 census blocks with the outline of the shapefiles marked as green circles
leaflet(NTIA_FL_CB) %>%
  addTiles() %>%
  addPolygons(popup = ~GEOID10) %>%
  addCircleMarkers(data = NTIA_FL_CB_Shape_xy, color = "green")

This image shows what I was thinking, If I could pass the lat/longs outlining each census block the team that uses my csv file output should be able to load that into their GIS software to overlay.

【问题讨论】:

    标签: r leaflet tigris tidycensus


    【解决方案1】:

    诀窍是先投射到点,然后导出。或者,如果您的团队使用 GIS 软件,您可以将多面体写入 shapefile?

    library(sf)
    
    nc <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
    nc_pt <- st_cast(nc, "POINT")
    st_write(nc_pt, "nc_pt.csv", layer_options="GEOMETRY=AS_XY")
    # st_write(nc, "nc.shp")
    

    https://gis.stackexchange.com/questions/294921/convert-shapefile-into-lat-long-points-and-export-it-as-csv-in-r

    【讨论】:

    • 谢谢!那成功了。您在获取此 csv 或什至在 st_write 中准备 kml 或 kmz 文件方面有什么技巧吗?
    • 很高兴为您提供帮助。您可以这样做:stackoverflow.com/questions/7813141/…。祝你好运!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-07
    • 2012-10-31
    • 1970-01-01
    • 1970-01-01
    • 2013-10-30
    相关资源
    最近更新 更多