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));
}
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));
}
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;
}
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);
}
}
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);
}
Aggregations