TransWikia.com

OpenLayers v6.5.0: How to create a non-intersecting polygon passing through all given points

Geographic Information Systems Asked by andzaOs on April 30, 2021

Is there any function/library that I can use to create a non-intersecting polygon?
Below is the code that I used to draw Polygon from the specified points but it is not working for the non-intersecting part.

  public drawPolygon(points: LonLat[]): Feature {
   let coordinates =  [];
   points.forEach(function (point) {
    coordinates.push(fromLonLat([point.lon, point.lat]))
   });
   let feature = new Feature(new Polygon([coordinates]));
   return feature;
  }

One Answer

This was a solution for my problem:

public drawPolygon(points: LonLat[]): Feature {
 let coordinates : Coordinate[] =  [];

 points.forEach(function (point) {
  coordinates.push(fromLonLat([point.lon, point.lat]))
 });

 let convexHullCoordinates = this.convexHull(coordinates);
 let feature = new Feature(new Polygon([convexHullCoordinates]));
 return feature;
}

Correct answer by andzaOs on April 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP