use of com.vividsolutions.jts.geom.Coordinate in project openems by OpenEMS.
the class SymmetricPower method intersectRect.
/**
* Creates a Rect with the coordinates pMin, pMax, qMin, qMax and intersects the rect with the base geometry.
*
* @param base
* @param pMin
* @param pMax
* @param qMin
* @param qMax
* @return resulting polygon after the intersection
*/
public static Geometry intersectRect(Geometry base, double pMin, double pMax, double qMin, double qMax) {
Coordinate[] coordinates = new Coordinate[] { new Coordinate(pMin, qMax), new Coordinate(pMin, qMin), new Coordinate(pMax, qMin), new Coordinate(pMax, qMax), new Coordinate(pMin, qMax) };
Geometry rect = new GeometryFactory().createPolygon(coordinates);
return base.intersection(rect);
}
use of com.vividsolutions.jts.geom.Coordinate in project openems by OpenEMS.
the class SymmetricPower method getClosestQ.
/**
* Calculates the colses reactivepower point according to the parameter q
*
* @param p
* @return
*/
private Long getClosestQ(long q) {
Coordinate[] coordinates = new Coordinate[] { new Coordinate(maxApparentPower, q), new Coordinate(maxApparentPower * -1, q) };
LineString line = FACTORY.createLineString(coordinates);
DistanceOp distance = new DistanceOp(geometry, line);
GeometryLocation[] locations = distance.nearestLocations();
for (GeometryLocation location : locations) {
if (!location.getGeometryComponent().equals(line)) {
return (long) location.getCoordinate().y;
}
}
return null;
}
use of com.vividsolutions.jts.geom.Coordinate in project openems by OpenEMS.
the class SymmetricPowerClusterImpl method getUnionAround.
private Geometry getUnionAround(Geometry g1, Geometry g2) {
Geometry g2dens = Densifier.densify(g2, getMaxApparentPower() / 10.0);
List<Geometry> geometries = new ArrayList<>();
geometries.add(g2);
for (Coordinate c : g2dens.getCoordinates()) {
geometries.add(AffineTransformation.translationInstance(c.x, c.y).transform(g1));
}
GeometryCollection collection = new GeometryCollection(geometries.toArray(new Geometry[geometries.size()]), FACTORY);
return collection.union();
}
use of com.vividsolutions.jts.geom.Coordinate in project openems by OpenEMS.
the class PEqualLimitation 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 smallerP = SymmetricPower.intersectRect(geometry, 0, p, maxApparentPower * -1, maxApparentPower);
if (!smallerP.isEmpty()) {
DistanceOp distance = new DistanceOp(smallerP, line);
GeometryLocation[] locations = distance.nearestLocations();
long maxP = 0;
for (GeometryLocation location : locations) {
if (!location.getGeometryComponent().equals(line)) {
maxP = (long) location.getCoordinate().x;
break;
}
}
Coordinate[] coordinates = new Coordinate[] { new Coordinate(maxP, maxApparentPower), new Coordinate(maxP, maxApparentPower * -1) };
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(location.getCoordinate().x, maxApparentPower), new Coordinate(location.getCoordinate().x, maxApparentPower * -1) };
line = factory.createLineString(coordinates);
return geometry.intersection(line);
}
}
}
} else {
return newGeometry;
}
}
return geometry;
}
use of com.vividsolutions.jts.geom.Coordinate in project osm4j-geometry by topobyte.
the class WayBuilder method buildOmitVertexIfNodeMissing.
public WayBuilderResult buildOmitVertexIfNodeMissing(OsmWay way, OsmEntityProvider resolver) {
WayBuilderResult result = new WayBuilderResult();
// Test if the way is closed, i.e. first node id == last node id
boolean closed = OsmModelUtil.isClosed(way);
// Remember if the first node is missing, so that we can handle closed
// ways appropriately
boolean firstMissing = false;
List<Coordinate> coords = new ArrayList<>();
for (int i = 0; i < way.getNumberOfNodes(); i++) {
OsmNode node;
try {
node = resolver.getNode(way.getNodeId(i));
} catch (EntityNotFoundException e) {
if (log) {
logMissingNode(way.getNodeId(i));
}
if (i == 0) {
firstMissing = true;
}
continue;
}
coords.add(new Coordinate(node.getLongitude(), node.getLatitude()));
}
if (coords.size() == 0) {
return result;
}
if (coords.size() == 1) {
if (!includePuntal) {
return result;
} else {
result.getCoordinates().add(coords.get(0));
return result;
}
}
// the way by replicating the first found coordinate at the end.
if (closed && firstMissing && coords.size() > 2) {
coords.add(coords.get(0));
}
CoordinateSequence cs = factory.getCoordinateSequenceFactory().create(coords.toArray(new Coordinate[0]));
createLine(result, cs, closed);
return result;
}
Aggregations