Search in sources :

Example 1 with CoordinateSequence

use of org.locationtech.jts.geom.CoordinateSequence in project hale by halestudio.

the class Line2D method toJTSLineString.

// functional methods ......................................................
/**
 * This method will return this Line as a Java Topology Suite LineString.
 *
 * @param geometryFactory the factory for JTS geometries
 * @return the converted LineString
 */
private org.locationtech.jts.geom.LineString toJTSLineString(GeometryFactory geometryFactory) {
    Coordinate[] coords = new Coordinate[this.getPoints().length];
    for (int i = 0; i < this.getPoints().length; i++) {
        coords[i] = new Coordinate(this.getPoints()[i].getX(), this.getPoints()[i].getY());
    }
    CoordinateSequenceFactory csf = CoordinateArraySequenceFactory.instance();
    CoordinateSequence cs = csf.create(coords);
    org.locationtech.jts.geom.LineString jts_ls = new org.locationtech.jts.geom.LineString(cs, geometryFactory);
    return jts_ls;
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) Coordinate(org.locationtech.jts.geom.Coordinate) CoordinateSequenceFactory(org.locationtech.jts.geom.CoordinateSequenceFactory)

Example 2 with CoordinateSequence

use of org.locationtech.jts.geom.CoordinateSequence in project thingsboard by thingsboard.

the class GeoUtil method buildPolygonFromCoordinates.

private static Geometry buildPolygonFromCoordinates(List<Coordinate> coordinates) {
    if (coordinates.size() == 2) {
        Coordinate a = coordinates.get(0);
        Coordinate c = coordinates.get(1);
        coordinates.clear();
        Coordinate b = new Coordinate(a.x, c.y);
        Coordinate d = new Coordinate(c.x, a.y);
        coordinates.addAll(List.of(a, b, c, d, a));
    }
    CoordinateSequence coordinateSequence = jtsCtx.getShapeFactory().getGeometryFactory().getCoordinateSequenceFactory().create(coordinates.toArray(new Coordinate[0]));
    return GeometryFixer.fix(jtsCtx.getShapeFactory().getGeometryFactory().createPolygon(coordinateSequence));
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) Coordinate(org.locationtech.jts.geom.Coordinate)

Example 3 with CoordinateSequence

use of org.locationtech.jts.geom.CoordinateSequence in project jena by apache.

the class GeometryTransformation method transformLinearRing.

private static LinearRing transformLinearRing(Geometry sourceGeometry, MathTransform transform) throws TransformException {
    GeometryFactory geometryFactory = sourceGeometry.getFactory();
    LinearRing linearRing = (LinearRing) sourceGeometry;
    CoordinateSequence coordSeq = linearRing.getCoordinateSequence();
    CoordinateSequence transformCoordSeq = transformCoordSeq(coordSeq, transform);
    return geometryFactory.createLinearRing(transformCoordSeq);
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) LinearRing(org.locationtech.jts.geom.LinearRing)

Example 4 with CoordinateSequence

use of org.locationtech.jts.geom.CoordinateSequence in project jena by apache.

the class GeometryTransformation method transformLineString.

private static LineString transformLineString(Geometry sourceGeometry, MathTransform transform) throws TransformException {
    GeometryFactory geometryFactory = sourceGeometry.getFactory();
    LineString lineString = (LineString) sourceGeometry;
    CoordinateSequence coordSeq = lineString.getCoordinateSequence();
    CoordinateSequence transformCoordSeq = transformCoordSeq(coordSeq, transform);
    return geometryFactory.createLineString(transformCoordSeq);
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString)

Example 5 with CoordinateSequence

use of org.locationtech.jts.geom.CoordinateSequence in project sis by apache.

the class GeometryCoordinateTransform method transform.

/**
 * Transforms the given sequence of coordinate tuples, producing a new sequence of tuples.
 * This method tries to transform coordinates in batches, in order to reduce the amount of
 * calls to {@link MathTransform#transform(double[], int, double[], int, int)}.
 *
 * @param  sequence   sequence of coordinate tuples to transform.
 * @param  minPoints  minimum number of points to preserve.
 * @return the transformed sequence of coordinate tuples.
 * @throws TransformException if an error occurred while transforming a tuple.
 */
@Override
protected CoordinateSequence transform(final CoordinateSequence sequence, final int minPoints) throws TransformException {
    final int srcDim = transform.getSourceDimensions();
    final int tgtDim = transform.getTargetDimensions();
    final int maxDim = Math.max(srcDim, tgtDim);
    final int count = sequence.size();
    final int capacity = Math.max(4, Math.min(100, count));
    final CoordinateSequence out = coordinateFactory.create(count, tgtDim);
    if (coordinates == null || coordinates.length / maxDim < capacity) {
        coordinates = new double[capacity * maxDim];
    }
    for (int base = 0, n; (n = Math.min(count - base, capacity)) > 0; base += n) {
        int batch = n * srcDim;
        for (int i = 0; i < batch; i++) {
            coordinates[i] = sequence.getOrdinate(base + i / srcDim, i % srcDim);
        }
        transform.transform(coordinates, 0, coordinates, 0, n);
        batch = n * tgtDim;
        for (int i = 0; i < batch; i++) {
            out.setOrdinate(base + i / tgtDim, i % tgtDim, coordinates[i]);
        }
    }
    return out;
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence)

Aggregations

CoordinateSequence (org.locationtech.jts.geom.CoordinateSequence)10 MultiPoint (org.locationtech.jts.geom.MultiPoint)5 Point (org.locationtech.jts.geom.Point)5 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)3 Coordinate (org.locationtech.jts.geom.Coordinate)2 LineString (org.locationtech.jts.geom.LineString)2 LinearRing (org.locationtech.jts.geom.LinearRing)2 MultiLineString (org.locationtech.jts.geom.MultiLineString)2 GeometryWrapper (org.apache.sis.internal.feature.GeometryWrapper)1 CoordinateSequenceFactory (org.locationtech.jts.geom.CoordinateSequenceFactory)1 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)1 Polygon (org.locationtech.jts.geom.Polygon)1