Skip to content

Commit

Permalink
add logo badge
Browse files Browse the repository at this point in the history
  • Loading branch information
jsta committed Mar 28, 2019
1 parent 62518f2 commit 5290a6d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 25 deletions.
3 changes: 1 addition & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ knitr::opts_chunk$set(
[![Travis-CI Build Status](https://travis-ci.org/jsta/nhdR.svg?branch=master)](https://travis-ci.org/jsta/nhdR)
[![DOI](https://zenodo.org/badge/75339263.svg)](https://zenodo.org/badge/latestdoi/75339263)

# nhdR
<!-- # nhdR <img src="man/figures/logo.png" align="right" height=140/> -->
# nhdR <img src="man/figures/logo.png" align="right" height=140/>

Tools for querying, downloading, and networking both the [National Hydrography Dataset (NHD)](https://nhd.usgs.gov/) and [NHDPlus](http://www.horizon-systems.com/nhdplus/) datasets.

Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://
Status](https://travis-ci.org/jsta/nhdR.svg?branch=master)](https://travis-ci.org/jsta/nhdR)
[![DOI](https://zenodo.org/badge/75339263.svg)](https://zenodo.org/badge/latestdoi/75339263)

# nhdR

<!-- # nhdR <img src="man/figures/logo.png" align="right" height=140/> -->
# nhdR <img src="man/figures/logo.png" align="right" height=140/>

Tools for querying, downloading, and networking both the [National
Hydrography Dataset (NHD)](https://nhd.usgs.gov/) and
Expand Down
81 changes: 61 additions & 20 deletions logo/logo_hex-streams.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,45 @@ library(LAGOSNEgis)
library(fontr)
library(sf)
library(mapview)
library(nhdR)
library(ggplot2)
library(cowplot)
library(hexSticker)

# ---- intersect text glyph with watershed ----
# https://djnavarro.net/post/in-between.html

hu12 <- LAGOSNEgis::query_gis("HU4", "ZoneID", "HU4_49")

n_raw <- fontr::glyph_polygon("n")
centroid <- st_centroid(st_as_sfc(st_bbox(hu12)))
centroid <- as.data.frame(st_coordinates(centroid))
n_raw$x <- (n_raw$x * 10) + centroid$X
n_raw$y <- (n_raw$y * 10) + centroid$Y
n <- st_sfc(st_polygon(list(as.matrix(n_raw))), crs = st_crs(hu12))
glyph_sf <- function(char, bbox, scale_factor = 3700){
# char <- "d"
# bbox <- hu12
n_raw <- fontr::glyph_polygon(char)
centroid <- st_centroid(st_as_sfc(st_bbox(bbox)))
centroid <- as.data.frame(st_coordinates(centroid))
# multiplication avoids rounding errors
n_raw$x <- (n_raw$x * 10) + centroid$X
n_raw$y <- (n_raw$y * 10) + centroid$Y

# adjust scale and position (see sf vignette #3)
ncg <- st_geometry(n)
cntrd <- st_centroid(ncg)
if(any(is.na(n_raw$x))){
n_raw_mat <- list(
as.matrix(n_raw[1:(which(is.na(n_raw$x)) - 1),]),
as.matrix(n_raw[(which(is.na(n_raw$x)) + 1):nrow(n_raw),]))
}else{
n_raw_mat <- list(as.matrix(n_raw))
}

ncg2 <- (ncg - cntrd) * 3700 + cntrd
ncg2 <- st_sfc(ncg2, crs = st_crs(hu12))
n <- st_sfc(st_polygon(n_raw_mat), crs = st_crs(bbox))

mapview(st_transform(hu12, 4326)) +
mapview(st_transform(ncg2, 4326))
# adjust scale and position (see sf vignette #3)
ncg <- st_geometry(n)
cntrd <- st_centroid(ncg)
ncg2 <- (ncg - cntrd) * scale_factor + cntrd
st_sfc(ncg2, crs = st_crs(hu12))
}

# mapview(st_transform(hu12, 4326)) +
# mapview(st_transform(ncg2, 4326))

# ---- pull_streams ----
lake_streams <- nhd_plus_query(poly = hu12,
Expand All @@ -36,16 +53,40 @@ lakes <- st_transform(lake_streams$sp$NHDWaterbody, st_crs(hu12))
# ---- clip streams to font glyph ----
# http://www.katiejolly.io/blog/2019-01-21/map-cutouts

test <- st_intersection(streams, ncg2)
mapview(test)
n <- glyph_sf("n", hu12)
n_streams <- st_intersection(streams, n)
h <- glyph_sf("h", hu12)
h_streams <- st_intersection(streams, h)
d <- glyph_sf("d", hu12)
d_streams <- st_intersection(streams, d)
R <- glyph_sf("R", hu12)
R_streams <- st_intersection(streams, R)

# ---- initial plotting ----

gg1 <- ggplot() +
geom_sf(data = huc_8, size = 1.2) +
geom_sf(data = big_streams, color = "cyan") +
geom_sf(data = big_lakes, fill = "cyan", color = "blue") +
gg_logo <- function(n, n_streams){
ggplot() +
geom_sf(data = n_streams, size = 0.3, color = "blue") +
geom_sf(data = n, size = 0.6, alpha = 0) +
coord_sf(datum = NA) +
cowplot::theme_nothing()
}

pl <- list(gg_logo(n, n_streams) + theme(plot.margin = margin(0, 0, 0, 0)),
gg_logo(h, h_streams),
gg_logo(d, d_streams),
gg_logo(R, R_streams)
)

pkg_name <- cowplot::plot_grid(plotlist = pl, nrow = 1,
align = "h",
axis = "b",
scale = c(1, 1, 1, 1))
# scale = c(0.65, 0.7, 0.7, 1))

hexSticker::sticker(pkg_name, s_x = 1, s_y = 1, s_width = 1.7, s_height = 0.7,
package = "", filename = "logo/logo.png",
h_fill = "#ffffff", h_color = "#595959", h_size = 0.8,
url = "https://github.com/jsta/nhdR", u_size = 5)

ggsave("gg1.png", gg1)
usethis::use_logo("logo/logo.png")

0 comments on commit 5290a6d

Please sign in to comment.