[R-sig-Geo] Adding Census polygons to OSM map?

Howard, Tim G (DEC) t|m@how@rd @end|ng |rom dec@ny@gov
Wed Jun 7 16:57:00 CEST 2023


Kevin,
the tmap​ package might be what you are looking for.

https://cran.r-project.org/web/packages/tmap/vignettes/tmap-getstarted.html

https://cran.r-project.org/web/packages/tmap/index.html


Cheers,
Tim

From: R-sig-Geo <r-sig-geo-bounces using r-project.org> on behalf of Kevin Zembower via R-sig-Geo <r-sig-geo using r-project.org>
Sent: Monday, June 5, 2023 11:21 AM
To: r-sig-geo using r-project.org <r-sig-geo using r-project.org>
Subject: [R-sig-Geo] Adding Census polygons to OSM map?

ATTENTION: This email came from an external source. Do not open attachments or click on links from unknown senders or unexpected emails.


Hello, again,

I've given up my work with leaflet, trying to map my neighborhood with
US Census boundaries. Even though it was quick and easy to add the
Census boundaries to the map, I couldn't create the labels I wanted (see
https://stat.ethz.ch/pipermail/r-sig-geo/2023-June/029284.html). Also,
it seems like leaflet added a lot of overhead that I didn't need, such
as interactive maps. I just need a color printed 2D map for my use.

I'm now trying to work with tigris and OpenStreetMap, but I can't draw
the US Census boundaries on the OSM map. Here's what I have so far:

==================================================
## Experiment, using sf:
library(tidyverse)
library(tigris)
options(tigris_use_cache = TRUE)
library(sf)
library(OpenStreetMap)
## library(sp)
## library(ggplot2)

lat_max <- 39.3525 #Distance from 39.35 to 39.34 = 0.691mi
long_max <- -76.617 #Distance from -76.61 to -76.62 = 0.5343 mi
lat_min <- 39.3455
long_min <- -76.6095
nw <- c(lat_max, long_max)
se <- c(lat_min, long_min)

rw_map <- openmap(nw, se,
                   type = "osm",
                   mergeTiles = TRUE) %>%
     openproj() %>%
     OpenStreetMap::autoplot.OpenStreetMap() +
     xlab("long") + ylab("lat")

rw_map

rw_tract <- tracts(state = "MD",
                     county = "Baltimore city",
                     year = "2020") %>%
     filter(NAME == "2711.01")
     ## openproj()
     ## st_transform('+proj=longlat +datum=WGS84')
     ## spTransform('osm')

OpenStreetMap::autoplot.OpenStreetMap(rw_tract, add = TRUE)
==================================================

The commented out sections show some of the things I've tried so far.
I'd like to be able to draw the rw_tract geometry data on the rw_map
image. What I'd like is a 'addPolygon()' function in OpenStreetMap, like
I found in leaflet.

Can anyone offer me any suggestions or advice for accomplishing my task?
Thanks so much.

-Kevin

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo using r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


More information about the R-sig-Geo mailing list