“R” 和 SQL 用于查询大型 JSON 数据

huangapple go评论98阅读模式
英文:

"R" and SQL to query large JSON data

问题

我有一个大的JSON文件(383,255KB)。它包含街道名称、地址和纬度/经度值。
我认为我说得对,这是WGS84世界大地测量系统84文件格式。

我只想在“R”中查询这些数据。
我正在考虑使用SQL,因为在这种情况下它很高效,但我不知道有哪些包/方法可以采用这种方法。

我想要做的是:

  1. select Latitude, Longitude From JSONData Where Address = "160" and LFNAME = "Transit Rd"

JSON数据文件的结构(以及一些相关的数据块)如下所示:

  1. {
  2. "type" : "FeatureCollection",
  3. "name" : "ADDRESS_POINT_WGS84",
  4. "features" : [
  5. {
  6. "type" : "Feature",
  7. "geometry" : {
  8. "type" : "Point",
  9. "coordinates" : [ -79.539538708, 43.586921565 ]
  10. },
  11. "properties" : {
  12. "GEO_ID" : 5729529,
  13. "LINK" : 5729516,
  14. "MAINT_STAG" : "REGULAR",
  15. "ADDRESS" : "399",
  16. "LFNAME" : "Lake Promenade",
  17. "LO_NUM" : 399,
  18. "LONUMSUF" : null,
  19. "HINUM" : null,
  20. "HINUMSUF" : null,
  21. "ARC_SIDE" : "L",
  22. "DISTANCE" : 4.15,
  23. "FCODE" : 115001,
  24. "FCODE_DES" : "Unknown",
  25. "CLASS" : "Land",
  26. "NAME" : null,
  27. "X" : 301607.151,
  28. "Y" : 4827443.931,
  29. "LONGITUDE" : -79.5395419864,
  30. "LATITUDE" : 43.5869301259,
  31. "OBJECTID" : 1491585,
  32. "MUN_NAME" : "Etobicoke",
  33. "WARD_NAME" : "Etobicoke-Lakeshore"
  34. }
  35. },
  36. ...
  37. ]
  38. }

我将查找成千上万个城市地址的纬度/经度值,因此将数据存储在内存中是有意义的。

我还没有完全阅读这篇文章:https://themockup.blog/posts/2020-05-22-parsing-json-in-r-with-jsonlite/

我已经阅读了关于“矩形化”的文章:https://tidyr.tidyverse.org/articles/rectangle.html。
我尝试了一些方法,但对我来说似乎过于复杂。

我一定是走错了路,老实说,我不知道该采取什么方法。
我只是要确定地址的纬度/经度值。
一旦我获得了“项目”所需的纬度/经度值,我将在地图上显示这些项目。

难道没有更好的方法吗?

感谢您的任何提示/建议/指导。

Richard

英文:

I have a large JSON file (383,255KB). It contains street names, addresses, and lat/long values.
I think I'm right in saying this is a WGS84 World Geodetic System 84 file format.

All I want to do is query this data, in "R".
I'm thinking in SQL, because it is efficient in this context, but
I am not aware of any package/method to take this approach.

I would like to:

  1. select Latitude, Longitude From JSONData Where Address = "160" and LFNAME = "Transit Rd"

The structure (and a few relevant data blocks) of the JSON data file are shown here:

  1. {
  2. "type" : "FeatureCollection",
  3. "name" : "ADDRESS_POINT_WGS84",
  4. "features" : [
  5. {
  6. "type" : "Feature",
  7. "geometry" : {
  8. "type" : "Point",
  9. "coordinates" : [ -79.539538708, 43.586921565 ]
  10. },
  11. "properties" : {
  12. "GEO_ID" : 5729529,
  13. "LINK" : 5729516,
  14. "MAINT_STAG" : "REGULAR",
  15. "ADDRESS" : "399",
  16. "LFNAME" : "Lake Promenade",
  17. "LO_NUM" : 399,
  18. "LONUMSUF" : null,
  19. "HINUM" : null,
  20. "HINUMSUF" : null,
  21. "ARC_SIDE" : "L",
  22. "DISTANCE" : 4.15,
  23. "FCODE" : 115001,
  24. "FCODE_DES" : "Unknown",
  25. "CLASS" : "Land",
  26. "NAME" : null,
  27. "X" : 301607.151,
  28. "Y" : 4827443.931,
  29. "LONGITUDE" : -79.5395419864,
  30. "LATITUDE" : 43.5869301259,
  31. "OBJECTID" : 1491585,
  32. "MUN_NAME" : "Etobicoke",
  33. "WARD_NAME" : "Etobicoke-Lakeshore"
  34. }
  35. },
  36. {
  37. "type" : "Feature",
  38. "geometry" : {
  39. "type" : "Point",
  40. "coordinates" : [ -79.540371034, 43.5882630139 ]
  41. },
  42. "properties" : {
  43. "GEO_ID" : 9950585,
  44. "LINK" : 9950578,
  45. "MAINT_STAG" : "REGULAR",
  46. "ADDRESS" : "7",
  47. "LFNAME" : "Hilo Rd",
  48. "LO_NUM" : 7,
  49. "LONUMSUF" : null,
  50. "HINUM" : null,
  51. "HINUMSUF" : null,
  52. "ARC_SIDE" : "L",
  53. "DISTANCE" : 43.77,
  54. "FCODE" : 115001,
  55. "FCODE_DES" : "Unknown",
  56. "CLASS" : "Land",
  57. "NAME" : null,
  58. "X" : 301540.011,
  59. "Y" : 4827592.989,
  60. "LONGITUDE" : -79.5403743125,
  61. "LATITUDE" : 43.5882715763,
  62. "OBJECTID" : 1491586,
  63. "MUN_NAME" : "Etobicoke",
  64. "WARD_NAME" : "Etobicoke-Lakeshore"
  65. }
  66. },
  67. {
  68. "type" : "Feature",
  69. "geometry" : {
  70. "type" : "Point",
  71. "coordinates" : [ -79.5390269742, 43.587174988 ]
  72. },
  73. "properties" : {
  74. "GEO_ID" : 5729496,
  75. "LINK" : 5729468,
  76. "MAINT_STAG" : "REGULAR",
  77. "ADDRESS" : "387",
  78. "LFNAME" : "Lake Promenade",
  79. "LO_NUM" : 387,
  80. "LONUMSUF" : null,
  81. "HINUM" : null,
  82. "HINUMSUF" : null,
  83. "ARC_SIDE" : "L",
  84. "DISTANCE" : 97.58,
  85. "FCODE" : 115001,
  86. "FCODE_DES" : "Unknown",
  87. "CLASS" : "Land",
  88. "NAME" : null,
  89. "X" : 301648.488,
  90. "Y" : 4827472.065,
  91. "LONGITUDE" : -79.5390302568,
  92. "LATITUDE" : 43.5871835468,
  93. "OBJECTID" : 1491591,
  94. "MUN_NAME" : "Etobicoke",
  95. "WARD_NAME" : "Etobicoke-Lakeshore"
  96. }
  97. },
  98. {
  99. "type" : "Feature",
  100. "geometry" : {
  101. "type" : "Point",
  102. "coordinates" : [ -79.3880422943, 43.6830929049 ]
  103. },
  104. "properties" : {
  105. "GEO_ID" : 850466,
  106. "LINK" : 20002604,
  107. "MAINT_STAG" : "REGULAR",
  108. "ADDRESS" : "1",
  109. "LFNAME" : "Ottawa St",
  110. "LO_NUM" : 1,
  111. "LONUMSUF" : null,
  112. "HINUM" : null,
  113. "HINUMSUF" : null,
  114. "ARC_SIDE" : "R",
  115. "DISTANCE" : 3.99,
  116. "FCODE" : 115001,
  117. "FCODE_DES" : "Unknown",
  118. "CLASS" : "Land",
  119. "NAME" : null,
  120. "X" : 313826.457,
  121. "Y" : 4838133.322,
  122. "LONGITUDE" : -79.388042294,
  123. "LATITUDE" : 43.683092902,
  124. "OBJECTID" : 4675851,
  125. "MUN_NAME" : "former Toronto",
  126. "WARD_NAME" : "University-Rosedale"
  127. }
  128. }
  129. ]
  130. }

I will be looking up lat/long values for thousands of city addresses, so it makes sense to have the data in memory.

I haven't completely read this article: https://themockup.blog/posts/2020-05-22-parsing-json-in-r-with-jsonlite/

I've read about "Rectangling" here: https://tidyr.tidyverse.org/articles/rectangle.html.
I monkeyed about, it seems too complicated to me.

I must be going about this the wrong way, and I honestly don't know what approach to take.
I'm just determining lat/long values for addresses.
Once I have the lat/long values for the "items" I'm tracking, I will show those items on a map.

Isn't there another better way?

Thank you for any tips/advice/pointers.

Richard

答案1

得分: 1

以下是您提供的代码的翻译部分:

  1. # 导入jsonlite和tidyverse库
  2. library(jsonlite)
  3. library(tidyverse)
  4. # 将给定的字符串存储在变量中
  5. json_string <- '{ "type" : "FeatureCollection", "name" : "ADDRESS_POINT_WGS84", "features" : [ { "type" : "Feature", "geometry" : { "type" : "Point", "coordinates" : [ -79.539538708, 43.586921565 ] }, "properties" : { "GEO_ID" : 5729529, "LINK" : 5729516, "MAINT_STAG" : "REGULAR", "ADDRESS" : "399", "LFNAME" : "Lake Promenade", "LO_NUM" : 399, "LONUMSUF" : null, "HINUM" : null, "HINUMSUF" : null, "ARC_SIDE" : "L", "DISTANCE" : 4.15, "FCODE" : 115001, "FCODE_DES" : "Unknown", "CLASS" : "Land", "NAME" : null, "X" : 301607.151, "Y" : 4827443.931, "LONGITUDE" : -79.5395419864, "LATITUDE" : 43.5869301259, "OBJECTID" : 1491585, "MUN_NAME" : "Etobicoke", "WARD_NAME" : "Etobicoke-Lakeshore" } } ] }'
  6. # 将字符串转换为JSON对象
  7. json_data <- jsonlite::fromJSON(json_string)
  8. my_df <- json_data$features
  9. my_df <- my_df %>%
  10. unnest_wider(col="properties")
  11. names(my_df)
  12. #> [1] "type" "geometry" "GEO_ID" "LINK" "MAINT_STAG"
  13. #> [6] "ADDRESS" "LFNAME" "LO_NUM" "LONUMSUF"
  14. #> [11] "HINUM" "HINUMSUF" "ARC_SIDE" "DISTANCE" "FCODE"
  15. #> [16] "FCODE_DES" "CLASS" "NAME" "X" "Y"
  16. #> [21] "LONGITUDE" "LATITUDE" "OBJECTID" "MUN_NAME" "WARD_NAME"
  17. my_df %>%
  18. filter(ADDRESS=="399") %>%
  19. filter(LFNAME=="Lake Promenade")
  20. #> # A tibble: 1 × 24
  21. #> type geometry$type GEO_ID LINK MAINT_STAG ADDRESS LFNAME LO_NUM LONUMSUF
  22. #> <chr> <chr> <int> <int> <chr> <chr> <chr> <int> <lgl>
  23. #> 1 Feature Point 5729529 5.73e6 REGULAR 399 Lake … 399 NA
  24. #> # ℹ 16 more variables: geometry$coordinates <list>, HINUM <lgl>,
  25. #> # HINUMSUF <lgl>, ARC_SIDE <chr>, DISTANCE <dbl>, FCODE <int>,
  26. #> # FCODE_DES <chr>, CLASS <chr>, NAME <lgl>, X <dbl>, Y <dbl>,
  27. #> # LONGITUDE <dbl>, LATITUDE <dbl>, OBJECTID <int>, MUN_NAME <chr>,
  28. #> # WARD_NAME <chr>

希望这有帮助!如果您需要任何进一步的翻译,请随时告诉我。

英文:
  1. library(jsonlite)
  2. library(tidyverse)
  3. # Store the given string in a variable
  4. json_string &lt;- &#39;{ &quot;type&quot; : &quot;FeatureCollection&quot;, &quot;name&quot; : &quot;ADDRESS_POINT_WGS84&quot;, &quot;features&quot; : [ { &quot;type&quot; : &quot;Feature&quot;, &quot;geometry&quot; : { &quot;type&quot; : &quot;Point&quot;, &quot;coordinates&quot; : [ -79.539538708, 43.586921565 ] }, &quot;properties&quot; : { &quot;GEO_ID&quot; : 5729529, &quot;LINK&quot; : 5729516, &quot;MAINT_STAG&quot; : &quot;REGULAR&quot;, &quot;ADDRESS&quot; : &quot;399&quot;, &quot;LFNAME&quot; : &quot;Lake Promenade&quot;, &quot;LO_NUM&quot; : 399, &quot;LONUMSUF&quot; : null, &quot;HINUM&quot; : null, &quot;HINUMSUF&quot; : null, &quot;ARC_SIDE&quot; : &quot;L&quot;, &quot;DISTANCE&quot; : 4.15, &quot;FCODE&quot; : 115001, &quot;FCODE_DES&quot; : &quot;Unknown&quot;, &quot;CLASS&quot; : &quot;Land&quot;, &quot;NAME&quot; : null, &quot;X&quot; : 301607.151, &quot;Y&quot; : 4827443.931, &quot;LONGITUDE&quot; : -79.5395419864, &quot;LATITUDE&quot; : 43.5869301259, &quot;OBJECTID&quot; : 1491585, &quot;MUN_NAME&quot; : &quot;Etobicoke&quot;, &quot;WARD_NAME&quot; : &quot;Etobicoke-Lakeshore&quot; } } ] }&#39;
  5. # Convert the string to a JSON object
  6. json_data &lt;- jsonlite::fromJSON(json_string)
  7. my_df &lt;- json_data$features
  8. my_df &lt;- my_df %&gt;%
  9. unnest_wider(col=&quot;properties&quot;)
  10. names(my_df)
  11. #&gt; [1] &quot;type&quot; &quot;geometry&quot; &quot;GEO_ID&quot; &quot;LINK&quot; &quot;MAINT_STAG&quot;
  12. #&gt; [6] &quot;ADDRESS&quot; &quot;LFNAME&quot; &quot;LO_NUM&quot; &quot;LONUMSUF&quot; &quot;HINUM&quot;
  13. #&gt; [11] &quot;HINUMSUF&quot; &quot;ARC_SIDE&quot; &quot;DISTANCE&quot; &quot;FCODE&quot; &quot;FCODE_DES&quot;
  14. #&gt; [16] &quot;CLASS&quot; &quot;NAME&quot; &quot;X&quot; &quot;Y&quot; &quot;LONGITUDE&quot;
  15. #&gt; [21] &quot;LATITUDE&quot; &quot;OBJECTID&quot; &quot;MUN_NAME&quot; &quot;WARD_NAME&quot;
  16. my_df %&gt;%
  17. filter(ADDRESS==&quot;399&quot;) %&gt;%
  18. filter(LFNAME==&quot;Lake Promenade&quot;)
  19. #&gt; # A tibble: 1 &#215; 24
  20. #&gt; type geometry$type GEO_ID LINK MAINT_STAG ADDRESS LFNAME LO_NUM LONUMSUF
  21. #&gt; &lt;chr&gt; &lt;chr&gt; &lt;int&gt; &lt;int&gt; &lt;chr&gt; &lt;chr&gt; &lt;chr&gt; &lt;int&gt; &lt;lgl&gt;
  22. #&gt; 1 Feature Point 5729529 5.73e6 REGULAR 399 Lake … 399 NA
  23. #&gt; # ℹ 16 more variables: geometry$coordinates &lt;list&gt;, HINUM &lt;lgl&gt;,
  24. #&gt; # HINUMSUF &lt;lgl&gt;, ARC_SIDE &lt;chr&gt;, DISTANCE &lt;dbl&gt;, FCODE &lt;int&gt;,
  25. #&gt; # FCODE_DES &lt;chr&gt;, CLASS &lt;chr&gt;, NAME &lt;lgl&gt;, X &lt;dbl&gt;, Y &lt;dbl&gt;,
  26. #&gt; # LONGITUDE &lt;dbl&gt;, LATITUDE &lt;dbl&gt;, OBJECTID &lt;int&gt;, MUN_NAME &lt;chr&gt;,
  27. #&gt; # WARD_NAME &lt;chr&gt;

<sup>Created on 2023-05-10 with reprex v2.0.2</sup>

答案2

得分: 0

提供的文件示例是有效的 GeoJSON 文件,空间包(如 sf)可以直接处理它。sf 对象基本上是一个带有特殊几何列的数据框,因此您可以主要使用标准的数据整理工具和方法来处理属性,无论是基本 R 还是 dplyr / Tidyverse。如果您真的想要的话,也可以使用 sf 进行 SQL 查询(仅在读取文件时可用,因此每个查询都会从磁盘读取整个数据集到内存,至少在存储为 json 时是这样的)。或者使用 sqldf 包在数据框上使用 SQL,尽管这样您会错过对 sf 工具的直接访问 - https://r-spatial.github.io/sf/

  1. library(sf)
  2. library(dplyr)
  3. # 读取示例数据集,保存为 sample.geojson
  4. sample_sf <- st_read("sample.geojson", quiet = TRUE, as_tibble = TRUE)
  5. sample_sf
  6. #> Simple feature collection with 4 features and 22 fields
  7. #> Geometry type: POINT
  8. #> Dimension: XY
  9. #> Bounding box: xmin: -79.54037 ymin: 43.58692 xmax: -79.38804 ymax: 43.68309
  10. #> Geodetic CRS: WGS 84
  11. #> # A tibble: 4 × 23
  12. #> GEO_ID LINK MAINT_STAG ADDRESS LFNAME LO_NUM LONUMSUF HINUM HINUMSUF
  13. #> <int> <int> <chr> <chr> <chr> <int> <chr> <chr> <chr>
  14. #> 1 5729529 5729516 REGULAR 399 Lake Prome… 399 <NA> <NA> <NA>
  15. #> 2 9950585 9950578 REGULAR 7 Hilo Rd 7 <NA> <NA> <NA>
  16. #> 3 5729496 5729468 REGULAR 387 Lake Prome… 387 <NA> <NA> <NA>
  17. #> 4 850466 20002604 REGULAR 1 Ottawa St 1 <NA> <NA> <NA>
  18. #> # ℹ 14 more variables: ARC_SIDE <chr>, DISTANCE <dbl>,
  19. #> # FCODE <int>, FCODE_DES <chr>, CLASS <chr>, NAME <chr>, X <dbl>, Y <dbl>,
  20. #> # LONGITUDE <dbl>, LATITUDE <dbl>, OBJECTID <int>, MUN_NAME <chr>,
  21. #> # WARD_NAME <chr>, geometry <POINT [°]>
  22. # 使用 mapview 过滤和绘制结果
  23. sample_sf %>%
  24. filter(ADDRESS == "7", LFNAME == "Hilo Rd") %>%
  25. mapview::mapview()

“R” 和 SQL 用于查询大型 JSON 数据

  1. # 在空间数据集上使用 SQL 查询:
  2. st_read("sample.geojson", quiet = TRUE, as_tibble = TRUE,
  3. query = "select Latitude, Longitude From ADDRESS_POINT_WGS84 Where ADDRESS = '7'")
  4. #> Simple feature collection with 1 feature and 2 fields
  5. #> Geometry type: POINT
  6. #> Dimension: XY
  7. #> Bounding box: xmin: -79.54037 ymin: 43.58826 xmax: -79.54037 ymax: 43.58826
  8. #> Geodetic CRS: WGS 84
  9. #> # A tibble: 1 × 3
  10. #> Latitude Longitude geometry
  11. #> <dbl> <dbl> <POINT [°]>
  12. #> 1 43.6 -79.5 (-79.54037 43.58826)
  13. # 对于较大的数据集,您可能希望考虑比 json 更紧凑的存储选项,例如 GeoPackage,它实际上是一个 SQLite 文件。
  14. st_write(sample_sf, "sample.gpkg")
  15. # 或者只是 R rds:
  16. readr::write_rds(sample_sf, "sample.rds")
  17. # 尽管对于这个小示例,生成的 gpkg 大小超过了 json 的大小:
  18. list.files() %>% file.info() %>% `[`(1)
  19. #> size
  20. #> sample.geojson 3537
  21. #> sample.gpkg 98304
  22. #> sample.rds 3411
  23. # 读取时,只需替换文件名;sf 会根据扩展名猜测类型/驱动程序
  24. sample_g <- st_read("sample.gpkg", quiet = TRUE, as_tibble = TRUE)

创建于2023-05-10,使用 reprex v2.0.2

英文:

Provided file sample is valid GeoJSON and spatial packages, like sf, can handle it directly. sf object is basically a dataframe with special geometry column(s), so you mostly use your standard data wrangling tools and methods to deal with attributes, be it base R or dplyr / Tidyverse. If you really want to, you can also use SQL queries with sf (only available when reading a file, so every single query reads the whole dataset from disk to memory, at least when it's stored as json). Or use sqldf package to use SQL on dataframes, though you'd then miss direct access to sf tools - https://r-spatial.github.io/sf/

  1. library(sf)
  2. library(dplyr)
  3. # read sample dataset, saved as sample.geojson
  4. sample_sf &lt;- st_read(&quot;sample.geojson&quot;, quiet = TRUE, as_tibble = TRUE)
  5. sample_sf
  6. #&gt; Simple feature collection with 4 features and 22 fields
  7. #&gt; Geometry type: POINT
  8. #&gt; Dimension: XY
  9. #&gt; Bounding box: xmin: -79.54037 ymin: 43.58692 xmax: -79.38804 ymax: 43.68309
  10. #&gt; Geodetic CRS: WGS 84
  11. #&gt; # A tibble: 4 &#215; 23
  12. #&gt; GEO_ID LINK MAINT_STAG ADDRESS LFNAME LO_NUM LONUMSUF HINUM HINUMSUF
  13. #&gt; &lt;int&gt; &lt;int&gt; &lt;chr&gt; &lt;chr&gt; &lt;chr&gt; &lt;int&gt; &lt;chr&gt; &lt;chr&gt; &lt;chr&gt;
  14. #&gt; 1 5729529 5729516 REGULAR 399 Lake Prome… 399 &lt;NA&gt; &lt;NA&gt; &lt;NA&gt;
  15. #&gt; 2 9950585 9950578 REGULAR 7 Hilo Rd 7 &lt;NA&gt; &lt;NA&gt; &lt;NA&gt;
  16. #&gt; 3 5729496 5729468 REGULAR 387 Lake Prome… 387 &lt;NA&gt; &lt;NA&gt; &lt;NA&gt;
  17. #&gt; 4 850466 20002604 REGULAR 1 Ottawa St 1 &lt;NA&gt; &lt;NA&gt; &lt;NA&gt;
  18. #&gt; # ℹ 14 more variables: ARC_SIDE &lt;chr&gt;, DISTANCE &lt;dbl&gt;, FCODE &lt;int&gt;,
  19. #&gt; # FCODE_DES &lt;chr&gt;, CLASS &lt;chr&gt;, NAME &lt;chr&gt;, X &lt;dbl&gt;, Y &lt;dbl&gt;,
  20. #&gt; # LONGITUDE &lt;dbl&gt;, LATITUDE &lt;dbl&gt;, OBJECTID &lt;int&gt;, MUN_NAME &lt;chr&gt;,
  21. #&gt; # WARD_NAME &lt;chr&gt;, geometry &lt;POINT [&#176;]&gt;
  22. # filter and plot results with mapview
  23. sample_sf %&gt;%
  24. filter(ADDRESS == &quot;7&quot;,LFNAME == &quot;Hilo Rd&quot;) %&gt;%
  25. mapview::mapview()

“R” 和 SQL 用于查询大型 JSON 数据<!-- -->

  1. # use SQL query on spatial dataset:
  2. st_read(&quot;sample.geojson&quot;, quiet = TRUE, as_tibble = TRUE,
  3. query = &quot;select Latitude, Longitude From ADDRESS_POINT_WGS84 Where ADDRESS = &#39;7&#39;&quot;)
  4. #&gt; Simple feature collection with 1 feature and 2 fields
  5. #&gt; Geometry type: POINT
  6. #&gt; Dimension: XY
  7. #&gt; Bounding box: xmin: -79.54037 ymin: 43.58826 xmax: -79.54037 ymax: 43.58826
  8. #&gt; Geodetic CRS: WGS 84
  9. #&gt; # A tibble: 1 &#215; 3
  10. #&gt; Latitude Longitude geometry
  11. #&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;POINT [&#176;]&gt;
  12. #&gt; 1 43.6 -79.5 (-79.54037 43.58826)
  13. # You might want to consider more compact storage options than json
  14. # for larger datasets, for example GeoPackage, which is actually an SQLite file.
  15. st_write(sample_sf, &quot;sample.gpkg&quot;)
  16. # or just R rds:
  17. readr::write_rds(sample_sf, &quot;sample.rds&quot;)
  18. # Though for this small sample, the resulting gpkg size exceeds json&#39;s:
  19. list.files() %&gt;% file.info() %&gt;% `[`(1)
  20. #&gt; size
  21. #&gt; sample.geojson 3537
  22. #&gt; sample.gpkg 98304
  23. #&gt; sample.rds 3411
  24. # For reading, just replace the filename; sf guesses the type / driver
  25. # from extension
  26. sample_g &lt;- st_read(&quot;sample.gpkg&quot;, quiet = TRUE, as_tibble = TRUE)

<sup>Created on 2023-05-10 with reprex v2.0.2</sup>

huangapple
  • 本文由 发表于 2023年5月10日 14:12:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76215357.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定