1

I need to be able to create a rectangle with height x from two points. This is probably not clear enough so I tried to draw it:

Example of what I'm trying to do

The two points that I have are the centroids of those circles, and what I need is the rectangle in orange. I have little experience with GIS, and my idea is probably silly, but I'm thinking that if I create a line connecting the two points, and find the intersection in the circle and then find a point 90 degrees from that point, I could calculate the 4 points that I need to create a rectangle.

This example in real life is like a tractor working from point A to point B, and there's this equipment attached to the tractor which has a known width, and the rectangle tells me the area that this tractor did something.

I'm working with this 'map' on a web page, in JavaScript with Turf.js.

2
  • 3
    I'd like to solve: "How to extremly difficult create a buffer without end caps?" No, serioulsy: You have two points which create a line. You may buffer that line by half the width of the equipment, which gives you the strip of field the tractor worked. This is rather easy using QGIS, though I don't know about Turf.
    – Erik
    Commented Oct 8, 2020 at 9:55
  • Ah, I see. Thank you, Erik! I can't believe it is that simple!
    – Pedro
    Commented Oct 8, 2020 at 10:28

1 Answer 1

2

With turf.js library you can use lineOffset method. To get four points of the rectangle, you have to use it twice, once with a negative offset.

Example of creating two lines that are offset one kilometer to both sides of an existing line would then look something like this:

var line = turf.lineString([[-83, 30], [-84, 36]]);

var offsetLine1 = turf.lineOffset(line, 1, {units: 'kilometers'});
var offsetLine2 = turf.lineOffset(line, -1, {units: 'kilometers'});

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.