Search in sources :

Example 16 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project crate by crate.

the class PolygonBuilder method polygon.

protected static Polygon polygon(GeometryFactory factory, Coordinate[][] polygon) {
    LinearRing shell = factory.createLinearRing(polygon[0]);
    LinearRing[] holes;
    if (polygon.length > 1) {
        holes = new LinearRing[polygon.length - 1];
        for (int i = 0; i < holes.length; i++) {
            holes[i] = factory.createLinearRing(polygon[i + 1]);
        }
    } else {
        holes = null;
    }
    return factory.createPolygon(shell, holes);
}
Also used : LinearRing(org.locationtech.jts.geom.LinearRing)

Example 17 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project crate by crate.

the class PolygonBuilder method toPolygon.

protected Polygon toPolygon(GeometryFactory factory) {
    final LinearRing shell = linearRing(factory, this.shell.coordinates);
    final LinearRing[] holes = new LinearRing[this.holes.size()];
    Iterator<LineStringBuilder> iterator = this.holes.iterator();
    for (int i = 0; iterator.hasNext(); i++) {
        holes[i] = linearRing(factory, iterator.next().coordinates);
    }
    return factory.createPolygon(shell, holes);
}
Also used : LinearRing(org.locationtech.jts.geom.LinearRing)

Example 18 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project dhis2-core by dhis2.

the class GeoToolsPrimitiveFromJsonFactory method createPolygonFromJson.

/**
 * Create a GeoTools geometric polygon primitive from coordinates in json.
 *
 * @param json the json array of linear ring
 * @return the polygon
 */
public static Polygon createPolygonFromJson(JsonNode json) {
    // Get the json array of coordinates representing the shell and make a
    // linear-ring out of them
    JsonNode shell = json.get(0);
    LinearRing sh = createLinearRingFromJson(shell);
    // Native array of linear-ring holes to pass to GeoFactory
    LinearRing[] holes = null;
    // Get the linear-ring holes if the polygon has any holes
    if (json.size() > 1) {
        // Allocate memory for the holes, i.e. minus the shell
        holes = new LinearRing[shell.size() - 1];
        // Read the json array of linear-ring into holes
        for (int i = 1; i < shell.size(); i++) {
            JsonNode hole = json.get(i);
            if (hole != null && hole.size() > 0) {
                holes[i] = createLinearRingFromJson(hole);
            }
        }
    }
    // Create the polygon from factory
    return FACTORY.createPolygon(sh, holes);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) LinearRing(org.locationtech.jts.geom.LinearRing) Point(org.locationtech.jts.geom.Point)

Example 19 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project ddf by codice.

the class Wfs20JTStoGML321Converter method convertToPolygonType.

public static PolygonType convertToPolygonType(Polygon polygon, String srsName) {
    PolygonType polygonType = GML320_OBJECT_FACTORY.createPolygonType();
    // exterior
    LineString lineString = polygon.getExteriorRing();
    LinearRing linearRing = lineString.getFactory().createLinearRing(lineString.getCoordinateSequence());
    RingType ringType = convertToRingType(linearRing, srsName);
    JAXBElement<RingType> ringTypeJAXBElement = GML320_OBJECT_FACTORY.createRing(ringType);
    AbstractRingPropertyType abstractRingPropertyType = GML320_OBJECT_FACTORY.createAbstractRingPropertyType();
    abstractRingPropertyType.setAbstractRing(ringTypeJAXBElement);
    polygonType.setExterior(abstractRingPropertyType);
    // interiors
    for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
        LineString interiorRingN = polygon.getInteriorRingN(i);
        LinearRing linearRing1 = interiorRingN.getFactory().createLinearRing(interiorRingN.getCoordinateSequence());
        RingType ringType1 = convertToRingType(linearRing1, srsName);
        JAXBElement<RingType> ringTypeJAXBElement1 = GML320_OBJECT_FACTORY.createRing(ringType1);
        AbstractRingPropertyType abstractRingPropertyType1 = GML320_OBJECT_FACTORY.createAbstractRingPropertyType();
        abstractRingPropertyType1.setAbstractRing(ringTypeJAXBElement1);
        polygonType.getInterior().add(abstractRingPropertyType1);
    }
    polygonType.setSrsName(srsName);
    return polygonType;
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) AbstractRingPropertyType(net.opengis.gml.v_3_2_1.AbstractRingPropertyType) PolygonType(net.opengis.gml.v_3_2_1.PolygonType) LinearRing(org.locationtech.jts.geom.LinearRing) RingType(net.opengis.gml.v_3_2_1.RingType) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 20 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project ddf by codice.

the class GmdTransformer method setLocationFromPolygon.

private void setLocationFromPolygon(String boundingPolygon, MetacardImpl metacard) {
    try {
        String[] stringArray = boundingPolygon.split(" ");
        List<Coordinate> coordinates = new ArrayList<>();
        for (int i = 0; i < stringArray.length - 1; i += 2) {
            coordinates.add(new Coordinate(Double.parseDouble(stringArray[i]), Double.parseDouble(stringArray[i + 1])));
        }
        LinearRing linearRing = factory.createLinearRing(coordinates.toArray(new Coordinate[coordinates.size()]));
        String wkt = WKT_WRITER_THREAD_LOCAL.get().write(factory.createPolygon(linearRing, null));
        if (wkt != null) {
            metacard.setAttribute(Core.LOCATION, wkt);
        }
    } catch (NumberFormatException nfe) {
        LOGGER.debug("Unable to parse double in {}. Metacard location will not be set.", boundingPolygon);
    }
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) ArrayList(java.util.ArrayList) LinearRing(org.locationtech.jts.geom.LinearRing)

Aggregations

LinearRing (org.locationtech.jts.geom.LinearRing)66 Coordinate (org.locationtech.jts.geom.Coordinate)39 Polygon (org.locationtech.jts.geom.Polygon)33 Test (org.junit.Test)27 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)23 LineString (org.locationtech.jts.geom.LineString)14 CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)10 Geometry (org.locationtech.jts.geom.Geometry)10 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)8 Point (org.locationtech.jts.geom.Point)8 MultiPoint (org.locationtech.jts.geom.MultiPoint)7 ArrayList (java.util.ArrayList)6 DimensionInfo (org.apache.jena.geosparql.implementation.DimensionInfo)6 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)6 Test (org.junit.jupiter.api.Test)4 DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)3 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)3 CRSDefinition (eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition)3 GeometryProperty (eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty)3 GeometryNotSupportedException (eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException)3