[R-sig-Geo] errors with stConstruct() and STFDF()

Benedikt Gräler ben.graeler at uni-muenster.de
Wed Apr 23 09:20:05 CEST 2014


Dear Cyrus,

regarding "stConstruct":
Reading the help page of stConstruct, you will find that "space" and
"time" (2nd and 3rd argument) need to be the name (character) or number
(integer) of the corresponding columns, not the full column as you
provided. Please pay careful attention to the package documentation.

regarding "STFDF":
The error message says, that the product of spatial and temporal
instances is not the same as the length of the data. This condition is
crucial for a STFDF object, as it assumes that for any combination of
space and time there is an observation.
In your case, the time slot has already as many instances as are rows in
your data.frame. You only have to provide each date once and it will be
associated with all spatial instances by the design of a STFDF. Note
that the ordering of the data slot assumes space to cycle fastest.
Furthermore, you need to make sure that your polygons have a matching
ordering to the spatial entities in the data frame.
See the vignette of spacetime [1] for further explanations and
illustrations (i.e. Figure 1) on STFDF, STSDF and STIDF.

[1] http://cran.r-project.org/web/packages/spacetime/vignettes/jss816.pdf

HTH,

 Ben


On 22.04.2014 22:32, Cyrus Mohammadian wrote:
> Hey everyone, I’m new to R and this forum so I apologize in advance for any ambiguity in my question. What I want to do is create a spatiotemporal object (class st) out of an esri shapefile with multiple features and csv file containing data in long format (each row is one observation in space-time). So what I’ve done is imported the shapefile into r using 
> 
> Library(rgdal)
> # read in shape files
> polygons.shp <- readOGR(“polygon.shp", layer=“polygon”)
> 
> # rgdal returns the .prj file associated with the shapefile
> print(proj4string(polygon.shp))
> [1] "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
> 
> # converted the csv file to a data.frame 
> long_format.df <- as.data.frame(long_format.csv)
> 
> # converted time variable to proper date format in R
> long_format.df$Date <- as.Date(as.character(long_format.df$Date), format= "%Y%m%d”) 
> 
> 
> My long format table looks something like this: each location is associated with an ID (that matches the polygon IDs in my shapefile) has a location name and   specific date and some variables. The variables fluctuate between temporal and static. For example, X3 and X4 only change over space but not time while X1  and X2 vary over space and time. The dates are the time at which the space-time variables were collected (the last day of each month). 
> 
>    ID   LocationName    Date 	X1 X2 X3 X4...
> 	1		California		2013-03-28	1  1  3	 0
> 	2		Washington	2013-03-28	0  1  9  9
> 	3		Oregon		2013-03-28	1  3  0	 8
> 	1		California		2013-04-30	0  4  3	 0
> 	2		Washington	2013-04-30	5  9  9  9
> 	3		Oregon		2013-04-30	1  0  0	 8	
> 	1		California		2013-05-31	7  6  3	 0
> 	2		Washington	2013-05-31	0  0  9  9
> 	3		Oregon		2013-05-31	1  5  0  8
> 
> When I try to use the stConstruct() I get this error:
> 
> stConstruct(long_format.df, long_format.df $ID, long_format.df $Date, SpatialObj =polygon.shp, TimeObj = NULL)
> Error in stConstruct(long_format.df, long_format.df $ID, long_format.df $Date, SpatialObj =polygon.shp, TimeObj = NULL) : 
>   unknown parameter combination
> 
> When I try to use the STFDF() I get this error:
> 
> STFDF(polygon, long_format.df$Date, long_format.df)
> Error: nrow(object at data) == length(object at sp) * nrow(object at time) is not TRUE
> 
> I also created a separate xts time object in place of ‘long_format.df$Date' and tried that but it resulted in the same error.
> 
> Any help or advice would be much appreciated!!!
> 
> Best,
> 
> Cyrus
> 
> 
> 	[[alternative HTML version deleted]]
> 
> 
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Benedikt Gräler

ifgi - Institute for Geoinformatics
University of Muenster

http://ifgi.uni-muenster.de/graeler

Phone: +49 251 83-33082
Mail: ben.graeler at uni-muenster.de

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 560 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20140423/76e245ae/attachment.bin>


More information about the R-sig-Geo mailing list