My problem is that after bringing these shapefile(s) into R and then converting them into GeoJSON files, the GeoJSON files do not display when I add them to a Leaflet object/map.
I have gone out and found other shapefile data of the same census year, used the process mentioned above, and then successfully displayed the GeoJSON file on a Leaflet map.
So I am confused as to why the NHGIS shapefiles are not converting correctly, while other shapefiles from other sources are. Both sources have all the necessary files for shapefiles (.DBF, .PRJ, .SBN, .SBX, etc...).
My code (that does not display on a Leaflet) is listed below, along with an image of a successful map with counties in 1790.
A helpful shapefile or GeoJSON converter can be found here; however, after using this GUI converter I still can't get the NHGIS shapefiles to convert correctly.
I am using a shapefile from NHGIS Data Finder and filtering to 1790 and requesting the STATE shapefile.
library(tidyverse) library(magrittr) library(rgdal) library(spdplyr) library(geojsonio) library(rmapshaper) # Import Shapefile into R. us = rgdal::readOGR(dsn="nhgis0004_shape/nhgis0004_shape/nhgis0004_shapefile_tl2000_us_county_1790", layer="US_state_1790", stringsAsFactors = FALSE) # Filter to get only up to 1790 us %<>% dplyr::mutate(START_YEAR = lubridate::year(us[["START_DATE"]]), END_YEAR = lubridate::year(us[["END_DATE"]])) us %<>% dplyr::filter(END_YEAR > 1790 & START_YEAR <= 1790) # Convert SP Data Frame to GeoJSON. us_json <- geojson_json(us) # Simplify the geometry information of GeoJSON. us_json_simplified <- ms_simplify(us_json) # Keep only the polygons inside the bbox (boundary box). us_json_clipped <- ms_clip(us_json_simplified, bbox = c(-170, 15, -55, 72)) # Save it to a local file system. geojson_write(us_json_clipped, file = "~/Downloads/us.geojson") leaflet::leaflet() %>% leaflet::addTiles() %>% leaflet::setView(lng = -98.583, lat = 39.833, zoom = 3) %>% leaflet::addGeoJSON(us_json_clipped)