Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy endpoint #39

Merged
merged 3 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ Collate:
clockwise.R
geod.R
wkt.R
RoxygenNote: 6.1.0
RoxygenNote: 6.1.1
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ S3method(st_transform_proj,sfg)
export(lwgeom_extSoftVersion)
export(st_asewkt)
export(st_astext)
export(st_endpoint)
export(st_force_polygon_cw)
export(st_geod_area)
export(st_geod_azimuth)
Expand Down
4 changes: 4 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ CPL_startpoint <- function(sfc) {
.Call('_lwgeom_CPL_startpoint', PACKAGE = 'lwgeom', sfc)
}

CPL_endpoint <- function(sfc) {
.Call('_lwgeom_CPL_endpoint', PACKAGE = 'lwgeom', sfc)
}

CPL_sfc_to_wkt <- function(sfc, precision) {
.Call('_lwgeom_CPL_sfc_to_wkt', PACKAGE = 'lwgeom', sfc, precision)
}
Expand Down
8 changes: 8 additions & 0 deletions R/startpoint.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@
#' m = matrix(c(0, 1, 2, 0, 1, 4), ncol = 2)
#' l = st_sfc(st_linestring(m))
#' lwgeom::st_startpoint(l)
#' lwgeom::st_endpoint(l)
#' l2 = st_sfc(st_linestring(m), st_linestring(m[3:1, ]))
#' lwgeom::st_startpoint(l2)
#' lwgeom::st_endpoint(l2)
st_startpoint = function(x) {
m <- CPL_startpoint(st_geometry(x))
st_sfc(lapply(seq_len(nrow(m)), function(i) st_point(m[i,])), crs = st_crs(x))
}
#' @rdname st_startpoint
#' @export
st_endpoint = function(x) {
m <- CPL_endpoint(st_geometry(x))
st_sfc(lapply(seq_len(nrow(m)), function(i) st_point(m[i,])), crs = st_crs(x))
}
5 changes: 5 additions & 0 deletions man/st_startpoint.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,17 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// CPL_endpoint
Rcpp::NumericMatrix CPL_endpoint(Rcpp::List sfc);
RcppExport SEXP _lwgeom_CPL_endpoint(SEXP sfcSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< Rcpp::List >::type sfc(sfcSEXP);
rcpp_result_gen = Rcpp::wrap(CPL_endpoint(sfc));
return rcpp_result_gen;
END_RCPP
}
// CPL_sfc_to_wkt
Rcpp::CharacterVector CPL_sfc_to_wkt(Rcpp::List sfc, Rcpp::IntegerVector precision);
RcppExport SEXP _lwgeom_CPL_sfc_to_wkt(SEXP sfcSEXP, SEXP precisionSEXP) {
Expand Down Expand Up @@ -317,6 +328,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_lwgeom_CPL_is_polygon_cw", (DL_FUNC) &_lwgeom_CPL_is_polygon_cw, 1},
{"_lwgeom_CPL_force_polygon_cw", (DL_FUNC) &_lwgeom_CPL_force_polygon_cw, 1},
{"_lwgeom_CPL_startpoint", (DL_FUNC) &_lwgeom_CPL_startpoint, 1},
{"_lwgeom_CPL_endpoint", (DL_FUNC) &_lwgeom_CPL_endpoint, 1},
{"_lwgeom_CPL_sfc_to_wkt", (DL_FUNC) &_lwgeom_CPL_sfc_to_wkt, 2},
{"_lwgeom_CPL_proj_version", (DL_FUNC) &_lwgeom_CPL_proj_version, 1},
{"_lwgeom_CPL_linesubstring", (DL_FUNC) &_lwgeom_CPL_linesubstring, 4},
Expand Down
19 changes: 19 additions & 0 deletions src/lwgeom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,25 @@ Rcpp::NumericMatrix CPL_startpoint(Rcpp::List sfc) {
// return sfc_from_lwgeom(lwgeom_cw);
}

// [[Rcpp::export]]
Rcpp::NumericMatrix CPL_endpoint(Rcpp::List sfc) {

std::vector<LWGEOM *> lwgeom_cw = lwgeom_from_sfc(sfc);
Rcpp::NumericMatrix m(lwgeom_cw.size(), 2);

// no lwgeom_endpoint so reverse in-place and use startpoint
POINT4D p;
for (size_t i = 0; i < lwgeom_cw.size(); i++) {
lwgeom_reverse_in_place(lwgeom_cw[i]);
lwgeom_startpoint(lwgeom_cw[i], &p);
m(i, 0) = p.x;
m(i, 1) = p.y;
}

return m;
}


// [[Rcpp::export]]
Rcpp::CharacterVector CPL_sfc_to_wkt(Rcpp::List sfc, Rcpp::IntegerVector precision) {

Expand Down