Search in sources :

Example 6 with CustomCoordinateSequence

use of org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence in project jena by apache.

the class GMLWriter method buildPoint.

private static Element buildPoint(final CoordinateSequence coordSeq, final String srsName) {
    CustomCoordinateSequence coordSequence = (CustomCoordinateSequence) coordSeq;
    Element gmlRoot = new Element("Point", GML_NAMESPACE);
    gmlRoot.setAttribute("srsName", srsName);
    if (coordSequence.size() > 0) {
        Element pos = new Element("pos", GML_NAMESPACE);
        pos.addContent(convertToGMLText(coordSequence));
        gmlRoot.addContent(pos);
    }
    return gmlRoot;
}
Also used : Element(org.jdom2.Element) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)

Example 7 with CustomCoordinateSequence

use of org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence in project jena by apache.

the class GMLReader method buildLineStringSegments.

private static LineString buildLineStringSegments(List<Element> segments, CoordinateSequenceDimensions dims) {
    int srsDimension = CoordinateSequenceDimensions.convertToInt(dims);
    List<Coordinate> lineStringCoords = new ArrayList<>();
    for (Element segment : segments) {
        List<Coordinate> segmentCoords = buildCoordinateList(segment, srsDimension);
        if (lineStringCoords.isEmpty()) {
            lineStringCoords = segmentCoords;
        } else {
            if (!segmentCoords.isEmpty()) {
                Coordinate lastCoord = lineStringCoords.get(lineStringCoords.size() - 1);
                Coordinate firstCoord = segmentCoords.get(0);
                if (!firstCoord.equals2D(lastCoord)) {
                    throw new DatatypeFormatException("GML LineString segments do not have matching last and first coordinates: " + lineStringCoords + " - " + segmentCoords);
                }
                segmentCoords.remove(0);
                lineStringCoords.addAll(segmentCoords);
            }
        }
    }
    CustomCoordinateSequence coordinateSequence = new CustomCoordinateSequence(dims, lineStringCoords);
    return GEOMETRY_FACTORY.createLineString(coordinateSequence);
}
Also used : DatatypeFormatException(org.apache.jena.datatypes.DatatypeFormatException) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)

Example 8 with CustomCoordinateSequence

use of org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence in project jena by apache.

the class WKTWriter method buildWKT.

private static String buildWKT(final String geometryType, final CoordinateSequence coordSeq, final String dimensionString) {
    CustomCoordinateSequence coordSequence = (CustomCoordinateSequence) coordSeq;
    String wktText = convertToWKTText(coordSequence);
    StringBuilder sb = new StringBuilder(geometryType);
    if (!wktText.equals(" EMPTY")) {
        sb.append(dimensionString);
    }
    sb.append(wktText);
    return sb.toString();
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)

Example 9 with CustomCoordinateSequence

use of org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence in project jena by apache.

the class GMLReaderTest method testExtractMutliCurve.

/**
 * Test of extract method, of class GMLReader.
 *
 * @throws org.jdom2.JDOMException
 * @throws java.io.IOException
 */
@Test
public void testExtractMutliCurve() throws JDOMException, IOException {
    LineString[] lineStrings = new LineString[2];
    lineStrings[0] = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "10 10, 20 20, 10 40"));
    lineStrings[1] = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "40 40, 30 30, 40 20, 30 10"));
    Geometry geometry = GEOMETRY_FACTORY.createMultiLineString(lineStrings);
    GMLReader expResult = new GMLReader(geometry, 2, SRS_URI.OSGB36_CRS);
    String gmlText = "<gml:MultiCurve xmlns:gml=\"http://www.opengis.net/ont/gml\" srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:curveMember><gml:LineString srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:posList>10 10 20 20 10 40</gml:posList></gml:LineString></gml:curveMember><gml:curveMember><gml:LineString srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:posList>40 40 30 30 40 20 30 10</gml:posList></gml:LineString></gml:curveMember></gml:MultiCurve>";
    GMLReader result = GMLReader.extract(gmlText);
    // 
    // 
    assertEquals(expResult, result);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) LineString(org.locationtech.jts.geom.LineString) LineString(org.locationtech.jts.geom.LineString) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence) Test(org.junit.Test)

Example 10 with CustomCoordinateSequence

use of org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence in project jena by apache.

the class GMLReaderTest method testGetGeometryPoint.

/**
 * Test of getGeometry method, of class GMLReader.
 */
@Test
public void testGetGeometryPoint() {
    GMLReader instance = new GMLReader(GEOMETRY_FACTORY.createPoint(new CoordinateXY(11.0, 12.0)), 2);
    Geometry expResult = GEOMETRY_FACTORY.createPoint(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "11.0 12.0"));
    Geometry result = instance.getGeometry();
    // 
    // 
    assertEquals(expResult, result);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) CoordinateXY(org.locationtech.jts.geom.CoordinateXY) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence) Test(org.junit.Test)

Aggregations

CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)72 Geometry (org.locationtech.jts.geom.Geometry)49 Test (org.junit.Test)48 LineString (org.locationtech.jts.geom.LineString)44 DimensionInfo (org.apache.jena.geosparql.implementation.DimensionInfo)39 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)39 LinearRing (org.locationtech.jts.geom.LinearRing)10 Polygon (org.locationtech.jts.geom.Polygon)8 Element (org.jdom2.Element)4 MultiLineString (org.locationtech.jts.geom.MultiLineString)3 MultiPoint (org.locationtech.jts.geom.MultiPoint)3 Point (org.locationtech.jts.geom.Point)3 DatatypeFormatException (org.apache.jena.datatypes.DatatypeFormatException)2 ArrayList (java.util.ArrayList)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 CoordinateXY (org.locationtech.jts.geom.CoordinateXY)1