{"id":24895431,"url":"https://github.com/symbolixau/geojsonsf","last_synced_at":"2025-04-05T19:13:59.355Z","repository":{"id":31394688,"uuid":"127064889","full_name":"SymbolixAU/geojsonsf","owner":"SymbolixAU","description":"Conversion between sf and geojson","archived":false,"fork":false,"pushed_at":"2024-07-30T05:06:23.000Z","size":11770,"stargazers_count":81,"open_issues_count":8,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-09-30T11:48:22.213Z","etag":null,"topics":["geojson","geospatial","gis","r","rstats","simplefeature","well-known-text"],"latest_commit_sha":null,"homepage":null,"language":"R","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/SymbolixAU.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-28T01:14:20.000Z","updated_at":"2024-07-29T22:55:35.000Z","dependencies_parsed_at":"2023-12-16T05:42:44.425Z","dependency_job_id":"a0868499-d2b5-4b8d-b94a-3e6bd87d8c77","html_url":"https://github.com/SymbolixAU/geojsonsf","commit_stats":{"total_commits":347,"total_committers":7,"mean_commits":49.57142857142857,"dds":"0.17002881844380402","last_synced_commit":"878de1a9b940444dcf2ed42b9922dbb6d793d150"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymbolixAU%2Fgeojsonsf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymbolixAU%2Fgeojsonsf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymbolixAU%2Fgeojsonsf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymbolixAU%2Fgeojsonsf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SymbolixAU","download_url":"https://codeload.github.com/SymbolixAU/geojsonsf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247386266,"owners_count":20930619,"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":["geojson","geospatial","gis","r","rstats","simplefeature","well-known-text"],"created_at":"2025-02-01T19:18:31.050Z","updated_at":"2025-04-05T19:13:59.326Z","avatar_url":"https://github.com/SymbolixAU.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\ntitle: geojsonsf\noutput: github_document\nalways_allow_html: yes\n---\n\n```{r setup, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"# \",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/geojsonsf)](https://CRAN.R-project.org/package=geojsonsf)\n![downloads](http://cranlogs.r-pkg.org/badges/grand-total/geojsonsf)\n[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/geojsonsf)](https://CRAN.R-project.org/package=geojsonsf)\n[![Github Stars](https://img.shields.io/github/stars/SymbolixAU/geojsonsf.svg?style=social\u0026label=Github)](https://github.com/SymbolixAU/geojsonsf)\n[![R build status](https://github.com/symbolixau/geojsonsf/workflows/R-CMD-check/badge.svg)](https://github.com/symbolixau/geojsonsf/actions)\n[![Coverage Status](https://codecov.io/github/SymbolixAU/geojsonsf/coverage.svg?branch=master)](https://codecov.io/github/SymbolixAU/geojsonsf?branch=master)\n\n--\n\n## geojsonsf\n\nA simple, low-dependency and **fast** converter between GeoJSON and Simple Feature objects in R. \n\n---\n\n**v1.3.2** \n\nConverts\n\n- GeoJSON --\u003e `sf`\n- GeoJSON --\u003e `sfc`\n- `sf`    --\u003e GeoJSON\n- `sfc`   --\u003e GeoJSON\n- GeoJSON --\u003e Well-known text\n- data.frame --\u003e GeoJSON (POINT only)\n\nAs per GeoJSON ([RFC 7946 specification)](https://tools.ietf.org/html/rfc7946#page-11), foreign members are ignored, and nested objects and arrays inside the `properties` object are converted to string/characters. \n\nAlso, as per the specification, **CRS** \n\n\u003e The coordinate reference system for all GeoJSON coordinates is a\ngeographic coordinate reference system, using the World Geodetic\nSystem 1984 (WGS 84) [WGS84] datum, with longitude and latitude units\nof decimal degrees. This is equivalent to the coordinate reference\nsystem identified by the Open Geospatial Consortium (OGC) URN\nurn:ogc:def:crs:OGC::CRS84\n\nFrom **v1.3.2**, if your coordinates are in a different CRS you can specify the CRS \u0026 proj4string values in the `geojson_sf()` and `geojson_sfc()` functions. \n\n## Installation\n\nInstall the CRAN version with\n\n\n```{r, eval = F}\ninstall.packages(\"geojsonsf\")\n```\n\n\nTo install the development version\n\n```{r gh-installation, eval = FALSE}\n# install.packages(\"devtools\")\ndevtools::install_github(\"SymbolixAU/geojsonsf\")\n```\n\n## Why did you build it?\n\nTo quickly parse between GeoJSON and `sf` objects, and to handle cases not supported by `sf`, e.g. arrays of geometries\n\n```{r, echo=FALSE, warning=FALSE, message=FALSE}\nlibrary(geojsonsf)\nlibrary(sf)        ## Loaded for sf print methods\n```\n\n\n## What do you mean, 'cases not supported'\n\nFor example, `sf` can't read an array of GeoJSON objects, so I wanted to make this work\n\n```{r}\njs \u003c- c(\n\t'[\n\t  {\"type\":\"Point\",\"coordinates\":[0,0]},\n\t  {\"type\":\"LineString\",\"coordinates\":[[-1,-1],[1,1]]},\n\t\t{\n      \"type\": \"FeatureCollection\",\n      \"features\": [\n      {\n        \"type\": \"Feature\",\n        \"properties\": {\"id\":1},\n        \"geometry\": {\"type\": \"Point\", \"coordinates\": [100.0, 0.0]}\n      }\n    ]\n  }\n\t]'\n)\n\nsf \u003c- geojson_sf( js )\nsf\n```\n\n\nAnd going the other way you can also return a vector of GeoJSON\n\n```{r}\njs \u003c- sf_geojson( sf, atomise = T )\njs\n```\n\n### What's the benefit of 'atomising'?\n\nIt's useful for when you work with geospatial databases and want an individual record for each individual feature. \n\n### What happens if you don't `atomise`?\n\nYou get a single GeoJSON object\n\n```{r}\nsf_geojson( sf )\n```\n\n\n### Can you remove the properites and just return the geometries\n\nYes. Call `sfc_geojson()` on the `sfc` object.\n\n```{r}\nsfc_geojson( sf$geometry )\n```\n\n### If I have an `sf` object without any properties, why does it 'atomise' by default?\n\n```{r}\nsf$id \u003c- NULL\nsf_geojson( sf )\n```\n\nThe `simplify` argument is `TRUE` by default, and it will try and 'simplify' the GeoJSON. If there are no properties in the `sf` object, then the GeoJSON won't have any properties.\n\nHowever, if you set `simplify = FALSE` you'll get a FeatureCollection with an empty properties field.\n\n```{r}\nsf_geojson(sf, simplify = F)\n```\n\n\n### How fast is it?\n\nThis benchmark shows a comparison with `library(sf)` for converting a string of GeoJSON of 3,221 counties in the US in to an `sf` object\n\n```{r,eval= FALSE}\nmyurl \u003c- \"http://eric.clst.org/assets/wiki/uploads/Stuff/gz_2010_us_050_00_500k.json\"\ngeo \u003c- readLines(myurl)\ngeo \u003c- paste0(geo, collapse = \"\")\n\nlibrary(microbenchmark)\n\nmicrobenchmark(\n    geojsonsf = {\n        geojson_sf(geo)\n    },\n    sf = {\n        sf::st_read(geo, quiet = T)\n    },\n    times = 2\n)\n\n#Unit: milliseconds\n#      expr       min        lq      mean    median        uq       max  neval\n# geojsonsf  709.2268  709.2268  722.0626  722.0626  734.8984  734.8984      2\n#        sf 1867.6840 1867.6840 1958.7968 1958.7968 2049.9097 2049.9097      2\n```\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsymbolixau%2Fgeojsonsf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsymbolixau%2Fgeojsonsf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsymbolixau%2Fgeojsonsf/lists"}