lawinslow / hydrolinks

National Hydrography Network Dataset Tools for R
Other
10 stars 4 forks source link

RStudio crashing on hydrolinks call #38

Closed lawinslow closed 6 years ago

lawinslow commented 6 years ago

@rainshapes Could you test this and see if you also get a crash? I am seeing hard crash on the centroid linking.

library(dataRetrieval)
library(hydrolinks)
library(dplyr)
library(sf)

sites = whatWQPsites(siteType ="Lake, Reservoir, Impoundment")

sites = sites %>% distinct(LongitudeMeasure, LatitudeMeasure, MonitoringLocationIdentifier) %>% 
  mutate(lat=LatitudeMeasure, lon=LongitudeMeasure)

## filter sites to be only those within lower 48
conus = USAboundaries::us_states()[!USAboundaries::us_states()$geoid %in% c('72', '02', '15'),]

wqp_points = st_as_sf(sites, coords=c('LongitudeMeasure', 'LatitudeMeasure'))
st_crs(wqp_points) = st_crs(conus)
wqp_conus = st_within(wqp_points, conus)
wqp_points = wqp_points[lengths(wqp_conus) > 0,]
st_geometry(wqp_points) = NULL

dists = c(0, 25, 50, 100, 200)
out = list()
for(i in seq_along(dists)){
  llinked = link_to_waterbodies(wqp_points$lat, wqp_points$lon, wqp_points$MonitoringLocationIdentifier, dataset='nhdh', buffer=dists[i])
  notlinked = wqp_points[!(wqp_points$MonitoringLocationIdentifier %in% llinked$MATCH_ID), ]
  clinked = link_waterbody_centroids(notlinked$lat, notlinked$lon, notlinked$MonitoringLocationIdentifier, dataset='nhdh', buffer=dists[i])
  save(llinked, clinked, file = paste0('data/lake_buffer_', dists[i], '.Rdata'))
  out[[i]] = data.frame(nlinked = length(unique(llinked$MATCH_ID)), n=length(unique(wqp_points$MonitoringLocationIdentifier)))
}
lawinslow commented 6 years ago

@rainshapes reports this cannot be reproduced.