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@data) == length(object@sp) * nrow(object@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@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to