I'm trying to create a polygon and calculate it's area using
final GeometryFactory gf = new GeometryFactory();
final ArrayList<Coordinate> points = new ArrayList<Coordinate>();
points.add(new Coordinate(0,0));
points.add(new Coordinate(0,1));
points.add(new Coordinate(1,0));
points.add(new Coordinate(1,1));
points.add(new Coordinate(0,0));
final Polygon polygon = gf.createPolygon(new LinearRing(new CoordinateArraySequence(points
.toArray(new Coordinate[points.size()])), gf), null);
System.out.println(polygon.getArea());
And I get the error:
points must form a closed linestring
When I tried to use the points :
points.add(new Coordinate(0,0));
points.add(new Coordinate(0,1));
points.add(new Coordinate(1,0));
points.add(new Coordinate(1,1));
points.add(new Coordinate(0,0));
I've received area = 0 .
I'd like to know what I've got to do in order to calculate the area correctly without getting any errors.