Skip to content

Commit 0f7328d

Browse files
Update lcmap.md
1 parent 491cf82 commit 0f7328d

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

docs/data-library/lcmap.md

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,79 @@ To accelerate your access to this dataset, the ESIIL team has made LCMAP 1.3 Pri
1010
~/data-store/data/iplant/home/shared/earthlab/forest_carbon_codefest/LCMAP_SR_1985_2021
1111
```
1212

13-
Additional LCMAP layers and products may be accessed via STAC and VSI.
13+
Additional LCMAP layers and products may be accessed via STAC and VSI (see below for example).
1414

1515
The script used to download the LCMAP data already available is located in the GitHub repo at /code/create-data-library/LCMAP_Direct_Access-adapted.ipynb. The code is from the LCMAP data access tutorial.
1616

17+
```
18+
19+
#Access LCMAP data from STAC
20+
#Adapted from 'Download data from a STAC API using R, rstac, and GDAL'
21+
#https://stacspec.org/en/tutorials/1-download-data-using-r/
22+
23+
24+
require(glue)
25+
require(sf)
26+
require(terra)
27+
require(rstac)
28+
29+
30+
#Access ecoregiosn via VSI
31+
epa_l3 <- glue::glue(
32+
"/vsizip/vsicurl/", #magic remote connection
33+
"https://gaftp.epa.gov/EPADataCommons/ORD/Ecoregions/us/us_eco_l3.zip", #copied link to download location
34+
"/us_eco_l3.shp") |> #path inside zip file
35+
sf::st_read()
36+
37+
#Get just S.Rockies and ensure that it is in EPSG:4326
38+
southernRockies <- epa_l3 |>
39+
dplyr::filter(US_L3NAME == "Southern Rockies") |>
40+
dplyr::group_by(US_L3NAME) |>
41+
dplyr::summarize(geometry = sf::st_union(geometry)) |>
42+
sf::st_transform("EPSG:4326")
43+
44+
bboxSR4326 <- sf::st_bbox(southernRockies)
45+
46+
# Create a stac query for just the 2021 LCMAP data
47+
stac_query <- rstac::stac(
48+
"https://planetarycomputer.microsoft.com/api/stac/v1"
49+
) |>
50+
rstac::stac_search(
51+
collections = "usgs-lcmap-conus-v13",
52+
bbox = bboxSR4326,
53+
datetime = "2021-01-01/2021-12-31"
54+
) |>
55+
rstac::get_request()
56+
57+
#A function to get a vsicurl url form a base url
58+
make_lcmap_vsicurl_url <- function(base_url) {
59+
paste0(
60+
"/vsicurl",
61+
"?pc_url_signing=yes",
62+
"&pc_collection=usgs-lcmap-conus-v13",
63+
"&url=",
64+
base_url
65+
)
66+
}
67+
68+
lcpri_url <- make_lcmap_vsicurl_url(rstac::assets_url(stac_query, "lcpri"))
69+
70+
#Pull the file
71+
out_file <- tempfile(fileext = ".tif")
72+
sf::gdal_utils(
73+
"warp",
74+
source = lcpri_url,
75+
destination = out_file,
76+
options = c(
77+
"-t_srs", sf::st_crs(southernRockies)$wkt,
78+
"-te", sf::st_bbox(southernRockies)
79+
)
80+
)
81+
82+
#Create the raster and plot!
83+
terra::rast(out_file) |>
84+
terra::plot()
85+
southernRockies |>
86+
sf::st_geometry() |>
87+
plot(lwd = 3, add = TRUE)
88+
```

0 commit comments

Comments
 (0)