Search in sources :

Example 1 with Surface

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;
}
Also used : MultiPrimitive(org.opengis.geometry.aggregate.MultiPrimitive) Set(java.util.Set) LineString(org.opengis.geometry.coordinate.LineString) Surface(org.opengis.geometry.primitive.Surface)

Example 2 with Surface

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);
}
Also used : DirectPosition(org.opengis.geometry.DirectPosition) CurveSegment(org.opengis.geometry.primitive.CurveSegment) TransfiniteSet(org.opengis.geometry.TransfiniteSet) Surface(org.opengis.geometry.primitive.Surface) Test(org.junit.Test)

Example 3 with Surface

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;
}
Also used : SurfaceBoundary(org.opengis.geometry.primitive.SurfaceBoundary) Curve(org.opengis.geometry.primitive.Curve) Surface(org.opengis.geometry.primitive.Surface)

Example 4 with 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);
}
Also used : DirectPosition(org.opengis.geometry.DirectPosition) Surface(org.opengis.geometry.primitive.Surface) Test(org.junit.Test)

Example 5 with Surface

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;
}
Also used : List(java.util.List) JTSPolygon(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSPolygon) Polygon(org.opengis.geometry.coordinate.Polygon) Surface(org.opengis.geometry.primitive.Surface) PolyhedralSurface(org.opengis.geometry.coordinate.PolyhedralSurface)

Aggregations

Surface (org.opengis.geometry.primitive.Surface)5 Test (org.junit.Test)2 DirectPosition (org.opengis.geometry.DirectPosition)2 List (java.util.List)1 Set (java.util.Set)1 JTSPolygon (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSPolygon)1 TransfiniteSet (org.opengis.geometry.TransfiniteSet)1 MultiPrimitive (org.opengis.geometry.aggregate.MultiPrimitive)1 LineString (org.opengis.geometry.coordinate.LineString)1 Polygon (org.opengis.geometry.coordinate.Polygon)1 PolyhedralSurface (org.opengis.geometry.coordinate.PolyhedralSurface)1 Curve (org.opengis.geometry.primitive.Curve)1 CurveSegment (org.opengis.geometry.primitive.CurveSegment)1 SurfaceBoundary (org.opengis.geometry.primitive.SurfaceBoundary)1