lhenneman / disperseR

New version of the hyspdisp package
4 stars 6 forks source link

Problem with link_all_units for counties. #58

Open michaelaoash opened 1 year ago

michaelaoash commented 1 year ago

There seems to be a problem in the Spatial handling of the counties boundaries file in link_all_units_subfun.R. The following elements create the problem

counties.sp <- sf::as_Spatial(USAboundaries::us_counties())
p4s <- "+proj=aea +lat_1=20 +lat_2=60 +lat_0=40 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m"
counties.sp <- spTransform(counties.sp, p4s)

This spTransform() of counties.sp results in

non finite transformation detected:
           [,1]     [,2] [,3] [,4]
 [1,] -102.8038 40.00255  Inf  Inf
 [2,] -102.7936 40.35128  Inf  Inf
 [3,] -102.7800 40.43845  Inf  Inf
 [4,] -102.6648 40.43847  Inf  Inf
 [5,] -102.0513 40.44001  Inf  Inf
 [6,] -102.0513 40.34922  Inf  Inf
 [7,] -102.0513 40.33838  Inf  Inf
 [8,] -102.0517 40.00308  Inf  Inf
 [9,] -102.0513 39.81899  Inf  Inf
[10,] -102.0500 39.57406  Inf  Inf
[11,] -102.8029 39.56784  Inf  Inf
[12,] -102.8038 40.00255  Inf  Inf

I substitute (without really knowing what I am doing!!) a different CRS object:

p4s <- "+init=epsg:3857" which at least resolves the error of non finite transformations and lets link_all_units finish for counties. But I don't know if the geography is appropriate. Please advise!