Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/program--/tg-r
R interface to the C geometry library `tg`
https://github.com/program--/tg-r
Last synced: 24 days ago
JSON representation
R interface to the C geometry library `tg`
- Host: GitHub
- URL: https://github.com/program--/tg-r
- Owner: program--
- License: other
- Created: 2023-10-07T21:35:10.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-07T18:47:30.000Z (8 months ago)
- Last Synced: 2024-06-11T17:05:05.428Z (7 months ago)
- Language: C
- Size: 109 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# tg
This package provides an interface to the [tg C library](https://github.com/tidwall/tg) similar
to [sf](https://github.com/r-spatial/sf) and [geos](https://github.com/paleolimbot/geos).## Installation
You can install the development version of tg like so:
``` r
pak::pkg_install("program--/tg")
```## Example Usage
Reading geometry from WKT:
```{r wkt_example}
tg::as_tg("POINT(1 1)")
```Reading geometry from a GeoJSON string:
```{r geojson_example}
gjson <- '
{ "type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
"properties": {"prop0": "value0"}
},
{ "type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
]
},
"properties": {
"prop0": "value0",
"prop1": 0.0
}
},
{ "type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
[100.0, 1.0], [100.0, 0.0] ]
]},
"properties": {
"prop0": "value0",
"prop1": {"this": "that"}
}
}
]
}
'tg_geometry <- tg::as_tg(gjson)
tg_geometry# Converting to a TG Collection
collection <- tg::as_tgc(tg_geometry)
collection# Creating a data.frame
data.frame(x = 1:3, geometry = collection)
```