Search in sources :

Example 71 with Polygon

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());
    }
}
Also used : GeometryCollection(org.locationtech.jts.geom.GeometryCollection) LineString(org.locationtech.jts.geom.LineString) Coordinate(org.locationtech.jts.geom.Coordinate) Point(org.locationtech.jts.geom.Point) Polygon(org.locationtech.jts.geom.Polygon) Point(org.locationtech.jts.geom.Point)

Example 72 with Polygon

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));
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) Polygon(org.locationtech.jts.geom.Polygon) DataByteArray(org.apache.pig.data.DataByteArray)

Example 73 with Polygon

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));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Coordinate(org.locationtech.jts.geom.Coordinate) Polygon(org.locationtech.jts.geom.Polygon) DataByteArray(org.apache.pig.data.DataByteArray)

Example 74 with Polygon

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.");
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) ParseException(org.locationtech.jts.io.ParseException) WKTReader(org.locationtech.jts.io.WKTReader) Polygon(org.locationtech.jts.geom.Polygon)

Example 75 with 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;
}
Also used : MultiPolygon(org.geosdi.geoplatform.gml.api.MultiPolygon) MultiPolygon(org.geosdi.geoplatform.gml.api.MultiPolygon) Polygon(org.locationtech.jts.geom.Polygon)

Aggregations

Polygon (org.locationtech.jts.geom.Polygon)179 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)89 Coordinate (org.locationtech.jts.geom.Coordinate)78 LinearRing (org.locationtech.jts.geom.LinearRing)55 Point (org.locationtech.jts.geom.Point)54 Test (org.junit.Test)51 Geometry (org.locationtech.jts.geom.Geometry)48 LineString (org.locationtech.jts.geom.LineString)48 ArrayList (java.util.ArrayList)37 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)30 MultiPoint (org.locationtech.jts.geom.MultiPoint)29 MultiLineString (org.locationtech.jts.geom.MultiLineString)19 List (java.util.List)15 Test (org.junit.jupiter.api.Test)15 GeometryCollection (org.locationtech.jts.geom.GeometryCollection)12 WKTReader (org.locationtech.jts.io.WKTReader)12 HashMap (java.util.HashMap)9 CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)8 ParseException (org.locationtech.jts.io.ParseException)7 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)5