Since you want a simple horizontal offset this is quite easy, you need to reverse the order of the points and then add each one in turn with the x offset applied and create a polygon from the linestring.
package spike;
import java.util.ArrayList;
import java.util.Arrays;
import org.apache.commons.lang.ArrayUtils;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.LineString;
import org.locationtech.jts.geom.Polygon;
public class LineToPoly {
static GeometryFactory gf = new GeometryFactory();
public static void main(String[] args) {
Coordinate[] points = {new Coordinate(10000,10000),new Coordinate(12300,40000),new Coordinate(16800,50000),new Coordinate(12354,60000)};
LineString line = gf.createLineString(points );
double offset = 1000; //1km
System.out.println(line);
Polygon p = generatePoly(line,offset);
System.out.println(p);
}
private static Polygon generatePoly(LineString line, double offset) {
Coordinate[] points = line.getCoordinates();
ArrayList<Coordinate> soln = new ArrayList<>();
//store initial points
soln.addAll(Arrays.asList(points));
// reverse the list
ArrayUtils.reverse(points);
// for each point move offset metres right
for (Coordinate c:points) {
soln.add(new Coordinate(c.x+offset, c.y));
}
// close the polygon
soln.add(soln.get(0));
// create polygon
Polygon poly = gf.createPolygon(soln.toArray(new Coordinate[] {}));
return poly;
}
}
This gives the following:
LINESTRING (10000 10000, 12300 40000, 16800 50000, 12354 60000)
POLYGON ((10000 10000, 12300 40000, 16800 50000, 12354 60000, 13354 60000, 17800 50000, 13300 40000, 11000 10000, 10000 10000))