3

Creating a buffer from a Point or other Geometry objects in JSTS seems to be quite simple when reading the documentation, but still I can't produce a buffer from a Point in my React application.

Let me first tell that I'm using 'create-react-app' boilerplate generator and I have intalled JSTS like this:

npm install --save jsts

Following this JSTS + ES6 example I came up with this code:

import extend from 'jsts/extend'
import GeoJSONReader from 'jsts/org/locationtech/jts/io/GeoJSONReader';
import GeoJSONWriter from 'jsts/org/locationtech/jts/io/GeoJSONWriter';
import Geometry from 'jsts/org/locationtech/jts/geom/Geometry';
import Coordinate from 'jsts/org/locationtech/jts/geom/Coordinate';
import {BufferOp} from 'jsts/org/locationtech/jts/operation/buffer';


// Add support for Geometry.buffer
extend(Geometry.prototype, {
    buffer: function () {
        return BufferOp.bufferOp(this, arguments);
    }
});


class Demo extends Component {


  bufferTest() {
    let reader = new GeoJSONReader();
    let writer = new GeoJSONWriter();

    let json = {
        "type": "Point",
        "coordinates": [
          -58.435420989990234,
          -34.60650846219738
        ]
      };

    let pt = reader.read(json);
    let buffered = pt.buffer(40); // Will crash
  }
}

export default Demo;

When I run this I get the following error:

RuntimeException: inconsistency in rightmost processing

I also created individual Coordinate and Geometry objects and tried to buffer the geometry using using a BufferOp instance and many other things with no success.

1 Answer 1

4

I wrote to the JSTS dev list asking about this issue and they told me to "Avoid using extend/hacks as in the third party example" and to instead use the BufferOp directly.

This is one way you can use BufferOp "directly" when you install JSTS from NPM and using ES6 modules (in this case I use the GeoJSON parser/reader):

import GeoJSONReader from 'jsts/org/locationtech/jts/io/GeoJSONReader';
import GeoJSONWriter from 'jsts/org/locationtech/jts/io/GeoJSONWriter';
import {BufferOp} from 'jsts/org/locationtech/jts/operation/buffer';

let reader = new GeoJSONReader();
let writer = new GeoJSONWriter();
let json = {
    "type": "Point",
    "coordinates": [
      -58.435420989990234,
      -34.60650846219738
    ]
  };
let spPoint = reader.read(json);
let spBuffer = BufferOp.bufferOp(spPoint, 0.2);
let polyGeoJSON = writer.write(spBuffer);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.