Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with STIDF class #3

Open
agila5 opened this issue Aug 21, 2020 · 1 comment
Open

Error with STIDF class #3

agila5 opened this issue Aug 21, 2020 · 1 comment

Comments

@agila5
Copy link
Collaborator

agila5 commented Aug 21, 2020

Working on the implementation of Vector Data Cubes defined in stars I found the same error that is documented here and here.

I will add a reprex as soon as possible

@agila5
Copy link
Collaborator Author

agila5 commented Aug 21, 2020

# Get CRAN version of plotKML and github version of stars
remotes::install_cran("plotKML")
#> Skipping install of 'plotKML' from a cran remote, the SHA1 (0.6-1) has not changed since last install.
#>   Use `force = TRUE` to force installation
remotes::install_github("r-spatial/stars")
#> Skipping install of 'stars' from a github remote, the SHA1 (b7b54c8e) has not changed since last install.
#>   Use `force = TRUE` to force installation

# packages
library(plotKML)
#> plotKML version 0.6-1 (2020-03-08)
#> URL: http://plotkml.r-forge.r-project.org/
library(stars)
#> Carico il pacchetto richiesto: abind
#> Carico il pacchetto richiesto: sf
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1

# Data
data(air, package = "spacetime")
d = st_dimensions(station = st_as_sfc(stations), time = dates)
aq = st_as_stars(list(PM10 = air), dimensions = d)
(agg = aggregate(aq, "months", mean, na.rm = TRUE))
#> stars object with 2 dimensions and 1 attribute
#> attribute(s):
#>      PM10       
#>  Min.   : 2.99  
#>  1st Qu.:13.01  
#>  Median :16.43  
#>  Mean   :17.68  
#>  3rd Qu.:20.83  
#>  Max.   :68.55  
#>  NA's   :4926   
#> dimension(s):
#>         from  to offset delta                     refsys point
#> time       1 144     NA    NA                       Date    NA
#> station    1  70     NA    NA +proj=longlat +datum=WGS84  TRUE
#>                                                          values
#> time                                  1998-01-01,...,2009-12-01
#> station POINT (9.585911 53.67057),...,POINT (9.446661 49.24068)

# Convert to STFDF 
agg_STFDF <- as(agg, "STFDF")
plotKML(agg_STFDF, open.kml = FALSE) 
#> Plotting the first variable on the list
#> KML file opened for writing...
#> Warning in proj4string(obj): CRS object has comment, which is lost in output
#> Warning in proj4string(obj): CRS object has comment, which is lost in output
#> Writing to KML...
#> Closing  agg_STFDF.kml
#> Object written to: agg_STFDF.kml

# Spatial aggregation of agg
(agg2 <- aggregate(agg, st_as_sf(DE_NUTS1), mean, na.rm = TRUE))
#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
#> stars object with 2 dimensions and 1 attribute
#> attribute(s):
#>      PM10        
#>  Min.   : 6.037  
#>  1st Qu.:14.072  
#>  Median :16.704  
#>  Mean   :17.897  
#>  3rd Qu.:20.378  
#>  Max.   :59.218  
#>  NA's   :832     
#> dimension(s):
#>          from  to offset delta                     refsys point
#> geometry    1  16     NA    NA +proj=longlat +datum=WGS84 FALSE
#> time        1 144     NA    NA                       Date    NA
#>                                                                     values
#> geometry MULTIPOLYGON (((9.65046 49....,...,MULTIPOLYGON (((10.77189 51...
#> time                                             1998-01-01,...,2009-12-01
agg2_STFDF <- as(agg2, "STFDF")
plotKML(agg2_STFDF, open.kml = FALSE)
#> Error in from@sp[from@index[, 1], ]: SpatialPolygons selection: can't find plot order if polygons are replicated

Created on 2020-08-21 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant