Skip to content
Prev 24081 / 29559 Next

adapting spatial points and wrld_smpl to a reference system implicit in a .nc file

On Wed, 24 Feb 2016 at 06:07 Dominik Schneider <
Dominik.Schneider at colorado.edu> wrote:

            
This looks right to me:

library(raster)
library(rgdal)
prj <- "+proj=lcc +lat_1=25.0 +lat_2=45.0 +lat_0=38.0 +lon_0=-100.0
+ellps=sphere +a=6370000 +b=6370000 +units=m +no_defs"

r <- raster("results_us_future_output_none_0.nc", varname = "dctmx")
## use  print(r) to see the nc header dump

## lons/lats from NetCDF
lon <- raster("results_us_future_output_none_0.nc", varname = "lon")
lat <- raster("results_us_future_output_none_0.nc", varname = "lat")

## the true projected coordinates (??)
xy <- project(cbind(values(lon), values(lat)), prj)

## looks right
plot(xy, pch = ".")

## this fails, so it's not exactly right
##grd <- rasterFromXYZ(cbind(xy, 0)

## could use sp::points2grid tools to control tolerances, or just fudge it

ex <- extent(xy)
resolution <- c(round(max(diff(sort(unique(xy[,1]))))),
round(max(diff(sort(unique(xy[,2]))))))
ex <- ex + c(-1, 1, -1, 1) * rep(resolution / 2, 2)

## finally
mp <- setExtent(r, ex)
projection(mp) <- prj

library(maptools)
data(wrld_simpl)
namer <- spTransform(subset(wrld_simpl, NAME %in% c("United States",
"Canada", "Mexico")), prj)

plot(mp)
plot(namer, add = TRUE)


("Why does this crucial metadata get thrown away?", he sighs . . .)

HTH
Dr. Michael Sumner
Software and Database Engineer
Australian Antarctic Division
203 Channel Highway
Kingston Tasmania 7050 Australia

Thread (18 messages)

Alex Mandel adapting spatial points and wrld_smpl to a reference system implicit in a .nc file Feb 22 Roger Bivand adapting spatial points and wrld_smpl to a reference system implicit in a .nc file Feb 23 Michael Sumner adapting spatial points and wrld_smpl to a reference system implicit in a .nc file Feb 23 Agus Camacho adapting spatial points and wrld_smpl to a reference system implicit in a .nc file Feb 23 Roger Bivand adapting spatial points and wrld_smpl to a reference system implicit in a .nc file Feb 23 Dominik Schneider adapting spatial points and wrld_smpl to a reference system implicit in a .nc file Feb 23 Agus Camacho adapting spatial points and wrld_smpl to a reference system implicit in a .nc file Feb 23 Chris Reudenbach adapting spatial points and wrld_smpl to a reference system implicit in a .nc file Feb 23 Agus Camacho adapting spatial points and wrld_smpl to a reference system implicit in a .nc file Feb 23 Chris Reudenbach adapting spatial points and wrld_smpl to a reference system implicit in a .nc file Feb 23 Agus Camacho adapting spatial points and wrld_smpl to a reference system implicit in a .nc file Feb 23 Michael Sumner adapting spatial points and wrld_smpl to a reference system implicit in a .nc file Feb 23 Agus Camacho adapting spatial points and wrld_smpl to a reference system implicit in a .nc file Feb 23 Dominik Schneider adapting spatial points and wrld_smpl to a reference system implicit in a .nc file Feb 23 Agus Camacho adapting spatial points and wrld_smpl to a reference system implicit in a .nc file Feb 23 Chris Reudenbach adapting spatial points and wrld_smpl to a reference system implicit in a .nc file Feb 24 Jonathan Greenberg adapting spatial points and wrld_smpl to a reference system implicit in a .nc file Feb 26 Jonathan Greenberg adapting spatial points and wrld_smpl to a reference system implicit in a .nc file Feb 26