Search in sources :

Example 71 with Coordinate

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);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate)

Example 72 with Coordinate

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;
}
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 73 with Coordinate

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();
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) Coordinate(com.vividsolutions.jts.geom.Coordinate) ArrayList(java.util.ArrayList)

Example 74 with Coordinate

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;
}
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 75 with Coordinate

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;
}
Also used : CoordinateSequence(com.vividsolutions.jts.geom.CoordinateSequence) Coordinate(com.vividsolutions.jts.geom.Coordinate) OsmNode(de.topobyte.osm4j.core.model.iface.OsmNode) ArrayList(java.util.ArrayList) EntityNotFoundException(de.topobyte.osm4j.core.resolve.EntityNotFoundException)

Aggregations

Coordinate (com.vividsolutions.jts.geom.Coordinate)336 LineString (com.vividsolutions.jts.geom.LineString)70 Geometry (com.vividsolutions.jts.geom.Geometry)67 ArrayList (java.util.ArrayList)65 Test (org.junit.Test)60 Point (com.vividsolutions.jts.geom.Point)52 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)48 Polygon (com.vividsolutions.jts.geom.Polygon)30 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)27 SimpleFeature (org.opengis.feature.simple.SimpleFeature)23 LinearRing (com.vividsolutions.jts.geom.LinearRing)22 Vertex (org.opentripplanner.routing.graph.Vertex)22 Envelope (com.vividsolutions.jts.geom.Envelope)21 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)20 Edge (org.opentripplanner.routing.graph.Edge)19 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)19 CoordinateSequence (com.vividsolutions.jts.geom.CoordinateSequence)14 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)13 File (java.io.File)11 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)11