use of com.vividsolutions.jts.geom.Polygon in project activityinfo by bedatadriven.
the class PathUtils method toPath.
public static GeneralPath toPath(TiledMap map, Geometry geometry) {
GeneralPath path = new GeneralPath();
for (int i = 0; i != geometry.getNumGeometries(); ++i) {
Polygon polygon = (Polygon) geometry.getGeometryN(i);
PathUtils.addRingToPath(map, path, polygon.getExteriorRing().getCoordinates());
for (int j = 0; j != polygon.getNumInteriorRing(); ++j) {
PathUtils.addRingToPath(map, path, polygon.getInteriorRingN(j).getCoordinates());
}
break;
}
return path;
}
use of com.vividsolutions.jts.geom.Polygon in project activityinfo by bedatadriven.
the class MySqlUpdateTest method updateGeometry.
@Test
public void updateGeometry() throws SQLException {
userId = 3;
ResourceId formId = CuidAdapter.adminLevelFormClass(1);
ResourceId recordId = entity(1);
ResourceId fieldId = CuidAdapter.field(formId, CuidAdapter.GEOMETRY_FIELD);
Optional<FormStorage> storage = catalog.getForm(formId);
GeometryFactory factory = new GeometryFactory();
Polygon polygon = new Polygon(new LinearRing(new CoordinateArraySequence(new Coordinate[] { new Coordinate(100, 0), new Coordinate(101, 0), new Coordinate(101, 1), new Coordinate(100, 1), new Coordinate(100, 0) }), factory), new LinearRing[0], factory);
storage.get().updateGeometry(recordId, fieldId, polygon);
query(formId, "_id", "ST_XMIN(boundary)", "ST_XMAX(boundary)");
}
use of com.vividsolutions.jts.geom.Polygon in project sldeditor by robward-scisys.
the class SLDEditorBufferedImageLegendGraphicBuilder method getSampleShape.
/**
* Returns a <code>java.awt.Shape</code> appropiate to render a legend graphic given the
* symbolizer type and the legend dimensions.
*
* @param symbolizer the Symbolizer for whose type a sample shape will be created
* @param legendWidth the requested width, in output units, of the legend graphic
* @param legendHeight the requested height, in output units, of the legend graphic
*
* @return an appropiate Line2D, Rectangle2D or LiteShape(Point) for the symbolizer, wether it
* is a LineSymbolizer, a PolygonSymbolizer, or a Point ot Text Symbolizer
*
* @throws IllegalArgumentException if an unknown symbolizer impl was passed in.
*/
private LiteShape2 getSampleShape(Symbolizer symbolizer, int legendWidth, int legendHeight) {
LiteShape2 sampleShape;
final float hpad = (legendWidth * LegendUtils.hpaddingFactor);
final float vpad = (legendHeight * LegendUtils.vpaddingFactor);
if (symbolizer instanceof LineSymbolizer) {
Coordinate[] coords = { new Coordinate(hpad, legendHeight - vpad - 1), new Coordinate(legendWidth - hpad - 1, vpad) };
LineString geom = geomFac.createLineString(coords);
try {
this.sampleLine = new LiteShape2(geom, null, null, false);
} catch (Exception e) {
this.sampleLine = null;
}
sampleShape = this.sampleLine;
} else if ((symbolizer instanceof PolygonSymbolizer) || (symbolizer instanceof RasterSymbolizer)) {
final float w = legendWidth - (2 * hpad) - 1;
final float h = legendHeight - (2 * vpad) - 1;
Coordinate[] coords = { new Coordinate(hpad, vpad), new Coordinate(hpad, vpad + h), new Coordinate(hpad + w, vpad + h), new Coordinate(hpad + w, vpad), new Coordinate(hpad, vpad) };
LinearRing shell = geomFac.createLinearRing(coords);
Polygon geom = geomFac.createPolygon(shell, null);
try {
this.sampleRect = new LiteShape2(geom, null, null, false);
} catch (Exception e) {
this.sampleRect = null;
}
sampleShape = this.sampleRect;
} else if (symbolizer instanceof PointSymbolizer || symbolizer instanceof TextSymbolizer) {
Coordinate coord = new Coordinate(legendWidth / 2, legendHeight / 2);
try {
this.samplePoint = new LiteShape2(geomFac.createPoint(coord), null, null, false);
} catch (Exception e) {
this.samplePoint = null;
}
sampleShape = this.samplePoint;
} else {
throw new IllegalArgumentException("Unknown symbolizer: " + symbolizer);
}
return sampleShape;
}
use of com.vividsolutions.jts.geom.Polygon in project incubator-rya by apache.
the class GeoIndexerTest method testAntiMeridianSearch.
// @Test
public void testAntiMeridianSearch() throws Exception {
// verify that a search works if the bounding box crosses the anti meridian
try (final GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
f.setConf(conf);
final ValueFactory vf = new ValueFactoryImpl();
final Resource context = vf.createURI("foo:context");
final Resource subjectEast = vf.createURI("foo:subj:east");
final URI predicateEast = GeoConstants.GEO_AS_WKT;
final Value objectEast = vf.createLiteral("Point(179 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
final Statement statementEast = new ContextStatementImpl(subjectEast, predicateEast, objectEast, context);
f.storeStatement(convertStatement(statementEast));
final Resource subjectWest = vf.createURI("foo:subj:west");
final URI predicateWest = GeoConstants.GEO_AS_WKT;
final Value objectWest = vf.createLiteral("Point(-179 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
final Statement statementWest = new ContextStatementImpl(subjectWest, predicateWest, objectWest, context);
f.storeStatement(convertStatement(statementWest));
f.flush();
final double[] ONE = { 178.1, 1, -178, 1, -178, -1, 178.1, -1, 178.1, 1 };
final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2));
final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
Assert.assertEquals(Sets.newHashSet(statementEast, statementWest), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
}
}
use of com.vividsolutions.jts.geom.Polygon in project incubator-rya by apache.
the class GeoIndexerTest method testDcSearchWithContext.
@Test
public void testDcSearchWithContext() throws Exception {
// test a ring around dc
try (final GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
f.setConf(conf);
final ValueFactory vf = new ValueFactoryImpl();
final Resource subject = vf.createURI("foo:subj");
final URI predicate = GeoConstants.GEO_AS_WKT;
final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
final Resource context = vf.createURI("foo:context");
final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
f.storeStatement(convertStatement(statement));
f.flush();
final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
// query with correct context
Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setContext(context))));
// query with wrong context
Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2")))));
}
}
Aggregations