Search in sources :

Example 1 with MultiLineString

use of org.locationtech.jts.geom.MultiLineString in project arctic-sea by 52North.

the class GeoJSONTest method testMultiLineStringWithZCoordinate.

@Test
public void testMultiLineStringWithZCoordinate() {
    MultiLineString geometry = randomMultiLineString(EPSG_4326);
    geometry.apply(new RandomZCoordinateFilter());
    geometry.geometryChanged();
    readWriteTest(geometry);
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) Test(org.junit.Test)

Example 2 with MultiLineString

use of org.locationtech.jts.geom.MultiLineString in project arctic-sea by 52North.

the class GmlEncoderv321 method createPosition.

private XmlObject createPosition(Geometry geom, EncodingContext ctx) throws EncodingException {
    String foiId = ctx.<String>get(XmlBeansEncodingFlags.GMLID).orElse(null);
    if (geom instanceof Point) {
        PointType xbPoint = PointType.Factory.newInstance(getXmlOptions());
        xbPoint.setId(getGmlID(geom, foiId));
        createPointFromJtsGeometry((Point) geom, xbPoint);
        if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
            PointDocument xbPointDoc = PointDocument.Factory.newInstance(getXmlOptions());
            xbPointDoc.setPoint(xbPoint);
            return xbPointDoc;
        } else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
            GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
            geometryPropertyType.setAbstractGeometry(xbPoint);
            geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_POINT_32, PointType.type);
            return geometryPropertyType;
        }
        return xbPoint;
    } else if (geom instanceof LineString) {
        LineStringType xbLineString = LineStringType.Factory.newInstance(getXmlOptions());
        xbLineString.setId(getGmlID(geom, foiId));
        createLineStringFromJtsGeometry((LineString) geom, xbLineString);
        if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
            LineStringDocument xbLineStringDoc = LineStringDocument.Factory.newInstance(getXmlOptions());
            xbLineStringDoc.setLineString(xbLineString);
            return xbLineStringDoc;
        } else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
            GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
            geometryPropertyType.setAbstractGeometry(xbLineString);
            geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_LINESTRING_32, LineStringType.type);
            return geometryPropertyType;
        }
        return xbLineString;
    } else if (geom instanceof MultiLineString) {
        MultiCurveType xbMultiCurve = MultiCurveType.Factory.newInstance(getXmlOptions());
        xbMultiCurve.setId(getGmlID(geom, foiId));
        xbMultiCurve.setSrsName(getSrsName(geom));
        for (int i = 0; i < geom.getNumGeometries(); ++i) {
            Geometry lineString = geom.getGeometryN(i);
            LineStringType xbLineString = LineStringType.Factory.newInstance(getXmlOptions());
            xbLineString.setId(getGmlID(geom, foiId));
            xbLineString.addNewPosList().setStringValue(JTSHelper.getCoordinatesString(lineString));
            CurvePropertyType xbCurveMember = xbMultiCurve.addNewCurveMember();
            xbCurveMember.addNewAbstractCurve().set(xbLineString);
            XmlHelper.substituteElement(xbCurveMember.getAbstractCurve(), xbLineString);
        }
        if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
            MultiCurveDocument xbMultiCurveDoc = MultiCurveDocument.Factory.newInstance(getXmlOptions());
            xbMultiCurveDoc.setMultiCurve(xbMultiCurve);
            return xbMultiCurveDoc;
        } else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
            GeometryPropertyType xbGeometryProperty = GeometryPropertyType.Factory.newInstance(getXmlOptions());
            xbGeometryProperty.addNewAbstractGeometry().set(xbMultiCurve);
            XmlHelper.substituteElement(xbGeometryProperty.getAbstractGeometry(), xbMultiCurve);
            return xbGeometryProperty;
        } else {
            return xbMultiCurve;
        }
    } else if (geom instanceof Polygon) {
        PolygonType xbPolygon = PolygonType.Factory.newInstance(getXmlOptions());
        xbPolygon.setId(getGmlID(geom, foiId));
        createPolygonFromJtsGeometry((Polygon) geom, xbPolygon);
        if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
            PolygonDocument xbPolygonDoc = PolygonDocument.Factory.newInstance(getXmlOptions());
            xbPolygonDoc.setPolygon(xbPolygon);
            return xbPolygonDoc;
        } else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
            GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
            geometryPropertyType.setAbstractGeometry(xbPolygon);
            geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_POLYGON_32, PolygonType.type);
            return geometryPropertyType;
        }
        return xbPolygon;
    } else if (geom instanceof MultiPoint) {
        MultiPointType xbMultiPoint = MultiPointType.Factory.newInstance(getXmlOptions());
        String id = getGmlID(geom, foiId);
        xbMultiPoint.setId(id);
        createMultiPointFromJtsGeometry((MultiPoint) geom, xbMultiPoint, id);
        if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
            MultiPointDocument xbMultiPointDoc = MultiPointDocument.Factory.newInstance(getXmlOptions());
            xbMultiPointDoc.setMultiPoint(xbMultiPoint);
            return xbMultiPointDoc;
        } else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
            GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
            geometryPropertyType.setAbstractGeometry(xbMultiPoint);
            geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_MULTI_POINT_32, PolygonType.type);
            return geometryPropertyType;
        }
        return xbMultiPoint;
    } else {
        throw new UnsupportedEncoderInputException(this, geom);
    }
}
Also used : MultiPoint(org.locationtech.jts.geom.MultiPoint) MultiLineString(org.locationtech.jts.geom.MultiLineString) PolygonDocument(net.opengis.gml.x32.PolygonDocument) MultiPointDocument(net.opengis.gml.x32.MultiPointDocument) PointDocument(net.opengis.gml.x32.PointDocument) MultiCurveType(net.opengis.gml.x32.MultiCurveType) MultiCurveDocument(net.opengis.gml.x32.MultiCurveDocument) PolygonType(net.opengis.gml.x32.PolygonType) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) MultiPoint(org.locationtech.jts.geom.MultiPoint) Point(org.locationtech.jts.geom.Point) LineStringType(net.opengis.gml.x32.LineStringType) MultiPointType(net.opengis.gml.x32.MultiPointType) MultiPointDocument(net.opengis.gml.x32.MultiPointDocument) MultiPoint(org.locationtech.jts.geom.MultiPoint) Point(org.locationtech.jts.geom.Point) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) EnvelopeOrGeometry(org.n52.shetland.util.EnvelopeOrGeometry) Geometry(org.locationtech.jts.geom.Geometry) AbstractGeometry(org.n52.shetland.ogc.gml.AbstractGeometry) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) LineStringDocument(net.opengis.gml.x32.LineStringDocument) MultiPointType(net.opengis.gml.x32.MultiPointType) PointType(net.opengis.gml.x32.PointType) CurvePropertyType(net.opengis.gml.x32.CurvePropertyType) Polygon(org.locationtech.jts.geom.Polygon) GeometryPropertyType(net.opengis.gml.x32.GeometryPropertyType)

Example 3 with MultiLineString

use of org.locationtech.jts.geom.MultiLineString in project yyl_example by Relucent.

the class JtsGeometryExample1 method createMLine.

/**
 * create multiLine
 * @return 多线
 */
public static MultiLineString createMLine() {
    Coordinate[] coords1 = new Coordinate[] { new Coordinate(2, 2), new Coordinate(2, 2) };
    LineString line1 = GEOMETRY_FACTORY.createLineString(coords1);
    Coordinate[] coords2 = new Coordinate[] { new Coordinate(2, 2), new Coordinate(2, 2) };
    LineString line2 = GEOMETRY_FACTORY.createLineString(coords2);
    LineString[] lineStrings = new LineString[2];
    lineStrings[0] = line1;
    lineStrings[1] = line2;
    MultiLineString ms = GEOMETRY_FACTORY.createMultiLineString(lineStrings);
    return ms;
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) Coordinate(org.locationtech.jts.geom.Coordinate) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString)

Example 4 with MultiLineString

use of org.locationtech.jts.geom.MultiLineString in project yyl_example by Relucent.

the class JtsGeometryExample1 method createMLineByWKT.

/**
 * create multiLine by WKT
 * @return 多线
 * @throws ParseException
 */
public static MultiLineString createMLineByWKT() throws ParseException {
    WKTReader reader = new WKTReader(GEOMETRY_FACTORY);
    MultiLineString line = (MultiLineString) reader.read("MULTILINESTRING((0 0, 2 0),(1 1,2 2))");
    return line;
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) WKTReader(org.locationtech.jts.io.WKTReader)

Example 5 with MultiLineString

use of org.locationtech.jts.geom.MultiLineString in project arctic-sea by 52North.

the class GeoJSONDecoder method decodeMultiLineString.

protected MultiLineString decodeMultiLineString(JsonNode node, GeometryFactory fac) throws GeoJSONDecodingException {
    JsonNode coordinates = requireCoordinates(node);
    LineString[] lineStrings = new LineString[coordinates.size()];
    for (int i = 0; i < coordinates.size(); ++i) {
        JsonNode coords = coordinates.get(i);
        lineStrings[i] = fac.createLineString(decodeCoordinates(coords));
    }
    return fac.createMultiLineString(lineStrings);
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) JsonNode(com.fasterxml.jackson.databind.JsonNode) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Aggregations

MultiLineString (org.locationtech.jts.geom.MultiLineString)7 LineString (org.locationtech.jts.geom.LineString)5 MultiPoint (org.locationtech.jts.geom.MultiPoint)3 Point (org.locationtech.jts.geom.Point)3 Geometry (org.locationtech.jts.geom.Geometry)2 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)1 OGCGeometry.createFromEsriGeometry (com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry)1 OGCLineString (com.esri.core.geometry.ogc.OGCLineString)1 GeometryUtils.createJtsEmptyLineString (com.facebook.presto.geospatial.GeometryUtils.createJtsEmptyLineString)1 GeometryUtils.createJtsLineString (com.facebook.presto.geospatial.GeometryUtils.createJtsLineString)1 GeometryUtils.jsonFromJtsGeometry (com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry)1 GeometryUtils.wktFromJtsGeometry (com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry)1 PrestoException (com.facebook.presto.spi.PrestoException)1 Description (com.facebook.presto.spi.function.Description)1 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)1 SqlNullable (com.facebook.presto.spi.function.SqlNullable)1 SqlType (com.facebook.presto.spi.function.SqlType)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1