DEM API

Table of Contents

GET GetMetricsList

This endpoint retrieves a list of all available metrics from the DEM database and their associated scales

URL:

https://devise.uwyo.edu/umbraco/api/demapi/GetMetricsList

Parameters:

This endpoint does not require any parameters

Response:

[
    {
        "metric": "crosc",
        "scale": "0990m"
    },
    {
        "metric": "crosc",
        "scale": "0510m"
    },
    {
        "metric": "crosc",
        "scale": "0330m"
    },
    {
        "metric": "crosc",
        "scale": "0090m"
    },
    {
        "metric": "crosc",
        "scale": "1530m"
    },
    {
        "metric": "cti",
        "scale": "0090m"
    },
    {
        "metric": "DEM",
        "scale": "0030m"
    },
    {
        "metric": "diss",
        "scale": "0510m"
    },
    {
        "metric": "diss",
        "scale": "0990m"
    },
    {
        "metric": "diss",
        "scale": "0330m"
    },
    {
        "metric": "diss",
        "scale": "1530m"
    },
    {
        "metric": "diss",
        "scale": "0090m"
    }...
]

GET GetByExtent

This endpoint retrieves filtered DEM data based on the given extent. Parameters are passed in through the URL.

URL:

https://devise.uwyo.edu/umbraco/api/demapi/GetByExtent?xmin={xmin}&xmax={xmax}&ymin={ymin}
&ymax={ymax}&metric={metric}&scale={scale}

Parameters:

  • xmin (string): Minimum x value of desired extent.
  • xmax (string): Maximum x value of desired extent.
  • ymin (string): Minimum y value of desired extent.
  • ymax (string): Maximum y value of desired extent.
  • metric (string): A string representing one of the DEM metrics.
  • scale (string): A string representing the scale of the extent.

Example API Call:

https://devise.uwyo.edu/umbraco/api/demapi/GetByExtent?xmin=-105.3&xmax=-96&ymin
=35&ymax=36&metric=DEM&scale=0030m

Response:

[
    {
        "filename": "Tile_N35_W100_DEM.tif",
        "metric": "DEM",
        "scale": "0030m",
        "url": "https://pathfinder.arcc.uwyo.edu/devise/DEM_Metrics/Tile_N35_W100/Tile_N35_W100_DEM.tif"
    },
    {
        "filename": "Tile_N35_W101_DEM.tif",
        "metric": "DEM",
        "scale": "0030m",
        "url": "https://pathfinder.arcc.uwyo.edu/devise/DEM_Metrics/Tile_N35_W101/Tile_N35_W101_DEM.tif"
    },
    {
        "filename": "Tile_N35_W102_DEM.tif",
        "metric": "DEM",
        "scale": "0030m",
        "url": "https://pathfinder.arcc.uwyo.edu/devise/DEM_Metrics/Tile_N35_W102/Tile_N35_W102_DEM.tif"
    },
    {
        "filename": "Tile_N35_W103_DEM.tif",
        "metric": "DEM",
        "scale": "0030m",
        "url": "https://pathfinder.arcc.uwyo.edu/devise/DEM_Metrics/Tile_N35_W103/Tile_N35_W103_DEM.tif"
    },
    {
        "filename": "Tile_N35_W104_DEM.tif",
        "metric": "DEM",
        "scale": "0030m",
        "url": "https://pathfinder.arcc.uwyo.edu/devise/DEM_Metrics/Tile_N35_W104/Tile_N35_W104_DEM.tif"
    },
    {
        "filename": "Tile_N35_W105_DEM.tif",
        "metric": "DEM",
        "scale": "0030m",
        "url": "https://pathfinder.arcc.uwyo.edu/devise/DEM_Metrics/Tile_N35_W105/Tile_N35_W105_DEM.tif"
    },
    {
        "filename": "Tile_N35_W97_DEM.tif",
        "metric": "DEM",
        "scale": "0030m",
        "url": "https://pathfinder.arcc.uwyo.edu/devise/DEM_Metrics/Tile_N35_W97/Tile_N35_W97_DEM.tif"
    },
    {
        "filename": "Tile_N35_W98_DEM.tif",
        "metric": "DEM",
        "scale": "0030m",
        "url": "https://pathfinder.arcc.uwyo.edu/devise/DEM_Metrics/Tile_N35_W98/Tile_N35_W98_DEM.tif"
    },
    {
        "filename": "Tile_N35_W99_DEM.tif",
        "metric": "DEM",
        "scale": "0030m",
        "url": "https://pathfinder.arcc.uwyo.edu/devise/DEM_Metrics/Tile_N35_W99/Tile_N35_W99_DEM.tif"
    }
]

POST GetScalesByMetricList

This endpoint retrieves the scale associated with the given metric

URL:

https://devise.uwyo.edu/umbraco/api/demapi/GetScalesByMetricList

Parameters:

  • Metric (string): A string representing one of the DEM metrics.

JSON Format:

{
  "Metric": "cti"
}

Response:

[
    {
        "metric": "cti",
        "scale": "0090m"
    }
]

R Examples

The following is a collection of R examples to show how to utilize the DEM API to obtain data independent of the DEVISE app

Extract Data From Extent:

    1. Create your point first if you do not already have it.
      require(terra)
      require(sf)
      require(httr)
      require(jsonlite)
      require(tidyverse)
      
      points <- data.frame(id = c(1, 2), x = c(-108.36312, -109.36312),  y = c(45.54731, 45.54731)) %>%
        sf::st_as_sf(coords = c("x", "y"), crs = 4326)
      
    2. After the points have been created we need to obtain the extent
      ext<- st_bbox(points)
      
    3. We also need to obtain the list of all available metrics and their associated scales.
      myDemMetrics<- httr::POST(
        "https://devise.uwyo.edu/umbraco/api/demapi/GetMetricsList",
        content_type_json()
      ) %>%
        content()
      
      myDemMetrics <- do.call(rbind.data.frame, myDemMetrics)
      
    4. Now we have a list of available metrics, their scales, and our extent of interest for the DEM dataset. Let's pick a metric and associated scale we're interested in. For this example we'll use the 'DEM' metric at a scale of '0030m' which happens to be the 7th metric in our `myDemMetrics` list.
      myFiles<- httr::GET(paste0("https://localhost:44375/umbraco/api/demapi/GetByExtent?xmin=", ext[1], "&xmax=", ext[3], "&ymin=", ext[2], "&ymax=", ext[4], "&metric=", myDemMetrics$metric[7], "&scale=", myDemMetrics$scale[7])) %>% 
                         content()
      
      myFiles <- do.call(rbind.data.frame, myFiles)
      
    5. Now we have obtained a list of files representing the DEM metric at a 30m scale within our extent. We want to download these files so we can extract the data. First we want to pick a directory to save the files to.
      outDir <- "D:/examplePath"
      
      Then we want to loop through our list of files and download each one to the desired destination
      # loop through each file and download
      for(j in 1:nrow(myFiles)){
        try(utils::download.file(url = myFiles$url[j], destfile = paste0(outDir, "/", myFiles$filename[j]), quiet = TRUE, mode = "wb"), silent = TRUE)
      }
      
    6. Now that we've got all of our files downloaded, we can merge them into a single raster.
      # Get the newly downloaded files
      myTiles <- dir(outDir, pattern = ".tif$", full.names = TRUE)
      
      # Create a spat raster collection with all the returned tiles
      r <- terra::sprc(myTiles)
      
      # Merge them all together into a single raster
      mergedTiles <- terra::merge(r)
      
      # Change the names to something more meaningful
      names(mergedTiles) <- "DEM"
      
    7. Before extracting the data from our raster, we have to ensure our points are in the correct format
      pts<- vect(as(points %>% st_transform(crs = 5072), "Spatial"))
      
    8. Now that our raster and points are in the correct format we can extract our data.
      ## Extract some sort of data here
      myDemData<- terra::extract(mergedTiles, pts, ID = FALSE)
      
    9. We have the data corresponding to our points. You can see it in R using view or we can attach our points to the data so it's easier to see which data corresponds with which point.
      # Use this to view the data as is
      View(myMaxPrcpData)
      
      dfPts<- cbind(points, myDemData)
      View(dfPts)