Search in sources :

Example 66 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project ili2db by claeis.

the class Iox2fgdb method multisurface2wkb.

public byte[] multisurface2wkb(// SurfaceOrAreaType type)
IomObject multisurfaceObj, // SurfaceOrAreaType type)
boolean asCurvePolygon, // SurfaceOrAreaType type)
double strokeP, // SurfaceOrAreaType type)
int srsId) throws IoxException {
    if (multisurfaceObj == null) {
        return null;
    }
    byte[] ret = null;
    os.reset();
    if (asCurvePolygon) {
        int shapeType = EsriShpConstants.ShapeGeneralPolygon;
        shapeType |= EsriShpConstants.shapeHasCurves;
        shapeType |= (outputDimension == 3 ? EsriShpConstants.shapeHasZs : 0);
        os.writeInt(shapeType);
    } else {
        if (outputDimension == 3) {
            os.writeInt(EsriShpConstants.ShapePolygonZ);
        } else {
            os.writeInt(EsriShpConstants.ShapePolygon);
        }
    }
    java.util.ArrayList<Polygon> polygons = new java.util.ArrayList<Polygon>();
    // boundingBox
    Envelope env = new Envelope();
    int surfacec = multisurfaceObj.getattrvaluecount("surface");
    for (int surfacei = 0; surfacei < surfacec; surfacei++) {
        IomObject surface = multisurfaceObj.getattrobj("surface", surfacei);
        IomObject iomSurfaceClone = new ch.interlis.iom_j.Iom_jObject("MULTISURFACE", null);
        iomSurfaceClone.addattrobj("surface", surface);
        Polygon polygon = Iox2jtsext.surface2JTS(iomSurfaceClone, strokeP);
        polygons.add(polygon);
        env.expandToInclude(polygon.getEnvelopeInternal());
    }
    os.writeDouble(env.getMinX());
    os.writeDouble(env.getMinY());
    os.writeDouble(env.getMaxX());
    os.writeDouble(env.getMaxY());
    // cParts The number of rings in the multisurface.
    // cPoints The total number of points for all parts.
    int cPart = 0;
    int cPoints = 0;
    for (Polygon polygon : polygons) {
        cPart += 1;
        cPoints += getNumPoints(polygon.getExteriorRing());
        int holec = polygon.getNumInteriorRing();
        cPart += holec;
        for (int holei = 0; holei < holec; holei++) {
            cPoints += getNumPoints(polygon.getInteriorRingN(holei));
        }
    }
    os.writeInt(cPart);
    os.writeInt(cPoints);
    // parts[cParts] An array of length NumParts. Stores, for each Ring, the index of its
    // first point in the points array. Array indexes are with respect to 0.
    int partStart = 0;
    for (Polygon polygon : polygons) {
        os.writeInt(partStart);
        partStart += getNumPoints(polygon.getExteriorRing());
        int holec = polygon.getNumInteriorRing();
        for (int holei = 0; holei < holec; holei++) {
            os.writeInt(partStart);
            partStart += getNumPoints(polygon.getInteriorRingN(holei));
        }
    }
    java.util.ArrayList<Arc> arcs = null;
    if (asCurvePolygon) {
        arcs = new java.util.ArrayList<Arc>();
    }
    java.util.ArrayList<Double> zv = null;
    if (outputDimension == 3) {
        zv = new java.util.ArrayList<Double>();
    }
    double[] zMin = new double[1];
    double[] zMax = new double[1];
    {
        Coordinate coord = polygons.get(0).getExteriorRing().getStartPoint().getCoordinate();
        if (outputDimension == 3) {
            zMin[0] = coord.z;
            zMax[0] = coord.z;
        }
    }
    int startPtIdx = 0;
    for (Polygon polygon : polygons) {
        // shell is always in clockwise order
        // holes are in a counterclockwise direction
        LineString polyline = polygon.getExteriorRing();
        polyline = asOneLine(polyline);
        if (CGAlgorithms.isCCW(polyline.getCoordinates())) {
            polyline = (LineString) polyline.reverse();
        }
        writePoints(polyline, false, zv, zMin, zMax, startPtIdx, arcs);
        startPtIdx += getNumPoints(polyline);
        int holec = polygon.getNumInteriorRing();
        for (int holei = 0; holei < holec; holei++) {
            polyline = polygon.getInteriorRingN(holei);
            polyline = asOneLine(polyline);
            if (!CGAlgorithms.isCCW(polyline.getCoordinates())) {
                polyline = (LineString) polyline.reverse();
            }
            writePoints(polyline, true, zv, zMin, zMax, startPtIdx, arcs);
            startPtIdx += getNumPoints(polyline);
        }
    }
    if (outputDimension == 3) {
        // zMin
        os.writeDouble(zMin[0]);
        // zMax
        os.writeDouble(zMax[0]);
        // Zs[cPoints]
        for (Double z : zv) {
            os.writeDouble(z);
        }
    }
    if (asCurvePolygon) {
        writeArcs(arcs);
    }
    ret = os.toByteArray();
    return ret;
}
Also used : ArrayList(java.util.ArrayList) Envelope(com.vividsolutions.jts.geom.Envelope) IomObject(ch.interlis.iom.IomObject) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 67 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project openems by OpenEMS.

the class SymmetricPowerProxy method writePower.

@Override
protected void writePower() {
    super.writePower();
    if (dynamicLimitations.size() > 0) {
        Point p = reduceToZero();
        Coordinate c = p.getCoordinate();
        try {
            setGeometry(p);
        } catch (PowerException e) {
        }
        double activePowerDelta = c.x - lastActivePower;
        double reactivePowerDelta = c.y - lastReactivePower;
        lastActivePower += activePowerDelta / 2;
        lastReactivePower += reactivePowerDelta / 2;
        this.activePower = Optional.of((long) lastActivePower);
        this.reactivePower = Optional.of((long) lastReactivePower);
    }
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) Point(com.vividsolutions.jts.geom.Point)

Example 68 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project openems by OpenEMS.

the class Test method getUnionAround.

private static Geometry getUnionAround(Geometry g1, Geometry g2) {
    GeometryFactory factory = new GeometryFactory();
    Geometry g1dens = Densifier.densify(g1, 10000);
    Geometry g2dens = Densifier.densify(g2, 10000);
    List<Geometry> geometries = new ArrayList<>();
    geometries.add(g1);
    for (Coordinate c : g1dens.getCoordinates()) {
        geometries.add(AffineTransformation.translationInstance(c.x, c.y).transform(g2));
    }
    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) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) ArrayList(java.util.ArrayList)

Example 69 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project openems by OpenEMS.

the class SMaxLimitation method setSMax.

public void setSMax(Long sMax, Long xNull, Long yNull) {
    if (sMax != this.sMax) {
        if (sMax != null) {
            shapeFactory.setCentre(new Coordinate(xNull, yNull));
            shapeFactory.setSize(sMax * 2);
            shapeFactory.setNumPoints(32);
            this.circle = shapeFactory.createCircle();
        } else {
            this.circle = null;
        }
        this.sMax = sMax;
        notifyListeners();
    }
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate)

Example 70 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate 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)

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