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;
}
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));
}
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);
}
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);
}
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;
}
Aggregations