The following sections explain how to manipulate Curves:
Creating a Curve
Curves, or line objects, are usually created from a series of CurveSegments. Curves can be created directly from the GeometryBuilder, or if you only want to use GeoAPI interfaces you can use factories:
Using GeometryBuilder
The following example shows how to create a CurveSegment and how to use it to build a Curve with the GeometryBuilder.
// create directpositions DirectPosition start = builder.createDirectPosition(new double[]{ 48.44, -123.37 }); DirectPosition middle = builder.createDirectPosition(new double[]{ 47, -122 }); DirectPosition end = builder.createDirectPosition(new double[]{ 46.5, -121.5 }); // add directpositions to a list ArrayList<Position> positions = new ArrayList<Position>(); positions .add(start); positions.add(middle); positions.add(end); // create linestring from directpositions LineString line = builder.createLineString(positions); // create curvesegments from line ArrayList<CurveSegment> segs = new ArrayList<CurveSegment>(); segs.add(line); // create curve Curve curve = builder.createCurve(segs);
Using Factories
Building a curve from factories is very similar to the process of using the GeometryBuilder, but it lets you only use GeoAPI interfaces:
// create directpositions DirectPosition start = posF.createDirectPosition(new double[]{ 48.44, -123.37 }); DirectPosition middle = posF.createDirectPosition(new double[]{ 47, -122 }); DirectPosition end = posF.createDirectPosition(new double[]{ 46.5, -121.5 }); // add directpositions to a list ArrayList<Position> positions = new ArrayList<Position>(); positions .add(start); positions.add(middle); positions.add(end); // create linestring from directpositions LineString line = geomF.createLineString(positions); // create curvesegments from line ArrayList<CurveSegment> segs = new ArrayList<CurveSegment>(); segs.add(line); // create curve Curve curve = primF.createCurve(segs);
Dissecting a Curve
Taking apart a Curve to get a list of points may not always return what you expect. For instance in a spline curve, the curve segment is given as a weighted vector sum of the control points. These control points are used to control its shape, and are not always on the curve itself. It can still be useful to obtain these control points, and the following shows how you can do that:
List<CurveSegment> segs = curve.getSegments(); Iterator<CurveSegment> iter = segs.iterator(); PointArray samplePoints = null; while (iter.hasNext()) { if (samplePoints == null) { samplePoints = iter.next().getSamplePoints(); } else { samplePoints.addAll(iter.next().getSamplePoints()); } }