Search in sources :

Example 6 with DistanceOp

use of com.vividsolutions.jts.operation.distance.DistanceOp in project openems by OpenEMS.

the class QEqualLimitation method applyLimit.

@Override
protected Geometry applyLimit(Geometry geometry) throws PowerException {
    if (line != null) {
        Geometry newGeometry = geometry.intersection(line);
        long maxApparentPower = power.getMaxApparentPower();
        if (newGeometry.isEmpty()) {
            Geometry smallerQ = SymmetricPowerImpl.intersectRect(geometry, maxApparentPower * -1, maxApparentPower, 0, q);
            if (!smallerQ.isEmpty()) {
                DistanceOp distance = new DistanceOp(smallerQ, line);
                GeometryLocation[] locations = distance.nearestLocations();
                long maxQ = 0;
                for (GeometryLocation location : locations) {
                    if (!location.getGeometryComponent().equals(line)) {
                        maxQ = (long) location.getCoordinate().y;
                        break;
                    }
                }
                Coordinate[] coordinates = new Coordinate[] { new Coordinate(maxApparentPower, maxQ), new Coordinate(maxApparentPower * -1, maxQ) };
                line = factory.createLineString(coordinates);
                return geometry.intersection(line);
            } else {
                DistanceOp distance = new DistanceOp(geometry, line);
                GeometryLocation[] locations = distance.nearestLocations();
                for (GeometryLocation location : locations) {
                    if (!location.getGeometryComponent().equals(line)) {
                        Coordinate[] coordinates = new Coordinate[] { new Coordinate(maxApparentPower, location.getCoordinate().y), new Coordinate(maxApparentPower * -1, location.getCoordinate().y) };
                        line = factory.createLineString(coordinates);
                        return geometry.intersection(line);
                    }
                }
            }
        } else {
            return newGeometry;
        }
    }
    return geometry;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryLocation(com.vividsolutions.jts.operation.distance.GeometryLocation) Coordinate(com.vividsolutions.jts.geom.Coordinate) DistanceOp(com.vividsolutions.jts.operation.distance.DistanceOp)

Example 7 with DistanceOp

use of com.vividsolutions.jts.operation.distance.DistanceOp in project openems by OpenEMS.

the class CosPhiLineLimitation method applyLimit.

@Override
protected Geometry applyLimit(Geometry geometry) throws PowerException {
    if (line != null) {
        Geometry newGeometry = geometry.intersection(line);
        if (newGeometry.isEmpty()) {
            DistanceOp distance = new DistanceOp(geometry, line);
            GeometryLocation[] locations = distance.nearestLocations();
            for (GeometryLocation location : locations) {
                if (!location.getGeometryComponent().equals(line)) {
                    return factory.createPoint(location.getCoordinate());
                }
            }
        } else {
            return newGeometry;
        }
    }
    return geometry;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryLocation(com.vividsolutions.jts.operation.distance.GeometryLocation) DistanceOp(com.vividsolutions.jts.operation.distance.DistanceOp)

Aggregations

DistanceOp (com.vividsolutions.jts.operation.distance.DistanceOp)7 GeometryLocation (com.vividsolutions.jts.operation.distance.GeometryLocation)7 Geometry (com.vividsolutions.jts.geom.Geometry)5 Coordinate (com.vividsolutions.jts.geom.Coordinate)4 LineString (com.vividsolutions.jts.geom.LineString)2 Point (com.vividsolutions.jts.geom.Point)1