mapshaper icon indicating copy to clipboard operation
mapshaper copied to clipboard

How to create a particular polygon from a line of points?

Open chris3522 opened this issue 2 years ago • 2 comments

Hello, I would like to obtain a polygon from 5 points. The points of the polygon must be distant from the line formed by the 5 points of 1km as in the attached image. Do you have an idea to do this? Many thanks shape

chris3522 avatar May 03 '22 07:05 chris3522

Not sure how it's related to mapshaper. You can do it using Turf JavaScript library. With it, create a line then do a buffer. You can go on https://turfjs.org, open the browser debugger, type the following code for a proof of concept.

var ordered_points = [
  [
    -1.5765380859375,
    47.21385485500642
  ],
  [
    -1.5621185302734373,
    47.20965696757036
  ],
  [
    -1.5480422973632812,
    47.20487563550239
  ],
  [
    -1.5308761596679688,
    47.201376826785406
  ],
  [
    -1.5140533447265625,
    47.19776114868993
  ]
]

var line = turf.lineString(ordered_points)
var buffered = turf.buffer(line, 1, {units: 'kilometers'});

Overview of the result

Sélection_672

ThomasG77 avatar May 03 '22 10:05 ThomasG77

Very effective, thanks for the tip.

Maybe "buffer" would be a good feature to add to Mapshaper?

chris3522 avatar May 03 '22 10:05 chris3522