This repository has been archived by the owner on Mar 30, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added wkb wkt converter using a node module, fix #5
- Loading branch information
Showing
29 changed files
with
5,803 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
.Rhistory | ||
.RData | ||
.DS_Store | ||
.V8history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#' @importFrom V8 new_context | ||
sh <- NULL | ||
.onLoad <- function(libname, pkgname){ | ||
sh <<- new_context(); | ||
sh$source(system.file("js/wkx.js", package = pkgname)) | ||
sh$source(system.file("js/buffer.js", package = pkgname)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#' Convert WKT to WKB | ||
#' | ||
#' @export | ||
#' @name wkb | ||
#' @param x A \code{character} string representing a WKT object, or an object | ||
#' of class \code{raw}, representing a WKB object | ||
#' @return \code{wkt_wkb} returns an object of class \code{raw}, a WKB reprsentation. | ||
#' \code{wkb_wkt} returns an object of class \code{character}, a WKT representation | ||
#' @examples | ||
#' # WKT to WKB | ||
#' ## point | ||
#' wkt_wkb("POINT (-116.4 45.2)") | ||
#' | ||
#' ## linestring | ||
#' wkt_wkb("LINESTRING (-116.4 45.2, -118.0 47.0)") | ||
#' | ||
#' ## multipoint | ||
#' ### only accepts the below format, not e.g., ((1 2), (3 4)) | ||
#' wkt_wkb("MULTIPOINT (100.000 3.101, 101.00 2.10, 3.14 2.18)") | ||
#' | ||
#' ## polygon | ||
#' wkt_wkb("POLYGON ((100.0 0.0, 101.1 0.0, 101.0 1.0, 100.0 0.0))") | ||
#' | ||
#' # WKB to WKT | ||
#' ## point | ||
#' (x <- wkt_wkb("POINT (-116.4 45.2)")) | ||
#' wkb_wkt(x) | ||
#' | ||
#' ## linestring | ||
#' (x <- wkt_wkb("LINESTRING (-116.4 45.2, -118.0 47.0)")) | ||
#' wkb_wkt(x) | ||
#' | ||
#' ## multipoint | ||
#' (x <- wkt_wkb("MULTIPOINT (100.000 3.101, 101.00 2.10, 3.14 2.18)")) | ||
#' wkb_wkt(x) | ||
#' | ||
#' ## polygon | ||
#' (x <- wkt_wkb("POLYGON ((100.0 0.0, 101.1 0.0, 101.0 1.0, 100.0 0.0))")) | ||
#' wkb_wkt(x) | ||
|
||
wkt_wkb <- function(x) { | ||
sh$eval(sprintf("var tt = wkx.Geometry.parse('%s').toWkb();", x)) | ||
as.raw(sh$get("tt")$data) | ||
} | ||
|
||
#' @export | ||
#' @rdname wkb | ||
wkb_wkt <- function(x) { | ||
sh$eval(sprintf("var w = new buffer('%s', 'hex')", paste0(x, collapse = ""))) | ||
sh$eval("var tt = wkx.Geometry.parse(w).toWkt();") | ||
sh$get("tt") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.