Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create Polygon from point collection with NetTopologySuite

What is the best way to create a polygon from list of point?

I have an array of points, if points are at least 3 I would like to join to create a polygon

Dim ClickedPoint As New NetTopologySuite.Geometries.Point(coordinates)
ClickedPointArray.Add(ClickedPoint)

if   ClickedPointArray.Count > 2 then

   Polygonizer = New Polygonizer()
   Polygonizer.Add(ClickedPointArray)

end if        

return Polygonizer.GetPolygons

I think I'm very far from solution. Could you help me?

like image 301
Maurizio Petrini Avatar asked Sep 29 '15 07:09

Maurizio Petrini


2 Answers

You can create a Polygon with an array of coordinates using GeometryFactory like this:

Dim coordinatesArray as Coordinate[] = YourMethodToGetCoordinates
Dim geomFactory As New GeometryFactory
Dim poly As geomFactory.CreatePolygon(coordinatesArray) //this returns an IPolygon that you can cast to Polygon
like image 91
xecollons Avatar answered Sep 30 '22 12:09

xecollons


Here is the C#

    Coordinate[] imageOutlineCoordinates = new Coordinate[] 
    {
        new Coordinate(1, 1),
        new Coordinate(2, 1),
        new Coordinate(2, 2),
        new Coordinate(1, 1)
    };
    GeometryFactory geometryFactory = new GeometryFactory();
    Polygon poly = geometryFactory.CreatePolygon(imageOutlineCoordinates);
like image 29
MBentley Avatar answered Sep 30 '22 13:09

MBentley