JtsAlgorithms implements GeomAlgorithms { public static IMultiCurve<ILineString> offsetCurve(ILineString line, double distance) { double d = Math.abs(distance); if (d == 0) { IMultiCurve<ILineString> result = new GM_MultiCurve<ILineString>(); result.add(line); return result; } int orientationIndex = (int) (d / distance); try { LineString lineString = JtsAlgorithms .getLineStringWithoutDuplicates((LineString) JtsGeOxygene .makeJtsGeom(line)); BufferParameters bufParams = new BufferParameters(); bufParams.setSingleSided(true); Geometry buffer = BufferOp.bufferOp(lineString, distance, bufParams); if (lineString != null) { buffer = lineString.buffer(d, 4, BufferParameters.CAP_ROUND); Polygon polygon = null; if (!(buffer instanceof Polygon)) { JtsAlgorithms.logger.error("Can't compute offsetcurve of " + buffer.getGeometryType()); return null; } polygon = (Polygon) buffer; IMultiCurve<ILineString> result = new GM_MultiCurve<ILineString>(); ILineString r = JtsAlgorithms.getOffsetCurveFromRing( polygon.getExteriorRing(), lineString, orientationIndex, d); if ((r != null) && !r.isEmpty() && (r.coord().size() != 1)) { result.add(r); } for (int i = 0; i < polygon.getNumInteriorRing(); i++) { LineString ring = polygon.getInteriorRingN(i); r = JtsAlgorithms.getOffsetCurveFromRing(ring, lineString, orientationIndex, d); if ((r != null) && !r.isEmpty() && (r.coord().size() != 1)) { result.add(r); } } return result; } } catch (Exception e) { e.printStackTrace(); } return null; } JtsAlgorithms(); @Override DirectPosition centroid(IGeometry geom); @Override IGeometry convexHull(IGeometry geom); @Override IGeometry buffer(IGeometry geom, double distance); IGeometry buffer(IGeometry geom, double distance, int nSegments); IGeometry buffer(IGeometry geom, double distance, int nSegments,
      int cap); IGeometry buffer(IGeometry geom, double distance, int nSegments,
      int cap, int join); IGeometry boundary(IGeometry geom); @Override IGeometry union(IGeometry g1, IGeometry g2); @Override IGeometry intersection(IGeometry g1, IGeometry g2); @Override IGeometry difference(IGeometry g1, IGeometry g2); @Override IGeometry symDifference(IGeometry g1, IGeometry g2); @Override boolean equals(IGeometry g1, IGeometry g2); boolean equalsExact(IGeometry g1, IGeometry g2); boolean equalsExact(IGeometry g1, IGeometry g2, double tol); @Override boolean contains(IGeometry g1, IGeometry g2); boolean crosses(IGeometry g1, IGeometry g2); boolean disjoint(IGeometry g1, IGeometry g2); boolean within(IGeometry g1, IGeometry g2); boolean isWithinDistance(IGeometry g1, IGeometry g2, double dist); @Override boolean intersects(IGeometry g1, IGeometry g2); boolean overlaps(IGeometry g1, IGeometry g2); boolean touches(IGeometry g1, IGeometry g2); boolean isEmpty(IGeometry geom); boolean isSimple(IGeometry geom); boolean isValid(IGeometry geom); @Override double distance(IGeometry g1, IGeometry g2); @Override double area(IGeometry geom); @Override double length(IGeometry geom); int dimension(IGeometry geom); int numPoints(IGeometry geom); IGeometry translate(IGeometry geom, final double tx, final double ty,
      final double tz); String relate(IGeometry g1, IGeometry g2); static IGeometry union(List<? extends IGeometry> listeGeometries); static Point getFurthestPoint(Point pt, Polygon poly); static IDirectPosition getClosestPoint(IDirectPosition pt,
      IPolygon poly); static IDirectPosition getClosestPoint(IDirectPosition pt,
      ILineString l); static IDirectPosition getFurthestPoint(ILineString base, ILineString l); static IDirectPositionList getClosestPoints(IGeometry g1, IGeometry g2); static void addActionListener(ActionListener l); static Geometry union(Geometry[] geometryArray); static Geometry union(Collection<Geometry> geometryCollection); static Geometry unionLineString(List<Geometry> geometryCollection); static boolean isCCW(ILineString line); static Geometry filtreDouglasPeucker(Geometry geom, double seuil); static Geometry fermeture(Geometry geometry, double distance,
      int quadrantSegments, int endCapStyle); static Geometry fermeture(Geometry geometry, double distance,
      int quadrantSegments); static Polygon supprimeTrous(Polygon poly); static MultiPolygon supprimeTrous(MultiPolygon mp); static Polygon supprimeTrous(Polygon poly, double minArea); static MultiPolygon supprimeTrous(MultiPolygon mp, double minArea); static IMultiCurve<ILineString> offsetCurve(ILineString line,
      double distance); @SuppressWarnings("unchecked") static IMultiCurve<ILineString> offsetCurve(IGeometry geometry,
      double distance); static double bufferError(LineString bufferRing, LineString line,
      double distance); static int orientationIndex(Coordinate c, LineString line,
      double tolerance); static ILineString cap(ILineString line, double distance, boolean start); static Polygon MBRAirePreservee(Geometry geom); static Polygon MBRAireCible(Geometry geom, double aireCible); static Polygon MBR(Geometry geom); static Polygon squareEnveloppe(Envelope env); static Polygon MBS(Geometry geom); static Polygon MBSAirePreservee(Geometry geom); static Polygon rotation(Polygon geom, Coordinate c, double angle); static Polygon homothetie(Polygon geom, double x0, double y0,
      double scale); static Polygon homothetie(Polygon geom, double x0, double y0,
      double scaleX, double scaleY); static Polygon homothetie(Polygon geom, double scaleX, double scaleY); static Polygon homothetie(Polygon geom, double scale);  }
@Test public void testOffsetCurveILineStringDouble() { IDirectPosition p1 = new DirectPosition(651049.4584816409, 6861902.601655778); IDirectPosition p2 = new DirectPosition(651069.3941174329, 6861891.803186391); ILineString line = new GM_LineString(p1, p2); double distance = 3.0 / 4.0; IMultiCurve<ILineString> offset1 = JtsAlgorithms.offsetCurve(line, distance); IMultiCurve<ILineString> offset2 = JtsAlgorithms.offsetCurve(line.reverse(), distance); System.out.println(offset1); System.out.println(offset2); IDirectPosition p3 = new DirectPosition(651345.6220778765, 6861505.810661668); IDirectPosition p4 = new DirectPosition(651246.3, 6861498.9); IDirectPosition p5 = new DirectPosition(651271.8, 6861500.7); IDirectPosition p6 = new DirectPosition(651304.3, 6861502.9); IDirectPosition p7 = new DirectPosition(651327.2000000001, 6861504.5); IDirectPosition p8 = new DirectPosition(651230.7842965396, 6861497.820646716); line = new GM_LineString(p3, p7, p6, p5, p4, p8); System.out.println(line); distance = 1.0; offset1 = JtsAlgorithms.offsetCurve(line, distance); offset2 = JtsAlgorithms.offsetCurve(line.reverse(), distance); System.out.println(offset1); System.out.println(offset2); }