{"id":24894782,"url":"https://github.com/symbolixau/spatialwidget","last_synced_at":"2025-10-16T10:30:37.066Z","repository":{"id":56535927,"uuid":"155018897","full_name":"SymbolixAU/spatialwidget","owner":"SymbolixAU","description":"Utility package to convert R data into JSON for use in htmlwidget mapping libraries","archived":false,"fork":false,"pushed_at":"2024-05-20T23:42:31.000Z","size":6272,"stargazers_count":18,"open_issues_count":9,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-01T08:47:55.269Z","etag":null,"topics":["gis","htmlwidgets","r","spatial"],"latest_commit_sha":null,"homepage":"https://symbolixau.github.io/spatialwidget/","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/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-10-27T23:32:10.000Z","updated_at":"2024-05-20T23:42:35.000Z","dependencies_parsed_at":"2024-01-22T22:18:19.193Z","dependency_job_id":"63cec559-967a-4557-a7b8-bd398a2ed7d3","html_url":"https://github.com/SymbolixAU/spatialwidget","commit_stats":{"total_commits":219,"total_committers":4,"mean_commits":54.75,"dds":0.3105022831050228,"last_synced_commit":"838768b83d31d1d9eaf2b616e01c9fb72d1fe5fa"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymbolixAU%2Fspatialwidget","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymbolixAU%2Fspatialwidget/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymbolixAU%2Fspatialwidget/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymbolixAU%2Fspatialwidget/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SymbolixAU","download_url":"https://codeload.github.com/SymbolixAU/spatialwidget/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236698038,"owners_count":19190684,"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":["gis","htmlwidgets","r","spatial"],"created_at":"2025-02-01T19:14:32.941Z","updated_at":"2025-10-16T10:30:31.680Z","avatar_url":"https://github.com/SymbolixAU.png","language":"C++","readme":"---\noutput: github_document\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 = \"# \",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# spatialwidget\n\n### What's a 'spatialwidget'\n\nWell, what do these packages have in common?\n\n- leaflet\n- googleway\n- mapdeck\n- mapview\n- tmap\n\n1. They are all [htmlwidgets](https://www.htmlwidgets.org/)\n2. They all plot interactive maps\n3. They all take data from R and display it on the maps.\n\nAnd on 22nd August 2017 on the [r-spatial github page](https://github.com/r-spatial/discuss/issues/15#issue-251762127) it was requested if there could be a common package which could be shared by all the interactive web-plotting libraries\n\n\u003e Currently there is code in the leaflet package that extracts data from sp and sf objects and converts it into a dataframe that is then passed to the Javascript side (by converting it into a JSON).\nThis code is fairly generic and not really dependent on anything leaflet specific. It makes a lot of sense to take out this code and make it a package of its own. That way we can build other web plotting R packages to wrap say d3.geo or mapboxGL or cesium and reuse a major chunk of the code that takes data from spatial objects and passes it to Javascript.\n\nso **spatialwidget** is my attempt at this library.\n\n### What does it do?\n\nIt takes a simple feature object (`sf`), plus some user-supplied arguments, and converts the data into JSON, ready for plotting/ parsing in whatever javascript library you chose. \n\n### Can you show me?\n\nSure. In this example I'm using the `capitals` data, which is an `sf` object of all the capital cities.\n\n```{r}\nlibrary(spatialwidget)\nlibrary(sf)\nsf \u003c- spatialwidget::widget_capitals\nsf\n```\n\nAs each capital is a POINT, you can use `widget_point()` to conver it to JSON. \n\n```{r}\nl \u003c- widget_point( data = sf[1:2, ], fill_colour = \"country\" , legend = F)\n```\n\nEach row of `capitals` has been converted into a JSON object. And all these objects are within an array.\n\nLook, here are the first two rows of `capitals` as JSON\n\n```{r}\nsf[1:2, ]\njsonify::pretty_json( l$data )\n```\n\nYou can see that the coordinates are inside a `geometry` object, and the user-defined `fill_colour` is within the `properties` object. \n\n### That looks a lot like GeoJSON\n\nWell spotted. But it's not quite GeoJSON for a very good reason. \n\nSome plotting libraries can use more than one geometry, such as [mapdeck::add_arc()](https://github.com/SymbolixAU/mapdeck#basic-use), which uses an origin and destination. So spatialwidget needs to handle multiple geometries.\n\nTypical GeoJSON will take the form\n\n```js\n[{\"type\":\"Feature\", \"properties\":{\"stroke_colour\":\"#440154FF\"},\"geometry\":{\"type\":\"Point\",\"coordinates\":[0,0]}}]\n```\n\nWhereas I've nested the geometries one-level deeper, so the pseudo-GeoJSON i'm using takes the form\n\n```js\n[{\"type\":\"Feature\", \"properties\":{\"stroke_colour\":\"#440154FF\"},\"geometry\":{\"myGeometry\":{\"type\":\"Point\",\"coordinates\":[0,0]}}}]\n```\n\nWhere the `myGeometry` object is defined on a per-application bases. You are free to call this whatever you want inside your library. \n\n### That sort of makes sense, but can you show me an example with multiple geometries?\n\nYep. \n\nThe `arcs` data is an `sf` object with two POINT geometry columns. So say we want to generate an arc-map showing an arc between Sydney and all the other capitals cities. Just call `widget_od`, supplying the origin and destination columns.\n\n\n```{r}\n\nl \u003c- widget_od( widget_arcs[1:2, ], origin = \"origin\", destination = \"destination\")\n\njsonify::pretty_json( l$data )\n\n```\n\nNotice now the `geometry` object has within it an `origin` and a `destination`. This is why I've nested the geometries one level deeper within the GeoJSON\n\n\n### How do I use it in my package?\n\nYou can use these R functions, but they have limited scope. This package has been designed so you use the C++ functions directly. I've gone into more detail in the [vignette](https://symbolixau.github.io/spatialwidget/), so it's probably best you read that to understand how to call the C++ functions. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsymbolixau%2Fspatialwidget","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsymbolixau%2Fspatialwidget","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsymbolixau%2Fspatialwidget/lists"}