Search in sources :

Example 61 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project tests by datanucleus.

the class JtsGeometrySpatialTest method testDisjoint.

public void testDisjoint() throws SQLException, ParseException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Polygon polygon = (Polygon) wktReader.read("POLYGON((10 10,40 10,40 40,10 40,10 10))");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && geom.disjoint(:polygon)");
        List list = (List) query.execute(polygon);
        assertEquals("Wrong number of geometries which are disjoint from a given polygon returned", 1, list.size());
        assertTrue("Polygon 2 should be in the list of geometries which are disjoint from a given polygon", list.contains(getSamplePolygon(2)));
        query = pm.newQuery(SamplePolygon.class, "id == :id");
        query.setResult("geom.disjoint(Spatial.geomFromText('POLYGON((10 10,40 10,40 40,10 40,10 10))', 4326))");
        query.setResultClass(Boolean.class);
        query.setUnique(true);
        Boolean equals = (Boolean) query.execute(new Long(getSamplePolygon(2).getId()));
        assertEquals("Polygon 2 should be disjoint from the given polygon", true, equals.booleanValue());
    } finally {
        tx.commit();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) SamplePolygon(org.datanucleus.samples.jtsgeometry.SamplePolygon) List(java.util.List) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) SamplePolygon(org.datanucleus.samples.jtsgeometry.SamplePolygon) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 62 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project coastal-hazards by USGS-CIDA.

the class Bbox method envelopeToPolygon.

public static Polygon envelopeToPolygon(Envelope e) {
    GeometryFactory factory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING_SINGLE), SRID);
    Coordinate coordA = new Coordinate(e.getMinX(), e.getMinY());
    Coordinate coordB = new Coordinate(e.getMinX(), e.getMaxY());
    Coordinate coordC = new Coordinate(e.getMaxX(), e.getMaxY());
    Coordinate coordD = new Coordinate(e.getMaxX(), e.getMinY());
    Coordinate coordE = coordA;
    Polygon bboxPoly = factory.createPolygon(new Coordinate[] { coordA, coordB, coordC, coordD, coordE });
    return bboxPoly;
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) PrecisionModel(com.vividsolutions.jts.geom.PrecisionModel) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 63 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project onebusaway-application-modules by camsys.

the class BoundingBoxController method index.

@RequestMapping()
public ModelAndView index() {
    GeometryFactory gf = new GeometryFactory();
    List<Polygon> polygons = new ArrayList<Polygon>();
    Map<String, CoordinateBounds> agencies = _agencyService.getAgencyIdsAndCoverageAreas();
    for (CoordinateBounds cb : agencies.values()) {
        Envelope e = new Envelope(cb.getMinLon(), cb.getMaxLon(), cb.getMinLat(), cb.getMaxLat());
        Polygon p = (Polygon) gf.toGeometry(e);
        polygons.add(p);
    }
    MultiPolygon mp = gf.createMultiPolygon(polygons.toArray(new Polygon[0]));
    Geometry hull = mp.convexHull();
    Envelope env = hull.getEnvelopeInternal();
    ModelAndView mv = new ModelAndView("bounding-box.jspx");
    mv.addObject("minY", env.getMinY());
    mv.addObject("minX", env.getMinX());
    mv.addObject("maxY", env.getMaxY());
    mv.addObject("maxX", env.getMaxX());
    mv.addObject("hullWKT", hull.toText());
    return mv;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) Envelope(com.vividsolutions.jts.geom.Envelope) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 64 with Polygon

use of com.vividsolutions.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(com.vividsolutions.jts.geom.Coordinate) Polygon(com.vividsolutions.jts.geom.Polygon) DataByteArray(org.apache.pig.data.DataByteArray)

Example 65 with Polygon

use of com.vividsolutions.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(com.vividsolutions.jts.geom.Geometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) Polygon(com.vividsolutions.jts.geom.Polygon) DataByteArray(org.apache.pig.data.DataByteArray)

Aggregations

Polygon (com.vividsolutions.jts.geom.Polygon)114 LinearRing (com.vividsolutions.jts.geom.LinearRing)50 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)34 Test (org.junit.Test)32 Coordinate (com.vividsolutions.jts.geom.Coordinate)30 Point (com.vividsolutions.jts.geom.Point)29 PackedCoordinateSequence (com.vividsolutions.jts.geom.impl.PackedCoordinateSequence)27 ArrayList (java.util.ArrayList)26 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)24 Resource (org.openrdf.model.Resource)24 Statement (org.openrdf.model.Statement)24 URI (org.openrdf.model.URI)24 Value (org.openrdf.model.Value)24 ValueFactory (org.openrdf.model.ValueFactory)24 ContextStatementImpl (org.openrdf.model.impl.ContextStatementImpl)24 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)24 Geometry (com.vividsolutions.jts.geom.Geometry)22 LineString (com.vividsolutions.jts.geom.LineString)21 List (java.util.List)20 PersistenceManager (javax.jdo.PersistenceManager)15