lineOrPolygon method
@param vertices the vertices of a linear ring, which may or may not be
flattened (i.e. vertices collinear)
@return a 2-vertex LineString
if the vertices are
collinear; otherwise, a Polygon
with unnecessary
(collinear) vertices removed
Implementation
Geometry lineOrPolygon(List<Coordinate> coordinates) {
coordinates = cleanRing(coordinates);
if (coordinates.length == 3) {
return geomFactory
.createLineString(<Coordinate>[coordinates[0], coordinates[1]]);
// return new LineString(new List<Coordinate>{coordinates[0], coordinates[1]},
// geometry.getPrecisionModel(), geometry.getSRID());
}
LinearRing linearRing = geomFactory.createLinearRing(coordinates);
return geomFactory.createPolygon(linearRing, null);
}