sf icon indicating copy to clipboard operation
sf copied to clipboard

Can't execute query from gdal_utils + ogrinfo

Open latot opened this issue 1 year ago • 4 comments

Hi!, I'm trying to use ogrinfo to remove a table from a gpkg:

a <- sf::st_sf(geom = sf::st_sfc())
sf::st_write(a, "tmp.gpkg", layer = "hahah")

sf::gdal_utils(
  util = "ogrinfo",
  "tmp.gpkg",
  options = c(
    "-sql", "DROP TABLE IF EXISTS hahah",
    "-dialect", "sqlite"
  )
)

And I got the next error:

In CPL_ogrinfo(if (missing(source)) character(0) else source, options,  :
  GDAL Error 1: In ExecuteSQL(): sqlite3_step(DROP TABLE IF EXISTS hahah):
  attempt to write a readonly database

This command works fine from ogrinfo in the terminal.

R version 4.4.1 (2024-06-14)
Platform: x86_64-pc-linux-gnu
Running under: Gentoo Linux

Matrix products: default
BLAS:   /usr/lib64/libblas.so.3.12.0 
LAPACK: /usr/lib64/liblapack.so.3.12.0

locale:
 [1] LC_CTYPE=es_CL.utf8       LC_NUMERIC=C             
 [3] LC_TIME=es_CL.utf8        LC_COLLATE=es_CL.utf8    
 [5] LC_MONETARY=es_CL.utf8    LC_MESSAGES=es_CL.utf8   
 [7] LC_PAPER=es_CL.utf8       LC_NAME=C                
 [9] LC_ADDRESS=C              LC_TELEPHONE=C           
[11] LC_MEASUREMENT=es_CL.utf8 LC_IDENTIFICATION=C      

time zone: Chile/Continental
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] compiler_4.4.1     magrittr_2.0.3     class_7.3-22       tools_4.4.1       
 [5] DBI_1.2.3          units_0.8-5        proxy_0.4-27       Rcpp_1.0.12       
 [9] KernSmooth_2.23-24 grid_4.4.1         e1071_1.7-14       classInt_0.4-10   
[13] sf_1.0-17 

Thx!

latot avatar Aug 01 '24 21:08 latot

Pls reinstall from source, and try again.

edzer avatar Aug 24 '24 18:08 edzer

@edzer sorry for the time, I was very busy, I reinstalled from source, restarted R, and I got the same result.

I upgraded the reprex above to also shows how to create the file.

latot avatar Sep 23 '24 18:09 latot

I get

INFO: Open of `tmp.gpkg'
      using driver `GPKG' successful.
Warning message:
In CPL_ogrinfo(if (missing(source)) character(0) else source, options,  :
  GDAL Message 1: Table/view hahah is referenced in gpkg_contents, but does not exist

with

> sf_extSoftVersion()
          GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H 
      "3.12.1"        "3.8.4"        "9.4.0"         "true"         "true" 
          PROJ 
       "9.4.0" 

edzer avatar Sep 23 '24 19:09 edzer

mm, I has this ones:

sf::sf_extSoftVersion()
          GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H 
      "3.12.1"        "3.9.1"        "9.2.1"         "true"         "true" 
          PROJ 
       "9.2.1"

We have GDAL and PROJ with different versions. Also I run this on /tmp folder.

latot avatar Sep 23 '24 19:09 latot

See #2460 - looks like we'll have to revert this and make update an option - "ogrinfo" after all suggests to provide info, also on read-only datasets.

edzer avatar Oct 23 '24 07:10 edzer

Since ogrinfo has a -ro option, I guess update is the right default.

edzer avatar Oct 23 '24 10:10 edzer