Skip to content

Commit

Permalink
leaflet() workaround for sf proj.db Error with mapView()
Browse files Browse the repository at this point in the history
  • Loading branch information
bbest committed Apr 9, 2024
1 parent 3fdb535 commit 2010368
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 302 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,52 @@ jobs:
# From https://github.com/rspatial/terra/blob/master/.github/workflows/pkgdown.yml
# - name: Install spatial dependencies
# run: brew install gdal proj

# https://github.com/r-spatial/sf/blob/2867dd290a3692cd9f041a7b9297149ea6cffe87/README.md#macos
# - name: Install spatial dependencies
# run: brew install pkg-config gdal


# remotes::install_github("r-spatial/sf", configure.args = "--with-proj-lib=$(brew --prefix)/lib/")

# PKG_CONFIG
# options(configure.args = list(
# sf = " \
# --with-gdal-lib=/opt/homebrew/opt/gdal/lib/ \
# --with-sqlite3-lib=/opt/homebrew/opt/sqlite/lib/ \
# --with-gdal-config=/opt/homebrew/bin/gdal-config \
# --with-proj-share=/opt/homebrew/opt/proj/share/ \
# --with-proj-lib=/opt/homebrew/opt/proj/lib \
# --with-proj-include=/opt/homebrew/opt/proj/include/ \
# --with-geos-config=/opt/homebrew/opt/geos/bin/geos-config \
# --pkg-config=/opt/homebrew/bin/pkg-config"))
# renv::install("r-spatial/sf")

renv::install("[email protected]")

Sys.setenv("PROJ_LIB"="")
install.packages("sf", type = "source")

install.packages("sf", type = "source", configure.args =
'--with-gdal-lib=/opt/homebrew/opt/gdal/lib/
--with-sqlite3-lib=/opt/homebrew/opt/sqlite/lib/
--with-gdal-config=/opt/homebrew/bin/gdal-config
--with-proj-share=/opt/homebrew/opt/proj/share/
--with-proj-lib=/opt/homebrew/opt/proj/lib
--with-proj-include=/opt/homebrew/opt/proj/include/
--with-geos-config=/opt/homebrew/opt/geos/bin/geos-config')
install.packages("sf", type = "source", configure.args="--with-proj-lib=/opt/homebrew/lib/")

# install.packages("sf", type = "source", configure.args =
'
--with-gdal-lib=/opt/homebrew/opt/gdal/lib/
--with-sqlite3-lib=/opt/homebrew/opt/sqlite/lib/
--with-gdal-config=/opt/homebrew/bin/gdal-config
--with-proj-share=/opt/homebrew/opt/proj/share/
--with-proj-lib=/opt/homebrew/opt/proj/lib
--with-proj-include=/opt/homebrew/opt/proj/include/
--with-geos-config=/opt/homebrew/opt/geos/bin/geos-config')

#
# From https://github.com/actions/setup-python
# - name: Setup Python
Expand Down
36 changes: 28 additions & 8 deletions data.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,22 @@ Materials:
#| eval: FALSE
librarian::shelf(
dplyr, here, mapview, readxl, sf, tbep-tech/tbeptools)
dplyr, here, leaflet,
# mapview,
readxl, sf, tbep-tech/tbeptools)
# register with renv
library(dplyr)
library(here)
library(mapview)
library(leaflet)
# library(mapview)
library(readxl)
library(sf)
library(tbeptools)
# from SWFWMD grid cells, use only if interested in areas finer than TB watershed
# this currently gets the same data as the compiled spreadsheet
grd <- st_read(here('../tbep-os-presentations/data/swfwmd-GARR-gisfiles-utm/swfwmd_pixel_2_utm_m_83.shp'), quiet = T)
mapView(grd)
# mapView(grd)
tbgrdcent <- grd %>%
st_transform(crs = st_crs(tbshed)) %>%
Expand Down Expand Up @@ -400,15 +403,19 @@ Temporal data availability:
#| messages: false
#| warning: false
# librarian::shelf(glue, here, lubridate, mapview, prism, stars, stringr, tbep-tech/tbeptools, terra)
# librarian::shelf(glue, here, leaflet, lubridate,
# # mapview, stars,
# prism, sf, stringr, tbep-tech/tbeptools, terra)
# renv register libraries
library(glue)
library(here)
library(leaflet)
library(lubridate)
library(mapview)
# library(mapview)
library(prism)
library(stars)
# library(stars)
library(sf)
library(stringr)
library(tbeptools)
library(terra)
Expand Down Expand Up @@ -487,6 +494,7 @@ r <- pd_stack(pd) |>
# tbshed_pd <- tbshed |>
tbshed_pd <- tbsegshed |>
st_transform(crs(r, proj=T))
# sf broken, so Warning: Cannot find proj.db
r_tb <- r |>
crop(tbshed_pd, mask = T, touches = T) |>
trim()
Expand All @@ -502,8 +510,20 @@ lyr <- glue("{var}<br>{period}<br>{date}")
# terra::writeRaster(r_tb[[i]], here("tmp", glue("{var}_{date}.tif")), overwrite = T)
mapView(r_tb[[i]], layer.name = lyr) +
mapView(tbshed_pd)
# mapView(r_tb[[i]], layer.name = lyr) +
# mapView(tbshed_pd)
# sf broken, so Error: Cannot find proj.db
library(leaflet)
leaflet() |>
addProviderTiles(
providers$CartoDB.Positron) |>
addRasterImage(
r_tb[[i]], opacity = 0.7) |>
addPolygons(
data = tbsegshed,
fillOpacity = 0,
color = "black", weight = 1)
```


Expand Down
Loading

0 comments on commit 2010368

Please sign in to comment.