Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial implementation of geoconnex reference features for #386 #388

Merged
merged 6 commits into from
May 23, 2024

Conversation

dblodgett-usgs
Copy link
Collaborator

@dblodgett-usgs dblodgett-usgs commented May 20, 2024

library(nhdplusTools)
dplyr::distinct(discover_geoconnex_reference()[c("id", "title")])
#> # A tibble: 18 × 2
#>    id            title                                                          
#>    <chr>         <chr>                                                          
#>  1 hu02          HU02                                                           
#>  2 hu04          HU04                                                           
#>  3 hu06          HU06                                                           
#>  4 hu08          HU08                                                           
#>  5 hu10          HU10                                                           
#>  6 nat_aq        USGS National Aquifers                                         
#>  7 principal_aq  USGS Principal Aquifers                                        
#>  8 sec_hydrg_reg USGS Secondary Hydrogeologic Regions                           
#>  9 gages         Reference Gages                                                
#> 10 mainstems     Reference Mainstems                                            
#> 11 dams          Reference Dams                                                 
#> 12 pws           Public Water Systems                                           
#> 13 states        States                                                         
#> 14 counties      Counties                                                       
#> 15 aiannh        American Indian/Alaska Native Areas/Hawaiian Home Lands (AIANN…
#> 16 cbsa          Core-based statistical areas (CBSA)                            
#> 17 ua10          Urban Areas                                                    
#> 18 places        Places

AOI <- sf::st_as_sfc(sf::st_bbox(c(xmin = -89.56684, ymin = 42.99816,
                                   xmax = -89.24681, ymax = 43.17192),
                                 crs = "+proj=longlat +datum=WGS84 +no_defs"))

get_geoconnex_reference(AOI, type = "hu04")
#> Starting download of first 1000 features.
#> Simple feature collection with 2 features and 7 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -91.15213 ymin: 41.22784 xmax: -88.18307 ymax: 46.21648
#> Geodetic CRS:  WGS 84
#> # A tibble: 2 × 8
#>   id    gnis_id   fid uri                     gnis_url name  loaddate           
#> * <chr> <chr>   <int> <chr>                   <chr>    <chr> <dttm>             
#> 1 0707  <NA>      189 https://geoconnex.us/r… ""       Wisc… 2017-02-01 00:53:08
#> 2 0709  <NA>       65 https://geoconnex.us/r… ""       Rock  2012-06-11 07:54:59
#> # ℹ 1 more variable: geometry <MULTIPOLYGON [°]>

get_geoconnex_reference(type = "hu04", ids = c("0707", "0709"))
#> Simple feature collection with 2 features and 7 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -91.15213 ymin: 41.22784 xmax: -88.18307 ymax: 46.21648
#> Geodetic CRS:  WGS 84
#> # A tibble: 2 × 8
#>   id    gnis_id   fid uri                     gnis_url name  loaddate           
#> * <chr> <chr>   <int> <chr>                   <chr>    <chr> <dttm>             
#> 1 0707  <NA>      189 https://geoconnex.us/r… ""       Wisc… 2017-02-01 00:53:08
#> 2 0709  <NA>       65 https://geoconnex.us/r… ""       Rock  2012-06-11 07:54:59
#> # ℹ 1 more variable: geometry <MULTIPOLYGON [°]>

AOI <- sf::st_sfc(sf::st_point(c(-89.56684, 42.99816)),
                  crs = "+proj=longlat +datum=WGS84 +no_defs")

get_geoconnex_reference(AOI, type = "hu04", buffer = 100000)
#> Starting download of first 1000 features.
#> Simple feature collection with 8 features and 7 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -93.95968 ymin: 40.31667 xmax: -84.7235 ymax: 46.73351
#> Geodetic CRS:  WGS 84
#> # A tibble: 8 × 8
#>   id    gnis_id   fid uri                     gnis_url name  loaddate           
#> * <chr> <chr>   <int> <chr>                   <chr>    <chr> <dttm>             
#> 1 0403  <NA>      187 https://geoconnex.us/r… ""       Nort… 2019-04-02 12:17:54
#> 2 0404  <NA>       66 https://geoconnex.us/r… ""       Sout… 2019-03-15 10:49:16
#> 3 0704  <NA>       96 https://geoconnex.us/r… ""       Uppe… 2017-04-18 15:32:25
#> 4 0706  <NA>       57 https://geoconnex.us/r… ""       Uppe… 2017-02-01 00:53:13
#> 5 0707  <NA>      189 https://geoconnex.us/r… ""       Wisc… 2017-02-01 00:53:08
#> 6 0708  <NA>       61 https://geoconnex.us/r… ""       Uppe… 2012-06-11 07:54:59
#> 7 0709  <NA>       65 https://geoconnex.us/r… ""       Rock  2012-06-11 07:54:59
#> 8 0712  <NA>       62 https://geoconnex.us/r… ""       Uppe… 2019-03-15 10:49:32
#> # ℹ 1 more variable: geometry <MULTIPOLYGON [°]>

Created on 2024-05-20 with reprex v2.1.0

@ksonda
Copy link

ksonda commented May 22, 2024

Some comments:

  1. discover_geoconnex_reference() is just the same thing as get_geoconnex_reference() with no args. Do you need discover_geoconnex_reference() at all?

  2. get_geoconnex_reference(ids = c('foo','bar')) pattern i dont think has many good use cases. most ids are totally illegible and I dont think many folks would ever search by them. More useful would be functionality to mimic dplyr::filter(queryable1 == 'foo' & queryable2 == 'bar') for any combination of queryable parameters. Could also allow toggle for exact or fuzzy match, to leverage the CQL filter's %ILIKE% e.g.

https://reference.geoconnex.us/collections/mainstems/items?filter=name_at_outlet%20ILIKE%20%27%25colorado%25%27
  1. get_geoconnex_reference(type = 'foo') should get the whole collection. Possible we should consider having the pygeoapi source config urls be the hydroshare gpkgs so that this function can pull from hydroshare and not need to iterate over the OAF.

  2. AOI should have bbox as an option since thats common and people wouldnt have to construct it manually with sfc POLYGON

  3. AOI could enable AOI-by-reference to other reference PIDs (i.e. HUCs, states, counties). Could leverage https://reference.geoconnex.us/processes/intersector

e.g.

curl -v -X 'POST' \
  'https://reference.geoconnex.us/processes/intersector/execution' \
  --compressed \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "inputs": {
    "url": "https://geoconnex.us/ref/places/5548000",
    "collection": "mainstems"
  }
}' > madison_mainstems.geojson
  1. roxygen manual for type parameter has inaccurate list of types (collections) that are possible.

@dblodgett-usgs
Copy link
Collaborator Author

Thanks for this @ksonda -- great feedback.

1, I like having direct ways to do stuff like that but then offer the other response, more or less, instead of an error.

2, I agree -- the "ids" thing is a hold over from other get_* functions. I'll drop it from this and bring some kind of more full featured filtering in.

3, If there's a convention I can use to get the whole dataset -- I'm game. Can we get some kind of "canonical data" link in the collection metadata? I would want to add that in addition to a link to a human readable landing page...

  1. It should! I will add.

  2. AOI could enable a lot of things. I'll look at allowing a by reference where it just tries to open it using sf.

  3. I saw that too -- over-zealous use of inheritance. Will fix.

@dblodgett-usgs dblodgett-usgs merged commit 8dacacd into main May 23, 2024
@dblodgett-usgs dblodgett-usgs deleted the geoconnex branch July 29, 2024 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants