{"id":13857950,"url":"https://github.com/ropensci/geojson","last_synced_at":"2026-02-21T17:35:01.206Z","repository":{"id":60722829,"uuid":"55250630","full_name":"ropensci/geojson","owner":"ropensci","description":"GeoJSON classes for R","archived":false,"fork":false,"pushed_at":"2023-08-10T00:44:20.000Z","size":11113,"stargazers_count":32,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-12-09T13:49:10.495Z","etag":null,"topics":["bbox","crs","geobuf","geojson","geospatial","ndgeojson","r","r-package","rstats","spatial"],"latest_commit_sha":null,"homepage":"https://docs.ropensci.org/geojson/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ropensci.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-04-01T17:36:59.000Z","updated_at":"2023-08-10T00:43:11.000Z","dependencies_parsed_at":"2023-09-21T19:58:49.228Z","dependency_job_id":null,"html_url":"https://github.com/ropensci/geojson","commit_stats":{"total_commits":180,"total_committers":7,"mean_commits":"25.714285714285715","dds":0.1333333333333333,"last_synced_commit":"3881c7df07e924b3afce2270b78e316e5e47e79d"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/ropensci/geojson","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fgeojson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fgeojson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fgeojson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fgeojson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ropensci","download_url":"https://codeload.github.com/ropensci/geojson/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fgeojson/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29688289,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T15:51:39.154Z","status":"ssl_error","status_checked_at":"2026-02-21T15:49:03.425Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["bbox","crs","geobuf","geojson","geospatial","ndgeojson","r","r-package","rstats","spatial"],"created_at":"2024-08-05T03:01:51.569Z","updated_at":"2026-02-21T17:34:56.195Z","avatar_url":"https://github.com/ropensci.png","language":"C++","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\n```{r echo=FALSE}\nlibrary(\"knitr\")\nhook_output \u003c- knitr::knit_hooks$get(\"output\")\nknitr::knit_hooks$set(output = function(x, options) {\n   lines \u003c- options$output.lines\n   if (is.null(lines)) {\n     return(hook_output(x, options))  # pass to default hook\n   }\n   x \u003c- unlist(strsplit(x, \"\\n\"))\n   more \u003c- \"...\"\n   if (length(lines)==1) {        # first n lines\n     if (length(x) \u003e lines) {\n       # truncate the output, but add ....\n       x \u003c- c(head(x, lines), more)\n     }\n   } else {\n     x \u003c- c(if (abs(lines[1])\u003e1) more else NULL,\n            x[lines],\n            if (length(x)\u003elines[abs(length(lines))]) more else NULL\n           )\n   }\n   # paste these lines together\n   x \u003c- paste(c(x, \"\"), collapse = \"\\n\")\n   hook_output(x, options)\n })\n\nknitr::opts_chunk$set(\n  comment = \"#\u003e\",\n  collapse = TRUE,\n  warning = FALSE,\n  message = FALSE\n)\n```\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/ropensci/geojson/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ropensci/geojson/actions/workflows/R-CMD-check.yaml)\n [![rstudio mirror downloads](https://cranlogs.r-pkg.org/badges/geojson)](https://github.com/r-hub/cranlogs.app)\n[![cran version](https://www.r-pkg.org/badges/version/geojson)](https://cran.r-project.org/package=geojson)\n\u003c!-- badges: end --\u003e\n\n# geojson\n\n\n`geojson` aims to deal only with geojson data in a lightweight way. \n\n\nWe've defined classes (`S3`) following the [GeoJSON spec][geojsonspec]. These\nclasses sort of overlap with `sp`'s classes, but not really. There's also some\noverlap in GeoJSON classes with Well-Known Text (WKT) classes, but GeoJSON has a\nsubset of WKT's classes.\n\nThe package [geoops](https://github.com/sckott/geoops) supports manipulations on\nthe classes defined in this package. This package is used within\n[geojsonio](https://github.com/ropensci/geojsonio) to make some tasks easier.\n\n## Installation\n\nStable CRAN version\n\n```{r eval=FALSE}\ninstall.packages(\"geojson\")\n```\n\nDev version\n\n```{r eval=FALSE}\nremotes::install_github(\"ropensci/geojson\")\n```\n\n```{r}\nlibrary(\"geojson\")\n```\n\n## geojson class\n\nEssentially a character string with S3 class `geojson` attached to make it\neasy to perform operations on\n\n```{r}\nx \u003c- \"{\\\"type\\\":\\\"FeatureCollection\\\",\\\"features\\\":[{\\\"type\\\":\\\"Feature\\\",\\\"geometry\\\":{\\\"type\\\":\\\"Point\\\",\\\"coordinates\\\":[-99.74,32.45]},\\\"properties\\\":{}}]}\"\nas.geojson(x)\n```\n\n## geometrycollection\n\n```{r}\nx \u003c- '{\n \"type\": \"GeometryCollection\",\n \"geometries\": [\n   {\n     \"type\": \"Point\",\n     \"coordinates\": [100.0, 0.0]\n   },\n   {\n     \"type\": \"LineString\",\n     \"coordinates\": [ [101.0, 0.0], [102.0, 1.0] ]\n   }\n  ]\n}'\n(y \u003c- geometrycollection(x))\n```\n\n### inspect the object\n\nget the string\n\n```{r}\ny[[1]]\n```\n\nget the type\n\n```{r}\ngeo_type(y)\n```\n\npretty print the geojson\n\n```{r}\ngeo_pretty(y)\n```\n\nwrite to disk\n\n```{r}\ngeo_write(y, f \u003c- tempfile(fileext = \".geojson\"))\njsonlite::fromJSON(f, FALSE)\n```\n\n```{r echo=FALSE}\nunlink(f)\n```\n\n## properties\n\nAdd properties\n\n```{r}\nx \u003c- '{ \"type\": \"LineString\", \"coordinates\": [ [100.0, 0.0], [101.0, 1.0] ]}'\nres \u003c- linestring(x) %\u003e% feature() %\u003e% properties_add(population = 1000)\nres\n```\n\nGet a property\n\n```{r}\nproperties_get(res, property = 'population')\n```\n\n## crs\n\nAdd crs\n\n```{r}\ncrs \u003c- '{\n  \"type\": \"name\",\n  \"properties\": {\n     \"name\": \"urn:ogc:def:crs:OGC:1.3:CRS84\"\n  }\n}'\nz \u003c- x %\u003e% feature() %\u003e% crs_add(crs)\nz\n```\n\nGet crs\n\n```{r}\ncrs_get(z)\n```\n\n## bbox\n\nAdd bbox\n\n```{r}\ntt \u003c- x %\u003e% feature() %\u003e% bbox_add()\ntt\n```\n\nGet bbox\n\n```{r}\nbbox_get(tt)\n```\n\n\n## geojson in data.frame's\n\n```{r}\nx \u003c- '{ \"type\": \"Point\", \"coordinates\": [100.0, 0.0] }'\n(pt \u003c- point(x))\n```\n\n```{r}\nlibrary(\"tibble\")\ntibble(a = 1:5, b = list(pt))\n```\n\n```{r}\nx \u003c- '{ \"type\": \"MultiLineString\",\n  \"coordinates\": [ [ [100.0, 0.0], [101.0, 1.0] ], [ [102.0, 2.0], [103.0, 3.0] ] ] }'\n(mls \u003c- multilinestring(x))\n```\n\n```{r}\ntibble(a = 1:5, b = list(mls))\n```\n\n```{r}\ntibble(a = 1:5, b = list(pt), c = list(mls))\n```\n\n## geobuf\n\nGeobuf is a compact binary encoding for geographic data\nusing protocol buffers \u003chttps://github.com/mapbox/geobuf\u003e (via the [protolite][])\npackage.\n\n```{r}\nfile \u003c- system.file(\"examples/test.pb\", package = \"geojson\")\n(json \u003c- from_geobuf(file))\npb \u003c- to_geobuf(json)\nclass(pb)\nf \u003c- tempfile(fileext = \".pb\")\nto_geobuf(json, f)\nfrom_geobuf(f)\n\nx \u003c- '{ \"type\": \"Polygon\",\n\"coordinates\": [\n  [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]\n  ]\n}'\ny \u003c- polygon(x)\nto_geobuf(y)\n\nx \u003c- '{\"type\": \"MultiPoint\", \"coordinates\": [ [100.0, 0.0], [101.0, 1.0] ] }'\ny \u003c- multipoint(x)\nto_geobuf(y)\n```\n\n## newline-delimited GeoJSON\n\nread nd-GeoJSON\n\n```{r}\nurl \u003c- \"https://raw.githubusercontent.com/ropensci/geojson/main/inst/examples/ndgeojson1.json\"\nf \u003c- tempfile(fileext = \".geojsonl\")\ndownload.file(url, f)\nx \u003c- ndgeo_read(f, verbose = FALSE)\nx\n```\n\n```{r echo=FALSE}\nunlink(f)\n```\n\nWrite nd-GeoJSON\n\nOne would think we could take the output of `ndego_read()` above\nand pass to `ndgeo_write()`. However, in this example, the json is too big\nfor `jqr` to handle, the underlying parser tool. So here's a smaller \nexample:\n\n\n```{r}\nfile \u003c- system.file(\"examples\", \"featurecollection2.geojson\",\n  package = \"geojson\")\nstr \u003c- paste0(readLines(file), collapse = \" \")\n(x \u003c- featurecollection(str))\n```\n\n```{r}\noutfile \u003c- tempfile(fileext = \".geojson\")\nndgeo_write(x, outfile)\njsonlite::stream_in(file(outfile))\n```\n\n## Meta\n\n* Please [report any issues or bugs](https://github.com/ropensci/geojson/issues).\n* License: MIT\n* Get citation information for `geojson` in R doing `citation(package = 'geojson')`\n* Please note that this project is released with a [Contributor Code of Conduct][coc].\nBy participating in this project you agree to abide by its terms.\n\n(This was originally setup without requiring any of the\n`GEOS/GDAL` stack but now the package sp depends on sf it can't be avoided without overhaul).\n\n[![ropensci_footer](https://ropensci.org/public_images/github_footer.png)](https://ropensci.org)\n\n\n[geojsonspec]: https://datatracker.ietf.org/doc/html/rfc7946\n[jqr]: https://github.com/ropensci/jqr\n[jq]: https://github.com/stedolan/jq\n[protolite]: https://github.com/jeroen/protolite\n[coc]: https://github.com/ropensci/geojson/blob/main/CODE_OF_CONDUCT.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropensci%2Fgeojson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fropensci%2Fgeojson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropensci%2Fgeojson/lists"}