Search in sources :

Example 56 with LinearRing

use of com.vividsolutions.jts.geom.LinearRing in project hibernate-orm by hibernate.

the class EnvelopeAdapter method toPolygon.

/**
 * Converts the specified {@code Envelope} to a {@code Polygon} having the specified srid.
 *
 * @param env The envelope to convert
 * @param srid The srid for the polygon
 *
 * @return The Polygon
 */
public static Polygon toPolygon(Envelope env, int srid) {
    final Coordinate[] coords = new Coordinate[5];
    coords[0] = new Coordinate(env.getMinX(), env.getMinY());
    coords[1] = new Coordinate(env.getMinX(), env.getMaxY());
    coords[2] = new Coordinate(env.getMaxX(), env.getMaxY());
    coords[3] = new Coordinate(env.getMaxX(), env.getMinY());
    coords[4] = new Coordinate(env.getMinX(), env.getMinY());
    final LinearRing shell = geomFactory.createLinearRing(coords);
    final Polygon pg = geomFactory.createPolygon(shell, null);
    pg.setSRID(srid);
    return pg;
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 57 with LinearRing

use of com.vividsolutions.jts.geom.LinearRing in project osm4j-geometry by topobyte.

the class ChainOfWays method toLinearRing.

public LinearRing toLinearRing(OsmEntityProvider resolver) throws EntityNotFoundException {
    int len = getLength();
    if (len < 4) {
        return new LinearRing(null, factory);
    }
    CoordinateSequence points = toCoordinateSequence(resolver);
    LinearRing shell = new LinearRing(points, factory);
    return shell;
}
Also used : CoordinateSequence(com.vividsolutions.jts.geom.CoordinateSequence) LinearRing(com.vividsolutions.jts.geom.LinearRing)

Example 58 with LinearRing

use of com.vividsolutions.jts.geom.LinearRing in project osm4j-geometry by topobyte.

the class RegionBuilder method build.

/**
 * Build a MultiPolygon from a Set of Ways.
 *
 * @param ways
 *            the ways to use for geometry construction.
 * @return the constructed MultiPolygon.
 * @throws EntityNotFoundException
 *             when a required entity cannot be obtained.
 */
public RegionBuilderResult build(MultiSet<OsmWay> ways, OsmEntityProvider resolver, Set<OsmNode> nodes) throws EntityNotFoundException {
    RegionBuilderResult result = new RegionBuilderResult();
    logger.debug("Have " + ways.keySet().size() + " ways");
    // Only keep ways with 2 or more nodes. Also don't keep ways with just 2
    // times the same node.
    List<OsmWay> invalidWays = new ArrayList<>();
    for (OsmWay way : ways.keySet()) {
        int numNodes = way.getNumberOfNodes();
        if (numNodes == 0 || numNodes == 1) {
            invalidWays.add(way);
        } else if (numNodes == 2 && OsmModelUtil.isClosed(way)) {
            invalidWays.add(way);
        }
    }
    ways.removeAllOccurences(invalidWays);
    logger.debug("Removed " + invalidWays.size() + " invalid ways");
    CountingMultiValMap<Long, OsmWay> wayTailMap = RelationUtil.buildWayTailMap(ways);
    List<ChainOfWays> chains = RelationUtil.buildRings(ways, wayTailMap);
    List<ChainOfNodes> rings = new ArrayList<>();
    List<ChainOfNodes> nonRings = new ArrayList<>();
    RelationUtil.convertToSegmentChainsAndResolveNodeIntersections(chains, rings, nonRings);
    try {
        RelationUtil.checkRings(chains, resolver, missingEntitiesStrategy);
    } catch (EntityNotFoundException e) {
        switch(missingEntitiesStrategy) {
            case BUILD_PARTIAL:
                // exception with BUILD_PARTIAL
                break;
            case BUILD_EMPTY:
                return new RegionBuilderResult();
            default:
            case THROW_EXCEPTION:
                throw (e);
        }
    }
    // This could be used to close non-closed chains
    // RelationUtil.closeUnclosedRingWithStraightLine(rings);
    List<LinearRing> linearRings = new ArrayList<>();
    convert(rings, nonRings, resolver, result.getCoordinates(), result.getLineStrings(), linearRings);
    Set<LinearRing> validRings = new HashSet<>();
    for (LinearRing r : linearRings) {
        Set<LinearRing> repaired = SelfIntersectionUtil.repair(r);
        for (LinearRing ring : repaired) {
            validRings.add(ring);
        }
    }
    MultiPolygon mp = PolygonHelper.multipolygonFromRings(validRings, false);
    result.setMultiPolygon(mp);
    if (includePuntal) {
        GeometryUtil.buildNodes(nodeBuilder, nodes, result.getCoordinates());
    }
    return result;
}
Also used : ChainOfWays(de.topobyte.osm4j.geometry.relation.ChainOfWays) ArrayList(java.util.ArrayList) EntityNotFoundException(de.topobyte.osm4j.core.resolve.EntityNotFoundException) OsmWay(de.topobyte.osm4j.core.model.iface.OsmWay) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) LinearRing(com.vividsolutions.jts.geom.LinearRing) ChainOfNodes(de.topobyte.osm4j.geometry.relation.ChainOfNodes) HashSet(java.util.HashSet)

Example 59 with LinearRing

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

the class JtsGeometryMappingTest method testLinearRingMapping.

public void testLinearRingMapping() throws SQLException, ParseException {
    if (!runTestsForDatastore()) {
        return;
    }
    LinearRing linearRing = (LinearRing) wktReader.read("LINEARRING(0 0,10 0,10 10,0 10,0 0)");
    SampleLinearRing sampleLinearRing;
    SampleLinearRing sampleLinearRing_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        sampleLinearRing = new SampleLinearRing(2101, "LinearRing", linearRing);
        pm.makePersistent(sampleLinearRing);
        id = JDOHelper.getObjectId(sampleLinearRing);
        sampleLinearRing = (SampleLinearRing) pm.detachCopy(sampleLinearRing);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        sampleLinearRing_read = (SampleLinearRing) pm.getObjectById(id, true);
        assertEquals(sampleLinearRing, sampleLinearRing_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) SampleLinearRing(org.datanucleus.samples.jtsgeometry.SampleLinearRing) SampleLinearRing(org.datanucleus.samples.jtsgeometry.SampleLinearRing) LinearRing(com.vividsolutions.jts.geom.LinearRing)

Example 60 with LinearRing

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

the class JtsGeometry3dMappingTest method testGeometryCollection3DMapping.

public void testGeometryCollection3DMapping() throws SQLException, ParseException {
    if (!runTestsForDatastore()) {
        return;
    }
    SampleGeometryCollection3D sampleGeometryCollection;
    SampleGeometryCollection3D sampleGeometryCollection_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        Point point = geomFactory.createPoint(new Coordinate(10.0, 10.0, 100.0));
        LineString linestring = geomFactory.createLineString(new Coordinate[] { new Coordinate(0.0, 50.0, 100.0), new Coordinate(100.0, 50.0, 100.0) });
        LinearRing extRing = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(25.0, 25.0, 100), new Coordinate(75.0, 25.0, 100.0), new Coordinate(75.0, 75.0, 100.0), new Coordinate(25.0, 75.0, 100.0), new Coordinate(25.0, 25.0, 100) });
        Polygon polygon = geomFactory.createPolygon(extRing, null);
        GeometryCollection collection = geomFactory.createGeometryCollection(new Geometry[] { point, linestring, polygon });
        sampleGeometryCollection = new SampleGeometryCollection3D(7101, "Collection of 3-dimensional geometries", collection);
        pm.makePersistent(sampleGeometryCollection);
        id = JDOHelper.getObjectId(sampleGeometryCollection);
        sampleGeometryCollection = (SampleGeometryCollection3D) pm.detachCopy(sampleGeometryCollection);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        sampleGeometryCollection_read = (SampleGeometryCollection3D) pm.getObjectById(id, true);
        assertEquals(sampleGeometryCollection, sampleGeometryCollection_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) SampleGeometryCollection3D(org.datanucleus.samples.jtsgeometry.SampleGeometryCollection3D) Point(com.vividsolutions.jts.geom.Point) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon)

Aggregations

LinearRing (com.vividsolutions.jts.geom.LinearRing)60 Polygon (com.vividsolutions.jts.geom.Polygon)48 PackedCoordinateSequence (com.vividsolutions.jts.geom.impl.PackedCoordinateSequence)27 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)24 Test (org.junit.Test)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 Coordinate (com.vividsolutions.jts.geom.Coordinate)18 ArrayList (java.util.ArrayList)18 StatementConstraints (org.apache.rya.indexing.StatementConstraints)12 Point (com.vividsolutions.jts.geom.Point)8 MongoGeoIndexer (org.apache.rya.indexing.mongodb.geo.MongoGeoIndexer)8 Geometry (com.vividsolutions.jts.geom.Geometry)7 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)7 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)5