javageometrycomputational-geometryjts

How to create a polygon in JTS when we have list of coordinate?


We can create a LineString using coordinates list like this:

     Geometry g1 = new GeometryFactory().createLineString(coordinates);

How can we create a polygon using coordinates list?

Thanks in advance.


Solution

  • Use these line of codes:

     GeometryFactory fact = new GeometryFactory();
     LinearRing linear = new GeometryFactory().createLinearRing(coordinates);
     Polygon poly = new Polygon(linear, null, fact);
    

    I hope it will help :)