Search in sources :

Example 81 with Coordinate

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

the class MakeBox method exec.

@Override
public DataByteArray exec(Tuple input) throws IOException {
    if (input.size() != 4)
        throw new GeoException("MakeBox takes four numerical arguments");
    double x1 = ESRIGeometryParser.parseDouble(input.get(0));
    double y1 = ESRIGeometryParser.parseDouble(input.get(1));
    double x2 = ESRIGeometryParser.parseDouble(input.get(2));
    double y2 = ESRIGeometryParser.parseDouble(input.get(3));
    Coordinate[] corners = new Coordinate[5];
    corners[0] = new Coordinate(x1, y1);
    corners[1] = new Coordinate(x1, y2);
    corners[2] = new Coordinate(x2, y2);
    corners[3] = new Coordinate(x2, y1);
    corners[4] = corners[0];
    Polygon box = geometryFactory.createPolygon(geometryFactory.createLinearRing(corners), null);
    return new DataByteArray(wkbWriter.write(box));
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) Polygon(com.vividsolutions.jts.geom.Polygon) DataByteArray(org.apache.pig.data.DataByteArray)

Example 82 with Coordinate

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

the class MakeLinePolygon method exec.

@Override
public DataByteArray exec(Tuple b) throws IOException {
    DataBag pointIDs = (DataBag) b.get(0);
    DataBag pointLocations = (DataBag) b.get(1);
    Coordinate[] coordinates = new Coordinate[(int) pointLocations.size()];
    int i = 0;
    Iterator<Tuple> iter_id = pointIDs.iterator();
    long first_point_id = -1;
    boolean is_polygon = false;
    for (Tuple t : pointLocations) {
        Object point_id_obj = iter_id.next().get(0);
        Geometry point = geometryParser.parseGeom(t.get(0));
        long point_id = point_id_obj instanceof Integer ? (Integer) point_id_obj : (Long) point_id_obj;
        if (i == 0) {
            first_point_id = point_id;
            coordinates[i++] = point.getCoordinate();
        } else if (i == pointIDs.size() - 1) {
            is_polygon = point_id == first_point_id;
            if (is_polygon)
                coordinates[i++] = coordinates[0];
            else
                coordinates[i++] = point.getCoordinate();
        } else {
            coordinates[i++] = point.getCoordinate();
        }
    }
    Geometry shape;
    if (coordinates.length == 1 || (coordinates.length == 2 && is_polygon)) {
        // A point
        shape = geometryFactory.createPoint(coordinates[0]);
    } else {
        if (is_polygon && coordinates.length <= 3) {
            // Cannot create a polygon with two corners, convert to Linestring
            Coordinate[] new_coords = new Coordinate[coordinates.length - 1];
            System.arraycopy(coordinates, 0, new_coords, 0, new_coords.length);
            coordinates = new_coords;
            is_polygon = false;
        }
        if (is_polygon) {
            shape = geometryFactory.createPolygon(geometryFactory.createLinearRing(coordinates), null);
        } else {
            shape = geometryFactory.createLineString(coordinates);
        }
    }
    return new DataByteArray(wkbWriter.write(shape));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) DataBag(org.apache.pig.data.DataBag) Coordinate(com.vividsolutions.jts.geom.Coordinate) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple)

Example 83 with Coordinate

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

the class MakeSegments method exec.

@Override
public DataBag exec(Tuple b) throws IOException {
    DataBag pointIDs = (DataBag) b.get(0);
    DataBag pointLocations = (DataBag) b.get(1);
    long[] ids = new long[(int) pointIDs.size()];
    Coordinate[] coordinates = new Coordinate[(int) pointLocations.size()];
    int i = 0;
    Iterator<Tuple> iter_id = pointIDs.iterator();
    for (Tuple t : pointLocations) {
        Object point_id_obj = iter_id.next().get(0);
        Geometry point = geometryParser.parseGeom(t.get(0));
        long point_id = point_id_obj instanceof Integer ? (Integer) point_id_obj : (Long) point_id_obj;
        ids[i] = point_id;
        coordinates[i++] = point.getCoordinate();
    }
    DataBag segmentsBag = BagFactory.getInstance().newDefaultBag();
    for (int n = 1; n < coordinates.length; n++) {
        Tuple segmentTuple = TupleFactory.getInstance().newTuple(7);
        segmentTuple.set(0, n - 1);
        segmentTuple.set(1, ids[n - 1]);
        segmentTuple.set(2, coordinates[n - 1].x);
        segmentTuple.set(3, coordinates[n - 1].y);
        segmentTuple.set(4, ids[n]);
        segmentTuple.set(5, coordinates[n].x);
        segmentTuple.set(6, coordinates[n].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) Tuple(org.apache.pig.data.Tuple)

Example 84 with Coordinate

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

the class XMax 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("XMax cannot work on empty geometires");
        if (coords.length == 1)
            return coords[0].x;
        if (coords.length == 2)
            return Math.max(coords[0].x, coords[1].x);
        return Math.max(coords[0].x, coords[2].x);
    } 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 85 with Coordinate

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

the class XMin method exec.

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

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