[R-sig-Geo] maps to PBSmapping conversion

Roger Bivand Roger.Bivand at nhh.no
Thu Nov 25 16:10:41 CET 2010


On Thu, 25 Nov 2010, Ted Rosenbaum wrote:

> Hi:
> When I run the following command to convert a US state polygon from the maps
> package to a polyset in PBSmapping, I obtain extra lines that should not be
> in there.
> plotMap(SpatialLines2PolySet(map2SpatialLines(map('state','maryland',interior=FALSE),proj4string=CRS("+proj=longlat
> +datum=wgs84"))))
> Compare to :
> map('state','maryland').
> I appreciate anyone's insight as to why this conversion is not working.

map() and plootMap() have different pen-up and pen-down conventions. The 
easiest correction is:

md <- map('state','maryland',interior=FALSE, plot=FALSE, fill=TRUE)
spmd <- map2SpatialLines(md)
xx <- SpatialLines2PolySet(spmd)
plotMap(xx)

where fill=TRUE reverses those lines that do not connect. I think that a 
PolySet thinks that it is a polygon, with fill=FALSE you get 11 lines, 
which although they are converted correctly with correct PID, seem to be 
closed by plotMap(). Indeed, using plotLines() instead of plotMap() 
achieves the effect you want (but with an odd axis artefact - plotLines() 
probably assumes that it is being added to an existing plot, and doesn't 
seem to set aspect correctly), plotMap() imposes the assumption that you 
have polygons.

Why not just plot(spmd)? Are you sure about the datum in your spatial 
reference (if it matters for you)?

Roger


> Thanks very much!
>
> ---------------------------------------------
> Ted Rosenbaum
> Graduate Student
> Department of Economics
> Yale University
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list