sp2tmap: Convert SpatialPolygons object for Stata tmap command

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/sp2tmap.R

Description

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

Usage

1
sp2tmap(SP)

Arguments

SP

a SpatialPolygons object

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

Author(s)

Roger Bivand

References

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

See Also

write.dta

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## Not run: 
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)
}

## End(Not run)

Example output

Loading required package: sp
Checking rgeos availability: FALSE
 	Note: when rgeos is not available, polygon geometry 	computations in maptools depend on gpclib,
 	which has a restricted licence. It is disabled by default;
 	to enable gpclib, type gpclibPermit()
Warning message:
readShapePoly is deprecated; use rgdal::readOGR or sf::st_read 
Loading required package: foreign

maptools documentation built on Sept. 7, 2021, 5:09 p.m.