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