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