walkerke / tigris

Download and use Census TIGER/Line shapefiles in R
Other
324 stars 45 forks source link

"Erase_water" function produces sf object that does not work with "mapview" operation in "mapview" package #158

Closed Steve-Koller closed 1 year ago

Steve-Koller commented 1 year ago

I am using the excellent "erase_water" function (thank you for developing!) on a sf object called "MDC_tracts," which is comprised of census tract-level polygons of Miami-Dade County downloaded from tidycensus. The new sf object produced by erase_water, named "MDC_tracts_erased," does not render at all when running the operation

mapview(MDC_tracts_erased)

This stands in contrast to running mapview on the pre-erasure sf object (code below), which runs fine.

mapview(MDC_tracts)

Are sf object outputs from erase_water known to be incompatible with "mapview?" Is there a way to use sf objects that have been altered by "erase_water" with mapview? Thank you!

walkerke commented 1 year ago

@Steve-Koller it should work with mapview. This is working fine for me:

library(tidycensus)
library(tigris)
options(tigris_use_cache = TRUE)
sf::sf_use_s2(FALSE)

dade_income <- get_acs(
  geography = "tract",
  variables = "B19013_001",
  state = "FL",
  county = "Miami-Dade",
  geometry = TRUE,
  cb = FALSE,
  year = 2021
)

dade_income_erase <- erase_water(
  dade_income, 
  area_threshold = 0.95,
  year = 2021
)

mapview::mapview(dade_income_erase,
                 zcol = "estimate",
                 layer.name = "Median household<br/>income, 2017-2021 ACS")

image

A couple questions for you:

Steve-Koller commented 1 year ago

Thank you so much! Bingo- I hadn't been including the below two lines. After adding those in, mapview worked perfectly.

options(tigris_use_cache = TRUE) sf::sf_use_s2(FALSE)

To your questions:

Much appreciated!