Search in sources :

Example 11 with JTSLineString

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

the class JTSGeometryBindingTest method MultiCurveMarshalingTest.

/**
 * Test Composite curve Marshalling.
 */
@Test
public void MultiCurveMarshalingTest() throws Exception {
    CoordinateReferenceSystem crs = CRS.forCode("urn:ogc:def:crs:epsg::4326");
    assertTrue(crs != null);
    DirectPosition p1 = new GeneralDirectPosition(crs);
    p1.setOrdinate(0, 35.840973);
    p1.setOrdinate(1, 0.14967346);
    DirectPosition p2 = new GeneralDirectPosition(crs);
    p2.setOrdinate(0, 44.11891);
    p2.setOrdinate(1, 3.6755037);
    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, 51.174034);
    p21.setOrdinate(1, 12.365124);
    DirectPosition p22 = new GeneralDirectPosition(crs);
    p22.setOrdinate(0, 55.288635);
    p22.setOrdinate(1, 7.583888);
    DirectPosition p23 = new GeneralDirectPosition(crs);
    p23.setOrdinate(0, 56.534782);
    p23.setOrdinate(1, 4.1457024);
    l2.getControlPoints().add(p21);
    l2.getControlPoints().add(p22);
    l2.getControlPoints().add(p23);
    c1.getSegments().add(l2);
    JTSMultiCurve multiCurve = new JTSMultiCurve(crs);
    multiCurve.getElements().add(c2);
    multiCurve.getElements().add(c1);
    StringWriter sw = new StringWriter();
    m.marshal(factory.createJTSMultiCurve(multiCurve), 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:MultiCurve xmlns:gml=\"http://www.opengis.net/gml\" srsName=\"urn:ogc:def:crs:epsg::4326\" >" + '\n' + "  <gml:curveMember>" + '\n' + "    <gml:LineString>" + '\n' + "      <gml:posList>35.840973 0.14967346 44.11891 3.6755037</gml:posList>" + '\n' + "    </gml:LineString>" + '\n' + "  </gml:curveMember>" + '\n' + "  <gml:curveMember>" + '\n' + "    <gml:LineString>" + '\n' + "      <gml:posList>51.174034 12.365124 55.288635 7.583888 56.534782 4.1457024</gml:posList>" + '\n' + "    </gml:LineString>" + '\n' + "  </gml:curveMember>" + '\n' + "</gml:MultiCurve>" + '\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) 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)

Example 12 with JTSLineString

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

the class PolyhedralSurfaceType method getIsoPolyHedralSurface.

public JTSPolyhedralSurface getIsoPolyHedralSurface() {
    JTSPolyhedralSurface result = new JTSPolyhedralSurface(coordinateReferenceSystem);
    for (JTSSurfaceBoundary s : patchList.getPatches()) {
        s.setCoordinateReferenceSystem(coordinateReferenceSystem);
        ((JTSRing) s.getExterior()).setCoordinateReferenceSystem(coordinateReferenceSystem);
        for (Primitive p : s.getExterior().getElements()) {
            if (p instanceof JTSCurve) {
                JTSCurve curve = (JTSCurve) p;
                curve.setCoordinateReferenceSystem(coordinateReferenceSystem);
                for (CurveSegment cv : curve.getSegments()) {
                    if (cv instanceof JTSLineString) {
                        JTSLineString line = (JTSLineString) cv;
                        PointArray pa = line.getControlPoints();
                        List<Position> newPositions = new ArrayList<Position>();
                        for (Position pos : pa) {
                            if (pos instanceof GeneralDirectPosition) {
                                ((GeneralDirectPosition) pos).setCoordinateReferenceSystem(coordinateReferenceSystem);
                                newPositions.add(pos);
                            }
                        }
                        line.getControlPoints().clear();
                        line.getControlPoints().addAll(newPositions);
                    }
                }
            }
        }
        if (s.getInteriors() != null) {
            for (Ring ring : s.getInteriors()) {
                ((JTSRing) ring).setCoordinateReferenceSystem(coordinateReferenceSystem);
                for (Primitive p : ring.getElements()) {
                    if (p instanceof JTSCurve) {
                        JTSCurve curve = (JTSCurve) p;
                        curve.setCoordinateReferenceSystem(coordinateReferenceSystem);
                        for (CurveSegment cv : curve.getSegments()) {
                            if (cv instanceof JTSLineString) {
                                JTSLineString line = (JTSLineString) cv;
                                PointArray pa = line.getControlPoints();
                                List<Position> newPositions = new ArrayList<Position>();
                                for (Position pos : pa) {
                                    if (pos instanceof GeneralDirectPosition) {
                                        ((GeneralDirectPosition) pos).setCoordinateReferenceSystem(coordinateReferenceSystem);
                                        newPositions.add(pos);
                                    }
                                }
                                line.getControlPoints().clear();
                                line.getControlPoints().addAll(newPositions);
                            }
                        }
                    }
                }
            }
        }
        result.getPatches().add(new JTSPolygon(s));
    }
    return result;
}
Also used : JTSPolyhedralSurface(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPolyhedralSurface) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) JTSRing(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSRing) Position(org.opengis.geometry.coordinate.Position) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) JTSSurfaceBoundary(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSSurfaceBoundary) JTSPolygon(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSPolygon) ArrayList(java.util.ArrayList) JTSCurve(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve) PointArray(org.opengis.geometry.coordinate.PointArray) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) Primitive(org.opengis.geometry.primitive.Primitive) CurveSegment(org.opengis.geometry.primitive.CurveSegment) JTSRing(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSRing) Ring(org.opengis.geometry.primitive.Ring)

Example 13 with JTSLineString

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

the class LineStringPosListType method getJTSLineString.

public JTSLineString getJTSLineString() {
    CoordinateReferenceSystem crs = null;
    if (this.srsName != null) {
        try {
            crs = CRS.forCode(srsName);
        } catch (FactoryException ex) {
            Logger.getLogger("org.geotoolkit.internal.jaxb").log(Level.WARNING, null, ex);
        }
    }
    final JTSLineString result = new JTSLineString(crs);
    if (posList != null) {
        for (int i = 0; i < posList.getValue().size(); i = i + 2) {
            result.getPositions().add(new GeneralDirectPosition(posList.getValue().get(i), posList.getValue().get(i + 1)));
        }
    } else if (coordinates != null) {
        for (int i = 0; i < coordinates.getValues().size(); i = i + 2) {
            result.getPositions().add(new GeneralDirectPosition(coordinates.getValues().get(i), coordinates.getValues().get(i + 1)));
        }
    }
    return result;
}
Also used : GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) FactoryException(org.opengis.util.FactoryException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString)

Example 14 with JTSLineString

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

the class LinearRingPosListType method getJTSRing.

public JTSRing getJTSRing() {
    final List<Double> values;
    if (posList != null) {
        values = posList.getValue();
    } else if (coordinates != null) {
        values = coordinates.getValues();
    } else {
        values = new ArrayList<Double>();
    }
    final JTSLineString line = new JTSLineString();
    for (int i = 0; i < values.size() - 1; i = i + 2) {
        double x = values.get(i);
        double y = values.get(i + 1);
        final DirectPosition pos = new GeneralDirectPosition(x, y);
        line.getControlPoints().add(pos);
    }
    JTSCurve curve = new JTSCurve();
    curve.getSegments().add(line);
    JTSRing ring = new JTSRing();
    ring.getElements().add(curve);
    return ring;
}
Also used : GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) DirectPosition(org.opengis.geometry.DirectPosition) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) JTSRing(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSRing) ArrayList(java.util.ArrayList) JTSCurve(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString)

Example 15 with JTSLineString

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

the class GeometryMapping method readValue.

@Override
public void readValue(XMLStreamReader reader, GenericName propName, Feature feature) throws XMLStreamException {
    final String localName = reader.getLocalName();
    if (decorated) {
        // check if we are dealing with a link href
        String link = reader.getAttributeValue(GMLConvention.XLINK_NAMESPACE, "href");
        if (link != null) {
            toTagEnd(reader, localName);
            Attribute attribute = (Attribute) feature.getProperty(propName.toString());
            AttributeType<String> charType = (AttributeType) attribute.getType().characteristics().get(GMLConvention.XLINK_HREF.tip().toString());
            Attribute<String> charValue = charType.newInstance();
            charValue.setValue(link);
            attribute.characteristics().put(GMLConvention.XLINK_HREF.tip().toString(), charValue);
            return;
        }
    }
    boolean skipCurrent = decorated;
    int event;
    Object value;
    // backward compatible with incorrect old writings
    final String propertyName = propertyType.getName().tip().toString();
    if (propertyName.equals(localName)) {
        skipCurrent = true;
    }
    // special case for SurfacePropertyType which may contain a simple polygon
    boolean forceMultiPolygon = propertyName.equalsIgnoreCase("multipolygon");
    if (skipCurrent) {
        event = reader.next();
    } else {
        event = reader.getEventType();
    }
    while (event != START_ELEMENT) {
        if (event == END_ELEMENT) {
            return;
        }
        event = reader.next();
    }
    try {
        Unmarshaller unmarshaller = pool.acquireUnmarshaller();
        final Geometry jtsGeom;
        final Object geometry = ((JAXBElement) unmarshaller.unmarshal(reader)).getValue();
        if (geometry instanceof JTSGeometry) {
            final JTSGeometry isoGeom = (JTSGeometry) geometry;
            if (isoGeom instanceof JTSMultiCurve) {
                ((JTSMultiCurve) isoGeom).applyCRSonChild();
            }
            jtsGeom = isoGeom.getJTSGeometry();
        } else if (geometry instanceof PolygonType) {
            final PolygonType polygon = ((PolygonType) geometry);
            jtsGeom = polygon.getJTSPolygon().getJTSGeometry();
            if (polygon.getCoordinateReferenceSystem() != null) {
                JTS.setCRS(jtsGeom, polygon.getCoordinateReferenceSystem());
            }
        } else if (geometry instanceof LineStringPosListType) {
            final JTSLineString line = ((LineStringPosListType) geometry).getJTSLineString();
            jtsGeom = line.getJTSGeometry();
            if (line.getCoordinateReferenceSystem() != null) {
                JTS.setCRS(jtsGeom, line.getCoordinateReferenceSystem());
            }
        } else if (geometry instanceof AbstractGeometry) {
            try {
                jtsGeom = GeometrytoJTS.toJTS((AbstractGeometry) geometry, longitudeFirst, forceMultiPolygon);
            } catch (FactoryException ex) {
                throw new XMLStreamException("Factory Exception while transforming GML object to JTS", ex);
            }
        } else {
            throw new IllegalArgumentException("unexpected geometry type:" + geometry);
        }
        value = jtsGeom;
        value = JTSMapping.convertType(jtsGeom, ((AttributeType) propertyType).getValueClass());
        pool.recycle(unmarshaller);
    } catch (JAXBException ex) {
        String msg = ex.getMessage();
        if (msg == null && ex.getLinkedException() != null) {
            msg = ex.getLinkedException().getMessage();
        }
        throw new IllegalArgumentException("JAXB exception while reading the feature geometry: " + msg, ex);
    }
    JAXPStreamFeatureReader.setValue(feature, propertyType, propName, null, value);
}
Also used : AbstractGeometry(org.geotoolkit.gml.xml.AbstractGeometry) Attribute(org.opengis.feature.Attribute) FactoryException(org.opengis.util.FactoryException) JAXBException(javax.xml.bind.JAXBException) PolygonType(org.geotoolkit.internal.jaxb.PolygonType) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) JAXBElement(javax.xml.bind.JAXBElement) JTSMultiCurve(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiCurve) LineStringPosListType(org.geotoolkit.internal.jaxb.LineStringPosListType) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) AbstractGeometry(org.geotoolkit.gml.xml.AbstractGeometry) JTSGeometry(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry) Geometry(org.locationtech.jts.geom.Geometry) XMLStreamException(javax.xml.stream.XMLStreamException) AttributeType(org.opengis.feature.AttributeType) Unmarshaller(javax.xml.bind.Unmarshaller) JTSGeometry(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry)

Aggregations

JTSLineString (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString)26 GeneralDirectPosition (org.apache.sis.geometry.GeneralDirectPosition)23 JTSCurve (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve)23 DirectPosition (org.opengis.geometry.DirectPosition)19 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)17 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 CurveSegment (org.opengis.geometry.primitive.CurveSegment)5 ArrayList (java.util.ArrayList)4 JTSMultiCurve (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiCurve)4 PointArray (org.opengis.geometry.coordinate.PointArray)4 Position (org.opengis.geometry.coordinate.Position)4 JAXBElement (javax.xml.bind.JAXBElement)3 JTSMultiPrimitive (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPrimitive)3 Primitive (org.opengis.geometry.primitive.Primitive)3