TransWikia.com

How to use sf:gdal_utils with extent option (-te)?

Geographic Information Systems Asked on March 4, 2021

I want to build a Gdal VRT dataset with several bands and cropped to a specific region. For that, I’m using sf::gdal_utils but somehow I can’t get the option -te to work. It either complains about an unknown option or does nothing.

How to correctly set the -te option?

Here goes a reprex:

# bug in gdal_utils and buidvrt
# trying to use sf::gdal_utils buildvrt with -te option

library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 7.0.0
library(raster)
#> Loading required package: sp

# just to check extent
#tm <- raster(system.file("tif/L7_ETMs.tif", package="stars"))

# crop file using gdal VRT -te option

# Unknown option -te
# also tried with options te, using just one string instead of c()...
# can't figure out how to use this
gdal_utils(util = 'buildvrt', source = system.file("tif/L7_ETMs.tif", package="stars"),
           destination = 'tm_crop_r.vrt',
           options = c("-te", "290000 9119000 295000 9120000"))
#> Warning in CPL_gdalbuildvrt(source, destination, options, oo, quiet): GDAL Error
#> 6: Unknown option name '-te'

# check the size of the VRT dataset
readLines('tm_crop_r.vrt', n = 1)
#> [1] "<VRTDataset rasterXSize="349" rasterYSize="352">"

# using gdal CLI works

system(paste("gdalbuildvrt -te 290000 9119000 295000 9120000",
             "tm_crop_cli.vrt /home/daniel/R/x86_64-pc-linux-gnu-library/4.0/stars/tif/L7_ETMs.tif"))

readLines('tm_crop_cli.vrt', n = 1)
#> [1] "<VRTDataset rasterXSize="175" rasterYSize="35">"


sessionInfo()
#> R version 4.0.2 (2020-06-22)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 18.04.5 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
#> 
#> locale:
#>  [1] LC_CTYPE=pt_BR.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=pt_BR.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=pt_BR.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=pt_BR.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=pt_BR.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] raster_3.3-13 sp_1.4-2      sf_0.9-6     
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.5         knitr_1.29         magrittr_1.5       units_0.6-7       
#>  [5] tidyselect_1.1.0   lattice_0.20-41    R6_2.4.1           rlang_0.4.7       
#>  [9] stringr_1.4.0      highr_0.8          dplyr_1.0.2        tools_4.0.2       
#> [13] grid_4.0.2         xfun_0.16          KernSmooth_2.23-17 e1071_1.7-3       
#> [17] DBI_1.1.0          ellipsis_0.3.1     htmltools_0.5.0    class_7.3-17      
#> [21] yaml_2.2.1         digest_0.6.25      tibble_3.0.3       lifecycle_0.2.0   
#> [25] crayon_1.3.4       purrr_0.3.4        codetools_0.2-16   vctrs_0.3.2       
#> [29] glue_1.4.1         evaluate_0.14      rmarkdown_2.3      stringi_1.4.6     
#> [33] pillar_1.4.6       compiler_4.0.2     generics_0.0.2     classInt_0.4-3    
#> [37] pkgconfig_2.0.3

Created on 2020-09-18 by the reprex package (v0.3.0)

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP