use of org.locationtech.jts.geom.Polygon 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());
}
}
use of org.locationtech.jts.geom.Polygon 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 org.locationtech.jts.geom.Polygon 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 org.locationtech.jts.geom.Polygon in project geo-platform by geosdi.
the class PolygonAdapter method unmarshal.
public Polygon unmarshal(String val) throws ParseException {
WKTReader wktReader = new WKTReader();
Geometry the_geom = wktReader.read(val);
if ((the_geom instanceof Polygon)) {
if (the_geom.getSRID() == 0) {
the_geom.setSRID(4326);
}
return (Polygon) the_geom;
}
throw new ParseException("WKB val is not a Polygon.");
}
use of org.locationtech.jts.geom.Polygon in project geo-platform by geosdi.
the class JTSMultiPolygonParser method canParseGeometry.
/**
* @param jtsGeometry
* @return {@link MultiPolygon}
* @throws ParserException
*/
@Override
protected MultiPolygon canParseGeometry(org.locationtech.jts.geom.MultiPolygon jtsGeometry) throws ParserException {
MultiPolygon multiPolygon = gmlObjectFactory.createMultiPolygonType();
for (int i = 0; i < jtsGeometry.getNumGeometries(); i++) {
Polygon polygon = (Polygon) jtsGeometry.getGeometryN(i);
multiPolygon.addPolygonMember(polygonParser.parseProperty(polygon));
}
return multiPolygon;
}
Aggregations