internetofwater / ref_gages

Reference Stream Gages
https://internetofwater.shinyapps.io/geoconnex-reference-features/
Creative Commons Zero v1.0 Universal
4 stars 4 forks source link

Add SWIM gages. #15

Closed dblodgett-usgs closed 2 years ago

dblodgett-usgs commented 2 years ago

Now available here. https://www.sciencebase.gov/catalog/item/5ebe92af82ce476925e44b8f

dblodgett-usgs commented 2 years ago
(f <- sbtools::item_file_download("5ebe92af82ce476925e44b8f", dest_dir = tempdir()))
#> [1] "C:\\Users\\DBLODG~2\\AppData\\Local\\Temp\\1\\RtmpqOPWnk/SWIM_gage_loc.dbf"         
#> [2] "C:\\Users\\DBLODG~2\\AppData\\Local\\Temp\\1\\RtmpqOPWnk/SWIM_gage_loc.prj"         
#> [3] "C:\\Users\\DBLODG~2\\AppData\\Local\\Temp\\1\\RtmpqOPWnk/SWIM_gage_loc.shp"         
#> [4] "C:\\Users\\DBLODG~2\\AppData\\Local\\Temp\\1\\RtmpqOPWnk/SWIM_gage_loc.shx"         
#> [5] "C:\\Users\\DBLODG~2\\AppData\\Local\\Temp\\1\\RtmpqOPWnk/SWIM_gage_loc_Metadata.xml"

d <- sf::read_sf(f[grepl("shp$", f)])

d <- cbind(sf::st_drop_geometry(d), sf::st_coordinates(d))

d <- as.data.frame(dplyr::distinct(d))

dup <- d$Gage_no[duplicated(d$Gage_no)]

dup <- d[d$Gage_no %in% dup, ]

dup <- split(dup, dup$Gage_no)

sapply(dup, function(x) {
    x[, which(sapply(seq_len(ncol(x)), function(col, x) {
        # finds columns that do not contain a duplicate.
        !any(duplicated(x[,col]))
    }, x = x))]
})
#> $`06429997`
#>      State    REVIEWED Rev_notes2 QC_final
#> 6756    SD TJS 8/17/17         OK       OK
#> 6874    WY        <NA>       <NA>  AutoRef
#> 
#> $`06454000`
#> [1] "WY" "NE"
#> 
#> $`09061500`
#>      Lat_nwis Long_nwis NHDPlusReg     CHECKED
#> 8752 39.37415 -106.2278         11 SEJ 6/21/17
#> 9820 39.37416 -106.2278         14  SEJ 5/2/17
#>                                QC_notes1         X        Y        M
#> 8752 Drop. Ditch not represented in NHD. -106.2278 39.37415 88.69669
#> 9820  Drop. Ditch not represented in NHD -106.2278 39.37416 74.83204
#> 
#> $`13302005`
#>                          Gage_name Lat_snap Long_snap COMID_meas REACH_meas
#> 11516 PAHSIMEROI RIVER AT ELLIS ID 44.69094 -114.0476   44.94978   44.94978
#> 11519   PAHSIMEROI RIVER NR MAY ID 44.68993 -114.0457   88.17094   88.17094
#>               X        Y        M
#> 11516 -114.0476 44.69094 44.94978
#> 11519 -114.0457 44.68993 88.17094

Created on 2022-01-21 by the reprex package (v2.0.1)