Learn R Programming

maptools (version 1.1-8)

sp2tmap: Convert SpatialPolygons object for Stata tmap command

Description

The function converts a SpatialPolygons object for use with the Stata tmap command, by creating a data frame with the required columns.

Usage

sp2tmap(SP)

Value

a data frame with three columns:

_ID

an integer vector of polygon identifiers in numeric order

_X

numeric x coordinate

_Y

numeric y coordinate

and an ID_n attribute with the named polygon identifiers

Arguments

SP

a SpatialPolygons object

Author

Roger Bivand

References

https://www.stata.com/search.cgi?query=tmap

See Also

Examples

Run this code
if (FALSE) {
xx <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1],
 IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))
plot(xx, border="blue", axes=TRUE, las=1)
tmapdf <- sp2tmap(as(xx, "SpatialPolygons"))
if (require(foreign)) {
td <- tempdir()
write.dta(tmapdf, file=file.path(td, "NCmap.dta"), version=7)
NCdf <- as(xx, "data.frame")
NCdf$ID_n <- attr(tmapdf, "ID_names")
write.dta(NCdf, file=file.path(td, "NC.dta"), version=7)
}
}

Run the code above in your browser using DataLab