{"id":13857934,"url":"https://github.com/mdsumner/RGDALDB","last_synced_at":"2025-07-13T22:31:27.821Z","repository":{"id":72211762,"uuid":"148343394","full_name":"mdsumner/RGDALDB","owner":"mdsumner","description":"See https://github.com/mdsumner/RGDALSQL (this was DBI for GDAL (and sf, after many patchy attempts)","archived":true,"fork":false,"pushed_at":"2019-10-14T01:30:30.000Z","size":136,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-22T15:41:30.844Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mdsumner.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-09-11T16:01:47.000Z","updated_at":"2023-01-28T16:56:34.000Z","dependencies_parsed_at":"2023-05-28T08:00:32.643Z","dependency_job_id":null,"html_url":"https://github.com/mdsumner/RGDALDB","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mdsumner/RGDALDB","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdsumner%2FRGDALDB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdsumner%2FRGDALDB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdsumner%2FRGDALDB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdsumner%2FRGDALDB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mdsumner","download_url":"https://codeload.github.com/mdsumner/RGDALDB/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdsumner%2FRGDALDB/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265218209,"owners_count":23729496,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-05T03:01:51.173Z","updated_at":"2025-07-13T22:31:27.550Z","avatar_url":"https://github.com/mdsumner.png","language":"R","readme":"---\noutput: github_document\neditor_options: \n  chunk_output_type: console\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r setup, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n# RGDALDB\n\nThe goal of RGDALDB is to provide a DBI wrapper for GDAL's `ExecuteSQL` in sf. \n\n## What's here?\n\nA patchy work through of *building a DBI backend* for GDAL using sf. \n\nThe core is `sf::st_read(, query = '')` in an unsupported branch of sf, it relies on **OGRSQL**, which is not a real database engine. \n\nhttps://www.gdal.org/ogr_sql.html\n\nBut, we should be able to make it useable using the DBI abstractions and support in dbplyr. \n\nThese official guides to doing this have been partly implemented in this package: \n\nhttps://cran.r-project.org/web/packages/DBI/vignettes/backend.html\n\nhttps://cran.r-project.org/web/packages/dbplyr/vignettes/new-backend.html\n\n\nThere is significant overlap in the support in sf to read from PostGIS, so that needs clarifying. \n\n## Installation\n\n\n\n```R\nremotes::install_cran(\"sf\")\ndevtools::install_github(\"mdsumner/RGDALDB\")\n```\n\n\n\n## Example\n\nA pretty good example, ideally no data is read until `collect()` is called.\n\n```{r example}\nlibrary(dplyr)\nlibrary(DBI)\nlibrary(RGDALDB)\n\ncon \u003c- DBI::dbConnect(RGDALDB::GDALDB(), dsn = system.file(\"shape/nc.shp\", package=\"sf\"))\n#con \u003c- DBI::dbConnect(RGDALDB::GDALDB(), dsn = system.file(\"gpkg/nc.gpkg\", package=\"sf\"))\n\n(nclazy \u003c- tbl(con, \"nc\"))\n\nlibrary(sf)\nnclazy %\u003e% \n  dplyr::filter(AREA \u003e .1) %\u003e% \n  dplyr::select(AREA, PERIMETER, BIR74, FIPS) %\u003e% \n  collect() %\u003e%  ## consider making plot and collect methods for the tbl_GDALDBConnection\n  st_as_sf() %\u003e% \n  plot()\n\n```\n\n\n\nRough and ready examples\n\n```{r rough}\nlibrary(dplyr)\nlibrary(DBI)\ncon \u003c- DBI::dbConnect(RGDALDB::GDALDB(), dsn = system.file(\"extdata/nc.gpkg\", package= \"RGDALDB\"))\n#DBI::dbWriteTable(con, \"mtcars\", mtcars)\n\ntbl(con, \"nc.gpkg\")\n\ntbl(con, \"nc.gpkg\") %\u003e% filter(between(AREA, 0.05, 1))\n\n# * summarise(), mutate(), filter() etc: powered by sql_select()\n# * left_join(), inner_join(): powered by sql_join()\n# * semi_join(), anti_join(): powered by sql_semi_join()\n# * union(), intersect(), setdiff(): powered by sql_set_op()\n\n## NO, because we expect sf not a data frame\n##  tbl(con, \"nc.gpkg\") %\u003e% filter(between(AREA, 0.05, 0.1)) %\u003e% summarize(min(AREA)) \n\n\ntbl(con, \"nc.gpkg\") %\u003e% filter(between(AREA, 0.05, 0.1)) %\u003e% mutate(AREA = AREA * 2)\n\n## this works, no sense until we have either multiple layers or control over the row_number\ntbl(con, \"nc.gpkg\") %\u003e% left_join(tbl(con, \"nc.gpkg\"), \"CRESS_ID\")\n\n## FID is not working, need to wrap for row_number\n#tbl(con, \"nc.gpkg\") %\u003e% select(geom, AREA)  %\u003e% mutate(ID =row_number())\n\n```\n\n---\n\n  Please note that the 'RGDALDB' project is released with a\n  [Contributor Code of Conduct](CODE_OF_CONDUCT.md).\n  By contributing to this project, you agree to abide by its terms.\n","funding_links":[],"categories":["R"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdsumner%2FRGDALDB","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmdsumner%2FRGDALDB","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdsumner%2FRGDALDB/lists"}