Search in sources :

Example 86 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project pigeon by aseldawy.

the class YMax method exec.

@Override
public Double exec(Tuple input) throws IOException {
    Geometry geom = null;
    try {
        Object v = input.get(0);
        geom = geometryParser.parseGeom(v);
        Coordinate[] coords = geom.getEnvelope().getCoordinates();
        if (coords.length == 0)
            throw new ExecException("YMax cannot work on empty geometires");
        if (coords.length == 1)
            return coords[0].y;
        if (coords.length == 2)
            return Math.max(coords[0].y, coords[1].y);
        return Math.max(coords[0].y, coords[2].y);
    } catch (ExecException ee) {
        throw new GeoException(geom, ee);
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) ExecException(org.apache.pig.backend.executionengine.ExecException)

Example 87 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project pigeon by aseldawy.

the class YMin method exec.

@Override
public Double exec(Tuple input) throws IOException {
    Geometry geom = null;
    try {
        Object v = input.get(0);
        geom = geometryParser.parseGeom(v);
        Coordinate[] coords = geom.getEnvelope().getCoordinates();
        if (coords.length == 0)
            throw new ExecException("YMin cannot work on empty geometires");
        if (coords.length == 1)
            return coords[0].y;
        if (coords.length == 2)
            return Math.min(coords[0].y, coords[1].y);
        return Math.min(coords[0].y, coords[2].y);
    } catch (ExecException ee) {
        throw new GeoException(geom, ee);
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) ExecException(org.apache.pig.backend.executionengine.ExecException)

Example 88 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project pigeon by aseldawy.

the class GridCell method exec.

@Override
public DataByteArray exec(Tuple b) throws IOException {
    int cellID = (Integer) b.get(0);
    Geometry gridMBR = geometryParser.parseGeom(b.get(1)).getEnvelope();
    int gridSize = (Integer) b.get(2);
    Coordinate[] gridCoords = gridMBR.getCoordinates();
    double gridX1 = Math.min(gridCoords[0].x, gridCoords[2].x);
    double gridY1 = Math.min(gridCoords[0].y, gridCoords[2].y);
    double gridX2 = Math.max(gridCoords[0].x, gridCoords[2].x);
    double gridY2 = Math.max(gridCoords[0].y, gridCoords[2].y);
    int column = cellID % gridSize;
    int row = cellID / gridSize;
    double cellX1 = column * (gridX2 - gridX1) / gridSize + gridX1;
    double cellX2 = (column + 1) * (gridX2 - gridX1) / gridSize + gridX1;
    double cellY1 = row * (gridY2 - gridY1) / gridSize + gridY1;
    double cellY2 = (row + 1) * (gridY2 - gridY1) / gridSize + gridY1;
    Coordinate[] corners = new Coordinate[5];
    corners[0] = new Coordinate(cellX1, cellY1);
    corners[1] = new Coordinate(cellX1, cellY2);
    corners[2] = new Coordinate(cellX2, cellY2);
    corners[3] = new Coordinate(cellX2, cellY1);
    corners[4] = corners[0];
    Polygon box = geometryFactory.createPolygon(geometryFactory.createLinearRing(corners), null);
    return new DataByteArray(wkbWriter.write(box));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) Polygon(com.vividsolutions.jts.geom.Polygon) DataByteArray(org.apache.pig.data.DataByteArray)

Example 89 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project pigeon by aseldawy.

the class Break method exec.

@Override
public DataBag exec(Tuple b) throws IOException {
    if (b.size() != 1)
        throw new GeoException("Invalid number of arguments. Expected 1 but found " + b.size());
    Geometry geom = geometryParser.parseGeom(b.get(0));
    Vector<Coordinate[]> segments = new Vector<Coordinate[]>();
    breakGeom(geom, segments);
    DataBag segmentsBag = BagFactory.getInstance().newDefaultBag();
    for (int i = 0; i < segments.size(); i++) {
        Tuple segmentTuple = TupleFactory.getInstance().newTuple(5);
        segmentTuple.set(0, i);
        segmentTuple.set(1, segments.get(i)[0].x);
        segmentTuple.set(2, segments.get(i)[0].y);
        segmentTuple.set(3, segments.get(i)[1].x);
        segmentTuple.set(4, segments.get(i)[1].y);
        segmentsBag.add(segmentTuple);
    }
    return segmentsBag;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) DataBag(org.apache.pig.data.DataBag) Coordinate(com.vividsolutions.jts.geom.Coordinate) Vector(java.util.Vector) Point(com.vividsolutions.jts.geom.Point) Tuple(org.apache.pig.data.Tuple)

Example 90 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project pigeon by aseldawy.

the class Break method breakGeom.

private void breakGeom(Geometry geom, Vector<Coordinate[]> segments) {
    if (geom == null)
        return;
    if (geom instanceof LineString) {
        LineString linestring = (LineString) geom;
        Coordinate[] coordinates = linestring.getCoordinates();
        for (int i = 1; i < coordinates.length; i++) {
            Coordinate[] segment = new Coordinate[2];
            segment[0] = new Coordinate(coordinates[i - 1]);
            segment[1] = new Coordinate(coordinates[i]);
            segments.add(segment);
        }
    } else if (geom instanceof Polygon) {
        Polygon polygon = (Polygon) geom;
        breakGeom(polygon.getExteriorRing(), segments);
        for (int n = 0; n < polygon.getNumInteriorRing(); n++) {
            breakGeom(polygon.getInteriorRingN(n), segments);
        }
    } else if (geom instanceof GeometryCollection) {
        GeometryCollection geomCollection = (GeometryCollection) geom;
        for (int n = 0; n < geomCollection.getNumGeometries(); n++) {
            breakGeom(geomCollection.getGeometryN(n), segments);
        }
    } else if (geom instanceof Point) {
    // Skip
    } else {
        throw new RuntimeException("Cannot break geometry of type " + geom.getClass());
    }
}
Also used : GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) LineString(com.vividsolutions.jts.geom.LineString) Coordinate(com.vividsolutions.jts.geom.Coordinate) Point(com.vividsolutions.jts.geom.Point) Polygon(com.vividsolutions.jts.geom.Polygon) Point(com.vividsolutions.jts.geom.Point)

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