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