0

I have a shapefile created in the raster package (ER_14.3_2000_poly).

> #read in a raster file
>   ER_14.3_2000<-raster('E:/Ecoregions Models/Outputs/ER_14.3/ER_14.3_ConsensusMap3.asc')
> #convert the raster to a shapefile and add CRS
>   ER_14.3_2000_poly<-rasterToPolygons (ER_14.3_2000, fun=function(x){x==1}, dissolve=TRUE)
>     projection (ER_14.3_2000_poly)<- "+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs"
>     ER_14.3_2000_poly<- spTransform(ER_14.3_2000_poly,CRS("+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs"))
> ER_14.3_2000_poly
class       : SpatialPolygonsDataFrame 
nfeatures   : 1 
extent      : -856895.9, 916774.1, -2897667, -1500787  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs 
nvariables  : 1
names       : value 
min values  :     1 
max values  :     1 

I want to overlay it on to a raster image (alt) and two shapefiles (MX_L0 and USA_L0) showing political boundaries.

raster:

> alt
class       : RasterLayer 
dimensions  : 365, 515, 187975  (nrow, ncol, ncell)
resolution  : 7880, 9190  (x, y)
extent      : -2713276, 1344924, -2952807, 401543  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs 
data source : in memory
names       : alt 
values      : -185.8762, 3942.444  (min, max)

Shapefiles:

 > MX_L0
    class       : SpatialPolygonsDataFrame 
    nfeatures   : 1 
    extent      : -1785794, 1407980, -3312074, -1222596  (xmin, xmax, ymin, ymax)
    coord. ref. : +proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs 
    nvariables  : 24
    names       : ID_0, ISO, NAME_ENGLI, NAME_ISO, NAME_FAO,                       NAME_LOCAL, NAME_OBSOL,                       NAME_VARIA, NAME_NONLA, NAME_FRENC, NAME_SPANI, NAME_RUSSI, NAME_ARABI, NAME_CHINE, WASPARTOF, ... 
    min values  :  145, MEX,     Mexico,   MEXICO,   Mexico, México|Estados Unidos Mexicanos,         NA, Estados Unidos Mexicanos|Méjico,         NA,    Mexique,    México,    ???????,    ???????,        ???,        NA, ... 
    max values  :  145, MEX,     Mexico,   MEXICO,   Mexico, México|Estados Unidos Mexicanos,         NA, Estados Unidos Mexicanos|Méjico,         NA,    Mexique,    México,    ???????,    ???????,        ???,        NA, ... 
    > USA_L0
    class       : SpatialPolygonsDataFrame 
    nfeatures   : 1 
    extent      : -5978257, 2516534, -2116922, 3910986  (xmin, xmax, ymin, ymax)
    coord. ref. : +proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs 
    nvariables  : 24
    names       : ID_0, ISO,    NAME_ENGLI,      NAME_ISO,                 NAME_FAO,    NAME_LOCAL, NAME_OBSOL,                                  NAME_VARIA, NAME_NONLA,  NAME_FRENC,     NAME_SPANI,                NAME_RUSSI,       NAME_ARABI, NAME_CHINE, WASPARTOF, ... 
    min values  :  240, USA, United States, UNITED STATES, United States of America, United States,         NA, United States of America|USA|US|U.S.|U.S.A.,         NA, États-Unis, Estados Unidos, ??????????? ????? ???????, ???????? ???????,         ??,        NA, ... 
    max values  :  240, USA, United States, UNITED STATES, United States of America, United States,         NA, United States of America|USA|US|U.S.|U.S.A.,         NA, États-Unis, Estados Unidos, ??????????? ????? ???????, ???????? ???????,         ??,        NA, ... 

When I plot it out, the shapefile is shifted to the east. The shapefile should be hugging the Mexican coast. Does anyone know where I went wrong? Any input helps! enter image description here

I am thinking that for some reason the xmax value of the extent has been modified. Does anyone have ideas on how to change it so they overlap?

  • Is the raster data publicly available? Otherwise it is hard to reconstruct your case. – AndreJ Jul 5 '13 at 3:52
  • @Andre Joost: The raster data is just a clipped image of the .bil file available from WorlClim.org (5 arcminute res) (worldclim.org/current); The shape file is a subset of the Level 2 ecoregions for North America avialable from the EPA site: (epa.gov/wed/pages/ecoregions/na_eco.htm) – I Del Toro Jul 5 '13 at 5:33
  • Loading the datasets you mention, I get no offset, and both fit to Openstreetmap background in QGIS. The .bil is in WGS84, while the shapefiles use a different ellipsoid. Maybe your reprojection of the raster went wromg. – AndreJ Jul 5 '13 at 6:37
  • 2
    How do you know the shapefile is shifted at all? You are using the same white value to plot NoData and low-elevation values. The edge of the light gray should not be the coastline, but should be the boundary of a contour at a few hundred meters or so. Why don't you use a more appropriate color scale to replot this map and show us what the raster coastline really looks like? – whuber Jul 5 '13 at 13:36
  • @whuber: I think the blue parts in the Gulf of Mexico are definitely misplaced. – AndreJ Jul 17 '13 at 5:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.