use of org.opengis.geometry.primitive.CurveSegment in project geotoolkit by Geomatys.
the class GeometryParser method readLinearRingText.
/**
* Creates a <code>Curve</code> using the next token in the stream.
*
* @param tokenizer tokenizer over a stream of text in Well-known Text
* format. The next tokens must form a <LineString Text>.
* @return a <code>Curve</code> specified by the next
* token in the stream
* @throws IOException if an I/O error occurs
* @throws ParseException if the coordinates used to create the <code>Curve</code>
* do not form a closed linestring, or if an unexpected token was
* encountered
*/
private Curve readLinearRingText(final StreamTokenizer tokenizer) throws IOException, ParseException {
List<Position> coordList = getCoordinates(tokenizer);
LineString lineString = geometryFactory.createLineString(coordList);
List<CurveSegment> curveSegmentList = Collections.singletonList((CurveSegment) lineString);
return primitiveFactory.createCurve(curveSegmentList);
}
use of org.opengis.geometry.primitive.CurveSegment in project geotoolkit by Geomatys.
the class JTSMultiCurve method applyCRSonChild.
public void applyCRSonChild() {
for (OrientableCurve child : getElements()) {
if (child.getCoordinateReferenceSystem() == null && child instanceof JTSCurve) {
JTSCurve childCurve = (JTSCurve) child;
childCurve.setCoordinateReferenceSystem(getCoordinateReferenceSystem());
for (CurveSegment cv : childCurve.getSegments()) {
if (cv instanceof JTSLineString) {
((JTSLineString) cv).setCoordinateReferenceSystem(getCoordinateReferenceSystem());
((JTSLineString) cv).applyCRSOnChild();
}
}
}
}
}
use of org.opengis.geometry.primitive.CurveSegment in project geotoolkit by Geomatys.
the class IntersectionTest method testEdgeIntersection.
@Test
public void testEdgeIntersection() {
DirectPosition[] pointsA = new DirectPosition[4];
pointsA[0] = createDirectPosition(0.0, 0.0);
pointsA[1] = createDirectPosition(1.0, 0.0);
pointsA[2] = createDirectPosition(0.0, 1.0);
pointsA[3] = createDirectPosition(0.0, 0.0);
DirectPosition[] pointsB = new DirectPosition[4];
pointsB[0] = createDirectPosition(1.0, 0.0);
pointsB[1] = createDirectPosition(1.0, 1.0);
pointsB[2] = createDirectPosition(0.0, 1.0);
pointsB[3] = createDirectPosition(1.0, 0.0);
Surface sA = createSurface(pointsA);
assertEquals(0.5, sA.getArea(), 1.0e-8);
assertEquals(1.0 + 1.0 + Math.sqrt(2.0), sA.getPerimeter(), 0.0);
Surface sB = createSurface(pointsB);
assertEquals(0.5, sB.getArea(), 1.0e-8);
assertEquals(1.0 + 1.0 + Math.sqrt(2.0), sB.getPerimeter(), 0.0);
TransfiniteSet result = sA.intersection(sB);
assertTrue("result was a " + result.getClass().getSimpleName(), result instanceof CurveSegment);
CurveSegment curveResult = (CurveSegment) result;
assertEquals(0.0, curveResult.getStartParam(), 1.0e-8);
// TODO
// assertEquals(Math.sqrt(2.0), curveResult.getEndParam(), 1.0e-8);
}
use of org.opengis.geometry.primitive.CurveSegment in project geotoolkit by Geomatys.
the class SurfaceImplTest method testLargeSurface.
/**
* We need to create a large surface with 7000 points
*/
@Test
public void testLargeSurface() {
int NUMBER = 100000;
double delta = 360.0 / (double) NUMBER;
PointArray points = postitionFactory.createPointArray();
for (double angle = 0.0; angle < 360.0; angle += delta) {
double[] coordinates = new double[] { Math.sin(Math.toRadians(angle)), Math.cos(Math.toRadians(angle)) };
DirectPosition point = postitionFactory.createDirectPosition(coordinates);
points.add(point);
}
List<OrientableCurve> curves = new ArrayList<OrientableCurve>();
// A curve will be created
// - The curve will be set as parent curves for the Curve segments
// - Start and end params for the CurveSegments will be set
List<CurveSegment> segmentList = new ArrayList<CurveSegment>();
for (int i = 0; i < points.size(); i++) {
int start = i;
int end = (i + 1) % points.size();
DirectPosition point1 = points.getDirectPosition(start, null);
DirectPosition point2 = points.getDirectPosition(end, null);
LineSegment segment = geometryFactory.createLineSegment(point1, point2);
segmentList.add(segment);
}
Curve curve = primitiveFactory.createCurve(segmentList);
curves.add(curve);
Ring ring = primitiveFactory.createRing(curves);
SurfaceBoundary boundary = primitiveFactory.createSurfaceBoundary(ring, new ArrayList());
JTSSurface surface = (JTSSurface) primitiveFactory.createSurface(boundary);
Geometry peer = surface.computeJTSPeer();
}
use of org.opengis.geometry.primitive.CurveSegment in project geotoolkit by Geomatys.
the class JTSCurve method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder(super.toString());
sb.append("segments:");
if (!curveSegments.isEmpty()) {
sb.append("\n");
for (CurveSegment seg : curveSegments) {
sb.append(seg.toString()).append("\n");
}
}
return sb.toString();
}
Aggregations