use of org.opengis.geometry.primitive.Surface in project geotoolkit by Geomatys.
the class GeometryParser method readMultiPolygonText.
/**
* Creates a {@code MultiPrimitive} using the next token in the stream.
*
* @param tokenizer tokenizer on top of a stream of text in Well-known Text
* format. The next tokens must form a <Polygon Text>.
* @return a <code>MultiPrimitive</code> specified by the next token
* in the stream
* @throws ParseException if the coordinates used to create the <code>Polygon</code>
* shell and holes do not form closed linestrings, or if an unexpected
* token was encountered.
* @throws IOException if an I/O error occurs
*/
private MultiPrimitive readMultiPolygonText(final StreamTokenizer tokenizer) throws IOException, ParseException {
String nextToken = getNextEmptyOrOpener(tokenizer);
if (nextToken.equals(EMPTY)) {
return null;
}
MultiPrimitive multi = geometryFactory.createMultiPrimitive();
Surface surface = readPolygonText(tokenizer);
// multi.getElements().add(surface);
Set elements = multi.getElements();
elements.add(surface);
nextToken = getNextCloserOrComma(tokenizer);
while (nextToken.equals(COMMA)) {
surface = readPolygonText(tokenizer);
// multi.getElements().add(surface);
elements.add(surface);
nextToken = getNextCloserOrComma(tokenizer);
}
return multi;
}
use of org.opengis.geometry.primitive.Surface 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.Surface in project geotoolkit by Geomatys.
the class AbstractGeometryTest method createSurface.
/**
* Creates a simple polygon with no holes
* @param points points defining the polygon (surface)
* @return the surface created out of the points
*/
protected Surface createSurface(final DirectPosition[] points) {
Curve curve = createCurve(points);
SurfaceBoundary surfaceBoundary = createSurfaceBoundary(curve);
Surface surface = PRIMITIVE_FACTORY.createSurface(surfaceBoundary);
return surface;
}
use of org.opengis.geometry.primitive.Surface in project geotoolkit by Geomatys.
the class IntersectionTest method testSimpleIntersection.
/**
* test the simple intersection of two polygons
*/
@Test
public void testSimpleIntersection() {
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(0.0, 0.0);
pointsB[1] = createDirectPosition(1.0, 0.0);
pointsB[2] = createDirectPosition(1.0, 1.0);
pointsB[3] = createDirectPosition(0.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 instanceof Surface);
// Surface surfaceResult = (Surface)result;
// assertEquals(1.0 + Math.sqrt(2.0), surfaceResult.getPerimeter(), 0.0);
}
use of org.opengis.geometry.primitive.Surface in project geotoolkit by Geomatys.
the class JTSPrimitiveFactory method createSurface.
/**
* {@inheritDoc }
*/
@Override
public Surface createSurface(final SurfaceBoundary boundary) {
// For now, our implementation has to assume that the boundary is a
// polygon.
Surface result = new JTSSurface(crs);
Polygon poly = geomFact.createPolygon(boundary);
// PENDING(jdc): the following line is 1.5 specific.
// the result.getPatches() list is a generic list with a type of "? extends SurfacePatch"
// we can compile without the generic if we cast down to List, but why do we need the cast?
// Polygon extends SurfacePatch, so in theory this should work...
// ((List<SurfacePatch>) result.getPatches()).add(poly);
((List) result.getPatches()).add(poly);
return result;
}
Aggregations