1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> suppressPackageStartupMessages(library(sp))
> suppressPackageStartupMessages(library(spacetime))
> suppressPackageStartupMessages(library(xts))
>
> # example 0: construction with STFDF:
>
> if (require(maps, quietly = TRUE)) {
+ states.m = map('state', plot=FALSE, fill=TRUE)
+ IDs <- sapply(strsplit(states.m$names, ":"), function(x) x[1])
+
+ if (require(maptools, quietly = TRUE)) {
+ states = map2SpatialPolygons(states.m, IDs=IDs)
+
+ if (require(plm, quietly = TRUE)) {
+ data(Produc)
+
+ yrs = 1970:1986
+ time = xts(1:17, as.POSIXct(paste(yrs, "-01-01", sep=""), tz = "GMT"))
+ # deselect District of Columbia, polygon 8, which is not present in Produc:
+ Produc.st = STFDF(states[-8], time, Produc[(order(Produc[,2], Produc[,1])),])
+ #stplot(Produc.st[,,"unemp"], yrs)
+
+ # example 1: st from long table, with states as Spatial object:
+ # use Date format for time:
+ Produc$time = as.Date(paste(yrs, "01", "01", sep = "-"))
+ xy = coordinates(states[-8])
+ Produc$x = xy[,1]
+ Produc$y = xy[,2]
+ #using stConstruct, use polygon centroids for location:
+ x = stConstruct(Produc, c("x", "y"), "time")
+ class(x)
+ stplot(x[,,"unemp"])
+
+ # alternatively, pass states:
+ Produc$state = gsub("TENNESSE", "TENNESSEE", Produc$state)
+ Produc$State = gsub("_", " ", tolower(Produc$state))
+ x = stConstruct(Produc, "State", "time", states[-8])
+ class(x)
+ #stplot(x[,,"unemp"], yrs)
+
+ if (require(rgdal, quietly = TRUE)) {
+ # stConstruct multivariable, time-wide
+ fname = system.file("shapes/sids.shp", package="maptools")[1]
+ nc = readOGR(fname)
+ timesList = list(
+ BIR=c("BIR74", "BIR79"),
+ NWBIR=c("NWBIR74", "NWBIR79"),
+ SID=c("SID74", "SID79")
+ )
+ t = xts(1:2, as.Date(c("1974-01-01","1979-01-01")))
+ nc.st = stConstruct(as(nc, "data.frame"), geometry(nc), timesList,
+ TimeObj = t)
+ }
+ }}}
Checking rgeos availability: TRUE
Please note that 'maptools' will be retired by the end of 2023,
plan transition at your earliest convenience;
some functionality will be moved to 'sp'.
Please note that rgdal will be retired by the end of 2023,
plan transition to sf/stars/terra functions using GDAL and PROJ
at your earliest convenience.
rgdal: version: 1.5-31, (SVN revision 1171)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 3.4.3, released 2022/04/22
Path to GDAL shared files: /usr/share/gdal
GDAL binary built with GEOS: TRUE
Loaded PROJ runtime: Rel. 8.2.0, November 1st, 2021, [PJ_VERSION: 820]
Path to PROJ shared files: /home/edzer/.local/share/proj:/usr/share/proj
PROJ CDN enabled: FALSE
Linking to sp version:1.4-7
To mute warnings of possible GDAL/OSR exportToProj4() degradation,
use options("rgdal_show_exportToProj4_warnings"="none") before loading sp or rgdal.
OGR data source with driver: ESRI Shapefile
Source: "/home/edzer/R/x86_64-pc-linux-gnu-library/4.0/maptools/shapes/sids.shp", layer: "sids"
with 100 features
It has 14 fields
Integer64 fields read as strings: CNTY_ CNTY_ID FIPSNO
>
> proc.time()
user system elapsed
1.900 0.068 1.982
|