Hi, I have been trying to add buffer to a polygon for the past few days but couldnt. I am trying to follow this existing snippet here:
.
import Coordinate from 'jsts/org/locationtech/jts/geom/Coordinate.js';
import GeometryFactory from 'jsts/org/locationtech/jts/geom/GeometryFactory.js';
import BufferParameters from 'jsts/org/locationtech/jts/operation/buffer/BufferParameters.js';
import {BufferOp} from 'jsts/org/locationtech/jts/operation/buffer';
function vectorCoordinates2JTS (polygon) {
var coordinates: any = [];
for (var i = 0; i < polygon.length; i++) {
coordinates.push(new Coordinate(polygon[i].x, polygon[i].y));
}
return coordinates;
}
function inflatePolygon(poly, spacing) {
var geoInput = vectorCoordinates2JTS(poly);
geoInput.push(geoInput[0]);
var geometryFactory = new GeometryFactory();
var shell = geometryFactory.createPolygon(geoInput);
var polygon = shell.buffer(spacing, BufferParameters.CAP_FLAT);
var inflatedCoordinates: any = [];
var oCoordinates;
oCoordinates = polygon.shell.points.coordinates;
console.log(oCoordinates.length)
for (let i = 0; i < oCoordinates.length; i++) {
var oItem;
oItem = oCoordinates[i];
inflatedCoordinates.push(Math.ceil(oItem.x), Math.ceil(oItem.y));
}
```
I am calling function inflatePolygon with arguments as followed:
poly: [{x: 1, y: 1}, {x: 2, y:2} ...] and spacing as 10.
It throws an error on this line `var polygon = shell.buffer(spacing, BufferParameters.CAP_FLAT);` where it says the shell object has no buffer function.
I have tried to see what's in the shell object and it indeed has no buffer function. What am I doing wrong here?
Any sort of help or guidance is highly appreciated. Thanks!