Search in sources :

Example 21 with LinearRing

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));
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) Geoshape(org.janusgraph.core.attribute.Geoshape) LinearRing(com.vividsolutions.jts.geom.LinearRing) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 22 with LinearRing

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()]));
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) LinearRing(com.vividsolutions.jts.geom.LinearRing) ArrayList(java.util.ArrayList) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) LinearRing(com.vividsolutions.jts.geom.LinearRing)

Example 23 with LinearRing

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)");
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) FormStorage(org.activityinfo.store.spi.FormStorage) ResourceId(org.activityinfo.model.resource.ResourceId) Coordinate(com.vividsolutions.jts.geom.Coordinate) Polygon(com.vividsolutions.jts.geom.Polygon) LinearRing(com.vividsolutions.jts.geom.LinearRing) CoordinateArraySequence(com.vividsolutions.jts.geom.impl.CoordinateArraySequence) Test(org.junit.Test)

Example 24 with LinearRing

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;
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) ServiceException(org.geoserver.platform.ServiceException) SchemaException(org.geotools.feature.SchemaException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) IllegalAttributeException(org.opengis.feature.IllegalAttributeException) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) TextSymbolizer(org.geotools.styling.TextSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) LiteShape2(org.geotools.geometry.jts.LiteShape2) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 25 with LinearRing

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)));
    }
}
Also used : ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) Statement(org.openrdf.model.Statement) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Resource(org.openrdf.model.Resource) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) Value(org.openrdf.model.Value) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon) PackedCoordinateSequence(com.vividsolutions.jts.geom.impl.PackedCoordinateSequence)

Aggregations

LinearRing (com.vividsolutions.jts.geom.LinearRing)101 Polygon (com.vividsolutions.jts.geom.Polygon)72 Coordinate (com.vividsolutions.jts.geom.Coordinate)52 Test (org.junit.Test)42 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)28 PackedCoordinateSequence (com.vividsolutions.jts.geom.impl.PackedCoordinateSequence)27 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 ArrayList (java.util.ArrayList)22 StatementConstraints (org.apache.rya.indexing.StatementConstraints)12 LineString (com.vividsolutions.jts.geom.LineString)10 Point (com.vividsolutions.jts.geom.Point)10 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)9 Geometry (com.vividsolutions.jts.geom.Geometry)8