Skip to content

Commit

Permalink
fixes #1330
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Oct 31, 2023
1 parent bdd96b5 commit b7b8295
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
42 changes: 28 additions & 14 deletions src/distRaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2369,7 +2369,7 @@ bool fix_date_line(SpatGeom &g, std::vector<double> &x, const std::vector<double
}


SpatVector SpatVector::point_buffer(std::vector<double> d, unsigned quadsegs, bool no_multipolygons) {
SpatVector SpatVector::point_buffer(std::vector<double> d, unsigned quadsegs, bool no_multipolygons, bool wrap) {

SpatVector out;
out.reserve(size());
Expand Down Expand Up @@ -2421,10 +2421,18 @@ SpatVector SpatVector::point_buffer(std::vector<double> d, unsigned quadsegs, bo
} else {
ptx.reserve(n);
pty.reserve(n);
for (size_t j=0; j < n; j++) {
geod_direct(&gd, xy[1][i], xy[0][i], brng[j], d[i], &lat, &lon, &azi);
ptx.push_back(lon);
pty.push_back(lat);
if (wrap) {
for (size_t j=0; j < n; j++) {
geod_direct(&gd, xy[1][i], xy[0][i], brng[j], d[i], &lat, &lon, &azi);
ptx.push_back(lon);
pty.push_back(lat);
}
} else {
for (size_t j=0; j < n; j++) {
geod_direct(&gd, xy[1][i], 0, brng[j], d[i], &lat, &lon, &azi);
ptx.push_back(lon+xy[0][i]);
pty.push_back(lat);
}
}
if (npole) {
sort_unique_2d(ptx, pty);
Expand Down Expand Up @@ -2465,17 +2473,23 @@ SpatVector SpatVector::point_buffer(std::vector<double> d, unsigned quadsegs, bo
} else {
ptx.push_back(ptx[0]);
pty.push_back(pty[0]);
bool split = false;
try {
split = fix_date_line(g, ptx, pty);
} catch(...) {}
if (split & no_multipolygons) {
for (size_t j=0; j<g.parts.size(); j++) {
SpatGeom gg(g.parts[j], polygons);
out.addGeom(gg);
if (wrap) {
bool split = false;
try {
split = fix_date_line(g, ptx, pty);
} catch(...) {}

if (split & no_multipolygons) {
for (size_t j=0; j<g.parts.size(); j++) {
SpatGeom gg(g.parts[j], polygons);
out.addGeom(gg);
}
} else {
out.addGeom(g);
}
} else {
out.addGeom(g);
g.reSetPart(SpatPart(ptx, pty));
out.addGeom(g);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/geos_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ SpatVector lonlat_buf(SpatVector x, double dist, unsigned quadsegs, bool ispol,
p.srs = x.srs;
p = p.as_points(false, true);
std::vector<double> d(p.size(), dist);
SpatVector b = p.point_buffer(d, quadsegs, true);
SpatVector b = p.point_buffer(d, quadsegs, true, false);
if (b.size() <= p.size()) {
SpatGeom g = hullify(b, ispol);
tmp.addGeom(g);
Expand All @@ -1128,6 +1128,8 @@ SpatVector lonlat_buf(SpatVector x, double dist, unsigned quadsegs, bool ispol,
}
tmp = tmp.aggregate(true);

tmp.fix_lonlat_overflow();

if (ispol) {
if (dist < 0) {
tmp = !ishole ? tmp.get_holes() : tmp.remove_holes();
Expand Down Expand Up @@ -1168,7 +1170,7 @@ SpatVector SpatVector::buffer(std::vector<double> d, unsigned quadsegs, std::str

if (islonlat) {
if (vt == "points") {
return point_buffer(d, quadsegs, false);
return point_buffer(d, quadsegs, false, true);
} else {
SpatVector p;
bool ispol = vt == "polygons";
Expand Down
2 changes: 1 addition & 1 deletion src/spatVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class SpatVector {

SpatVector buffer(std::vector<double> d, unsigned quadsegs, std::string capstyle, std::string joinstyle, double mitrelimit, bool singlesided);

SpatVector point_buffer(std::vector<double> d, unsigned quadsegs, bool no_multipolygons);
SpatVector point_buffer(std::vector<double> d, unsigned quadsegs, bool no_multipolygons, bool wrap);

SpatVector centroid(bool check_lonlat);
SpatVector point_on_surface(bool check_lonlat);
Expand Down

0 comments on commit b7b8295

Please sign in to comment.