Search in sources :

Example 1 with GeometryLocation

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

the class SymmetricPower method getClosestP.

/**
 * Calculates the colses activepower point according to the parameter p
 *
 * @param p
 * @return
 */
private Long getClosestP(long p) {
    Coordinate[] coordinates = new Coordinate[] { new Coordinate(p, maxApparentPower), new Coordinate(p, maxApparentPower * -1) };
    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().x;
        }
    }
    return null;
}
Also used : GeometryLocation(com.vividsolutions.jts.operation.distance.GeometryLocation) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) DistanceOp(com.vividsolutions.jts.operation.distance.DistanceOp)

Example 2 with GeometryLocation

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

the class SymmetricPower method reduceToZero.

protected Point reduceToZero() {
    if (getGeometry() instanceof Point) {
        return (Point) getGeometry();
    }
    Point pZero = FACTORY.createPoint(ZERO);
    DistanceOp distance = new DistanceOp(getGeometry(), pZero);
    GeometryLocation[] locations = distance.nearestLocations();
    Point result = pZero;
    for (GeometryLocation location : locations) {
        Geometry g = location.getGeometryComponent();
        if (!g.equals(pZero)) {
            result = FACTORY.createPoint(location.getCoordinate());
            break;
        }
    }
    return result;
}
Also used : GeometryLocation(com.vividsolutions.jts.operation.distance.GeometryLocation) Geometry(com.vividsolutions.jts.geom.Geometry) DistanceOp(com.vividsolutions.jts.operation.distance.DistanceOp) Point(com.vividsolutions.jts.geom.Point)

Example 3 with GeometryLocation

use of com.vividsolutions.jts.operation.distance.GeometryLocation 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;
}
Also used : GeometryLocation(com.vividsolutions.jts.operation.distance.GeometryLocation) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) DistanceOp(com.vividsolutions.jts.operation.distance.DistanceOp)

Example 4 with GeometryLocation

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

the class CosPhiLineCharacteristicLimitation 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)

Example 5 with GeometryLocation

use of com.vividsolutions.jts.operation.distance.GeometryLocation 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;
}
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)

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