Search in sources :

Example 1 with JTSCurve

use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve in project geotoolkit by Geomatys.

the class JTSUtils method toISO.

/**
 * Creates a 19107 primitive geometry from the given JTS geometry.
 */
public static Geometry toISO(final org.locationtech.jts.geom.Geometry jtsGeom, CoordinateReferenceSystem crs) {
    if (jtsGeom == null) {
        return null;
    }
    if (crs == null) {
        // try to extract the crs from the srid
        final int srid = jtsGeom.getSRID();
        if (srid != 0) {
            final String strCRS = SRIDGenerator.toSRS(srid, SRIDGenerator.Version.V1);
            try {
                crs = CRS.forCode(strCRS);
            } catch (FactoryException ex) {
                Logger.getLogger("org.geotoolkit.geometry.isoonjts").log(Level.SEVERE, null, ex);
            }
        }
    }
    // TODO use factory finder when primitive factory and geometry factory are ready.
    // FactoryFinder.getPrimitiveFactory(hints);
    final PrimitiveFactory pf = new JTSPrimitiveFactory(crs);
    // FactoryFinder.getGeometryFactory(hints);
    final GeometryFactory gf = new JTSGeometryFactory(crs);
    if (jtsGeom instanceof org.locationtech.jts.geom.Point) {
        org.locationtech.jts.geom.Point candidate = (org.locationtech.jts.geom.Point) jtsGeom;
        DirectPosition dp = pointToDirectPosition(candidate, crs);
        return pf.createPoint(dp);
    } else if (jtsGeom instanceof org.locationtech.jts.geom.LineString) {
        org.locationtech.jts.geom.LineString candidate = (org.locationtech.jts.geom.LineString) jtsGeom;
        LineString ls = gf.createLineString(new ArrayList<Position>());
        PointArray pointList = ls.getControlPoints();
        for (int i = 0, n = candidate.getNumPoints(); i < n; i++) {
            pointList.add(coordinateToDirectPosition(candidate.getCoordinateN(i), crs));
        }
        return (JTSLineString) ls;
    } else if (jtsGeom instanceof org.locationtech.jts.geom.LinearRing) {
        return linearRingToRing((org.locationtech.jts.geom.LinearRing) jtsGeom, crs);
    } else if (jtsGeom instanceof org.locationtech.jts.geom.Polygon) {
        org.locationtech.jts.geom.Polygon jtsPolygon = (org.locationtech.jts.geom.Polygon) jtsGeom;
        Ring externalRing = linearRingToRing((org.locationtech.jts.geom.LinearRing) jtsPolygon.getExteriorRing(), crs);
        ArrayList internalRings = new ArrayList();
        for (int i = 0, n = jtsPolygon.getNumInteriorRing(); i < n; i++) {
            internalRings.add(linearRingToRing((org.locationtech.jts.geom.LinearRing) jtsPolygon.getInteriorRingN(i), crs));
        }
        SurfaceBoundary boundary = pf.createSurfaceBoundary(externalRing, internalRings);
        Polygon polygon = gf.createPolygon(boundary);
        return (JTSPolygon) polygon;
    /*ArrayList<Polygon> patches = new ArrayList<Polygon>();
            patches.add(polygon);
            PolyhedralSurface result = gf.createPolyhedralSurface(patches);
            return result;*/
    } else if (jtsGeom instanceof GeometryCollection) {
        org.locationtech.jts.geom.GeometryCollection jtsCollection = (org.locationtech.jts.geom.GeometryCollection) jtsGeom;
        boolean multiPoint = jtsGeom instanceof MultiPoint;
        boolean multiCurve = jtsGeom instanceof MultiLineString;
        boolean multiSurface = jtsGeom instanceof MultiPolygon;
        // determine it by analyzing its content.
        if (!(multiPoint || multiCurve || multiSurface || jtsGeom.isEmpty())) {
            multiPoint = multiCurve = multiSurface = true;
            for (int i = 0, n = jtsCollection.getNumGeometries(); i < n && (multiPoint || multiCurve || multiSurface); i++) {
                if (!(jtsCollection.getGeometryN(i) instanceof org.locationtech.jts.geom.Point)) {
                    multiPoint = false;
                }
                if (!(jtsCollection.getGeometryN(i) instanceof org.locationtech.jts.geom.LineString)) {
                    multiCurve = false;
                }
                if (!(jtsCollection.getGeometryN(i) instanceof org.locationtech.jts.geom.Polygon)) {
                    multiSurface = false;
                }
            }
        }
        AbstractJTSAggregate result;
        if (multiPoint) {
            result = new JTSMultiPoint(crs);
            Set elements = result.getElements();
            for (int i = 0, n = jtsCollection.getNumGeometries(); i < n; i++) {
                // result.getElements().add(jtsToGo1(jtsCollection.getGeometryN(i), crs));
                elements.add(toISO(jtsCollection.getGeometryN(i), crs));
            }
        } else if (multiCurve) {
            result = new JTSMultiCurve(crs);
            Set elements = result.getElements();
            for (int i = 0, n = jtsCollection.getNumGeometries(); i < n; i++) {
                // result.getElements().add(jtsToGo1(jtsCollection.getGeometryN(i), crs));
                Geometry element = toISO(jtsCollection.getGeometryN(i), crs);
                if (element instanceof JTSLineString) {
                    JTSCurve curve = new JTSCurve(crs);
                    curve.getSegments().add((JTSLineString) element);
                    element = curve;
                }
                elements.add(element);
            }
        } else if (multiSurface) {
            result = new JTSMultiSurface(crs);
            Set elements = result.getElements();
            for (int i = 0, n = jtsCollection.getNumGeometries(); i < n; i++) {
                // result.getElements().add(jtsToGo1(jtsCollection.getGeometryN(i), crs));
                elements.add(toISO(jtsCollection.getGeometryN(i), crs));
            }
        } else {
            result = new JTSMultiPrimitive();
            Set elements = result.getElements();
            for (int i = 0, n = jtsCollection.getNumGeometries(); i < n; i++) {
                // result.getElements().add(jtsToGo1(jtsCollection.getGeometryN(i), crs));
                elements.add(toISO(jtsCollection.getGeometryN(i), crs));
            }
        }
        return result;
    } else {
        throw new IllegalArgumentException("Unsupported geometry type: " + jtsGeom.getGeometryType());
    }
}
Also used : MultiPoint(org.locationtech.jts.geom.MultiPoint) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) DirectPosition(org.opengis.geometry.DirectPosition) MultiLineString(org.locationtech.jts.geom.MultiLineString) GeometryFactory(org.opengis.geometry.coordinate.GeometryFactory) JTSGeometryFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSGeometryFactory) Set(java.util.Set) FactoryException(org.opengis.util.FactoryException) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint) ArrayList(java.util.ArrayList) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) LineString(org.opengis.geometry.coordinate.LineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) JTSMultiCurve(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiCurve) JTSCurve(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) JTSPolygon(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSPolygon) Polygon(org.opengis.geometry.coordinate.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) AbstractJTSAggregate(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.AbstractJTSAggregate) JTSGeometryFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSGeometryFactory) SurfaceBoundary(org.opengis.geometry.primitive.SurfaceBoundary) JTSMultiSurface(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiSurface) MultiPoint(org.locationtech.jts.geom.MultiPoint) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint) JTSPrimitiveFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPrimitiveFactory) JTSPrimitiveFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPrimitiveFactory) PrimitiveFactory(org.opengis.geometry.primitive.PrimitiveFactory) PointArray(org.opengis.geometry.coordinate.PointArray) MultiPoint(org.locationtech.jts.geom.MultiPoint) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint) JTSMultiPrimitive(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPrimitive) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) Geometry(org.opengis.geometry.Geometry) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) LineString(org.opengis.geometry.coordinate.LineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Ring(org.opengis.geometry.primitive.Ring)

Example 2 with JTSCurve

use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve 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();
                }
            }
        }
    }
}
Also used : CurveSegment(org.opengis.geometry.primitive.CurveSegment) OrientableCurve(org.opengis.geometry.primitive.OrientableCurve) JTSCurve(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString)

Example 3 with JTSCurve

use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve in project geotoolkit by Geomatys.

the class JTSGeometryBindingTest method RingMarshalingTest.

/**
 * Test Ring Unmarshalling.
 */
@Test
public void RingMarshalingTest() throws Exception {
    CoordinateReferenceSystem crs = CRS.forCode("urn:ogc:def:crs:epsg::27572");
    assertTrue(crs != null);
    JTSRing ring = new JTSRing(crs);
    JTSCurve c1 = new JTSCurve(crs);
    JTSLineString c1l1 = new JTSLineString();
    DirectPosition c1l1p1 = new GeneralDirectPosition(crs);
    c1l1p1.setOrdinate(0, 401500);
    c1l1p1.setOrdinate(1, 3334500);
    DirectPosition c1l1p2 = new GeneralDirectPosition(crs);
    c1l1p2.setOrdinate(0, 401700);
    c1l1p2.setOrdinate(1, 3334850);
    DirectPosition c1l1p3 = new GeneralDirectPosition(crs);
    c1l1p3.setOrdinate(0, 402200);
    c1l1p3.setOrdinate(1, 3335200);
    c1l1.getControlPoints().add(c1l1p1);
    c1l1.getControlPoints().add(c1l1p2);
    c1l1.getControlPoints().add(c1l1p3);
    c1.getSegments().add(c1l1);
    JTSLineString c1l2 = new JTSLineString();
    DirectPosition c1l2p1 = new GeneralDirectPosition(crs);
    c1l2p1.setOrdinate(0, 402320);
    c1l2p1.setOrdinate(1, 3334850);
    DirectPosition c1l2p2 = new GeneralDirectPosition(crs);
    c1l2p2.setOrdinate(0, 402200);
    c1l2p2.setOrdinate(1, 3335200);
    c1l2.getControlPoints().add(c1l2p1);
    c1l2.getControlPoints().add(c1l2p2);
    c1.getSegments().add(c1l2);
    ring.getElements().add(c1);
    StringWriter sw = new StringWriter();
    m.marshal(ring, sw);
    String result = sw.toString();
    result = result.replaceAll("(?i)epsg\\:\\d+\\.\\d+\\.?\\d*\\:", "epsg::");
    String expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<gml:Ring xmlns:gml=\"http://www.opengis.net/gml\" srsName=\"urn:ogc:def:crs:epsg::27572\" >" + '\n' + "  <gml:curveMember>" + '\n' + "    <gml:Curve srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + "      <gml:segments>" + '\n' + "        <gml:LineStringSegment interpolation=\"linear\">" + '\n' + "          <gml:pos>401500.0 3334500.0</gml:pos>" + '\n' + "          <gml:pos>401700.0 3334850.0</gml:pos>" + '\n' + "          <gml:pos>402200.0 3335200.0</gml:pos>" + '\n' + "        </gml:LineStringSegment>" + '\n' + "        <gml:LineStringSegment interpolation=\"linear\">" + '\n' + "          <gml:pos>402320.0 3334850.0</gml:pos>" + '\n' + "          <gml:pos>402200.0 3335200.0</gml:pos>" + '\n' + "        </gml:LineStringSegment>" + '\n' + "      </gml:segments>" + '\n' + "    </gml:Curve>" + '\n' + "  </gml:curveMember>" + '\n' + "</gml:Ring>" + '\n';
    assertXmlEquals(expResult, result, "xmlns:*");
}
Also used : GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) DirectPosition(org.opengis.geometry.DirectPosition) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) StringWriter(java.io.StringWriter) JTSRing(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSRing) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) JTSCurve(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString)

Example 4 with JTSCurve

use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve in project geotoolkit by Geomatys.

the class JTSGeometryBindingTest method PolyHedralSurfaceUnmarshalingTest.

/**
 * Test PolyHedral surface Unmarshalling.
 */
@Test
public void PolyHedralSurfaceUnmarshalingTest() throws Exception {
    CoordinateReferenceSystem crs = CRS.forCode("urn:ogc:def:crs:epsg::27572");
    assertTrue(crs != null);
    JTSPolyhedralSurface expResult = new JTSPolyhedralSurface(crs);
    /*
         * FIRST POLYGON
         */
    // EXTERIOR
    JTSRing exterior1 = new JTSRing(crs);
    JTSCurve c1 = new JTSCurve(crs);
    JTSLineString c1l1 = new JTSLineString();
    DirectPosition c1l1p1 = new GeneralDirectPosition(crs);
    c1l1p1.setOrdinate(0, 401500);
    c1l1p1.setOrdinate(1, 3334500);
    DirectPosition c1l1p2 = new GeneralDirectPosition(crs);
    c1l1p2.setOrdinate(0, 401700);
    c1l1p2.setOrdinate(1, 3334850);
    DirectPosition c1l1p3 = new GeneralDirectPosition(crs);
    c1l1p3.setOrdinate(0, 402200);
    c1l1p3.setOrdinate(1, 3335200);
    DirectPosition c1l2p1 = new GeneralDirectPosition(crs);
    c1l2p1.setOrdinate(0, 402320);
    c1l2p1.setOrdinate(1, 3334850);
    DirectPosition c1l2p2 = new GeneralDirectPosition(crs);
    c1l2p2.setOrdinate(0, 402200);
    c1l2p2.setOrdinate(1, 3335200);
    c1l1.getControlPoints().add(c1l1p1);
    c1l1.getControlPoints().add(c1l1p2);
    c1l1.getControlPoints().add(c1l1p3);
    c1l1.getControlPoints().add(c1l2p1);
    c1l1.getControlPoints().add(c1l2p2);
    c1.getSegments().add(c1l1);
    exterior1.getElements().add(c1);
    // INTERIOR
    Ring[] interiors1 = new Ring[1];
    JTSRing interior1 = new JTSRing(crs);
    JTSCurve c2 = new JTSCurve(crs);
    JTSLineString c2l1 = new JTSLineString();
    DirectPosition c2l1p1 = new GeneralDirectPosition(crs);
    c2l1p1.setOrdinate(0, 401500);
    c2l1p1.setOrdinate(1, 3334500);
    DirectPosition c2l1p2 = new GeneralDirectPosition(crs);
    c2l1p2.setOrdinate(0, 401700);
    c2l1p2.setOrdinate(1, 3334850);
    DirectPosition c2l1p3 = new GeneralDirectPosition(crs);
    c2l1p3.setOrdinate(0, 402200);
    c2l1p3.setOrdinate(1, 3335200);
    c2l1.getControlPoints().add(c2l1p1);
    c2l1.getControlPoints().add(c2l1p2);
    c2l1.getControlPoints().add(c2l1p3);
    c2.getSegments().add(c2l1);
    interior1.getElements().add(c2);
    interiors1[0] = interior1;
    JTSSurfaceBoundary bound1 = new JTSSurfaceBoundary(crs, exterior1, interiors1);
    JTSPolygon p1 = new JTSPolygon(bound1);
    /*
         * SECOND POLYGON
         */
    // EXTERIOR
    JTSRing exterior2 = new JTSRing(crs);
    JTSCurve c3 = new JTSCurve(crs);
    JTSLineString c3l1 = new JTSLineString();
    DirectPosition c3l1p1 = new GeneralDirectPosition(crs);
    c3l1p1.setOrdinate(0, 401500);
    c3l1p1.setOrdinate(1, 3334500);
    DirectPosition c3l1p2 = new GeneralDirectPosition(crs);
    c3l1p2.setOrdinate(0, 401700);
    c3l1p2.setOrdinate(1, 3334850);
    DirectPosition c3l1p3 = new GeneralDirectPosition(crs);
    c3l1p3.setOrdinate(0, 402200);
    c3l1p3.setOrdinate(1, 3335200);
    c3l1.getControlPoints().add(c3l1p1);
    c3l1.getControlPoints().add(c3l1p2);
    c3l1.getControlPoints().add(c3l1p3);
    c3.getSegments().add(c3l1);
    exterior2.getElements().add(c3);
    // INTERIOR
    JTSRing interior2 = new JTSRing(crs);
    JTSCurve c4 = new JTSCurve(crs);
    JTSLineString c4l1 = new JTSLineString();
    DirectPosition c4l1p1 = new GeneralDirectPosition(crs);
    c4l1p1.setOrdinate(0, 401500);
    c4l1p1.setOrdinate(1, 3334500);
    DirectPosition c4l1p2 = new GeneralDirectPosition(crs);
    c4l1p2.setOrdinate(0, 401700);
    c4l1p2.setOrdinate(1, 3334850);
    DirectPosition c4l1p3 = new GeneralDirectPosition(crs);
    c4l1p3.setOrdinate(0, 402200);
    c4l1p3.setOrdinate(1, 3335200);
    c4l1.getControlPoints().add(c4l1p1);
    c4l1.getControlPoints().add(c4l1p2);
    c4l1.getControlPoints().add(c4l1p3);
    c4.getSegments().add(c4l1);
    interior2.getElements().add(c4);
    Ring[] interiors2 = new Ring[1];
    interiors2[0] = interior2;
    JTSSurfaceBoundary bound2 = new JTSSurfaceBoundary(crs, exterior2, interiors2);
    JTSPolygon p2 = new JTSPolygon(bound2);
    expResult.getPatches().add(p1);
    expResult.getPatches().add(p2);
    // TODO remove the srsName
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<gml:PolyhedralSurface srsName=\"urn:ogc:def:crs:epsg::27572\" xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + "  <gml:polygonPatches>" + '\n' + "    <gml:PolygonPatch>" + '\n' + "      <gml:exterior>" + '\n' + "        <gml:LinearRing>" + '\n' + "          <gml:posList>401500.0 3334500.0 401700.0 3334850.0 402200.0 3335200.0 402320.0 3334850.0 402200.0 3335200.0</gml:posList>" + '\n' + "        </gml:LinearRing>" + '\n' + "      </gml:exterior>" + '\n' + "      <gml:interior>" + '\n' + "        <gml:LinearRing>" + '\n' + "          <gml:posList>401500.0 3334500.0 401700.0 3334850.0 402200.0 3335200.0</gml:posList>" + '\n' + "        </gml:LinearRing>" + '\n' + "      </gml:interior>" + '\n' + "    </gml:PolygonPatch>" + '\n' + "    <gml:PolygonPatch>" + '\n' + "      <gml:exterior>" + '\n' + "        <gml:LinearRing>" + '\n' + "          <gml:posList>401500.0 3334500.0 401700.0 3334850.0 402200.0 3335200.0</gml:posList>" + '\n' + "        </gml:LinearRing>" + '\n' + "      </gml:exterior>" + '\n' + "      <gml:interior>" + '\n' + "        <gml:LinearRing>" + '\n' + "          <gml:posList>401500.0 3334500.0 401700.0 3334850.0 402200.0 3335200.0</gml:posList>" + '\n' + "        </gml:LinearRing>" + '\n' + "      </gml:interior>" + '\n' + "    </gml:PolygonPatch>" + '\n' + "  </gml:polygonPatches>" + '\n' + "</gml:PolyhedralSurface>" + '\n';
    PolyhedralSurfaceType tmp = (PolyhedralSurfaceType) ((JAXBElement) un.unmarshal(new StringReader(xml))).getValue();
    JTSPolyhedralSurface result = tmp.getIsoPolyHedralSurface();
    JTSSurfaceBoundary expBoundary = (JTSSurfaceBoundary) expResult.getPatches().get(0).getBoundary();
    JTSSurfaceBoundary resBoundary = (JTSSurfaceBoundary) result.getPatches().get(0).getBoundary();
    JTSCurve expCurve = (JTSCurve) expBoundary.getExterior().getElements().iterator().next();
    JTSCurve resCurve = (JTSCurve) resBoundary.getExterior().getElements().iterator().next();
    assertEquals(((JTSLineString) expCurve.getSegments().get(0)).getControlPoints().get(0), ((JTSLineString) resCurve.getSegments().get(0)).getControlPoints().get(0));
    assertEquals(expCurve.getSegments().get(0), resCurve.getSegments().get(0));
    assertEquals(expCurve, resCurve);
    assertEquals(expBoundary.getExterior(), resBoundary.getExterior());
    assertEquals(expBoundary.getInteriors(), resBoundary.getInteriors());
    assertEquals(expBoundary, resBoundary);
    assertEquals(expResult.getPatches().get(0), result.getPatches().get(0));
    assertEquals(expResult.getPatches().get(1), result.getPatches().get(1));
    assertEquals(expResult.getPatches(), result.getPatches());
    assertEquals(expResult, result);
}
Also used : GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) DirectPosition(org.opengis.geometry.DirectPosition) JTSPolyhedralSurface(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPolyhedralSurface) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) JTSRing(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSRing) JTSSurfaceBoundary(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSSurfaceBoundary) JTSPolygon(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSPolygon) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) JTSCurve(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) JTSRing(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSRing) Ring(org.opengis.geometry.primitive.Ring) StringReader(java.io.StringReader) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) PolyhedralSurfaceType(org.geotoolkit.internal.jaxb.PolyhedralSurfaceType)

Example 5 with JTSCurve

use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve in project geotoolkit by Geomatys.

the class JTSGeometryBindingTest method CompositeCurveMarshalingTest.

/**
 * Test Composite curve Marshalling.
 */
@Test
public void CompositeCurveMarshalingTest() throws Exception {
    CoordinateReferenceSystem crs = CRS.forCode("urn:ogc:def:crs:epsg::27572");
    assertTrue(crs != null);
    DirectPosition p1 = new GeneralDirectPosition(crs);
    p1.setOrdinate(0, 402000);
    p1.setOrdinate(1, 3334850);
    DirectPosition p2 = new GeneralDirectPosition(crs);
    p2.setOrdinate(0, 402200);
    p2.setOrdinate(1, 3335200);
    JTSLineString l1 = new JTSLineString();
    l1.getControlPoints().add(p1);
    l1.getControlPoints().add(p2);
    JTSCurve c2 = new JTSCurve(crs);
    c2.getSegments().add(l1);
    JTSCurve c1 = new JTSCurve(crs);
    JTSLineString l2 = new JTSLineString();
    DirectPosition p21 = new GeneralDirectPosition(crs);
    p21.setOrdinate(0, 401500);
    p21.setOrdinate(1, 3334500);
    DirectPosition p22 = new GeneralDirectPosition(crs);
    p22.setOrdinate(0, 401700);
    p22.setOrdinate(1, 3334850);
    DirectPosition p23 = new GeneralDirectPosition(crs);
    p23.setOrdinate(0, 402200);
    p23.setOrdinate(1, 3335200);
    l2.getControlPoints().add(p21);
    l2.getControlPoints().add(p22);
    l2.getControlPoints().add(p23);
    c1.getSegments().add(l2);
    JTSLineString l3 = new JTSLineString();
    DirectPosition p31 = new GeneralDirectPosition(crs);
    p31.setOrdinate(0, 402320);
    p31.setOrdinate(1, 3334850);
    DirectPosition p32 = new GeneralDirectPosition(crs);
    p32.setOrdinate(0, 402200);
    p32.setOrdinate(1, 3335200);
    l3.getControlPoints().add(p31);
    l3.getControlPoints().add(p32);
    c1.getSegments().add(l3);
    JTSCompositeCurve compositeCurve = new JTSCompositeCurve(null, crs);
    // compositeCurve.getElements().add(l1); TODO
    compositeCurve.getElements().add(c1);
    compositeCurve.getElements().add(c2);
    StringWriter sw = new StringWriter();
    m.marshal(factory.createJTSCompositeCurve(compositeCurve), sw);
    String result = sw.toString();
    result = result.replaceAll("(?i)epsg\\:\\d+\\.\\d+\\.?\\d*\\:", "epsg::");
    String expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<gml:CompositeCurve xmlns:gml=\"http://www.opengis.net/gml\" srsName=\"urn:ogc:def:crs:epsg::27572\" >" + '\n' + "  <gml:curveMember>" + '\n' + "    <gml:Curve srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + "      <gml:segments>" + '\n' + "        <gml:LineStringSegment interpolation=\"linear\">" + '\n' + "          <gml:pos>401500.0 3334500.0</gml:pos>" + '\n' + "          <gml:pos>401700.0 3334850.0</gml:pos>" + '\n' + "          <gml:pos>402200.0 3335200.0</gml:pos>" + '\n' + "        </gml:LineStringSegment>" + '\n' + "        <gml:LineStringSegment interpolation=\"linear\">" + '\n' + "          <gml:pos>402320.0 3334850.0</gml:pos>" + '\n' + "          <gml:pos>402200.0 3335200.0</gml:pos>" + '\n' + "        </gml:LineStringSegment>" + '\n' + "      </gml:segments>" + '\n' + "    </gml:Curve>" + '\n' + "  </gml:curveMember>" + '\n' + "  <gml:curveMember>" + '\n' + "    <gml:Curve srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + "      <gml:segments>" + '\n' + "        <gml:LineStringSegment interpolation=\"linear\">" + '\n' + "          <gml:pos>402000.0 3334850.0</gml:pos>" + '\n' + "          <gml:pos>402200.0 3335200.0</gml:pos>" + '\n' + "        </gml:LineStringSegment>" + '\n' + "      </gml:segments>" + '\n' + "    </gml:Curve>" + '\n' + "  </gml:curveMember>" + '\n' + "</gml:CompositeCurve>" + '\n';
    assertXmlEquals(expResult, result, "xmlns:*");
}
Also used : GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) DirectPosition(org.opengis.geometry.DirectPosition) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) StringWriter(java.io.StringWriter) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) JTSCurve(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve) JTSCompositeCurve(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.complex.JTSCompositeCurve) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString)

Aggregations

JTSLineString (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString)23 JTSCurve (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve)23 GeneralDirectPosition (org.apache.sis.geometry.GeneralDirectPosition)21 DirectPosition (org.opengis.geometry.DirectPosition)18 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)16 JTSRing (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSRing)14 JTSPolygon (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSPolygon)12 Ring (org.opengis.geometry.primitive.Ring)12 JTSSurfaceBoundary (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSSurfaceBoundary)10 StringReader (java.io.StringReader)8 StringWriter (java.io.StringWriter)8 JTSPolyhedralSurface (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPolyhedralSurface)5 ArrayList (java.util.ArrayList)4 PointArray (org.opengis.geometry.coordinate.PointArray)4 CurveSegment (org.opengis.geometry.primitive.CurveSegment)4 JTSMultiCurve (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiCurve)3 JTSMultiPrimitive (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPrimitive)3 Position (org.opengis.geometry.coordinate.Position)3 Primitive (org.opengis.geometry.primitive.Primitive)3 JAXBElement (javax.xml.bind.JAXBElement)2