-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
3,012 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"hash": "c905e21f89488be81c960ab0cedd6660", | ||
"result": { | ||
"engine": "knitr", | ||
"markdown": "---\ntitle: \"6: duckdb\"\nauthor: Carl Boettiger\ndate: \"2024-03-06\"\n---\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(duckdbfs)\nlibrary(dplyr)\nlibrary(sf)\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\n# SQL\n\npad <- open_dataset(\"https://data.source.coop/cboettig/pad-us-3/pad-us3-combined.parquet\")\n\npad_meta <- duckdbfs::st_read_meta(\"https://data.source.coop/cboettig/pad-us-3/pad-us3-combined.fgb\", tblname = \"pad_meta\")\npad_meta\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 1 × 7\n feature_count geom_column_name geom_type name code wkt proj4\n <dbl> <chr> <chr> <chr> <chr> <chr> <chr>\n1 440107 geom Unknown (any) ESRI 102039 \"PROJCS[\\\"USA… +pro…\n```\n\n\n:::\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\npad |> \n filter(State_Nm == \"CA\") |> \n group_by(FeatClass) |> \n summarise(total_area = sum(SHAPE_Area),\n n = n()) |>\n collect()\n```\n\n::: {.cell-output .cell-output-stderr}\n\n```\nWarning: Missing values are always removed in SQL aggregation functions.\nUse `na.rm = TRUE` to silence this warning\nThis warning is displayed once every 8 hours.\n```\n\n\n:::\n\n::: {.cell-output .cell-output-stdout}\n\n```\n# A tibble: 5 × 3\n FeatClass total_area n\n <chr> <dbl> <dbl>\n1 Proclamation 173843820097. 324\n2 Easement 7275244842. 11337\n3 Marine 36793465608. 214\n4 Designation 129887995064. 1293\n5 Fee 194547665576. 17873\n```\n\n\n:::\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nduckdbfs::load_spatial()\n```\n:::\n\n\n\nReading in as a normal tibble, and then converting to a spatial object:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nca_fee <- pad |> \n filter(State_Nm == \"CA\", FeatClass == \"Fee\") |> \n collect()\n\nca_fee |> st_as_sf(sf_column_name = \"geometry\", crs = pad_meta$wkt)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\nSimple feature collection with 17873 features and 34 fields\nGeometry type: GEOMETRY\nDimension: XY\nBounding box: xmin: -2349024 ymin: 1242361 xmax: -1646723 ymax: 2452203\nProjected CRS: USA_Contiguous_Albers_Equal_Area_Conic_USGS_version\n# A tibble: 17,873 × 35\n FeatClass Category Own_Type Own_Name Loc_Own Mang_Type Mang_Name Loc_Mang\n * <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> \n 1 Fee Fee LOC CITY San Diego,… LOC CITY San Die…\n 2 Fee Fee LOC CITY San Diego,… LOC CITY San Die…\n 3 Fee Fee STAT OTHS University… STAT OTHS Univers…\n 4 Fee Fee STAT OTHS University… STAT OTHS Univers…\n 5 Fee Fee LOC CITY San Diego,… LOC CITY San Die…\n 6 Fee Fee LOC CITY San Diego,… LOC CITY San Die…\n 7 Fee Fee LOC CITY City of Sa… LOC CITY City of…\n 8 Fee Fee LOC CITY San Diego,… LOC CITY San Die…\n 9 Fee Fee LOC CITY San Diego,… LOC CITY San Die…\n10 Fee Fee LOC CITY San Diego,… LOC CITY San Die…\n# ℹ 17,863 more rows\n# ℹ 27 more variables: Des_Tp <chr>, Loc_Ds <chr>, Unit_Nm <chr>, Loc_Nm <chr>,\n# State_Nm <chr>, Agg_Src <chr>, GIS_Src <chr>, Src_Date <chr>,\n# GIS_Acres <int>, Source_PAID <chr>, WDPA_Cd <int>, Pub_Access <chr>,\n# Access_Src <chr>, Access_Dt <chr>, GAP_Sts <chr>, GAPCdSrc <chr>,\n# GAPCdDt <chr>, IUCN_Cat <chr>, IUCNCtSrc <chr>, IUCNCtDt <chr>,\n# Date_Est <chr>, Comments <chr>, EsmtHldr <chr>, EHoldTyp <chr>, …\n```\n\n\n:::\n:::\n\n\nSimilarly, any normal data frame can be coerced to a spatial `sf` object, e.g.:\n\n::: {.cell}\n\n```{.r .cell-code}\ndata.frame(lon = c(1,2), lat=c(0,0)) |> st_as_sf(coords = c(\"lon\", \"lat\"), crs=4326)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\nSimple feature collection with 2 features and 0 fields\nGeometry type: POINT\nDimension: XY\nBounding box: xmin: 1 ymin: 0 xmax: 2 ymax: 0\nGeodetic CRS: WGS 84\n geometry\n1 POINT (1 0)\n2 POINT (2 0)\n```\n\n\n:::\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nspatial_ex <- paste0(\"https://raw.githubusercontent.com/cboettig/duckdbfs/\",\n \"main/inst/extdata/spatial-test.csv\") |>\n open_dataset(format = \"csv\") \n\nspatial_ex |>\n mutate(geometry = st_point(longitude, latitude)) |>\n to_sf(crs = 4326)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\nSimple feature collection with 10 features and 3 fields\nGeometry type: POINT\nDimension: XY\nBounding box: xmin: 1 ymin: 1 xmax: 10 ymax: 10\nGeodetic CRS: WGS 84\n site latitude longitude geom\n1 a 1 1 POINT (1 1)\n2 b 2 2 POINT (2 2)\n3 c 3 3 POINT (3 3)\n4 d 4 4 POINT (4 4)\n5 e 5 5 POINT (5 5)\n6 f 6 6 POINT (6 6)\n7 g 7 7 POINT (7 7)\n8 h 8 8 POINT (8 8)\n9 i 9 9 POINT (9 9)\n10 j 10 10 POINT (10 10)\n```\n\n\n:::\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nca_fee <- pad |> \n filter(State_Nm == \"CA\", FeatClass == \"Fee\") |> \n group_by(Own_Type) |>\n summarise(total = sum(SHAPE_Area)) |> head(1000) |> collect()\n```\n:::", | ||
"supporting": [ | ||
"duckdb-example_files" | ||
], | ||
"filters": [ | ||
"rmarkdown/pagebreak.lua" | ||
], | ||
"includes": {}, | ||
"engineDependencies": {}, | ||
"preserve": {}, | ||
"postProcess": true | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file modified
BIN
+203 Bytes
(100%)
_freeze/notebook/fire-example/figure-html/unnamed-chunk-11-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+194 Bytes
(100%)
_freeze/notebook/fire-example/figure-html/unnamed-chunk-12-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.