[R-sig-Geo] problem with extract() raster package using weight=TRUE

up u.p at operamail.com
Tue Sep 17 14:10:34 CEST 2013


Hi everybody! I'm a new user, sorry for any kind of errors in posting :-).

I'm trying to use* extract()* from raster library to get data values from
netcdf file that are inside a shapefile.
I'm using rgdal library to manage shapefiles, and raster library to read
netcdf file (a very simple file).
This is the simple code:

> t500 <-raster("t500.nc")
> projection(t500)
[1] "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"

> regioni <- readOGR(".", "ITA_adm1")
#ITA_adm1 from GADM database of Global Administrative Areas, shapefile
format

> summary(regioni)
Object of class SpatialPolygonsDataFrame
Coordinates:
        min      max
x  6.630879 18.52069
y 35.492917 47.09096
Is projected: FALSE 
proj4string :
[+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0]
(...)

> lombardia <-regioni[regioni$NAME_1=="Lombardia",]
> liguria <-regioni[regioni$NAME_1=="Liguria",]

Now, I extract values from netcdf file that fall into lombardia:

>extract(t500,lombardia)
[[1]]
  [1] 249.3597 249.3362 249.3284 249.9573 249.5706 249.5081 249.4065
250.2269
  [9] 250.2581 250.2151 250.1058 249.9964 249.9261 249.8831 249.8245
249.7347
(...)

Now into liguria:

> extract(t500,liguria)
[[1]]
 [1] 249.9729 250.3440 250.2269 250.1800 250.1331 250.0823 250.0198 249.9729
 [9] 249.9573 249.9651 250.4026 250.3128 250.2425 250.1956 250.0862 250.0550
[17] 250.0628 250.1019 250.1487 250.4808 250.4222 250.3753 250.2737 250.2972
[25] 250.3284 250.7972 250.4495 250.4456 250.4495 250.4808 250.8362 250.6800
[33] 250.5940 250.5862 251.1409 251.0003 250.8753 250.8011 250.7894

Now I try to extract with weight enabled.

> extract(t500,lombardia,weight=T)
[[1]]
          value weight
  [1,] 249.4651   0.23
  [2,] 249.3948   0.27
  [3,] 249.8323   0.15
  [4,] 249.8206   0.42
  [5,] 249.8206   0.10
  [6,] 249.4183   0.06
  [7,] 249.3597   0.99
  [8,] 249.3362   0.99
  [9,] 249.3284   0.90
(...)

Nice one!
Now I do the same thing on the second shapefile:

> extract(t500,liguria,weight=T)
Error: identicalCRS(x, y) is not TRUE

That's the problem! I can extract from liguria netcdf values, but I cannot
extract them with weight.

Any suggestion?

Manymany thanks in advance!

Umberto



--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/problem-with-extract-raster-package-using-weight-TRUE-tp7584665.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list