Skip to content

map2SpatialPolygons' 'proj4string' in spmaps

5 messages · Sébastien Bihorel, Roger Bivand

#
Hi,

I don't understand what the 'proj4string' argument in
map2SpatialPolygons() does.  map() in the maps package has a
'projection' argument:

,-----[ *help[R](map)* ]
| projection: character string that names a map projection to use. See
|           'mapproject' (in the 'mapproj' library). The default is to
|           use a rectangular projection with the aspect ratio chosen so
|           that longitude and latitude scales are equivalent at the
|           center of the picture. 
`-----

so I don't know what projection was actually used in a given map() call
with that default 'projection' argument.  I suppose 'proj4string' in
map2SpatialPolygons() should match the actual projection used in the
map() call, shouldn't it?  Thanks.


Cheers,
#
On Wed, 15 Oct 2008, Sebastian P. Luque wrote:

            
No, not at all. The coordinates returned by map() if projection= is used 
are only for plotting, are in arbitrary units, and are only documented in 
code. map2SpatialPolygons() assumes that the data are in geographical 
coordinates, and ought perhaps to guess an ellipse and datum based on the 
age of the dataset (world possibly WGS84, US counties probably NAD27), but 
allows the user to set the CRS object directly. The projection= argument 
of map() makes the function call mapproject() with the given projection on 
the data flowing through, I believe.

If you do str() of map(projection=) output, you will see the projection 
name used, but note that the coordinates are arbitrary.

Roger

  
    
#
On Wed, 15 Oct 2008 19:24:18 +0200 (CEST),
Roger Bivand <Roger.Bivand at nhh.no> wrote:
[...]
Thanks a lot Roger, so here:

se.baffin <- map("worldHires", xlim=c(-70, -60), ylim=c(62, 69),
                 resolution=0, interior=FALSE)

or in any of the world* databases, can we safely assume "+proj=longlat
+ellps=WGS84" (possibly with "+over" in some cases) in the returned
object?  This would be good info to have in ?map.

One problem I also run into with map2SpatialPolygons() with the above
map object, is that the ring is not closed.  Do you know of any examples
showing how one may close such rings, based on a polygon?  Say we have a
rectangle over the map object and want to close the ring so we enclose
all the land (or water)?


Cheers,
#
On Wed, 15 Oct 2008, Sebastian P. Luque wrote:

            
If the fill=TRUE argument to map() is omitted, the rings are not built:

se.baffin <- map("worldHires", xlim=c(-70, -60), ylim=c(62, 69),
   resolution=0, interior=FALSE, fill=TRUE, plot=FALSE)
baff <- map2SpatialPolygons(se.baffin,
   IDs=se.baffin$names)[match("Canada:Baffin Island", se.baffin$names)]
plot(baff, axes=TRUE)

looks OK to me. Add the CRS later. I don't think that we know definitely 
that WGS84 was used, WDBII seems to have been around since 1985. Try 
overlaying on GE, for example, to get a feel.
By hand, you need to insert coordinates into the coords slot of the 
Polygon object of interest and re-generate it. A recent question on the 
list about houses east of a road was handled this way (stitch the bounding 
box to the road and use overlay()).

Otherwise look at the unionSpatialPolygons() code for ideas on interfacing 
gpclib classes and methods (also in PBSmapping).

Best wishes,

Roger

  
    
#
On Wed, 15 Oct 2008 20:20:16 +0200 (CEST),
Roger Bivand <Roger.Bivand at nhh.no> wrote:

            
[...]
Great, I'll check on this.
Thanks so much, I'll follow these leads!


All the best,