use of com.vividsolutions.jts.geom.LinearRing in project janusgraph by JanusGraph.
the class GeoshapeTest method testGeoJsonMultiPolygon.
@Test
public void testGeoJsonMultiPolygon() throws IOException {
Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
Map json = new ObjectMapper().readValue("{\n" + " \"type\": \"Feature\",\n" + " \"geometry\": {\n" + " \"type\": \"MultiPolygon\",\n" + " \"coordinates\": [[[[102.0,2.0],[103.0,2.0],[103.0,3.0],[102.0,3.0],[102.0,2.0]]]," + "[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]],[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]]\n" + " }" + "}", HashMap.class);
assertEquals(HELPER.geoshape(GF.createMultiPolygon(new Polygon[] { GF.createPolygon(new Coordinate[] { new Coordinate(102, 2), new Coordinate(103, 2), new Coordinate(103, 3), new Coordinate(102, 3), new Coordinate(102, 2) }), GF.createPolygon(GF.createLinearRing(new Coordinate[] { new Coordinate(100, 0), new Coordinate(101, 0), new Coordinate(101, 1), new Coordinate(100, 1), new Coordinate(100, 0) }), new LinearRing[] { GF.createLinearRing(new Coordinate[] { new Coordinate(100.2, 0.2), new Coordinate(100.8, 0.2), new Coordinate(100.8, 0.8), new Coordinate(100.2, 0.8), new Coordinate(100.2, 0.2) }) }) })), s.convert(json));
}
use of com.vividsolutions.jts.geom.LinearRing in project OsmAnd-tools by osmandapp.
the class Multipolygon method toMultiPolygon.
public MultiPolygon toMultiPolygon() {
GeometryFactory geometryFactory = new GeometryFactory();
MultiPolygon emptyMultiPolygon = geometryFactory.createMultiPolygon(new Polygon[0]);
List<Polygon> polygons = new ArrayList<>();
for (Ring outerRing : outerRings) {
if (!outerRing.isClosed()) {
return emptyMultiPolygon;
}
List<LinearRing> innerLinearRings = new ArrayList<>();
Set<Ring> innerRings = containedInnerInOuter.get(outerRing);
if (!Algorithms.isEmpty(innerRings)) {
for (Ring innerRing : innerRings) {
if (!innerRing.isClosed()) {
return emptyMultiPolygon;
}
innerLinearRings.add(innerRing.toLinearRing());
}
}
polygons.add(geometryFactory.createPolygon(outerRing.toLinearRing(), innerLinearRings.toArray(new LinearRing[innerLinearRings.size()])));
}
return geometryFactory.createMultiPolygon(polygons.toArray(new Polygon[polygons.size()]));
}
use of com.vividsolutions.jts.geom.LinearRing 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.LinearRing 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.LinearRing 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)));
}
}
Aggregations