-
Notifications
You must be signed in to change notification settings - Fork 95
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
return raw wkb? #1609
Comments
I got this to work by adding this to 'geos_methods.cpp' Rcpp::List SpatVector::wkb_raw() {
GEOSContextHandle_t hGEOSCtxt = geos_init();
std::vector<GeomPtr> g = geos_geoms(this, hGEOSCtxt);
Rcpp::List out;
size_t len = 0;
for (size_t i = 0; i < g.size(); i++) {
unsigned char *hex = GEOSGeomToWKB_buf_r(hGEOSCtxt, g[i].get(), &len);
Rcpp::RawVector raw(len);
memcpy(&(raw[0]), hex, len);
out.push_back(raw);
free(hex);
}
geos_finish(hGEOSCtxt);
return out;
} and the required
That means Rcpp.h added as well which is probably not welcome? I'll keep exploring how to structure this. Example: wk::wkb(vect(cbind(1:10, rnorm(10)), "line")@ptr$wkb_raw())
<wk_wkb[1]>
[1] <LINESTRING (1 0.5928676, 2 0.9755936, 3 -1.12088, 4 0.08522013, 5 0.4874861, 6 0.2880466...> |
Update, I figured it out, added wkb_raw() to 'geos_methods' with idiomatic style. Implemented here: https://github.com/mdsumner/terra/tree/raw-wkb-1609 Can we add 'wkb = FALSE' to geom() to control this? |
Thanks. Implemented with your PR #1612 |
Here raw binary wkb is obtained but then converted to string:
terra/src/geos_methods.cpp
Line 107 in e62c733
I'd like to request returning it as a list of raw vectors, I don't think that's otherwise possible in terra atm? We can get wkt string or hex string, but not the raw vector in a list.
I'm interested to have general interop via {wk} with this (SpatVector is really the only major missing type for wk), and not go through character vectors or file or other expanded in-memory form. Thank you. I can probably manage a PR if it's not unwelcome. Not sure what to call the method ... "wkb_raw()" ?
The text was updated successfully, but these errors were encountered: