[R] map and shapefile help

Michael Sumner mdsumner at gmail.com
Sun Apr 1 10:51:27 CEST 2012


Sorry I take that back, I was using the (independent of GDAL)
shapefile reader in maptools. Using the rgdal package, we get the full
projection information from the auxiliary .xml file that ships with
the other shapefile files.

library(rgdal)

## Here my working directory "." contains "NA_CEC_Eco_Level3.shp"

x <- readOGR(".", "NA_CEC_Eco_Level3")
OGR data source with driver: ESRI Shapefile
Source: ".", layer: "NA_CEC_Eco_Level3"
with 2548 features and 11 fields
Feature type: wkbPolygon with 2 dimensions


summary(x)
Object of class SpatialPolygonsDataFrame
Coordinates:
       min     max
x -4334052 3324076
y -3313739 4267265
Is projected: TRUE
proj4string :
[+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997
+units=m +no_defs]
Data attributes:
   NA_L3CODE
...

So, now we can do this:

library(maps)
require(rgdal)

map("state", col = "aliceblue", fill = TRUE, lwd = 2)
plot(spTransform(x, CRS("+proj=longlat +ellps=WGS84")), add = TRUE)

(Clearly I should have taken this to R-Sig-Geo some time ago).

Cheers, Mike.


On Sun, Apr 1, 2012 at 6:09 PM, Michael Sumner <mdsumner at gmail.com> wrote:
> There is no coordinate system defined for these files- proj4string is
> NA, see below - otherwise transforming them to that used by the maps
> package is trivial. I suggest you find out the coordinate system from
> the provider of the data and ask any further questions on R-Sig-Geo.
> This is a big file, ~34 Mb and you should warn people of that.
>
> library(maptools)
> x <- readShapeSpatial("NA_CEC_Eco_Level3.shp")
>
>  summary(x)
> Object of class SpatialPolygonsDataFrame
> Coordinates:
>       min     max
> x -4334052 3324076
> y -3313739 4267265
> Is projected: NA
> proj4string : [NA]
> Data attributes:
>   NA_L3CODE                                           NA_L3NAME
>  8.5.2  : 217   Mississippi Alluvial Plain                  : 217
>  7.1.5  : 208   Coastal Western Hemlock-Sitka Spruce Forests: 208
>  8.5.1  : 163   Middle Atlantic Coastal Plain               : 163
>  8.5.3  : 147   Southern Coastal Plain                      : 147
>  2.1.5  : 135   Foxe Uplands                                : 135
>  8.1.8  :  98   Acadian Plains and Hills                    :  98
>  (Other):1580   (Other)                                     :1580
> ...
>
>
>
> On Sun, Apr 1, 2012 at 4:55 PM, Michael Sumner <mdsumner at gmail.com> wrote:
>> Try the R-Sig-Geo mailing list for a better target community, but if these
>> are shapefiles there is read support in rgdal (or maptools for a simpler
>> alternative) and if these are in long-lat like the maps package then plot(x,
>> add=TRUE) will be most of the way there.
>>
>> If you need to transform either layer then see spTransform or project in
>> rgdal.
>>
>> Cheers, Mike
>>
>>
>> On Sunday, April 1, 2012, chuck.01 wrote:
>>>
>>> Hi,
>>> I want to use map("state") and have the ecoregion shape (please see link)
>>> file projected onto this.
>>>
>>> ftp://ftp.epa.gov/wed/ecoregions/cec_na/NA_CEC_Eco_Level3.zip
>>> ftp://ftp.epa.gov/wed/ecoregions/cec_na/NA_CEC_Eco_Level3.zip
>>>
>>> Could someone please show me how; I have never messed with this sort of
>>> thing.
>>> Thanks.
>>>
>>> --
>>> View this message in context:
>>> http://r.789695.n4.nabble.com/map-and-shapefile-help-tp4522794p4522794.html
>>> Sent from the R help mailing list archive at Nabble.com.
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>
>> --
>> Michael Sumner
>> Institute for Marine and Antarctic Studies, University of Tasmania
>> Hobart, Australia
>> e-mail: mdsumner at gmail.com
>
>
>
> --
> Michael Sumner
> Institute for Marine and Antarctic Studies, University of Tasmania
> Hobart, Australia
> e-mail: mdsumner at gmail.com



-- 
Michael Sumner
Institute for Marine and Antarctic Studies, University of Tasmania
Hobart, Australia
e-mail: mdsumner at gmail.com



More information about the R-help mailing list